View Javadoc
1 /* 2 * SingletonCfgImpl.java 3 * Created on July 24, 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.cfg; 27 28 /*** 29 * Generic implementation of {@link SingletonCfg}. 30 * 31 * @author Lonnie Pryor 32 * @version $Revision: 1.1 $ 33 */ 34 public class SingletonCfgImpl extends AbstractBeanCfg implements SingletonCfg, 35 Verifiable { 36 /*** The public singleton type. */ 37 private Class singletonType = null; 38 /*** The type used to implement the singleon. */ 39 private Class implementationType = null; 40 41 /*** 42 * Creates a new SingletonCfgImpl object. 43 */ 44 public SingletonCfgImpl () { 45 } 46 47 /*** 48 * Sets the public singleton type. 49 * 50 * @param singletonType The public singleton type. 51 */ 52 public void setClass (Class singletonType) { 53 this.singletonType = singletonType; 54 } 55 56 /*** 57 * Sets the type used to implement the singleon. 58 * 59 * @param implementationType The type used to implement the singleon. 60 */ 61 public void setImpl (Class implementationType) { 62 this.implementationType = implementationType; 63 } 64 65 /* (non-Javadoc) 66 * @see com.lonniepryor.blues.cfg.Verifyable#verify() 67 */ 68 public void verify () { 69 if (singletonType == null) 70 throw new IllegalStateException("No singleton type specified"); 71 if (!validSingletonTypes.isSatisfiedBy(singletonType)) 72 throw new IllegalStateException( 73 singletonType.getName() + " is not a valid singleton type"); 74 if (implementationType == null) 75 implementationType = singletonType; 76 if (!validImplementationTypes.isSatisfiedBy(implementationType)) 77 throw new IllegalStateException( 78 implementationType.getName() + " is not a valid implementation type"); 79 if (!singletonType.isAssignableFrom(implementationType)) 80 throw new IllegalArgumentException( 81 singletonType.getName() + " is not assignable from " 82 + implementationType.getName()); 83 } 84 85 /* (non-Javadoc) 86 * @see com.lonniepryor.blues.cfg.SingletonCfg#getSingeltonClass() 87 */ 88 public Class getSingeltonType () { 89 return singletonType; 90 } 91 92 /* (non-Javadoc) 93 * @see com.lonniepryor.blues.cfg.SingletonCfg#getImplementationClass() 94 */ 95 public Class getImplementationType () { 96 return implementationType; 97 } 98 99 /* (non-Javadoc) 100 * @see com.lonniepryor.blues.cfg.SingletonCfg#configure(java.lang.Object) 101 */ 102 public void configure (Object implementationInstance) { 103 configureBean(implementationInstance, null); 104 } 105 }

This page was automatically generated by Maven