KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > EjbJarObjectFactory


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
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.deployment;
23
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import org.jboss.logging.Logger;
28 import org.jboss.metadata.ApplicationMetaData;
29 import org.jboss.metadata.DDObjectFactory;
30 import org.jboss.metadata.EntityMetaData;
31 import org.jboss.metadata.IconMetaData;
32 import org.jboss.metadata.MessageDestinationMetaData;
33 import org.jboss.metadata.MessageDrivenMetaData;
34 import org.jboss.metadata.MethodMetaData;
35 import org.jboss.metadata.QueryMetaData;
36 import org.jboss.metadata.RelationMetaData;
37 import org.jboss.metadata.RelationshipRoleMetaData;
38 import org.jboss.metadata.SecurityIdentityMetaData;
39 import org.jboss.metadata.SecurityRoleMetaData;
40 import org.jboss.metadata.SessionMetaData;
41 import org.jboss.metadata.BeanMetaData;
42 import org.jboss.metadata.ActivationConfigPropertyMetaData;
43 import org.jboss.metadata.EjbLocalRefMetaData;
44 import org.jboss.metadata.EjbRefMetaData;
45 import org.jboss.metadata.ResourceRefMetaData;
46 import org.jboss.metadata.ResourceEnvRefMetaData;
47 import org.jboss.metadata.EnvEntryMetaData;
48 import org.jboss.metadata.MessageDestinationRefMetaData;
49 import org.jboss.xb.binding.ObjectModelFactory;
50 import org.jboss.xb.binding.UnmarshallingContext;
51 import org.jboss.webservice.metadata.serviceref.ServiceRefMetaData;
52 import org.xml.sax.Attributes JavaDoc;
53
54
55 /**
56  * An ObjectModelFactory implementation for parsing ejb-jar.xml descriptors.
57  *
58  * @author Scott.Stark@jboss.org
59  * @author Alexey.Loubyansky@jboss.org
60  * @author Anil.Saldhana@jboss.org
61  * @version $Revision:$
62  */

