KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ejb > dd > RelationTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.ejb.dd;
6
7 import java.util.*;
8
9 import org.apache.commons.logging.Log;
10
11 import xjavadoc.*;
12
13 import xdoclet.XDocletException;
14 import xdoclet.modules.ejb.EjbTagsHandler;
15 import xdoclet.modules.ejb.XDocletModulesEjbMessages;
16 import xdoclet.modules.ejb.entity.CmpTagsHandler;
17 import xdoclet.tagshandler.MethodTagsHandler;
18
19 import xdoclet.util.LogUtil;
20 import xdoclet.util.Translator;
21 import xdoclet.util.TypeConversionUtil;
22
23 /**
24  * @author <a HREF="mailto:aslak.nospam@users.sf.net">Aslak Hellesøy</a>
25  * @author Ara Abrahamian (ara_e@email.com)
26  * @created Oct 15, 2001
27  * @xdoclet.taghandler namespace="EjbRel"
28  * @version $Revision: 1.12 $
29  */

30 public class RelationTagsHandler extends EjbTagsHandler
31 {
32     /**
33      * A map containing all relations.
34      */

35     protected static Map relationMap = new HashMap();
36
37     /**
38      * The current relation, set by forAllRelationships and used by forAllRelationshipRoles. It somehow is like the
39      * current index for the forAllRelationships loop.
40      *
41      * @see #forAllRelationships(java.lang.String)
42      */

43     protected static RelationHolder currentRelation;
44
45     /**
46      * Evaluates the body if the left side of this relation has cascade-delete=yes
47      *
48      * @param template The body of the block tag
49      * @exception XDocletException
50      */

51     public void ifLeftCascadeDelete(String JavaDoc template) throws XDocletException
52     {
53         if (currentRelation.isLeftCascadeDelete()) {
54             generate(template);
55         }
56     }
57
58     /**
59      * Evaluates the body if the right side of this relation has cascade-delete=yes, or the left side has
60      * target-relation cascade-delete="yes"
61      *
62      * @param template The body of the block tag
63      * @exception XDocletException
64      */

65     public void ifRightCascadeDelete(String JavaDoc template) throws XDocletException
66     {
67         if (currentRelation.isRightCascadeDelete()) {
68             generate(template);
69         }
70     }
71
72     /**
73      * Returns the EJB Name of the left side of this relationship
74      *
75      * @return Left side's EJB name
76      * @exception XDocletException
77      */

78     public String JavaDoc leftEJBName() throws XDocletException
79     {
80         if (currentRelation.getLeft() != null) {
81             return EjbTagsHandler.getEjbNameFor(currentRelation.getLeft());
82         }
83         else {
84             String JavaDoc name = getTagValue(
85                 FOR_METHOD,
86                 currentRelation.getRightMethod().getDoc(),
87                 "ejb:relation",
88                 "target-ejb",
89                 null,
90                 null,
91                 true,
92                 !currentRelation.isBidirectional()
93                 );
94
95             return name;
96         }
97     }
98
99     /**
100      * Returns the EJB Name of the right side of this relationship
101      *
102      * @return Right side's EJB name
103      * @exception XDocletException
104      */

105     public String JavaDoc rightEJBName() throws XDocletException
106     {
107         if (currentRelation.getRight() != null) {
108             return EjbTagsHandler.getEjbNameFor(currentRelation.getRight());
109         }
110         else {
111             String JavaDoc name = getTagValue(
112                 FOR_METHOD,
113                 currentRelation.getLeftMethod().getDoc(),
114                 "ejb:relation",
115                 "target-ejb",
116                 null,
117                 null,
118                 true,
119                 !currentRelation.isBidirectional()
120                 );
121
122             return name;
123         }
124     }
125
126     /**
127      * Evaluates the body if at least one of the classes has an ejb:relation tag, otherwise not.
128      *
129      * @param template The body of the block tag
130      * @exception XDocletException
131      */

132     public void ifHasRelationships(String JavaDoc template) throws XDocletException
133     {
134         boolean hasRelationships = hasRelationships();
135
136         if (hasRelationships) {
137             generate(template);
138         }
139     }
140
141     /**
142      * Evaluates the body if none of the classes has an ejb:relation tag, otherwise not.
143      *
144      * @param template The body of the block tag
145      * @exception XDocletException
146      */

147     public void ifNotHasRelationships(String JavaDoc template) throws XDocletException
148     {
149         boolean hasRelationships = hasRelationships();
150
151         if (!hasRelationships) {
152             generate(template);
153         }
154     }
155
156     /**
157      * @return the name of the current relation
158      * @exception XDocletException
159      */

160     public String JavaDoc relationName() throws XDocletException
161     {
162         return currentRelation.getName();
163     }
164
165     /**
166      * Evaluates the body block for each relationship. Relations are denoted by ejb:relation for the getter method of
167      * the cmr-field.
168      *
169      * @param template The body of the block tag
170      * @exception XDocletException
171      * @see xdoclet.modules.ejb.entity.CmpTagsHandler#isEntityCmp(xjavadoc.XClass)
172      * @see xdoclet.modules.ejb.entity.PersistentTagsHandler#isPersistentField(xjavadoc.XMethod)
173      * @see xdoclet.tagshandler.MethodTagsHandler#isGetter(java.lang.String)
174      * @see #isSetOrCollection(java.lang.String)
175      * @doc.tag type="block"
176      */

177     public void forAllRelationships(String JavaDoc template) throws XDocletException
178     {
179         Log log = LogUtil.getLog(RelationTagsHandler.class, "forAllRelationships");
180
181         Collection classes = getXJavaDoc().getSourceClasses();
182
183         relationMap.clear();
184
185         for (Iterator i = classes.iterator(); i.hasNext(); ) {
186             XClass clazz = (XClass) i.next();
187
188             setCurrentClass(clazz);
189
190             Collection methods = clazz.getMethods();
191
192             for (Iterator j = methods.iterator(); j.hasNext(); ) {
193                 XMethod method = (XMethod) j.next();
194
195                 setCurrentMethod(method);
196
197                 XTag relationTag = method.getDoc().getTag("ejb:relation");
198
199                 if (relationTag != null) {
200                     String JavaDoc relationName = relationTag.getAttributeValue("name");
201
202                     if (relationName == null) {
203                         throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.RELATION_MUST_HAVE_NAME, new String JavaDoc[]{getCurrentClass().getName()}));
204                     }
205
206                     RelationHolder relationHolder = (RelationHolder) relationMap.get(relationName);
207
208                     if (relationHolder != null && relationHolder.getLeft() != null && relationHolder.getRight() != null) {
209                         String JavaDoc leftSignature = relationHolder.getLeftMethod().getContainingClass().getQualifiedName() + "." + relationHolder.getLeftMethod();
210                         String JavaDoc rightSignature = relationHolder.getRightMethod().getContainingClass().getQualifiedName() + "." + relationHolder.getRightMethod();
211                         String JavaDoc currentSignature = method.getContainingClass().getQualifiedName() + "." + method;
212
213                         throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.RELATION_TOO_MANY_NAMES, new String JavaDoc[]{
214                             relationName,
215                             leftSignature,
216                             rightSignature,
217                             currentSignature
218                             }));
219                     }
220
221                     if (relationHolder == null) {
222                         if (log.isDebugEnabled()) {
223                             log.debug("Created new relationship for " + clazz + "." + method);
224                         }
225
226                         relationHolder = new RelationHolder();
227                         relationHolder.left = clazz;
228                         relationHolder.leftMethod = method;
229                         relationMap.put(relationName, relationHolder);
230                     }
231                     else {
232                         if (log.isDebugEnabled()) {
233                             log.debug("Added " + clazz + " to relationship: " + relationHolder);
234                         }
235                         relationHolder.right = clazz;
236                         relationHolder.rightMethod = method;
237                     }
238                 }
239             }
240         }
241
242         // Now swap relations so that right is always many (if there is a many side). This may result
243
// in left being null, in case of a unidirectional relationship
244
// Possible cases are (left-right):
245
// 1-->1
246
// 1<--1
247
// 1-->N
248
// 1<--N
249
// M-->N
250
// N<--M
251
// 1<->1
252
// 1<->N
253
// M<->N
254
// Impossible cases are (left-right):
255
// N-->1
256
// N<--1
257
Iterator relations = relationMap.entrySet().iterator();
258
259         while (relations.hasNext()) {
260             Map.Entry entry = (Map.Entry) relations.next();
261             RelationHolder relationHolder = (RelationHolder) entry.getValue();
262
263             if (relationHolder.isLeftMany() && !relationHolder.isRightMany()) {
264                 // swap
265
if (log.isDebugEnabled()) {
266                     log.debug("Swapping left -> right in attempt to make 1-n be 1-n (rather than n-1)");
267                 }
268                 relationHolder.swap();
269             }
270             if (!relationHolder.isBidirectional() &&
271                 relationHolder.isOne2Many() &&
272                 relationHolder.getLeftMethod() == null) {
273                 relationHolder.swap();
274             }
275         }
276
277         // Loop over all relations
278
Iterator relationNameIterator = relationMap.keySet().iterator();
279
280         while (relationNameIterator.hasNext()) {
281             // The name is only needed to provide potential error messages.
282
String JavaDoc relationName = (String JavaDoc) relationNameIterator.next();
283
284             RelationHolder relationHolder = (RelationHolder) relationMap.get(relationName);
285
286             setCurrentClass(relationHolder.getLeft());
287             setCurrentMethod(relationHolder.getLeftMethod());
288
289             currentRelation = relationHolder;
290
291             // Get the target-ejb value (null or not), so we can perform sanity checks.
292
// String target = relationHolder.getLeftMethod().doc().tagAttributeValue( "ejb:relation", "target-ejb" );
293
// if( relationHolder.getRight() == null )
294
// {
295
// // Relation has only been declared in one method. That means it is unidirectional and requires
296
// // target-ejb to be set. Perform the sanity check here before we give the template
297
// // a chance to do something stupid.
298
//
299
// if( target == null )
300
// {
301
// throw new XDocletException( Translator.getString( XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.RELATION_NEEDS_TARGET,
302
// new String[]{relationName, relationHolder.getLeft().name() + "." + relationHolder.getLeftMethod().name()} ) );
303
// }
304
// }
305
// else
306
// {
307
// // Relation has been declared in exactly two methods. That means target-ejb is forbidden, since its
308
// // presence will result in invalid relations element in ejb-jar.xml
309
// if( target != null )
310
// {
311
// throw new XDocletException( Translator.getString( XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.RELATION_NEEDS_NO_TARGET,
312
// new String[]{relationName, relationHolder.getLeft().name() + "." + relationHolder.getLeftMethod().name()} ) );
313
// }
314
// }
315

316             if (log.isDebugEnabled()) {
317                 log.debug("Generating template for Relation: " + currentRelation);
318             }
319             generate(template);
320         }
321     }
322
323     /**
324      * Describe what the method does
325      *
326      * @param template Describe what the parameter does
327      * @exception XDocletException
328      */

