View Javadoc
1 /*
2 * ServiceCfgImpl.java
3 * Created on August 16, 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 import java.util.LinkedList;
29 import java.util.List;
30
31 import com.lonniepryor.blues.aop.Imposter;
32
33 /***
34 * Generic implementation of {@link ServiceCfg}.
35 *
36 * @author Lonnie Pryor
37 * @version $Revision: 1.1 $
38 */
39 public class ServiceCfgImpl extends AbstractBeanCfg implements ServiceCfg, Verifiable {
40 /*** The name of this service. */
41 private String name = null;
42 /*** The type used to implement the service. */
43 private Class serviceType = null;
44 /*** The interfaces to introduce on the service. */
45 private List introducedInterfaces = new LinkedList();
46
47 /***
48 * Creates a new ServiceCfgImpl object.
49 */
50 public ServiceCfgImpl () {
51 }
52
53 /***
54 * Sets the name of this service.
55 *
56 * @param name The name of this service.
57 */
58 public void setName (String name) {
59 this.name = name;
60 }
61
62 /***
63 * Sets the type used to implement the service.
64 *
65 * @param serviceType The type used to implement the service.
66 */
67 public void setClass (Class serviceType) {
68 this.serviceType = serviceType;
69 }
70
71 /***
72 * Declares an introduced interface on this service.
73 *
74 * @param introducton The introducton configuration.
75 */
76 public void declareIntroduce (IntroduceCfg introducton) {
77 if (introducton == null)
78 throw new NullPointerException("Introduce config cannot be null");
79 if (!Imposter.class.isAssignableFrom(serviceType))
80 throw new IllegalArgumentException(
81 "Cannot introduce interfaces to " + serviceType.getName()
82 + ", it does not implement " + Imposter.class.getName());
83 introducedInterfaces.add(introducton.getInterface());
84 }
85
86 /* (non-Javadoc)
87 * @see com.lonniepryor.blues.cfg.Verifiable#verify()
88 */
89 public void verify () {
90 if (name == null)
91 throw new IllegalStateException("No service name specified");
92 if (name.length() == 0)
93 throw new IllegalStateException("Illegal empty service name");
94 if (serviceType == null)
95 throw new IllegalStateException("No service type specified");
96 if (!validServiceTypes.isSatisfiedBy(serviceType))
97 throw new IllegalStateException(
98 serviceType.getName() + " is not a valid service class");
99 }
100
101 /* (non-Javadoc)
102 * @see com.lonniepryor.blues.cfg.ServiceCfg#getName()
103 */
104 public String getName () {
105 return name;
106 }
107
108 /* (non-Javadoc)
109 * @see com.lonniepryor.blues.cfg.ServiceCfg#getImplementationClass()
110 */
111 public Class getServiceType () {
112 return serviceType;
113 }
114
115 /* (non-Javadoc)
116 * @see com.lonniepryor.blues.cfg.ServiceCfg#getIntroducedInterfaces()
117 */
118 public Class[] getIntroducedInterfaces () {
119 return (Class[])introducedInterfaces.toArray(
120 new Class[introducedInterfaces.size()]);
121 }
122
123 /* (non-Javadoc)
124 * @see com.lonniepryor.blues.cfg.AdviceCfg#configure(java.lang.Object,
125 * com.lonniepryor.blues.cfg.Directory)
126 */
127 public void configure (Object serviceInstance, Directory serviceDirectory) {
128 configureBean(serviceInstance, serviceDirectory);
129 }
130
131 /***
132 * Child element for introducing interfaces.
133 *
134 * @author Lonnie Pryor
135 * @version $Revision: 1.1 $
136 */
137 public static class IntroduceCfg implements Verifiable {
138 /*** The interface to introduce. */
139 private Class toIntroduce = null;
140
141 /***
142 * Creates a new IntroduceCfg object.
143 */
144 public IntroduceCfg () {
145 }
146
147 /***
148 * Sets the interface to introduce.
149 *
150 * @param toIntroduce The interface to introduce.
151 */
152 public void setInterface (Class toIntroduce) {
153 this.toIntroduce = toIntroduce;
154 }
155
156 /* (non-Javadoc)
157 * @see com.lonniepryor.blues.cfg.Verifiable#verify()
158 */
159 public void verify () {
160 if (toIntroduce == null)
161 throw new IllegalStateException("No interface specified");
162 if (!toIntroduce.isInterface())
163 throw new IllegalStateException(
164 "Cannot introduce " + toIntroduce.getName() + ", it is not an interface.");
165 }
166
167 /***
168 * Returns the interface to introduce.
169 *
170 * @return The interface to introduce.
171 */
172 public Class getInterface () {
173 return toIntroduce;
174 }
175 }
176 }
This page was automatically generated by Maven