View Javadoc
1 /* 2 * Singleton.java 3 * Created on August 8, 2003 4 * 5 * The Blues Framework - A lightweight application framework 6 * Copyright (C) 2003 Lonnie Pryor 7 * http://blues.lonniepryor.com 8 * 9 * This library is free software; you can redistribute it and/or modify it under the 10 * terms of the GNU Lesser General Public License as published by the Free Software 11 * Foundation; either version 2.1 of the License, or (at your option) any later 12 * version. 13 * 14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License along 19 * with this library; if not, write to: 20 * 21 * The Free Software Foundation, Inc. 22 * 59 Temple Place, Suite 330 23 * Boston, MA 02111-1307 USA 24 * 25 */ 26 package com.lonniepryor.blues.sys; 27 28 import com.lonniepryor.blues.cfg.SingletonCfg; 29 import com.lonniepryor.blues.util.BeanHelper; 30 31 /*** 32 * Models the abstract view of a Blues singleton. 33 * 34 * @author Lonnie Pryor 35 * @version $Revision: 1.1 $ 36 */ 37 public final class Singleton extends Component { 38 /*** The singleton configuration information. */ 39 private final SingletonCfg configuration; 40 /*** The singleton instance. */ 41 private final Object singletonInstance; 42 43 /*** 44 * Creates a new Singleton object. 45 * 46 * @param configuration The singleton configuration information. 47 */ 48 Singleton (SingletonCfg configuration) { 49 this.configuration = configuration; 50 if ( 51 !SingletonCfg.validSingletonTypes.isSatisfiedBy( 52 configuration.getSingeltonType())) 53 throw new SystemException( 54 "Invalid singleton type: " + configuration.getSingeltonType().getName()); 55 if ( 56 !SingletonCfg.validImplementationTypes.isSatisfiedBy( 57 configuration.getImplementationType())) 58 throw new SystemException( 59 "Invalid implementation type: " 60 + configuration.getImplementationType().getName()); 61 this.singletonInstance = BeanHelper.introspect( 62 configuration.getImplementationType()).newBeanInstance(); 63 } 64 65 /* (non-Javadoc) 66 * @see com.lonniepryor.blues.sys.Component#getComponentBean() 67 */ 68 Object getComponentInstance () { 69 return singletonInstance; 70 } 71 72 /* (non-Javadoc) 73 * @see com.lonniepryor.blues.sys.Component#configureInstance() 74 */ 75 void configureInstance () { 76 try { 77 configuration.configure(singletonInstance); 78 } catch (RuntimeException re) { 79 throw new SystemException( 80 "Error configuring singleton of type " + configuration.getSingeltonType() 81 + ": " + re.getMessage(), re); 82 } 83 } 84 85 /*** 86 * Registers the singleton instance with the supplied registry. 87 * 88 * @param reg The registry to register with. 89 */ 90 void registerWith (Registry reg) { 91 reg.registerSingleton(configuration.getSingeltonType(), singletonInstance); 92 } 93 }

This page was automatically generated by Maven