329     public void ifIsLeftMany(String JavaDoc template) throws XDocletException
330     {
331         if (currentRelation.isLeftMany()) {
332             generate(template);
333         }
334     }
335
336     /**
337      * Describe what the method does
338      *
339      * @param template Describe what the parameter does
340      * @exception XDocletException
341      */

342     public void ifIsRightMany(String JavaDoc template) throws XDocletException
343     {
344         if (currentRelation.isRightMany()) {
345             generate(template);
346         }
347     }
348
349     /**
350      * Describe what the method does
351      *
352      * @return Describe the return value
353      * @exception XDocletException
354      */

355     public String JavaDoc leftFieldName() throws XDocletException
356     {
357         return CmpTagsHandler.getFieldNameFor(currentRelation.getLeftMethod());
358     }
359
360     /**
361      * Describe what the method does
362      *
363      * @return Describe the return value
364      * @exception XDocletException
365      */

366     public String JavaDoc rightFieldName() throws XDocletException
367     {
368         return CmpTagsHandler.getFieldNameFor(currentRelation.getRightMethod());
369     }
370
371     /**
372      * Describe what the method does
373      *
374      * @return Describe the return value
375      * @exception XDocletException
376      */

377     public String JavaDoc leftFieldType() throws XDocletException
378     {
379         return MethodTagsHandler.getMethodTypeFor(currentRelation.getLeftMethod());
380     }
381
382     /**
383      * Describe what the method does
384      *
385      * @return Describe the return value
386      * @exception XDocletException
387      */

