KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > profileservice > simple1 > ProfileImpl2


1 package org.jboss.test.profileservice.simple1;
2
3 import java.io.IOException JavaDoc;
4 import java.net.URL JavaDoc;
5 import java.util.Collection JavaDoc;
6 import java.util.Collections JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import org.jboss.deployers.spi.management.ManagedObject;
11 import org.jboss.deployers.spi.structure.DeploymentContext;
12 import org.jboss.profileservice.spi.DeploymentTemplate;
13 import org.jboss.profileservice.spi.NoSuchDeploymentException;
14 import org.jboss.profileservice.spi.Profile;
15 import org.jboss.profileservice.spi.PropertyInfo;
16 import org.jboss.profileservice.spi.SimpleType;
17
18 /**
19  * A test profile for deploying pretend Datasources
20  *
21  * @author ccrouch@jboss.org
22  * @version $Revision$
23  */

24 public class ProfileImpl2
25    implements Profile
26 {
27    private HashMap JavaDoc<String JavaDoc, DeploymentContext> deployments;
28
29    public ProfileImpl2() throws IOException JavaDoc
30    {
31       deployments = new HashMap JavaDoc<String JavaDoc, DeploymentContext>();
32       String JavaDoc deployDir = SecurityActions.getSystemProperty("jbosstest.deploy.dir");
33       URL JavaDoc libURL;
34       if( deployDir == null )
35       {
36          // Used codesource + ../lib
37
URL JavaDoc classes = getClass().getProtectionDomain().getCodeSource().getLocation();
38          libURL = new URL JavaDoc(classes, "../lib-not-found/");
39       }
40       else
41       {
42          libURL = new URL JavaDoc(deployDir);
43       }
44
45       DeploymentImpl p0 = new DeploymentImpl();
46       p0.setName("DefaultDS");
47       p0.setRootURL(libURL);
48       String JavaDoc[] files = {"p0-not-here.jar"};
49       p0.setFiles(files);
50       /*
51       ArrayList<DeploymentBean> beans = new ArrayList<DeploymentBean>();
52
53       // DefaultDS datasource
54       // ignoring dependencies on TxMgr for right now
55       String defaultConnFacName = "name=DefaultDS,service=ManagedConnectionFactory";
56       DeploymentBeanImpl<BeanMetaData> defaultConnFac = new DeploymentBeanImpl<BeanMetaData>(defaultConnFacName,
57                "org.jboss.test.profileservice.profiles.p0.beans.RARDeployment");
58       AbstractBeanMetaData amd1 = new AbstractBeanMetaData(defaultConnFacName,
59          "org.jboss.test.profileservice.profiles.p0.beans.RARDeployment");
60       defaultConnFac.setBeanMetaData(amd1);
61       beans.add(defaultConnFac);
62
63       String defaultLocalTxCMName = "name=DefaultDS,service=LocalTxCM";
64       DeploymentBeanImpl<BeanMetaData> defaultLocalTxCM = new DeploymentBeanImpl<BeanMetaData>(defaultLocalTxCMName,
65               "org.jboss.test.profileservice.profiles.p0.beans.TxConnectionManager");
66       AbstractBeanMetaData amd2 = new AbstractBeanMetaData(defaultLocalTxCMName,
67          "org.jboss.test.profileservice.profiles.p0.beans.TxConnectionManager");
68       defaultLocalTxCM.setBeanMetaData(amd2);
69       beans.add(defaultLocalTxCM);
70
71       String defaultConnPoolName = "name=DefaultDS,service=ManagedConnectionPool";
72       DeploymentBeanImpl<BeanMetaData> defaultConnPool = new DeploymentBeanImpl<BeanMetaData>(defaultConnPoolName,
73               "org.jboss.test.profileservice.profiles.p0.beans.JBossManagedConnectionPool");
74       AbstractBeanMetaData amd3 = new AbstractBeanMetaData(defaultConnPoolName,
75          "org.jboss.test.profileservice.profiles.p0.beans.JBossManagedConnectionPool");
76       defaultConnPool.setBeanMetaData(amd3);
77       beans.add(defaultConnPool);
78
79       DeploymentBean[] tmp = new DeploymentBean[beans.size()];
80       p0.setBeans(beans.toArray(tmp));
81
82       // eventually this should get populated by examining the annotations on the beans described by the
83       // deploymentBeans above
84
85       // We will have to use something like ManagedPropertyRef in order to perform round trip operations,
86       // since the PropertyInfoImpl objects don't have any knowledge of the beans used to populate them
87       ManagedObject localDataSource = new ManagedObject();
88      // localDataSource.addPropertyRef(new PropertyInfoImpl("Connection Factory Property 1", "a property passed to the connection factory")); // connectionFactoryProperty1
89      // localDataSource.addPropertyRef(new PropertyInfoImpl("Track Connection By Tx", "whether to track conns by txn or not")); // trackConnectionByTx
90
91
92      // localDataSource.addPropertyRef(new PropertyInfoImpl("Blocking Timeout Millis", "how long to block for")); // blockingTimeoutMillis
93       // how do we specify using PropertyInfo that this is a read-only field?
94      // localDataSource.addPropertyRef(new PropertyInfoImpl("Connection Created Count", "STAT: # of conn's created")); // connectionCreatedCount
95
96       // how do we deal with wanting to have another ManagedObject representing the Pool separate from the one
97       // representing the DataSource, since there is a one-to-one mapping between ManagedObject's and Deployment's
98       p0.setManagedObject(localDataSource);
99
100       deployments.put(p0.getName(), p0);
101       */

102
103       DeploymentImpl p1 = new DeploymentImpl();
104       p1.setName("notxDS");
105       p1.setRootURL(libURL);
106       String JavaDoc[] files2 = {"p1-not-here.jar"};
107       p1.setFiles(files);
108 /*
109       ArrayList<DeploymentBean> beans2 = new ArrayList<DeploymentBean>();
110       // NoTx datasource
111       // ignoring dependencies on TxMgr for right now
112       String notxConnFacName = "name=notxDS,service=ManagedConnectionFactory";
113       DeploymentBeanImpl<BeanMetaData> notxConnFac = new DeploymentBeanImpl<BeanMetaData>(notxConnFacName,
114          "org.jboss.test.profileservice.profiles.p0.beans.RARDeployment");
115       AbstractBeanMetaData amd4 = new AbstractBeanMetaData(notxConnFacName,
116          "org.jboss.test.profileservice.profiles.p0.beans.RARDeployment");
117       notxConnFac.setBeanMetaData(amd4);
118       beans2.add(notxConnFac);
119
120       // specify the correct ConnMgr for this DataSource
121       String notxNoTxCMName = "name=notxDS,service=NoTxCM";
122       DeploymentBeanImpl<BeanMetaData> notxNoTxCM = new DeploymentBeanImpl<BeanMetaData>(notxNoTxCMName,
123          "org.jboss.test.profileservice.profiles.p0.beans.NoTxConnectionManager");
124       AbstractBeanMetaData amd41 = new AbstractBeanMetaData(notxNoTxCMName,
125          "org.jboss.test.profileservice.profiles.p0.beans.NoTxConnectionManager");
126       notxNoTxCM.setBeanMetaData(amd41);
127       beans2.add(notxNoTxCM);
128
129       String notxConnPoolName = "name=notxDS,service=ManagedConnectionPool";
130       DeploymentBeanImpl<BeanMetaData> notxConnPool = new DeploymentBeanImpl<BeanMetaData>(notxConnPoolName,
131          "org.jboss.test.profileservice.profiles.p0.beans.JBossManagedConnectionPool");
132       AbstractBeanMetaData amd5 = new AbstractBeanMetaData(notxConnPoolName,
133          "org.jboss.test.profileservice.profiles.p0.beans.JBossManagedConnectionPool");
134       notxConnPool.setBeanMetaData(amd5);
135       beans2.add(notxConnPool);
136
137       DeploymentBean[] tmp2 = new DeploymentBean[beans2.size()];
138       p1.setBeans(beans2.toArray(tmp2));
139 */

140       ManagedObject notxDataSource = new ManagedObject();
141       PropertyInfo jndiNameProperty = new PropertyInfoImpl("jndiName", SimpleType.STRING);
142       jndiNameProperty.setFields(new String JavaDoc[] {
143         //"defaultValue",
144
//"descriptionResourceBundleBaseName",
145
//"descriptionResourceKey",
146
//"legalValues",
147
//"maxValue",
148
//"metricValue",
149
//"minValue",
150
//"openType",
151
//"units",
152
"org.jboss.profileservice.description",
153         "org.jboss.profileservice.label",
154         //"org.jboss.profileservice.labelResourceBundleBaseName",
155
//"org.jboss.profileservice.labelResourceKey",
156
"org.jboss.profileservice.requiredNotEmpty",
157         "org.jboss.profileservice.typicalLength"
158         },
159         new Object JavaDoc[] {
160         //"defaultValue",
161
//"descriptionResourceBundleBaseName",
162
//"descriptionResourceKey",
163
//"legalValues",
164
//"maxValue",
165
//"metricValue",
166
//"minValue",
167
//"openType",
168
//"units",
169
"The name the Datasource will be registered under in JNDI",
170         "JNDI Name",
171         //"org.jboss.profileservice.labelResourceBundleBaseName",
172
//"org.jboss.profileservice.labelResourceKey",
173
Boolean.TRUE,
174         new Integer JavaDoc (30)
175         });
176
177       notxDataSource.addPropertyRef(jndiNameProperty);
178
179       PropertyInfo useJavaContextProperty = new PropertyInfoImpl("useJavaContext", SimpleType.BOOLEAN);
180       useJavaContextProperty.setFields(new String JavaDoc[] {
181         "defaultValue",
182         //"descriptionResourceBundleBaseName",
183
//"descriptionResourceKey",
184
//"legalValues",
185
//"maxValue",
186
//"metricValue",
187
//"minValue",
188
//"openType",
189
//"units",
190
"org.jboss.profileservice.description",
191         "org.jboss.profileservice.label",
192         //"org.jboss.profileservice.labelResourceBundleBaseName",
193
//"org.jboss.profileservice.labelResourceKey",
194
"org.jboss.profileservice.requiredNotEmpty",
195         //"org.jboss.profileservice.typicalLength"
196
},
197         new Object JavaDoc[] {
198         Boolean.TRUE,
199         //"descriptionResourceBundleBaseName",
200
//"descriptionResourceKey",
201
//"legalValues",
202
//"maxValue",
203
//"metricValue",
204
//"minValue",
205
//"openType",
206
//"units",
207
"Whether the Datasource should be registered under java: in JNDI",
208         "Use java: context",
209         //"org.jboss.profileservice.labelResourceBundleBaseName",
210
//"org.jboss.profileservice.labelResourceKey",
211
Boolean.TRUE,
212         //"org.jboss.profileservice.typicalLength"
213
});
214       notxDataSource.addPropertyRef(useJavaContextProperty);
215
216
217       //notxDataSource.addPropertyRef(new PropertyInfoImpl("Connection Factory Property 1", "a property passed to the connection factory")); // connectionFactoryProperty1
218
// pick a property which is actually on the NoTxConnectionManager bean
219
//notxDataSource.addPropertyRef(new PropertyInfoImpl("Security Domain Jndi Name", "security domain")); // securityDomainJndiName
220
//notxDataSource.addPropertyRef(new PropertyInfoImpl("Blocking Timeout Millis", "how long to block for")); // blockingTimeoutMillis
221
//notxDataSource.addPropertyRef(new PropertyInfoImpl("Connection Created Count", "STAT: # of conn's created")); // connectionCreatedCount
222

223       // how can we differentiate between the ManagedObject create above, for a LocalTxDataSource,
224
// and the one in use now, for a NoTxDataSource?
225
/* TODO
226       p1.setManagedObject(notxDataSource);
227       deployments.put(p1.getName(), p1);
228       */

229    }
230
231    public String JavaDoc getVersion()
232    {
233       return "1.0.0";
234    }
235
236    public DeploymentTemplate getTemplate(String JavaDoc name)
237    {
238       return null;
239    }
240
241    public void addDeployment(DeploymentContext d)
242    {
243       throw new UnsupportedOperationException JavaDoc("simple1 is read-only");
244    }
245
246    public void removeDeployment(String JavaDoc name)
247    {
248       throw new UnsupportedOperationException JavaDoc("simple1 is read-only");
249    }
250
251    public Collection JavaDoc<DeploymentContext> getDeployments()
252    {
253       return Collections.unmodifiableCollection(deployments.values());
254    }
255
256    public Map JavaDoc<String JavaDoc, Object JavaDoc> getConfig()
257    {
258       return null;
259    }
260
261    public DeploymentContext getDeployment(String JavaDoc name)
262       throws NoSuchDeploymentException
263    {
264       DeploymentContext d = deployments.get(name);
265       if( d == null )
266          throw new NoSuchDeploymentException(name);
267       return d;
268    }
269
270    public void addBootstrap(DeploymentContext d)
271    {
272       // @todo addBootstrap
273
throw new org.jboss.util.NotImplementedException("addBootstrap");
274    }
275
276    public void addDeployer(DeploymentContext d)
277    {
278       // @todo addDeployer
279
throw new org.jboss.util.NotImplementedException("addDeployer");
280    }
281
282    public DeploymentContext getBootstrap(String JavaDoc name) throws NoSuchDeploymentException
283    {
284       // @todo getBootstrap
285
throw new org.jboss.util.NotImplementedException("getBootstrap");
286    }
287
288    public Collection JavaDoc<DeploymentContext> getBootstraps()
289    {
290       // @todo getBootstraps
291
throw new org.jboss.util.NotImplementedException("getBootstraps");
292    }
293
294    public DeploymentContext getDeployer(String JavaDoc name) throws NoSuchDeploymentException
295    {
296       // @todo getDeployer
297
throw new org.jboss.util.NotImplementedException("getDeployer");
298    }
299
300    public Collection JavaDoc<DeploymentContext> getDeployers()
301    {
302       // @todo getDeployers
303
throw new org.jboss.util.NotImplementedException("getDeployers");
304    }
305
306    public void removeBootstrap(String JavaDoc name)
307    {
308       // @todo removeBootstrap
309
throw new org.jboss.util.NotImplementedException("removeBootstrap");
310    }
311
312    public void removeDeployer(String JavaDoc name)
313    {
314       // @todo removeDeployer
315
throw new org.jboss.util.NotImplementedException("removeDeployer");
316    }
317 }
318
Popular Tags