KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > DDObjectFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata;
23
24 import org.jboss.webservice.metadata.serviceref.ServiceRefMetaData;
25 import org.jboss.xb.binding.ObjectModelFactory;
26 import org.jboss.xb.binding.UnmarshallingContext;
27
28 import org.jboss.logging.Logger;
29 import org.xml.sax.Attributes JavaDoc;
30
31 import javax.persistence.PersistenceContextType;
32 import javax.xml.namespace.QName JavaDoc;
33
34 /**
35  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
36  * @author Scott.Stark@jboss.org
37  * @version <tt>$Revision: 56531 $</tt>
38  */

39 public abstract class DDObjectFactory implements ObjectModelFactory
40 {
41    private static final Logger log = Logger
42    .getLogger(DDObjectFactory.class);
43
44    public Object JavaDoc newChild(PersistenceUnitRef ref,
45                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
46                           Attributes JavaDoc attrs)
47    {
48       return newRefChild(ref, localName);
49    }
50
51    public Object JavaDoc newChild(PersistenceContextRef ref,
52                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
53                           Attributes JavaDoc attrs)
54    {
55       return newRefChild(ref, localName);
56    }
57
58    public Object JavaDoc newChild(EnvEntryMetaData ref,
59                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
60                           Attributes JavaDoc attrs)
61    {
62       return newRefChild(ref, localName);
63    }
64
65    public Object JavaDoc newChild(EjbRefMetaData ref,
66                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
67                           Attributes JavaDoc attrs)
68    {
69       return newRefChild(ref, localName);
70    }
71
72    public Object JavaDoc newChild(EjbLocalRefMetaData ref,
73                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
74                           Attributes JavaDoc attrs)
75    {
76       return newRefChild(ref, localName);
77    }
78
79    public Object JavaDoc newChild(ResourceRefMetaData ref,
80                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
81                           Attributes JavaDoc attrs)
82    {
83       return newRefChild(ref, localName);
84    }
85
86    public Object JavaDoc newChild(ResourceEnvRefMetaData ref,
87                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
88                           Attributes JavaDoc attrs)
89    {
90       return newRefChild(ref, localName);
91    }
92
93    public Object JavaDoc newChild(MessageDestinationRefMetaData ref,
94                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
95                           Attributes JavaDoc attrs)
96    {
97       return newRefChild(ref, localName);
98    }
99
100    public Object JavaDoc newChild(ServiceRefMetaData ref,
101                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
102                           Attributes JavaDoc attrs)
103    {
104       return newRefChild(ref, localName);
105       //
106

107    }
108
109    public Object JavaDoc newChild(JndiRef ref,
110                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
111                           Attributes JavaDoc attrs)
112    {
113       return newRefChild(ref, localName);
114    }
115
116    public void addChild(PersistenceUnitRef parent, InjectionTarget target,
117                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
118    {
119       parent.setInjectionTarget(target);
120    }
121
122    public void addChild(PersistenceContextRef parent, InjectionTarget target,
123                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
124    {
125       parent.setInjectionTarget(target);
126    }
127
128    public void addChild(EnvEntryMetaData parent, InjectionTarget target,
129                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
130    {
131       parent.setInjectionTarget(target);
132    }
133
134    public void addChild(EjbRefMetaData parent, InjectionTarget target,
135                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
136    {
137       parent.setInjectionTarget(target);
138    }
139
140    public void addChild(EjbLocalRefMetaData parent, InjectionTarget target,
141                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
142    {
143       parent.setInjectionTarget(target);
144    }
145
146    public void addChild(ResourceRefMetaData parent, InjectionTarget target,
147                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
148    {
149       parent.setInjectionTarget(target);
150    }
151
152    public void addChild(ResourceEnvRefMetaData parent, InjectionTarget target,
153                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
154    {
155       parent.setInjectionTarget(target);
156    }
157
158    public void addChild(MessageDestinationRefMetaData parent, InjectionTarget target,
159                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
160    {
161       parent.setInjectionTarget(target);
162    }
163
164    public void addChild(ServiceRefMetaData parent, InjectionTarget target,
165                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
166    {
167       parent.setInjectionTarget(target);
168    }
169
170    public void addChild(JndiRef parent, InjectionTarget target,
171                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
172    {
173       parent.setInjectionTarget(target);
174    }
175
176    public void setValue(EjbLocalRefMetaData ref, UnmarshallingContext navigator,
177                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
178    {
179       if (localName.equals("ejb-ref-name"))
180       {
181          ref.setName(getValue(localName, value));
182       }
183       else if (localName.equals("ejb-ref-type"))
184       {
185          ref.setType(getValue(localName, value));
186       }
187       else if (localName.equals("local-home"))
188       {
189          ref.setLocalHome(getValue(localName, value));
190       }
191       else if (localName.equals("local"))
192       {
193          ref.setLocal(getValue(localName, value));
194       }
195       else if (localName.equals("ejb-link"))
196       {
197          ref.setLink(getValue(localName, value));
198       }
199       else if (localName.equals("mapped-name") || localName.equals("local-jndi-name") || localName.equals("jndi-name"))
200       {
201          ref.setJndiName(getValue(localName, value));
202       }
203       else if (localName.equals("ignore-dependency"))
204       {
205          ref.setIgnoreDependency(true);
206       }
207    }
208
209    public void setValue(EjbRefMetaData ref, UnmarshallingContext navigator,
210                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
211    {
212       if (localName.equals("ejb-ref-name"))
213       {
214          ref.setName(getValue(localName, value));
215       }
216       else if (localName.equals("ejb-ref-type"))
217       {
218          ref.setType(getValue(localName, value));
219       }
220       else if (localName.equals("home"))
221       {
222          ref.setHome(getValue(localName, value));
223       }
224       else if (localName.equals("remote"))
225       {
226          ref.setRemote(getValue(localName, value));
227       }
228       else if (localName.equals("ejb-link"))
229       {
230          ref.setLink(getValue(localName, value));
231       }
232       else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
233       {
234          ref.setJndiName(getValue(localName, value));
235       }
236       else if (localName.equals("ignore-dependency"))
237       {
238          ref.setIgnoreDependency(true);
239       }
240    }
241
242    /**
243     * Called when a child element with simple content is read for DD.
244     */

245    public void setValue(InjectionTarget target, UnmarshallingContext navigator,
246                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
247    {
248       if (localName.equals("injection-target-class"))
249       {
250          target.setTargetClass(getValue(localName, value));
251       }
252       else if (localName.equals("injection-target-name"))
253       {
254          target.setTargetName(getValue(localName, value));
255       }
256    }
257
258    /**
259     * Called when a child element with simple content is read for DD.
260     */

261    public void setValue(MessageDestinationRefMetaData ref, UnmarshallingContext navigator,
262                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
263    {
264       if (localName.equals("description"))
265       {
266          ref.setDescription(getValue(localName, value));
267       }
268       else if (localName.equals("message-destination-ref-name"))
269       {
270          ref.setRefName(getValue(localName, value));
271       }
272       else if (localName.equals("message-destination-type"))
273       {
274          ref.setType(getValue(localName, value));
275       }
276       else if (localName.equals("message-destination-usage"))
277       {
278          ref.setUsage(getValue(localName, value));
279       }
280       else if (localName.equals("message-destination-link"))
281       {
282          ref.setLink(getValue(localName, value));
283       }
284       else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
285       {
286          ref.setJndiName(getValue(localName, value));
287       }
288    }
289
290    public void setValue(EnvEntryMetaData entry, UnmarshallingContext navigator,
291                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
292    {
293       if (localName.equals("description"))
294       {
295          entry.setDescription(getValue(localName, value));
296       }
297       else if (localName.equals("env-entry-name"))
298       {
299          entry.setName(getValue(localName, value));
300       }
301       else if (localName.equals("env-entry-type"))
302       {
303          entry.setType(getValue(localName, value));
304       }
305       else if (localName.equals("env-entry-value"))
306       {
307          entry.setValue(getValue(localName, value));
308       }
309    }
310
311    public void setValue(ResourceEnvRefMetaData envRef, UnmarshallingContext navigator,
312                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
313    {
314       if (localName.equals("res-ref-name")
315               || localName.equals("resource-env-ref-name"))
316       {
317          envRef.setRefName(getValue(localName, value));
318       }
319       else if (localName.equals("res-type")
320               || localName.equals("resource-env-ref-type"))
321       {
322          envRef.setType(getValue(localName, value));
323       }
324       else if (localName.equals("res-auth"))
325       {
326          envRef.setContainerAuth(getValue(localName, value));
327       }
328       else if (localName.equals("res-sharing-scope"))
329       {
330          envRef.setSharable(getValue(localName, value));
331       }
332       else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
333       {
334          envRef.setJndiName(getValue(localName, value));
335       }
336    }
337
338    public void setValue(ResourceRefMetaData ref, UnmarshallingContext navigator,
339                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
340    {
341       if (localName.equals("res-ref-name")
342               || localName.equals("resource-env-ref-name"))
343       {
344          ref.setRefName(getValue(localName, value));
345       }
346       else if (localName.equals("res-type")
347               || localName.equals("resource-env-ref-type"))
348       {
349          ref.setType(getValue(localName, value));
350       }
351       else if (localName.equals("res-auth"))
352       {
353          ref.setContainerAuth(getValue(localName, value));
354       }
355       else if (localName.equals("res-sharing-scope"))
356       {
357          ref.setSharable(getValue(localName, value));
358       }
359       else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
360       {
361          ref.setJndiName(getValue(localName, value));
362       }
363       else if (localName.equals("res-url"))
364       {
365          ref.setResURL(getValue(localName, value));
366       }
367       else if (localName.equals("resource-name"))
368       {
369          ref.setResourceName(getValue(localName, value));
370       }
371    }
372
373    public void setValue(ServiceRefMetaData ref, UnmarshallingContext navigator,
374                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
375    {
376       if (localName.equals("service-ref-name"))
377       {
378          ref.setServiceRefName(getValue(localName, value));
379       }
380       else if (localName.equals("service-res-type"))
381       {
382          ref.setServiceResType(getValue(localName, value));
383       }
384       else if (localName.equals("service-interface"))
385       {
386          ref.setServiceInterface(getValue(localName, value));
387       }
388       else if (localName.equals("service-qname"))
389       {
390          QName JavaDoc serviceQName = new QName JavaDoc(namespaceURI, value);
391          ref.setServiceQName(serviceQName);
392       }
393       else if (localName.equals("wsdl-file"))
394       {
395          ref.setWsdlFile(getValue(localName, value));
396       }
397       else if (localName.equals("jaxrpc-mapping-file"))
398       {
399          ref.setJaxrpcMappingFile(getValue(localName, value));
400       }
401       else if (localName.equals("mapped-name"))
402       {
403          ref.setMappedName(getValue(localName, value));
404       }
405    }
406
407    public void setValue(SecurityRoleMetaData role, UnmarshallingContext navigator,
408                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
409    {
410       if (localName.equals("role-name"))
411       {
412          role.setRoleName(getValue(localName, value));
413       }
414    }
415
416    public void setValue(JndiRef ref, UnmarshallingContext navigator,
417                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
418    {
419       if (localName.equals("mapped-name"))
420       {
421          ref.setMappedName(getValue(localName, value));
422       }
423       else if (localName.equals("jndi-ref-name"))
424       {
425          ref.setJndiRefName(getValue(localName, value));
426       }
427    }
428
429    public void setValue(RunAs runAs, UnmarshallingContext navigator,
430                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
431    {
432       if (localName.equals("role-name"))
433       {
434          runAs.setRoleName(getValue(localName, value));
435       }
436    }
437
438    public void setValue(SecurityRoleRefMetaData ref, UnmarshallingContext navigator,
439                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
440    {
441       if (localName.equals("role-name"))
442       {
443          ref.setName(getValue(localName, value));
444       }
445       else if (localName.equals("role-link"))
446       {
447          ref.setLink(getValue(localName, value));
448       }
449    }
450
451    public void setValue(Listener listener, UnmarshallingContext navigator,
452                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
453    {
454       if (localName.equals("listener-class"))
455       {
456          listener.setListenerClass(getValue(localName, value));
457       }
458    }
459
460    public void setValue(MessageDestinationMetaData destination, UnmarshallingContext navigator,
461                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
462    {
463       if (localName.equals("message-destination-name"))
464       {
465          destination.setName(getValue(localName, value));
466       }
467       else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
468       {
469          destination.setJNDIName(getValue(localName, value));
470       }
471    }
472
473    public void setValue(PersistenceUnitRef ref, UnmarshallingContext navigator,
474                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
475    {
476       if (localName.equals("persistence-unit-ref-name"))
477       {
478          ref.setRefName(getValue(localName, value));
479       }
480       else if (localName.equals("persistence-unit-name"))
481       {
482          ref.setUnitName(getValue(localName, value));
483       }
484       else
485       {
486          throw new RuntimeException JavaDoc("INVALID element<" + localName + "> in <persistence-unit-ref>");
487       }
488    }
489
490    protected Object JavaDoc newEnvRefGroupChild(String JavaDoc localName)
491    {
492       Object JavaDoc child = null;
493
494       if (localName.equals("ejb-local-ref"))
495       {
496          child = new EjbLocalRefMetaData();
497       }
498       else if (localName.equals("ejb-ref"))
499       {
500          child = new EjbRefMetaData();
501       }
502       else if (localName.equals("resource-ref"))
503       {
504          child = new ResourceRefMetaData();
505       }
506       else if (localName.equals("resource-env-ref"))
507       {
508          child = new ResourceEnvRefMetaData();
509       }
510       else if (localName.equals("env-entry"))
511       {
512          child = new EnvEntryMetaData();
513       }
514       else if (localName.equals("message-destination-ref"))
515       {
516          child = new MessageDestinationRefMetaData();
517       }
518       else if (localName.equals("service-ref"))
519       {
520          child = new ServiceRefMetaData();
521       }
522       else if (localName.equals("jndi-ref"))
523       {
524          child = new JndiRef();
525       }
526       else if (localName.equals("persistence-unit-ref"))
527       {
528          child = new PersistenceUnitRef();
529       }
530       else if (localName.equals("persistence-context-ref"))
531       {
532          child = new PersistenceContextRef();
533       }
534
535       return child;
536    }
537
538    protected Object JavaDoc newRefChild(Ref ref, String JavaDoc localName)
539    {
540       Object JavaDoc child = null;
541
542       if (localName.equals("ignore-dependency"))
543       {
544          ref.setIgnoreDependency(true);
545       }
546       else if (localName.equals("injection-target"))
547       {
548          InjectionTarget target = new InjectionTarget();
549          child = target;
550       }
551
552       return child;
553    }
554
555    public void setValue(PersistenceContextRef ref, UnmarshallingContext navigator,
556                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
557    {
558       if (localName.equals("persistence-context-ref-name"))
559       {
560          ref.setRefName(getValue(localName, value));
561       }
562       else if (localName.equals("persistence-unit-name"))
563       {
564          ref.setUnitName(getValue(localName, value));
565       }
566       else if(localName.equals("persistence-context-type"))
567       {
568          if (value.toLowerCase().equals("transaction"))
569          {
570             ref.setPersistenceContextType(PersistenceContextType.TRANSACTION);
571          }
572          else
573          {
574             ref.setPersistenceContextType(PersistenceContextType.EXTENDED);
575          }
576       }
577    }
578    
579    protected String JavaDoc getValue(String JavaDoc name, String JavaDoc value)
580    {
581       return value;
582    }
583 }
584
Popular Tags