388     public String JavaDoc rightFieldType() throws XDocletException
389     {
390         return MethodTagsHandler.getMethodTypeFor(currentRelation.getRightMethod());
391     }
392
393     /**
394      * Evaluates the body block if current method's return type is not a java.util.Collection or java.util.Set. Used by
395      * forAllRelationships.
396      *
397      * @param template The body of the block tag
398      * @exception XDocletException
399      * @see #forAllRelationships(java.lang.String)
400      * @doc.tag type="block"
401      */

402     public void ifIsNotACollection(String JavaDoc template) throws XDocletException
403     {
404         if (!isSetOrCollection(MethodTagsHandler.getMethodTypeFor(getCurrentMethod()))) {
405             generate(template);
406         }
407     }
408
409     /**
410      * Describe what the method does
411      *
412      * @return Describe the return value
413      */

414     public String JavaDoc relationComment()
415     {
416         return "<!-- " + currentRelation.toString() + " -->";
417     }
418
419     /**
420      * Evaluates the body block if the current relationship is a one to one type, meaning, neither side of the relation
421      * returns java.util.Collection or java.util.Set. Used by forAllRelationships.
422      *
423      * @param template The body of the block tag
424      * @exception XDocletException
425      * @see #forAllRelationships(java.lang.String)
426      * @doc.tag type="block"
427      */