63 public class EjbJarObjectFactory extends DDObjectFactory
64    implements ObjectModelFactory
65 {
66    private static Logger log = Logger.getLogger(EjbJarObjectFactory.class);
67    private int ejbVersion = 2;
68    private int ejbMinorVersion = 0;
69
70    public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
71    {
72       // Check for a known public Id
73
if (publicId.startsWith("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0"))
74       {
75          ejbVersion = 2;
76       }
77       else if (publicId.startsWith("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1"))
78       {
79          ejbVersion = 1;
80       }
81    }
82
83    public ApplicationMetaData newRoot(Object JavaDoc root, UnmarshallingContext navigator,
84          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
85    {
86       ApplicationMetaData metaData = null;
87       if (root != null)
88          metaData = (ApplicationMetaData) root;
89       else
90          metaData = new ApplicationMetaData();
91       
92       String JavaDoc version = attrs.getValue(namespaceURI, "version");
93       // Wolf: somehow the namespace doesn't work
94
if(version == null)
95          version = attrs.getValue("", "version");
96       if(version != null)
97       {
98          if(version.equals("3.0"))
99          {
100             metaData.setEjbVersion(3);
101             metaData.setEjbMinorVersion(0);
102             // make sure we don't get smacked later on
103
ejbVersion = 3;
104             ejbMinorVersion = 0;
105          }
106       }
107       
108       return metaData;
109    }
110
111    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx,
112          String JavaDoc uri, String JavaDoc name)
113    {
114       return root;
115    }
116
117    /**
118     * Create the application child elements
119     *
120     * @param dd
121     * @param navigator
122     * @param namespaceURI
123     * @param localName
124     * @param attrs
125     * @return
126     */

127    public Object JavaDoc newChild(ApplicationMetaData dd, UnmarshallingContext navigator,
128          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
129    {
130       Object JavaDoc child = null;
131
132 // log.info("attrs.length = " + attrs.getLength());
133
// for(int i = 0; i < attrs.getLength(); i++)
134
// {
135
// log.info("attrs[" + i + "] : " + attrs.getURI(i) + " " + attrs.getLocalName(i) + " = " + attrs.getValue(i));
136
// }
137
// Check version
138
String JavaDoc version = attrs.getValue(namespaceURI, "version");
139       if( version != null )
140       {
141          if( version.equals("2.1") )
142          {
143             dd.setEjbVersion(2);
144             dd.setEjbMinorVersion(1);
145          }
146       }
147       else
148       {
149          // Use version from dtd
150
dd.setEjbVersion(ejbVersion);
151          dd.setEjbMinorVersion(ejbMinorVersion);
152       }
153
154       // Check elements
155
if (localName.equals("enterprise-beans"))
156          child = dd;
157       else if(localName.equals("entity"))
158          child = new EntityMetaData(dd);
159       else if(localName.equals("session"))
160          child = new SessionMetaData(dd);
161       else if(localName.equals("message-driven"))
162          child = new MessageDrivenMetaData(dd);
163       else if(localName.equals("relationships"))
164          child = dd;
165       else if (localName.equals("ejb-relation"))
166          child = new RelationMetaData();
167       else if( localName.equals("assembly-descriptor"))
168          child = new AssemblyDescriptor(dd);
169       else if(localName.equals("icon"))
170          child = new IconMetaData();
171       else if (log.isTraceEnabled())
172       {
173          log.trace("Ignoring: " + localName);
174       }
175       return child;
176    }
177
178    public Object JavaDoc newChild(EntityMetaData entity, UnmarshallingContext navigator,
179          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
180    {
181       Object JavaDoc child = null;
182       // Handle the *-ref elements
183
if ((child = newEnvRefGroupChild(localName)) != null)
184       {
185          return child;
186       }
187       else if (localName.equals("security-identity"))
188       {
189          child = new SecurityIdentityMetaData();
190       }
191       else if(localName.equals("cmp-field"))
192       {
193          child = new CMPFieldMetaData();
194       }
195       else if (localName.equals("query"))
196       {
197          child = new QueryMetaData();
198       }
199       else if(log.isTraceEnabled())
200       {
201          log.trace("Ignoring child of entity: " + localName);
202       }
203       return child;
204    }
205
206    public Object JavaDoc newChild(MessageDrivenMetaData mdb, UnmarshallingContext navigator,
207          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
208    {
209       Object JavaDoc child = null;
210       // Handle the *-ref elements
211
if ((child = newEnvRefGroupChild(localName)) != null)
212          return child;
213       else if (localName.equals("security-identity"))
214          child = new SecurityIdentityMetaData();
215       else if(localName.equals("message-driven-destination"))
216          child = mdb;
217       else if(localName.equals("activation-config"))
218          child = mdb;
219       else if(localName.equals("activation-config-property"))
220          child = new ActivationConfigPropertyMetaData();
221       else if(log.isTraceEnabled())
222       {
223          log.trace("Ignoring child of message-driven: " + localName);
224       }
225       return child;
226    }
227
228    public Object JavaDoc newChild(SessionMetaData session, UnmarshallingContext navigator,
229          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
230    {
231       Object JavaDoc child = null;
232       // Handle the *-ref elements
233
if ((child = newEnvRefGroupChild(localName)) != null)
234          return child;
235       else if (localName.equals("security-identity"))
236          child = new SecurityIdentityMetaData();
237       else if(log.isTraceEnabled())
238       {
239          log.trace("Ignoring child of session: " + localName);
240       }
241       return child;
242    }
243
244    public Object JavaDoc newChild(RelationMetaData relation, UnmarshallingContext navigator,
245          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
246    {
247       Object JavaDoc child = null;
248       
249       // left role
250
if( localName.equals("ejb-relationship-role") )
251       {
252          child = new RelationshipRoleMetaData(relation);
253       }
254       else if(log.isTraceEnabled())
255       {
256          log.trace("Ignoring child of relation: " + localName);
257       }
258       return child;
259    }
260
261    public Object JavaDoc newChild(RelationshipRoleMetaData role, UnmarshallingContext navigator,
262          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
263    {
264       Object JavaDoc child = null;
265       if(localName.equals("cascade-delete"))
266       {
267          role.setCascadeDelete(true);
268       }
269       else if(localName.equals("relationship-role-source") ||
270          localName.equals("cmr-field"))
271       {
272          child = role;
273       }
274       return child;
275    }
276
277    public Object JavaDoc newChild(AssemblyDescriptor ad, UnmarshallingContext navigator,
278          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
279    {
280       if(localName.equals("security-role"))
281       {
282          return ad;
283       }
284       else if(localName.equals("method-permission"))
285       {
286          return new MethodPermission(ad);
287       }
288       else if(localName.equals("container-transaction"))
289       {
290          return new ContainerTransaction();
291       }
292       else if(localName.equals("exclude-list"))
293       {
294          return ad;
295       }
296       else if(localName.equals("method"))
297       {
298          MethodMetaData method = new MethodMetaData();
299          method.setExcluded();
300          return method;
301       }
302       else if(localName.equals("message-destination"))
303       {
304          MessageDestinationMetaData mdmd = new MessageDestinationMetaData();
305          return mdmd;
306       }
307       return null;
308    }
309
310    public Object JavaDoc newChild(MethodMetaData method, UnmarshallingContext navigator,
311          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
312    {
313       if(localName.equals("method") ||
314          localName.equals("method-params"))
315       {
316          return method;
317       }
318       else if(localName.equals("unchecked"))
319       {
320          method.setUnchecked();
321       }
322       return null;
323    }
324
325    public Object JavaDoc newChild(QueryMetaData query, UnmarshallingContext navigator,
326          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
327    {
328       if(localName.equals("query-method") || localName.equals("method-params"))
329       {
330          return query;
331       }
332       return null;
333    }
334
335    public Object JavaDoc newChild(SecurityIdentityMetaData parent, UnmarshallingContext navigator,
336          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
337    {
338       if(localName.equals("run-as"))
339       {
340          return parent;
341       }
342       else if(localName.equals("use-caller-identity"))
343       {
344          parent.setUseCallerIdentity(true);
345       }
346       return null;
347    }
348
349    public Object JavaDoc newChild(MethodPermission parent, UnmarshallingContext navigator,
350          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
351    {
352       if(localName.equals("method"))
353       {
354          return new MethodMetaData();
355       }
356       return null;
357    }
358
359    public Object JavaDoc newChild(ContainerTransaction parent, UnmarshallingContext navigator,
360          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
361    {
362       if(localName.equals("method"))
363       {
364          MethodMetaData method = new MethodMetaData();
365          parent.methods.add(method);
366          return method;
367       }
368       return null;
369    }
370
371    public void addChild(ApplicationMetaData parent, EntityMetaData entity,
372          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
373    {
374       if(parent.isEJB1x() && entity.isCMP())
375       {
376          entity.setCmpVersion(1);
377       }
378       parent.addBeanMetaData(entity);
379    }
380
381    public void addChild(ApplicationMetaData parent, SessionMetaData session,
382          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
383    {
384       parent.addBeanMetaData(session);
385    }
386
387    public void addChild(ApplicationMetaData parent, MessageDrivenMetaData mdb,
388          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
389    {
390       parent.addBeanMetaData(mdb);
391    }
392
393    public void addChild(ApplicationMetaData parent, RelationMetaData relation,
394          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
395    {
396       if(relation.getRelationName() == null)
397       {
398          relation.setDefaultRelationName();
399       }
400       parent.addRelationship(relation);
401    }
402
403    public void addChild(EntityMetaData parent, SecurityIdentityMetaData child,
404          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
405    {
406       parent.setSecurityIdentityMetaData(child);
407    }
408
409    public void addChild(EntityMetaData parent, CMPFieldMetaData field,
410          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
411    {
412       parent.getCmpFields().add(field.name);
413    }
414
415    public void addChild(EntityMetaData parent, QueryMetaData query,
416          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
417    {
418       parent.addQuery(query);
419    }
420
421    public void addChild(EntityMetaData parent, EjbLocalRefMetaData child,
422          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
423    {
424       parent.addEjbLocalReference(child);
425    }
426
427    public void addChild(EntityMetaData parent, EjbRefMetaData child,
428          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
429    {
430       parent.addEjbReference(child);
431    }
432
433    public void addChild(EntityMetaData parent, ResourceRefMetaData child,
434          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
435    {
436       parent.addResourceReference(child);
437    }
438
439    public void addChild(EntityMetaData parent, ResourceEnvRefMetaData child,
440          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
441    {
442       parent.addResourceEnvReference(child);
443    }
444
445    public void addChild(EntityMetaData parent, EnvEntryMetaData child,
446          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
447    {
448       parent.addEnvironmentEntry(child);
449    }
450
451    public void addChild(EntityMetaData parent, MessageDestinationRefMetaData child,
452          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
453    {
454       parent.addMessageDestinationReference(child);
455    }
456
457    public void addChild(EntityMetaData parent, ServiceRefMetaData child,
458          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
459    {
460       parent.addServiceReference(child);
461    }
462
463    public void addChild(SessionMetaData parent, SecurityIdentityMetaData child,
464          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
465    {
466       parent.setSecurityIdentityMetaData(child);
467    }
468
469    public void addChild(SessionMetaData parent, EjbLocalRefMetaData child,
470          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
471    {
472       parent.addEjbLocalReference(child);
473    }
474
475    public void addChild(SessionMetaData parent, EjbRefMetaData child,
476          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
477    {
478       parent.addEjbReference(child);
479    }
480
481    public void addChild(SessionMetaData parent, ResourceRefMetaData child,
482          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
483    {
484       parent.addResourceReference(child);
485    }
486
487    public void addChild(SessionMetaData parent, ResourceEnvRefMetaData child,
488          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
489    {
490       parent.addResourceEnvReference(child);
491    }
492
493    public void addChild(SessionMetaData parent, EnvEntryMetaData child,
494          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
495    {
496       parent.addEnvironmentEntry(child);
497    }
498
499    public void addChild(SessionMetaData parent, MessageDestinationRefMetaData child,
500          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
501    {
502       parent.addMessageDestinationReference(child);
503    }
504
505    public void addChild(SessionMetaData parent, ServiceRefMetaData child,
506          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
507    {
508       parent.addServiceReference(child);
509    }
510
511    public void addChild(RelationMetaData relation, RelationshipRoleMetaData role,
512                         UnmarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
513    {
514       if(role.getRelationshipRoleName() == null)
515       {
516          role.setRelationshipRoleName(
517             role.getEntityName() + (role.getCMRFieldName() == null ? "" : "_" + role.getCMRFieldName())
518          );
519       }
520
521       if(relation.getLeftRelationshipRole() == null)
522       {
523          relation.setLeftRelationshipRole(role);
524       }
525       else
526       {
527          relation.setRightRelationshipRole(role);
528       }
529    }
530
531    public void addChild(AssemblyDescriptor ad, MessageDestinationMetaData mdmd,
532          UnmarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
533    {
534       ad.app.getAssemblyDescriptor().addMessageDestinationMetaData(mdmd);
535    }
536
537    public void addChild(AssemblyDescriptor parent, ContainerTransaction child,
538          UnmarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
539    {
540       for(int i = 0; i < child.methods.size(); ++i)
541       {
542          MethodMetaData method = (MethodMetaData)child.methods.get(i);
543          BeanMetaData bean = getBeanForMethod(parent, method);
544
545          method.setTransactionType(child.transAttr);
546          bean.addTransactionMethod(method);
547       }
548    }
549
550    public void addChild(AssemblyDescriptor parent, MethodMetaData child,
551          UnmarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
552    {
553       BeanMetaData bean = getBeanForMethod(parent, child);
554       bean.addExcludedMethod(child);
555    }
556
557    public void addChild(MessageDrivenMetaData parent, SecurityIdentityMetaData child,
558          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
559    {
560       parent.setSecurityIdentityMetaData(child);
561    }
562
563    public void addChild(MessageDrivenMetaData mdb, ActivationConfigPropertyMetaData child,
564                         UnmarshallingContext ctx, String JavaDoc namespaceURI, String JavaDoc localName)
565    {
566       mdb.getActivationConfigProperties().put(child.getName(), child);
567    }
568
569    public void addChild(MessageDrivenMetaData parent, EjbLocalRefMetaData child,
570          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
571    {
572       parent.addEjbLocalReference(child);
573    }
574
575    public void addChild(MessageDrivenMetaData parent, EjbRefMetaData child,
576          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
577    {
578       parent.addEjbReference(child);
579    }
580
581    public void addChild(MessageDrivenMetaData parent, ResourceRefMetaData child,
582          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
583    {
584       parent.addResourceReference(child);
585    }
586
587    public void addChild(MessageDrivenMetaData parent, ResourceEnvRefMetaData child,
588          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
589    {
590       parent.addResourceEnvReference(child);
591    }
592
593    public void addChild(MessageDrivenMetaData parent, EnvEntryMetaData child,
594          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
595    {
596       parent.addEnvironmentEntry(child);
597    }
598
599    public void addChild(MessageDrivenMetaData parent, MessageDestinationRefMetaData child,
600          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
601    {
602       parent.addMessageDestinationReference(child);
603    }
604
605    public void addChild(MessageDrivenMetaData parent, ServiceRefMetaData child,
606          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
607    {
608       parent.addServiceReference(child);
609    }
610
611    public void addChild(MethodPermission parent, MethodMetaData child,
612          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
613    {
614       BeanMetaData bean = getBeanForMethod(parent.ad, child);
615
616       if(parent.roles == null)
617       {
618          child.setUnchecked();
619       }
620       else
621       {
622          child.getRoles().addAll(parent.roles);
623       }
624
625       bean.addPermissionMethod(child);
626    }
627
628    /**
629     * Set text values of ejb-jar/* children
630     * @param dd
631     * @param navigator
632     * @param namespaceURI
633     * @param localName
634     * @param value
635     */

636    public void setValue(ApplicationMetaData dd,
637          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
638          String JavaDoc value)
639    {
640       if( localName.equals("display-name") )
641          dd.setDisplayName(value);
642       else if( localName.equals("description") )
643          dd.setDescription(value);
644       else if(localName.equals("ejb-client-jar"))
645          dd.setClientJar(value);
646    }
647
648    /**
649     * Set text values of entity/* children
650     * @param entity
651     * @param navigator
652     * @param namespaceURI
653     * @param localName
654     * @param value
655     */

656    public void setValue(EntityMetaData entity,
657          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
658          String JavaDoc value)
659    {
660       if( localName.equals("display-name") )
661          entity.setDisplayName(value);
662       else if( localName.equals("description") )
663          entity.setDescription(value);
664       else if( localName.equals("ejb-name") )
665          entity.setEjbName(value);
666       else if( localName.equals("home") )
667          entity.setHome(value);
668       else if( localName.equals("remote") )
669          entity.setRemote(value);
670       else if( localName.equals("local-home") )
671          entity.setLocalHome(value);
672       else if( localName.equals("local") )
673          entity.setLocal(value);
674       else if( localName.equals("ejb-class") )
675          entity.setEjbClass(value);
676       else if( localName.equals("persistence-type") )
677       {
678          boolean cmp = false;
679          if( value.equals("Bean") )
680          {
681             cmp = false;
682          }
683          else if( value.equals("Container") )
684          {
685             cmp = true;
686          }
687          else
688          {
689             throw new IllegalStateException JavaDoc( entity.getEjbName() + ": " +
690                "persistence-type must be 'Bean' or 'Container'!" );
691          }
692          entity.setCmp(cmp);
693       }
694       else if( localName.equals("prim-key-class") )
695          entity.setPrimaryKeyClass(value);
696       else if( localName.equals("reentrant") )
697       {
698          boolean flag = Boolean.valueOf(value);
699          entity.setReentrant(flag);
700       }
701       else if( localName.equals("cmp-version") )
702       {
703          int cmpVersion = 2;
704          if( "1.x".equals(value) )
705          {
706             cmpVersion = 1;
707          }
708          else if( "2.x".equals(value) )
709          {
710             cmpVersion = 2;
711          }
712          entity.setCmpVersion(cmpVersion);
713       }
714       else if( localName.equals("abstract-schema-name") )
715          entity.setAbstractSchemaName(value);
716       else if( localName.equals("primkey-field") )
717          entity.setPrimKeyField(value);
718    }
719
720    /**
721     * Set text values of session/* children
722     * @param bean
723     * @param navigator
724     * @param namespaceURI
725     * @param localName
726     * @param value
727     */

728    public void setValue(SessionMetaData bean,
729          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
730          String JavaDoc value)
731    {
732       if( localName.equals("display-name") )
733          bean.setDisplayName(value);
734       else if( localName.equals("description") )
735          bean.setDescription(value);
736       else if( localName.equals("ejb-name") )
737          bean.setEjbName(value);
738       else if( localName.equals("home") )
739          bean.setHome(value);
740       else if( localName.equals("remote") )
741          bean.setRemote(value);
742       else if( localName.equals("local-home") )
743          bean.setLocalHome(value);
744       else if( localName.equals("local") )
745          bean.setLocal(value);
746       else if( localName.equals("ejb-class") )
747          bean.setEjbClass(value);
748       else if( localName.equals("session-type") )
749       {
750          if( value.equals("Stateful") )
751          {
752             bean.setStateful(true);
753          }
754          else if( value.equals("Stateless") )
755          {
756             bean.setStateful(false);
757          }
758          else
759          {
760             throw new IllegalStateException JavaDoc( bean.getEjbName() + ": " +
761                "session-type must be 'Stateful' or 'Stateless' but was " + value );
762          }
763       }
764       else if(localName.equals("transaction-type"))
765       {
766          if("Bean".equals(value))
767          {
768             bean.setContainerManagedTx(false);
769          }
770          else if("Container".equals(value))
771          {
772             bean.setContainerManagedTx(true);
773          }
774          else
775          {
776             throw new IllegalStateException JavaDoc("Unexpected value for transaction-type: " + value);
777          }
778       }
779    }
780
781    public void setValue(MessageDrivenMetaData mdb,
782          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
783          String JavaDoc value)
784    {
785       if( localName.equals("display-name") )
786          mdb.setDisplayName(value);
787       else if( localName.equals("description") )
788          mdb.setDescription(value);
789       else if( localName.equals("ejb-name") )
790          mdb.setEjbName(value);
791       else if(localName.equals("ejb-class"))
792          mdb.setEjbClass(value);
793       else if(localName.equals("transaction-type"))
794       {
795          if("Bean".equals(value))
796          {
797             mdb.setContainerManagedTx(false);
798          }
799          else if("Container".equals(value))
800          {
801             mdb.setContainerManagedTx(true);
802          }
803          else
804          {
805             throw new IllegalStateException JavaDoc("Unexpected value for transaction-type: " + value);
806          }
807       }
808       else if(localName.equals("message-selector"))
809       {
810          mdb.setMessageSelector(value);
811       }
812       else if(localName.equals("messaging-type"))
813       {
814          mdb.setMessagingType(value);
815       }
816       else if(localName.equals("message-destination-type") || localName.equals("destination-type"))
817       {
818          mdb.setDestinationType(value);
819       }
820       else if(localName.equals("message-destination-type"))
821       {
822          mdb.setDestinationType(value);
823       }
824       else if(localName.equals("message-destination-link"))
825       {
826          mdb.setDestinationLink(value);
827       }
828       else if(localName.equals("acknowledge-mode"))
829       {
830          mdb.setAcknowledgeMode(value);
831       }
832       else if(localName.equals("subscription-durability"))
833       {
834          mdb.setSubscriptionDurability(value);
835       }
836    }
837
838    public void setValue(IconMetaData icon,
839          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
840          String JavaDoc value)
841    {
842       if( localName.equals("small-icon") )
843          icon.setSmallIcon(value);
844       if( localName.equals("large-icon") )
845          icon.setLargeIcon(value);
846    }
847
848    public void setValue(RelationMetaData relation,
849          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
850          String JavaDoc value)
851    {
852       if( localName.equals("description") )
853       {
854          relation.setDescription(value);
855       }
856       else if( localName.equals("display-name") )
857       {
858          relation.setDisplayName(value);
859       }
860       else if( localName.equals("ejb-relation-name") )
861       {
862          relation.setRelationName(value);
863       }
864       else if( localName.equals("ejb-relation-name") )
865       {
866          relation.setRelationName(value);
867       }
868    }
869
870    public void setValue(RelationshipRoleMetaData role,
871          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
872          String JavaDoc value)
873    {
874       if(localName.equals("ejb-relationship-role-name"))
875       {
876          role.setRelationshipRoleName(value);
877       }
878       else if(localName.equals("multiplicity"))
879       {
880          role.setMultiplicity(value);
881       }
882       else if(localName.equals("ejb-name"))
883       {
884          role.setEntityName(value);
885       }
886       else if(localName.equals("cmr-field-name"))
887       {
888          role.setCmrFieldName(value);
889       }
890       else if(localName.equals("cmr-field-type"))
891       {
892          role.setCmrFieldType(value);
893       }
894    }
895
896    public void setValue(CMPFieldMetaData field,
897          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
898          String JavaDoc value)
899    {
900       if(localName.equals("field-name"))
901       {
902          field.name = value;
903       }
904    }
905
906    public void setValue(AssemblyDescriptor ad,
907          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
908          String JavaDoc value)
909    {
910       if(localName.equals("role-name"))
911       {
912          ad.app.getAssemblyDescriptor().addSecurityRoleMetaData(new SecurityRoleMetaData(value));
913       }
914    }
915
916    public void setValue(MethodPermission method,
917          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
918          String JavaDoc value)
919    {
920       if(localName.equals("role-name"))
921       {
922          method.addRole(value);
923       }
924    }
925
926    public void setValue(ContainerTransaction parent,
927          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
928          String JavaDoc value)
929    {
930       if(localName.equals("trans-attribute"))
931       {
932          parent.transAttr = MethodMetaData.getTransactionAttribute(value);
933       }
934    }
935
936    public void setValue(MethodMetaData method,
937          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
938          String JavaDoc value)
939    {
940       if(localName.equals("ejb-name"))
941       {
942          method.setEjbName(value);
943       }
944       else if(localName.equals("method-intf"))
945       {
946          method.setInterfaceType(value);
947       }
948       else if(localName.equals("method-name"))
949       {
950          method.setMethodName(value);
951       }
952       else if(localName.equals("method-param"))
953       {
954          method.addParam(value);
955       }
956    }
957
958    public void setValue(QueryMetaData query,
959          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
960          String JavaDoc value)
961    {
962       if(localName.equals("result-type-mapping"))
963       {
964          query.setResultTypeMapping(value);
965       }
966       else if(localName.equals("ejb-ql"))
967       {
968          query.setEjbQl(value);
969       }
970       else if(localName.equals("method-name"))
971       {
972          query.setMethodName(value);
973       }
974       else if(localName.equals("method-param"))
975       {
976          query.addMethodParam(value);
977       }
978    }
979
980    public void setValue(ActivationConfigPropertyMetaData prop,
981          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
982          String JavaDoc value)
983    {
984       if(localName.equals("activation-config-property-name"))
985       {
986          prop.setName(value);
987       }
988       else if(localName.equals("activation-config-property-value"))
989       {
990          prop.setValue(value);
991       }
992    }
993
994    /**
995     * <!ELEMENT security-identity (description?, (use-caller-identity|run-as))>
996     */

997    public void setValue(SecurityIdentityMetaData parent,
998          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
999          String JavaDoc value)
1000   {
1001      if(localName.equals("role-name"))
1002      {
1003         parent.setRunAsRoleName(value);
1004      }
1005   }
1006   
1007   public void setValue(MessageDestinationMetaData mdmd,
1008         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
1009         String JavaDoc value)
1010   {
1011      if(localName.equals("message-destination-name"))
1012      {
1013         mdmd.setName(value);
1014      }
1015   }
1016
1017   // private
1018

1019   private BeanMetaData getBeanForMethod(AssemblyDescriptor parent, MethodMetaData child)
1020   {
1021      if(child.getEjbName() == null)
1022      {
1023         throw new IllegalStateException JavaDoc("Method permission without ejb-name!");
1024      }
1025
1026      BeanMetaData bean = parent.app.getBeanByEjbName(child.getEjbName());
1027      if(bean == null)
1028      {
1029         throw new IllegalStateException JavaDoc("Bean " + child.getEjbName() + " not found in the application.");
1030      }
1031      return bean;
1032   }
1033
1034   // inner
1035

1036   public static class CMPFieldMetaData
1037   {
1038      String JavaDoc name;
1039   }
1040
1041   public static class AssemblyDescriptor
1042   {
1043      ApplicationMetaData app;
1044
1045      public AssemblyDescriptor(ApplicationMetaData app)
1046      {
1047         this.app = app;
1048      }
1049   }
1050
1051   public static class MethodPermission
1052   {
1053      AssemblyDescriptor ad;
1054      List JavaDoc roles;
1055
1056      public MethodPermission(AssemblyDescriptor ad)
1057      {
1058         this.ad = ad;
1059      }
1060
1061      void addRole(String JavaDoc role)
1062      {
1063         if(roles == null)
1064         {
1065            roles = new ArrayList JavaDoc();
1066         }
1067         roles.add(role);
1068      }
1069   }
1070
1071   public static class ContainerTransaction
1072   {
1073      List JavaDoc methods = new ArrayList JavaDoc();
1074      byte transAttr;
1075   }
1076}
1077
Popular Tags