KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metamodel > descriptor > 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.metamodel.descriptor;
23
24 import javax.persistence.PersistenceContextType;
25
26 import org.jboss.logging.Logger;
27 import org.jboss.xb.binding.ObjectModelFactory;
28 import org.jboss.xb.binding.UnmarshallingContext;
29 import org.xml.sax.Attributes JavaDoc;
30
31 /**
32  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
33  * @version <tt>$Revision: 58121 $</tt>
34  */

35 public abstract class DDObjectFactory implements ObjectModelFactory
36 {
37    private static final Logger log = Logger
38    .getLogger(DDObjectFactory.class);
39
40    public Object JavaDoc newChild(PersistenceUnitRef ref,
41                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
42                           Attributes JavaDoc attrs)
43    {
44       return newRefChild(ref, localName);
45    }
46
47    public Object JavaDoc newChild(PersistenceContextRef ref,
48                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
49                           Attributes JavaDoc attrs)
50    {
51       return newRefChild(ref, localName);
52    }
53
54    public Object JavaDoc newChild(EnvEntry ref,
55                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
56                           Attributes JavaDoc attrs)
57    {
58       return newRefChild(ref, localName);
59    }
60
61    public Object JavaDoc newChild(EjbRef ref,
62                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
63                           Attributes JavaDoc attrs)
64    {
65       return newRefChild(ref, localName);
66    }
67
68    public Object JavaDoc newChild(EjbLocalRef ref,
69                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
70                           Attributes JavaDoc attrs)
71    {
72       return newRefChild(ref, localName);
73    }
74
75    public Object JavaDoc newChild(ResourceRef ref,
76                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
77                           Attributes JavaDoc attrs)
78    {
79       return newRefChild(ref, localName);
80    }
81
82    public Object JavaDoc newChild(ResourceEnvRef ref,
83                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
84                           Attributes JavaDoc attrs)
85    {
86       return newRefChild(ref, localName);
87    }
88
89    public Object JavaDoc newChild(MessageDestinationRef ref,
90                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
91                           Attributes JavaDoc attrs)
92    {
93       return newRefChild(ref, localName);
94    }
95
96    public Object JavaDoc newChild(ServiceRef ref,
97                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
98                           Attributes JavaDoc attrs)
99    {
100       return newRefChild(ref, localName);
101    }
102
103    public Object JavaDoc newChild(JndiRef ref,
104                           UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
105                           Attributes JavaDoc attrs)
106    {
107       return newRefChild(ref, localName);
108    }
109
110    public void addChild(PersistenceUnitRef parent, InjectionTarget target,
111                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
112    {
113       parent.setInjectionTarget(target);
114    }
115
116    public void addChild(PersistenceContextRef parent, InjectionTarget target,
117                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
118    {
119       parent.setInjectionTarget(target);
120    }
121
122    public void addChild(EnvEntry parent, InjectionTarget target,
123                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
124    {
125       parent.setInjectionTarget(target);
126    }
127
128    public void addChild(EjbRef parent, InjectionTarget target,
129                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
130    {
131       parent.setInjectionTarget(target);
132    }
133
134    public void addChild(EjbLocalRef parent, InjectionTarget target,
135                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
136    {
137       parent.setInjectionTarget(target);
138    }
139
140    public void addChild(ResourceRef parent, InjectionTarget target,
141                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
142    {
143       parent.setInjectionTarget(target);
144    }
145
146    public void addChild(ResourceEnvRef parent, InjectionTarget target,
147                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
148    {
149       parent.setInjectionTarget(target);
150    }
151
152    public void addChild(MessageDestinationRef parent, InjectionTarget target,
153                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
154    {
155       parent.setInjectionTarget(target);
156    }
157
158    public void addChild(ServiceRef parent, InjectionTarget target,
159                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
160    {
161       parent.setInjectionTarget(target);
162    }
163
164    public void addChild(JndiRef parent, InjectionTarget target,
165                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
166    {
167       parent.setInjectionTarget(target);
168    }
169
170    public void setValue(EjbLocalRef ref, UnmarshallingContext navigator,
171                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
172    {
173       if (localName.equals("ejb-ref-name"))
174       {
175          ref.setEjbRefName(getValue(localName, value));
176       }
177       else if (localName.equals("ejb-ref-type"))
178       {
179          ref.setEjbRefType(getValue(localName, value));
180       }
181       else if (localName.equals("local-home"))
182       {
183          ref.setLocalHome(getValue(localName, value));
184       }
185       else if (localName.equals("local"))
186       {
187          ref.setLocal(getValue(localName, value));
188       }
189       else if (localName.equals("ejb-link"))
190       {
191          ref.setEjbLink(getValue(localName, value));
192       }
193       else if (localName.equals("mapped-name") || localName.equals("local-jndi-name") || localName.equals("jndi-name"))
194       {
195          ref.setMappedName(getValue(localName, value));
196       }
197       else if (localName.equals("ignore-dependency"))
198       {
199          ref.setIgnoreDependency(true);
200       }
201    }
202
203    public void setValue(EjbRef ref, UnmarshallingContext navigator,
204                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
205    {
206       if (localName.equals("ejb-ref-name"))
207       {
208          ref.setEjbRefName(getValue(localName, value));
209       }
210       else if (localName.equals("ejb-ref-type"))
211       {
212          ref.setEjbRefType(getValue(localName, value));
213       }
214       else if (localName.equals("home"))
215       {
216          ref.setHome(getValue(localName, value));
217       }
218       else if (localName.equals("remote"))
219       {
220          ref.setRemote(getValue(localName, value));
221       }
222       else if (localName.equals("ejb-link"))
223       {
224          ref.setEjbLink(getValue(localName, value));
225       }
226       else if (localName.equals("mapped-name") || localName.equals("jndi-name"))
227       {
228          ref.setMappedName(getValue(localName, value));
229       }
230       else if (localName.equals("ignore-dependency"))
231       {
232          ref.setIgnoreDependency(true);
233       }
234    }
235
236    /**
237     * Called when a child element with simple content is read for DD.
238     */

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

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