428     public void ifIsOne2One(String JavaDoc template) throws XDocletException
429     {
430         if (currentRelation.isOne2One()) {
431             generate(template);
432         }
433     }
434
435     /**
436      * Evaluates the body block if the current relationship IS NOT a one to one type, meaning, at least one side of the
437      * relation returns java.util.Collection or java.util.Set. Used by forAllRelationships.
438      *
439      * @param template The body of the block tag
440      * @exception XDocletException
441      * @see #forAllRelationships(java.lang.String)
442      * @doc.tag type="block"
443      */

444     public void ifNotIsOne2One(String JavaDoc template) throws XDocletException
445     {
446         if (!currentRelation.isOne2One()) {
447             generate(template);
448         }
449     }
450
451     /**
452      * Evaluates the body block if the current relationship is a one to many type, meaning, ONLY ONE side of the
453      * relation returns java.util.Collection or java.util.Set. Used by forAllRelationships.
454      *
455      * @param template The body of the block tag
456      * @exception XDocletException
457      * @see #forAllRelationships(java.lang.String)
458      * @doc.tag type="block"
459      */

460     public void ifIsOne2Many(String JavaDoc template) throws XDocletException
461     {
462         if (currentRelation.isOne2Many()) {
463             generate(template);
464         }
465     }
466
467     /**
468      * Evaluates the body block if the current relationship IS NOT a one to many type, meaning, either both sides, or
469      * neither side of the relation returns java.util.Collection or java.util.Set. Used by forAllRelationships.
470      *
471      * @param template The body of the block tag
472      * @exception XDocletException
473      * @see #forAllRelationships(java.lang.String)
474      * @doc.tag type="block"
475      */

