User: rinkrank
  Date: 02/03/23 07:03:35

  Modified:    core/src/xdoclet/ejb/tags Tag: XJAVADOC_REFACTORING
                        RelationTagsHandler.java
  Log:
  Fixed a bug with unidirectional n->1relationships
  Fixed WLS persistence bug for BMP
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.20.2.3  +180 -127  xdoclet/core/src/xdoclet/ejb/tags/RelationTagsHandler.java
  
  Index: RelationTagsHandler.java
  ===================================================================
  RCS file: 
/cvsroot/xdoclet/xdoclet/core/src/xdoclet/ejb/tags/RelationTagsHandler.java,v
  retrieving revision 1.20.2.2
  retrieving revision 1.20.2.3
  diff -u -w -r1.20.2.2 -r1.20.2.3
  --- RelationTagsHandler.java  17 Mar 2002 07:21:26 -0000      1.20.2.2
  +++ RelationTagsHandler.java  23 Mar 2002 15:03:35 -0000      1.20.2.3
  @@ -11,6 +11,7 @@
   
   import xdoclet.util.Log;
   import xdoclet.util.Translator;
  +import xdoclet.util.TypeConversionUtil;
   
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -22,7 +23,7 @@
    * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @author    Ara Abrahamian ([EMAIL PROTECTED])
    * @created   Oct 15, 2001
  - * @version   $Revision: 1.20.2.2 $
  + * @version   $Revision: 1.20.2.3 $
    */
   public class RelationTagsHandler extends EjbTagsHandler
   {
  @@ -49,19 +50,10 @@
         */
        public void ifLeftCascadeDelete( String template ) throws XDocletException
        {
  -             String cd = getTagValue(
  -                     currentRelation.getLeftMethod().doc(),
  -                     "ejb:relation",
  -                     "cascade-delete",
  -                     "yes,no",
  -                     "no",
  -                     false,
  -                     false
  -             );
  -
  -             if( "yes".equals( cd ) )
  +             if( currentRelation.isLeftCascadeDelete() ) {
                        generate( template );
        }
  +     }
   
        /**
         * Evaluates the body if the right side of this relation has
  @@ -73,32 +65,10 @@
         */
        public void ifRightCascadeDelete( String template ) throws XDocletException
        {
  -             String cd = null;
  -
  -             if( isBidirectional() )
  -                     cd = getTagValue(
  -                             currentRelation.getRightMethod().doc(),
  -                             "ejb:relation",
  -                             "cascade-delete",
  -                             "yes,no",
  -                             "no",
  -                             false,
  -                             false
  -                     );
  -             else
  -                     cd = getTagValue(
  -                             currentRelation.getLeftMethod().doc(),
  -                             "ejb:relation",
  -                             "target-cascade-delete",
  -                             "yes,no",
  -                             "no",
  -                             false,
  -                             false
  -                     );
  -
  -             if( "yes".equals( cd ) )
  +             if( currentRelation.isRightCascadeDelete() ) {
                        generate( template );
        }
  +     }
   
        /**
         * Returns the EJB Name of the left side of this relationship
  @@ -108,8 +78,22 @@
         */
        public String leftEJBName() throws XDocletException
        {
  +             if( currentRelation.getLeft() != null ) {
                return EjbTagsHandler.getEjbNameFor( currentRelation.getLeft() );
        }
  +             else {
  +                     String name = getTagValue(
  +                             currentRelation.getRightMethod().doc(),
  +                             "ejb:relation",
  +                             "target-ejb",
  +                             null,
  +                             null,
  +                             true,
  +                             !currentRelation.isBidirectional()
  +                     );
  +                     return name;
  +             }
  +     }
   
        /**
         * Returns the EJB Name of the right side of this relationship
  @@ -119,18 +103,21 @@
         */
        public String rightEJBName() throws XDocletException
        {
  -             if( isBidirectional() )
  +             if( currentRelation.getRight() != null ) {
                        return EjbTagsHandler.getEjbNameFor( 
currentRelation.getRight() );
  -             else
  -                     return getTagValue(
  +             }
  +             else {
  +                     String name = getTagValue(
                                currentRelation.getLeftMethod().doc(),
                                "ejb:relation",
                                "target-ejb",
                                null,
                                null,
                                true,
  -                             true
  +                             !currentRelation.isBidirectional()
                        );
  +                     return name;
  +             }
        }
   
        /**
  @@ -242,36 +229,38 @@
                                                relationHolder = new RelationHolder();
                                                relationHolder.left = classes[i];
                                                relationHolder.leftMethod = methods[j];
  -                                             relationHolder.right = null;
                                                relationMap.put( relationName, 
relationHolder );
                                        }
                                        else
                                        {
  -                                             if( cat.isDebugEnabled() )
  +                                             if( cat.isDebugEnabled() ) {
                                                        cat.debug( "Added " + 
classes[i] + " to relationship: " + relationHolder );
  -                                             //Check current "left" method to see 
if it returns a collection.  If it doesn't, it may be
  -                                             //the n side of a 1-n.  If the current 
method is a collection, this is 1-n, so order them
  -                                             //that way (makes templates easier to 
code)
  -                                             if( !isSetOrCollection( 
MethodTagsHandler.getMethodTypeFor( relationHolder.leftMethod ) )
  -                                                      && isSetOrCollection( 
MethodTagsHandler.getMethodTypeFor( methods[j] ) ) )
  -                                             {
  -                                                     if( cat.isDebugEnabled() )
  -                                                             cat.debug( "Swapping 
left -> right in attempt to make 1-n be 1-n (rather than n-1)" );
  -                                                     relationHolder.right = 
relationHolder.left;
  -                                                     relationHolder.rightMethod = 
relationHolder.leftMethod;
  -                                                     relationHolder.left = 
classes[i];
  -                                                     relationHolder.leftMethod = 
methods[j];
                                                }
  -                                             else
  -                                             {
  -                                                     //left wasn't a collection
                                                        relationHolder.right = 
classes[i];
                                                        relationHolder.rightMethod = 
methods[j];
                                                }
                                        }
                                }
                        }
  -             }
  +             // Now swap relations so that right is always many. This may result
  +             // in left being null, in case of a unidirectional relationship
  +//           Iterator relations = relationMap.entrySet().iterator();
  +//           while( relations.hasNext() ) {
  +//                   Map.Entry entry = (Map.Entry) relations.next();
  +//                   RelationHolder relationHolder = (RelationHolder) 
entry.getValue();
  +//                   if( relationHolder.isLeftMany() && 
!relationHolder.isRightMany() ) {
  +//                           // swap
  +//                           if( cat.isDebugEnabled() ) {
  +//                                   cat.debug( "Swapping left -> right in attempt 
to make 1-n be 1-n (rather than n-1)" );
  +//                           }
  +//                           XClass c = relationHolder.right;
  +//                           XMethod m = relationHolder.rightMethod;
  +//                           relationHolder.right = relationHolder.left;
  +//                           relationHolder.rightMethod = relationHolder.leftMethod;
  +//                           relationHolder.left = c;
  +//                           relationHolder.leftMethod = m;
  +//                   }
  +//                   }
   
                // Loop over all relations
                Iterator relationNameIterator = relationMap.keySet().iterator();
  @@ -289,29 +278,29 @@
                        currentRelation = relationHolder;
   
                        // Get the target-ejb value (null or not), so we can perform 
sanity checks.
  -                     String target = 
relationHolder.getLeftMethod().doc().tagAttributeValue( "ejb:relation", "target-ejb" );
  -                     if( relationHolder.getRight() == null )
  -                     {
  -                             // Relation has only been declared in one method. That 
means it is unidirectional and requires
  -                             // target-ejb to be set. Perform the sanity check here 
before we give the template
  -                             // a chance to do something stupid.
  -
  -                             if( target == null )
  -                             {
  -                                     throw new XDocletException( 
Translator.getString( "xdoclet.ejb.Messages", "relation_needs_target",
  -                                             new String[]{relationName, 
relationHolder.getLeft().name() + "." + relationHolder.getLeftMethod().name()} ) );
  -                             }
  -                     }
  -                     else
  -                     {
  -                             // Relation has been declared in exactly two methods. 
That means target-ejb is forbidden, since its
  -                             // presence will result in invalid relations element 
in ejb-jar.xml
  -                             if( target != null )
  -                             {
  -                                     throw new XDocletException( 
Translator.getString( "xdoclet.ejb.Messages", "relation_needs_no_target",
  -                                             new String[]{relationName, 
relationHolder.getLeft().name() + "." + relationHolder.getLeftMethod().name()} ) );
  -                             }
  -                     }
  +//                   String target = 
relationHolder.getLeftMethod().doc().tagAttributeValue( "ejb:relation", "target-ejb" );
  +//                   if( relationHolder.getRight() == null )
  +//                   {
  +//                           // Relation has only been declared in one method. That 
means it is unidirectional and requires
  +//                           // target-ejb to be set. Perform the sanity check here 
before we give the template
  +//                           // a chance to do something stupid.
  +//
  +//                           if( target == null )
  +//                           {
  +//                                   throw new XDocletException( 
Translator.getString( "xdoclet.ejb.Messages", "relation_needs_target",
  +//                                           new String[]{relationName, 
relationHolder.getLeft().name() + "." + relationHolder.getLeftMethod().name()} ) );
  +//                           }
  +//                   }
  +//                   else
  +//                   {
  +//                           // Relation has been declared in exactly two methods. 
That means target-ejb is forbidden, since its
  +//                           // presence will result in invalid relations element 
in ejb-jar.xml
  +//                           if( target != null )
  +//                           {
  +//                                   throw new XDocletException( 
Translator.getString( "xdoclet.ejb.Messages", "relation_needs_no_target",
  +//                                           new String[]{relationName, 
relationHolder.getLeft().name() + "." + relationHolder.getLeftMethod().name()} ) );
  +//                           }
  +//                   }
   
                        if( cat.isDebugEnabled() )
                                cat.debug( "Generating template for Relation: " + 
currentRelation );
  @@ -383,7 +372,7 @@
         */
        public void ifIsOne2One( String template ) throws XDocletException
        {
  -             if( isOne2One() )
  +             if( currentRelation.isOne2One() )
                        generate( template );
        }
   
  @@ -399,7 +388,7 @@
         */
        public void ifNotIsOne2One( String template ) throws XDocletException
        {
  -             if( !isOne2One() )
  +             if( !currentRelation.isOne2One() )
                        generate( template );
        }
   
  @@ -415,7 +404,7 @@
         */
        public void ifIsOne2Many( String template ) throws XDocletException
        {
  -             if( isOne2Many() )
  +             if( currentRelation.isOne2Many() )
                        generate( template );
        }
   
  @@ -431,7 +420,7 @@
         */
        public void ifNotIsOne2Many( String template ) throws XDocletException
        {
  -             if( !isOne2Many() )
  +             if( !currentRelation.isOne2Many() )
                        generate( template );
        }
   
  @@ -447,7 +436,7 @@
         */
        public void ifIsMany2Many( String template ) throws XDocletException
        {
  -             if( isMany2Many() )
  +             if( currentRelation.isMany2Many() )
                        generate( template );
        }
   
  @@ -463,19 +452,19 @@
         */
        public void ifNotIsMany2Many( String template ) throws XDocletException
        {
  -             if( !isMany2Many() )
  +             if( !currentRelation.isMany2Many() )
                        generate( template );
        }
   
        public void ifIsBidirectional( String template ) throws XDocletException
        {
  -             if( isBidirectional() )
  +             if( currentRelation.isBidirectional() )
                        generate( template );
        }
   
        public void ifIsUnidirectional( String template ) throws XDocletException
        {
  -             if( !isBidirectional() )
  +             if( !currentRelation.isBidirectional() )
                        generate( template );
        }
   
  @@ -495,6 +484,22 @@
                }
        }
   
  +     public void ifLeftNavigable( String template ) throws XDocletException
  +     {
  +             if( currentRelation.isLeftNavigable() )
  +             {
  +                     generate( template );
  +             }
  +     }
  +
  +     public void ifRightNavigable( String template ) throws XDocletException
  +     {
  +             if( currentRelation.isRightNavigable() )
  +             {
  +                     generate( template );
  +             }
  +     }
  +
        public String leftRoleName() throws XDocletException
        {
                return currentRelation.getLeftRoleName();
  @@ -527,26 +532,6 @@
                return ( type.equals( "java.util.Collection" ) || type.equals( 
"java.util.Set" ) );
        }
   
  -     protected boolean isMany2Many() throws XDocletException
  -     {
  -             return currentRelation.isMany2Many();
  -     }
  -
  -     protected boolean isOne2One() throws XDocletException
  -     {
  -             return currentRelation.isOne2One();
  -     }
  -
  -     protected boolean isOne2Many() throws XDocletException
  -     {
  -             return currentRelation.isOne2Many();
  -     }
  -
  -     protected boolean isBidirectional() throws XDocletException
  -     {
  -             return currentRelation.isBidirectional();
  -     }
  -
        /**
         * Holds class/method of the two end points of a relationship.
         *
  @@ -564,7 +549,7 @@
   
                public boolean isBidirectional()
                {
  -                     return getRightMethod() != null;
  +                     return getRightMethod() != null && getLeftMethod() != null;
                }
   
                public boolean isOne2One() throws XDocletException
  @@ -612,39 +597,99 @@
                        return rightMethod;
                }
   
  +             public boolean isRightNavigable() {
  +                     return getRightMethod() != null;
  +             }
  +
  +             public boolean isLeftNavigable() {
  +                     return getLeftMethod() != null;
  +             }
  +
                public String getLeftRoleName() throws XDocletException
                {
  -                     return getLeftMethod().doc().tagAttributeValue( 
"ejb:relation", "role-name", false );
  +                     String result = null;
  +                     if( getLeftMethod() != null )
  +                             result = getLeftMethod().doc().tagAttributeValue( 
"ejb:relation", "role-name", false );
  +                     else
  +                     {
  +                             result = getRightMethod().doc().tagAttributeValue( 
"ejb:relation", "target-role-name", false );
  +                     }
  +                     return result;
                }
   
                public String getRightRoleName() throws XDocletException
                {
  -                     if( isBidirectional() )
  -                     {
  -                             return getRightMethod().doc().tagAttributeValue( 
"ejb:relation", "role-name", false );
  -                     }
  +                     String result = null;
  +                     if( getRightMethod() != null )
  +                             result = getRightMethod().doc().tagAttributeValue( 
"ejb:relation", "role-name", false );
                        else
                        {
  -                             return getLeftMethod().doc().tagAttributeValue( 
"ejb:relation", "target-role-name", false );
  +                             result = getLeftMethod().doc().tagAttributeValue( 
"ejb:relation", "target-role-name", false );
                        }
  +                     return result;
                }
   
                public boolean isLeftMany() throws XDocletException
                {
  -                     return isSetOrCollection( MethodTagsHandler.getMethodTypeFor( 
getLeftMethod() ) );
  +                     boolean result;
  +                     if( getLeftMethod() != null )
  +                             result = isSetOrCollection( 
getLeftMethod().returnType().qualifiedName() );
  +                     else
  +                     {
  +                             String targetMultiple = 
getRightMethod().doc().tagAttributeValue( "ejb:relation", "target-multiple", false );
  +                             result = 
TypeConversionUtil.stringToBoolean(targetMultiple,false);
  +                     }
  +                     return result;
                }
   
                public boolean isRightMany() throws XDocletException
                {
                        boolean result;
  -
                        if( getRightMethod() != null )
  -                             result = isSetOrCollection( 
MethodTagsHandler.getMethodTypeFor( getRightMethod() ) );
  +                             result = isSetOrCollection( 
getRightMethod().returnType().qualifiedName() );
                        else
                        {
                                String targetMultiple = 
getLeftMethod().doc().tagAttributeValue( "ejb:relation", "target-multiple", false );
  +                             result = 
TypeConversionUtil.stringToBoolean(targetMultiple,false);
  +                     }
  +                     return result;
  +             }
   
  -                             result = "yes".equals( targetMultiple );
  +             private boolean isCascadeDelete( XMethod method, String tag ) throws 
XDocletException
  +             {
  +                     String cd = null;
  +                     cd = getTagValue(
  +                             method.doc(),
  +                             "ejb:relation",
  +                             tag,
  +                             "yes,no,true,false",
  +                             "no",
  +                             false,
  +                             false
  +                     );
  +                     return TypeConversionUtil.stringToBoolean(cd, false);
  +             }
  +
  +             public boolean isLeftCascadeDelete() throws XDocletException
  +             {
  +                     boolean result;
  +                     if( getLeftMethod() != null )
  +                             result = isCascadeDelete( getLeftMethod(), 
"cascade-delete" );
  +                     else
  +                     {
  +                             result = isCascadeDelete( getRightMethod(), 
"target-cascade-delete" );
  +                     }
  +                     return result;
  +             }
  +
  +             public boolean isRightCascadeDelete() throws XDocletException
  +             {
  +                     boolean result;
  +                     if( getRightMethod() != null )
  +                             result = isCascadeDelete( getRightMethod(), 
"cascade-delete" );
  +                     else
  +                     {
  +                             result = isCascadeDelete( getLeftMethod(), 
"target-cascade-delete" );
                        }
                        return result;
                }
  @@ -655,14 +700,22 @@
                 */
                public String getName() throws XDocletException
                {
  -                     return getLeftMethod().doc().tagAttributeValue( 
"ejb:relation", "name", false );
  +                     String result = null;
  +                     if( getRightMethod() != null )
  +                             result = getRightMethod().doc().tagAttributeValue( 
"ejb:relation", "name", false );
  +                     else
  +                     {
  +                             result = getLeftMethod().doc().tagAttributeValue( 
"ejb:relation", "name", false );
  +                     }
  +                     return result;
                }
   
                public int hashCode()
                {
                        int result = 17;
  -
  +                     if( getLeft() != null )
                        result = 37 * result + getLeft().hashCode();
  +                     if( getLeftMethod() != null )
                        result = 37 * result + getLeftMethod().hashCode();
                        if( getRight() != null )
                                result = 37 * result + getRight().hashCode();
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to