476     public void ifNotIsOne2Many(String JavaDoc template) throws XDocletException
477     {
478         if (!currentRelation.isOne2Many()) {
479             generate(template);
480         }
481     }
482
483     /**
484      * Evaluates the body block if the current relationship is a many to many type, meaning, both sides of the relation
485      * returns java.util.Collection or java.util.Set. Used by forAllRelationships.
486      *
487      * @param template The body of the block tag
488      * @exception XDocletException
489      * @see #forAllRelationships(java.lang.String)
490      * @doc.tag type="block"
491      */

492     public void ifIsMany2Many(String JavaDoc template) throws XDocletException
493     {
494         if (currentRelation.isMany2Many()) {
495             generate(template);
496         }
497     }
498
499     /**
500      * Evaluates the body block if the current relationship IS NOT a many to many type, meaning, at least one side of
501      * the relation does not return java.util.Collection or java.util.Set. Used by forAllRelationships.
502      *
503      * @param template The body of the block tag
504      * @exception XDocletException
505      * @see #forAllRelationships(java.lang.String)
506      * @doc.tag type="block"
507      */

508     public void ifNotIsMany2Many(String JavaDoc template) throws XDocletException
509     {
510         if (!currentRelation.isMany2Many()) {
511             generate(template);
512         }
513     }
514
515     /**
516      * Describe what the method does
517      *
518      * @param template Describe what the parameter does
519      * @exception XDocletException
520      */

521     public void ifIsBidirectional(String JavaDoc template) throws XDocletException
522     {
523         if (currentRelation.isBidirectional()) {
524             generate(template);
525         }
526     }
527
528     /**
529      * Describe what the method does
530      *
531      * @param template Describe what the parameter does
532      * @exception XDocletException
533      */

534     public void ifIsUnidirectional(String JavaDoc template) throws XDocletException
535     {
536         if (!currentRelation.isBidirectional()) {
537             generate(template);
538         }
539     }
540
541     /**
542      * Describe what the method does
543      *
544      * @param template Describe what the parameter does
545      * @exception XDocletException
546      */

547     public void ifHasLeftRoleName(String JavaDoc template) throws XDocletException
548     {
549         if (leftRoleName() != null) {
550             generate(template);
551         }
552     }
553
554     /**
555      * Describe what the method does
556      *
557      * @param template Describe what the parameter does
558      * @exception XDocletException
559      */

560     public void ifHasRightRoleName(String JavaDoc template) throws XDocletException
561     {
562         if (rightRoleName() != null) {
563             generate(template);
564         }
565     }
566
567     /**
568      * Describe what the method does
569      *
570      * @param template Describe what the parameter does
571      * @exception XDocletException
572      */

573     public void ifLeftNavigable(String JavaDoc template) throws XDocletException
574     {
575         if (currentRelation.isLeftNavigable()) {
576             generate(template);
577         }
578     }
579
580     /**
581      * Describe what the method does
582      *
583      * @param template Describe what the parameter does
584      * @exception XDocletException
585      */

586     public void ifRightNavigable(String JavaDoc template) throws XDocletException
587     {
588         if (currentRelation.isRightNavigable()) {
589             generate(template);
590         }
591     }
592
593     /**
594      * Describe what the method does
595      *
596      * @return Describe the return value
597      * @exception XDocletException
598      */

599     public String JavaDoc leftRoleName() throws XDocletException
600     {
601         return currentRelation.getLeftRoleName();
602     }
603
604     /**
605      * Describe what the method does
606      *
607      * @return Describe the return value
608      * @exception XDocletException
609      */

610     public String JavaDoc rightRoleName() throws XDocletException
611     {
612         return currentRelation.getRightRoleName();
613     }
614
615     /**
616      * Describe what the method does
617      *
618      * @return Describe the return value
619      * @exception XDocletException
620      */

621     public String JavaDoc leftMultiplicity() throws XDocletException
622     {
623         return currentRelation.getLeftMultiplicity();
624     }
625
626     /**
627      * Describe what the method does
628      *
629      * @return Describe the return value
630      * @exception XDocletException
631      */

632     public String JavaDoc rightMultiplicity() throws XDocletException
633     {
634         return currentRelation.getRightMultiplicity();
635     }
636
637     /**
638      * Returns true if current method's return type is a java.util.Collection or java.util.Set, false otherwise.
639      *
640      * @param type Description of Parameter
641      * @return true if Collection or Set
642      */

643     protected boolean isSetOrCollection(String JavaDoc type)
644     {
645         return (type.equals("java.util.Collection") || type.equals("java.util.Set"));
646     }
647
648     protected boolean hasRelationships()
649     {
650         Collection classes = getXJavaDoc().getSourceClasses();
651         boolean hasRelationships = false;
652
653         for (Iterator i = classes.iterator(); i.hasNext(); ) {
654             XClass clazz = (XClass) i.next();
655
656             setCurrentClass(clazz);
657
658             Collection methods = clazz.getMethods();
659
660             for (Iterator j = methods.iterator(); j.hasNext(); ) {
661                 XMethod method = (XMethod) j.next();
662
663                 setCurrentMethod(method);
664
665                 XTag relation = method.getDoc().getTag("ejb:relation");
666
667                 if (relation != null) {
668                     hasRelationships = true;
669                     break;
670                 }
671             }
672             if (hasRelationships) {
673                 break;
674             }
675         }
676         return hasRelationships;
677     }
678
679     /**
680      * Holds class/method of the two end points of a relationship.
681      *
682      * @author Aslak Hellesøy
683      * @created August 28, 2001
684      */

685     public class RelationHolder
686     {
687         private final static String JavaDoc ONE = "One";
688
689         private final static String JavaDoc MANY = "Many";
690
691         private XClass left;
692
693         private XMethod leftMethod;
694
695         private XClass right;
696
697         private XMethod rightMethod;
698
699         /**
700          * Gets the Bidirectional attribute of the RelationHolder object
701          *
702          * @return The Bidirectional value
703          */

704         public boolean isBidirectional()
705         {
706             return getRightMethod() != null && getLeftMethod() != null;
707         }
708
709         /**
710          * Gets the One2One attribute of the RelationHolder object
711          *
712          * @return The One2One value
713          * @exception XDocletException
714          */

715         public boolean isOne2One() throws XDocletException
716         {
717             return !isLeftMany() && !isRightMany();
718         }
719
720         /**
721          * Gets the One2Many attribute of the RelationHolder object
722          *
723          * @return The One2Many value
724          * @exception XDocletException
725          */

726         public boolean isOne2Many() throws XDocletException
727         {
728             return !isLeftMany() && isRightMany();
729         }
730
731         /**
732          * Gets the Many2Many attribute of the RelationHolder object
733          *
734          * @return The Many2Many value
735          * @exception XDocletException
736          */

737         public boolean isMany2Many() throws XDocletException
738         {
739             return isLeftMany() && isRightMany();
740         }
741
742         /**
743          * Gets the LeftMultiplicity attribute of the RelationHolder object
744          *
745          * @return The LeftMultiplicity value
746          * @exception XDocletException
747          */

748         public String JavaDoc getLeftMultiplicity() throws XDocletException
749         {
750             return isLeftMany() ? MANY : ONE;
751         }
752
753         /**
754          * Gets the RightMultiplicity attribute of the RelationHolder object
755          *
756          * @return The RightMultiplicity value
757          * @exception XDocletException
758          */

759         public String JavaDoc getRightMultiplicity() throws XDocletException
760         {
761             return isRightMany() ? MANY : ONE;
762         }
763
764         /**
765          * Gets the Left attribute of the RelationHolder object
766          *
767          * @return The Left value
768          */

769         public XClass getLeft()
770         {
771             return left;
772         }
773
774         /**
775          * Gets the LeftMethod attribute of the RelationHolder object
776          *
777          * @return The LeftMethod value
778          */

779         public XMethod getLeftMethod()
780         {
781             return leftMethod;
782         }
783
784         /**
785          * Gets the Right attribute of the RelationHolder object
786          *
787          * @return The Right value
788          */

789         public XClass getRight()
790         {
791             return right;
792         }
793
794         /**
795          * Gets the RightMethod attribute of the RelationHolder object
796          *
797          * @return The RightMethod value
798          */

799         public XMethod getRightMethod()
800         {
801             return rightMethod;
802         }
803
804         /**
805          * Gets the RightNavigable attribute of the RelationHolder object
806          *
807          * @return The RightNavigable value
808          */

809         public boolean isRightNavigable()
810         {
811             return getRightMethod() != null;
812         }
813
814         /**
815          * Gets the LeftNavigable attribute of the RelationHolder object
816          *
817          * @return The LeftNavigable value
818          */

819         public boolean isLeftNavigable()
820         {
821             return getLeftMethod() != null;
822         }
823
824         /**
825          * Gets the LeftRoleName attribute of the RelationHolder object
826          *
827          * @return The LeftRoleName value
828          * @exception XDocletException
829          */

830         public String JavaDoc getLeftRoleName() throws XDocletException
831         {
832             String JavaDoc result = null;
833
834             if (getLeftMethod() != null) {
835                 result = getLeftMethod().getDoc().getTagAttributeValue("ejb:relation", "role-name", false);
836             }
837             else {
838                 result = getRightMethod().getDoc().getTagAttributeValue("ejb:relation", "target-role-name", false);
839             }
840             return result;
841         }
842
843         /**
844          * Gets the RightRoleName attribute of the RelationHolder object
845          *
846          * @return The RightRoleName value
847          * @exception XDocletException
848          */

849         public String JavaDoc getRightRoleName() throws XDocletException
850         {
851             String JavaDoc result = null;
852
853             if (getRightMethod() != null) {
854                 result = getRightMethod().getDoc().getTagAttributeValue("ejb:relation", "role-name", false);
855             }
856             else {
857                 result = getLeftMethod().getDoc().getTagAttributeValue("ejb:relation", "target-role-name", false);
858             }
859             return result;
860         }
861
862         /**
863          * Gets the LeftMany attribute of the RelationHolder object
864          *
865          * @return The LeftMany value
866          * @exception XDocletException
867          */

868         public boolean isLeftMany() throws XDocletException
869         {
870             boolean result;
871
872             if (getLeftMethod() != null) {
873                 result = isSetOrCollection(getLeftMethod().getReturnType().getType().getQualifiedName());
874             }
875             else {
876                 String JavaDoc targetMultiple = getRightMethod().getDoc().getTagAttributeValue("ejb:relation", "target-multiple", false);
877
878                 result = TypeConversionUtil.stringToBoolean(targetMultiple, false);
879             }
880             return result;
881         }
882
883         /**
884          * Gets the RightMany attribute of the RelationHolder object
885          *
886          * @return The RightMany value
887          * @exception XDocletException
888          */

889         public boolean isRightMany() throws XDocletException
890         {
891             boolean result;
892
893             if (getRightMethod() != null) {
894                 result = isSetOrCollection(getRightMethod().getReturnType().getType().getQualifiedName());
895             }
896             else {
897                 String JavaDoc targetMultiple = getLeftMethod().getDoc().getTagAttributeValue("ejb:relation", "target-multiple", false);
898
899                 result = TypeConversionUtil.stringToBoolean(targetMultiple, false);
900             }
901             return result;
902         }
903
904         /**
905          * Gets the LeftCascadeDelete attribute of the RelationHolder object
906          *
907          * @return The LeftCascadeDelete value
908          * @exception XDocletException
909          */

910         public boolean isLeftCascadeDelete() throws XDocletException
911         {
912             boolean result;
913
914             if (getLeftMethod() != null) {
915                 result = isCascadeDelete(getLeftMethod(), "cascade-delete");
916             }
917             else {
918                 result = isCascadeDelete(getRightMethod(), "target-cascade-delete");
919             }
920             return result;
921         }
922
923         /**
924          * Gets the RightCascadeDelete attribute of the RelationHolder object
925          *
926          * @return The RightCascadeDelete value
927          * @exception XDocletException
928          */

929         public boolean isRightCascadeDelete() throws XDocletException
930         {
931             boolean result;
932
933             if (getRightMethod() != null) {
934                 result = isCascadeDelete(getRightMethod(), "cascade-delete");
935             }
936             else {
937                 result = isCascadeDelete(getLeftMethod(), "target-cascade-delete");
938             }
939             return result;
940         }
941
942         /**
943          * @return the name of the relation
944          * @exception XDocletException
945          */

946         public String JavaDoc getName() throws XDocletException
947         {
948             String JavaDoc result = null;
949
950             if (getRightMethod() != null) {
951                 result = getRightMethod().getDoc().getTagAttributeValue("ejb:relation", "name", false);
952             }
953             else {
954                 result = getLeftMethod().getDoc().getTagAttributeValue("ejb:relation", "name", false);
955             }
956             return result;
957         }
958
959         /**
960          * Describe what the method does
961          */

962         public void swap()
963         {
964             XClass c = right;
965             XMethod m = rightMethod;
966
967             right = left;
968             rightMethod = leftMethod;
969             left = c;
970             leftMethod = m;
971         }
972
973         /**
974          * Describe what the method does
975          *
976          * @return Describe the return value
977          */

978         public int hashCode()
979         {
980             int result = 17;
981
982             if (getLeft() != null) {
983                 result = 37 * result + getLeft().hashCode();
984             }
985             if (getLeftMethod() != null) {
986                 result = 37 * result + getLeftMethod().hashCode();
987             }
988             if (getRight() != null) {
989                 result = 37 * result + getRight().hashCode();
990             }
991             if (getRightMethod() != null) {
992                 result = 37 * result + getRightMethod().hashCode();
993             }
994
995             return result;
996         }
997
998         /**
999          * Describe what the method does
1000         *
1001         * @return Describe the return value
1002         */

1003        public String JavaDoc toString()
1004        {
1005            return new StringBuffer JavaDoc("RelationHolder left=").append(getLeft()).append('.').append(getLeftMethod()).append(" right=").append(getRight()).append('.').append(getRightMethod()).toString();
1006        }
1007
1008        /**
1009         * Describe what the method does
1010         *
1011         * @param o Describe what the parameter does
1012         * @return Describe the return value
1013         */

1014        public boolean equals(Object JavaDoc o)
1015        {
1016            if (o == this) {
1017                return true;
1018            }
1019
1020            if (!(o instanceof RelationHolder)) {
1021                return false;
1022            }
1023
1024            RelationHolder other = (RelationHolder) o;
1025
1026            return (
1027                (getLeft() == null ? other.getLeft() == null : getLeft().equals(other.getLeft())) &&
1028                (getLeftMethod() == null ? other.getLeftMethod() == null : getLeftMethod().equals(other.getLeftMethod())) &&
1029                (getRight() == null ? other.getRight() == null : getRight().equals(other.getRight())) &&
1030                (getRightMethod() == null ? other.getRightMethod() == null : getRightMethod().equals(other.getRightMethod())));
1031        }
1032
1033        /**
1034         * Gets the CascadeDelete attribute of the RelationHolder object
1035         *
1036         * @param method Describe what the parameter does
1037         * @param tag Describe what the parameter does
1038         * @return The CascadeDelete value
1039         * @exception XDocletException
1040         */

1041        private boolean isCascadeDelete(XMethod method, String JavaDoc tag) throws XDocletException
1042        {
1043            String JavaDoc cd = null;
1044
1045            cd = getTagValue(
1046                FOR_METHOD,
1047                method.getDoc(),
1048                "ejb:relation",
1049                tag,
1050                "yes,no,true,false",
1051                "no",
1052                false,
1053                false
1054                );
1055            return TypeConversionUtil.stringToBoolean(cd, false);
1056        }
1057    }
1058}
1059
Popular Tags