User: dsundstrom
  Date: 01/11/03 11:51:17

  Modified:    src/main/org/jboss/metadata ApplicationMetaData.java
                        RelationMetaData.java RelationshipRoleMetaData.java
  Log:
  Added code to assure that ejb-relation-name is unique in the application
  and that ejb-relationship-role-name is unique in the relation.
  
  Revision  Changes    Path
  1.23      +18 -1     jboss/src/main/org/jboss/metadata/ApplicationMetaData.java
  
  Index: ApplicationMetaData.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/metadata/ApplicationMetaData.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ApplicationMetaData.java  2001/08/03 17:15:54     1.22
  +++ ApplicationMetaData.java  2001/11/03 19:51:17     1.23
  @@ -28,7 +28,7 @@
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>.
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  - *   @version $Revision: 1.22 $
  + *   @version $Revision: 1.23 $
    */
   public class ApplicationMetaData extends MetaData
   {
  @@ -204,6 +204,10 @@
         // Relationships
                Element relationshipsElement = getOptionalChild(element, 
"relationships");
                if(relationshipsElement != null) {
  +         
  +         // used to assure that a relationship name is not reused
  +         Set relationNames = new HashSet();
  +         
                        iterator = getChildrenByTagName(relationshipsElement, 
"ejb-relation");
                        while(iterator.hasNext()) {
                                Element relationElement = (Element)iterator.next();
  @@ -213,6 +217,19 @@
                                } catch (DeploymentException e) {
                                        throw new DeploymentException("Error in 
ejb-jar.xml for relation " + relationMetaData.getRelationName() + ": " + 
e.getMessage());
                                }
  +            
  +            // if the relationship has a name, assure that 
  +            // it has not already been used
  +            String relationName = relationMetaData.getRelationName();
  +            if(relationName != null) {
  +               if(relationNames.contains(relationName)) {
  +                  throw new DeploymentException("ejb-relation-name must be " +
  +                        "unique in ejb-jar.xml file: ejb-relation-name is " +
  +                        relationName);
  +               }
  +               relationNames.add(relationName);
  +            }
  +            
                                relationships.add(relationMetaData);
                        }
                }       
  
  
  
  1.4       +102 -82   jboss/src/main/org/jboss/metadata/RelationMetaData.java
  
  Index: RelationMetaData.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/metadata/RelationMetaData.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RelationMetaData.java     2001/08/03 17:15:54     1.3
  +++ RelationMetaData.java     2001/11/03 19:51:17     1.4
  @@ -17,91 +17,111 @@
    * file's relationships elements.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class RelationMetaData extends MetaData {
  -     /** Name of the relation. Loaded from the ejb-relation-name element. */
  -     private String relationName;
  -     
  -     /** 
  -      * The left relationship role. Loaded from an ejb-relationship-role.
  -      * Left/right assignment is completely arbitrary.
  -      */
  -     private RelationshipRoleMetaData left;
  +   /** Name of the relation. Loaded from the ejb-relation-name element. */
  +   private String relationName;
  +   
  +   /** 
  +    * The left relationship role. Loaded from an ejb-relationship-role.
  +    * Left/right assignment is completely arbitrary.
  +    */
  +   private RelationshipRoleMetaData left;
   
  -     /** 
  -      * The right relationship role. Loaded from an ejb-relationship-role.
  -      * Left/right assignment is completely arbitrary.
  -      */
  -     private RelationshipRoleMetaData right;         
  -     
  -     /** 
  -      * Gets the relation name. 
  -      * Relation name is loaded from the ejb-relation-name element.
  -      */
  -     public String getRelationName() {
  -             return relationName;
  -     }
  -     
  -     /** 
  -      * Gets the left relationship role. 
  -      * The relationship role is loaded from an ejb-relationship-role.
  -      * Left/right assignment is completely arbitrary.
  -      */
  -     public RelationshipRoleMetaData getLeftRelationshipRole() {
  -             return left;
  -     }
  -     
  -     /** 
  -      * Gets the right relationship role.
  -      * The relationship role is loaded from an ejb-relationship-role.
  -      * Left/right assignment is completely arbitrary.
  -      */
  -     public RelationshipRoleMetaData getRightRelationshipRole() {
  -             return right;
  -     }
  -     
  -     public RelationshipRoleMetaData 
getOtherRelationshipRole(RelationshipRoleMetaData role) {
  -             if(left == role) {
  -                     return right;
  -             } else if(right == role) {
  -                     return left;
  -             } else {
  -                     throw new IllegalArgumentException("Specified role is not the 
left or right role. role=" + role);
  -             }
  -     }
  +   /** 
  +    * The right relationship role. Loaded from an ejb-relationship-role.
  +    * Left/right assignment is completely arbitrary.
  +    */
  +   private RelationshipRoleMetaData right;      
  +   
  +   /** 
  +    * Gets the relation name. 
  +    * Relation name is loaded from the ejb-relation-name element.
  +    */
  +   public String getRelationName() {
  +      return relationName;
  +   }
  +   
  +   /** 
  +    * Gets the left relationship role. 
  +    * The relationship role is loaded from an ejb-relationship-role.
  +    * Left/right assignment is completely arbitrary.
  +    */
  +   public RelationshipRoleMetaData getLeftRelationshipRole() {
  +      return left;
  +   }
  +   
  +   /** 
  +    * Gets the right relationship role.
  +    * The relationship role is loaded from an ejb-relationship-role.
  +    * Left/right assignment is completely arbitrary.
  +    */
  +   public RelationshipRoleMetaData getRightRelationshipRole() {
  +      return right;
  +   }
  +   
  +   public RelationshipRoleMetaData getOtherRelationshipRole(
  +         RelationshipRoleMetaData role) {
  +
  +      if(left == role) {
  +         return right;
  +      } else if(right == role) {
  +         return left;
  +      } else {
  +         throw new IllegalArgumentException("Specified role is not the left " +
  +               "or right role. role=" + role);
  +      }
  +   }
  +
      public void importEjbJarXml (Element element) throws DeploymentException {
  -        // name
  -             relationName = getElementContent(getOptionalChild(element, 
"ejb-relation-name"));
  -             
  -             // left role
  -             Iterator iter = getChildrenByTagName(element, "ejb-relationship-role");
  -             if(iter.hasNext()) {
  -                     left = new RelationshipRoleMetaData(this);
  -                     left.importEjbJarXml((Element) iter.next());
  -             } else {
  -                     throw new DeploymentException("Expected 2 
ejb-relationship-role roles but found none");
  -             }
  -             
  -             // right role
  -             if(iter.hasNext()) {
  -                     right = new RelationshipRoleMetaData(this);
  -                     right.importEjbJarXml((Element) iter.next());
  -             } else {
  -                     throw new DeploymentException("Expected 2 
ejb-relationship-role but only found one");
  -             }
  +      // name
  +      relationName = getOptionalChildContent(element, "ejb-relation-name");
  +      
  +      // left role
  +      Iterator iter = getChildrenByTagName(element, "ejb-relationship-role");
  +      if(iter.hasNext()) {
  +         left = new RelationshipRoleMetaData(this);
  +         left.importEjbJarXml((Element) iter.next());
  +      } else {
  +         throw new DeploymentException("Expected 2 ejb-relationship-role " +
  +               "roles but found none");
  +      }
  +      
  +      // right role
  +      if(iter.hasNext()) {
  +         right = new RelationshipRoleMetaData(this);
  +         right.importEjbJarXml((Element) iter.next());
  +      } else {
  +         throw new DeploymentException("Expected 2 ejb-relationship-role " +
  +               "but only found one");
  +      }
   
  -             // assure there are only two ejb-relationship-role elements
  -             if(iter.hasNext()) {
  -                     throw new DeploymentException("Expected only 2 
ejb-relationship-role but found more then 2");
  -             }
  -             
  -             // verify cascade delete
  -             if(left.isCascadeDelete() && right.isMultiplicityMany()) {
  -                     throw new DeploymentException("cascade-delete is only allowed 
in ejb-relationship-role where the other role has a multiplicity One");
  -             }
  -             if(right.isCascadeDelete() && left.isMultiplicityMany()) {
  -                     throw new DeploymentException("cascade-delete is only allowed 
in ejb-relationship-role where the other role has a multiplicity One");
  -             }
  -     }
  +      // assure there are only two ejb-relationship-role elements
  +      if(iter.hasNext()) {
  +         throw new DeploymentException("Expected only 2 ejb-relationship-" +
  +               "role but found more then 2");
  +      }
  +      
  +      // assure that the left role and right role do not have the same name
  +      String leftName = left.getRelationshipRoleName();
  +      String rightName = right.getRelationshipRoleName();
  +      if(leftName != null && leftName.equals(rightName)) {
  +         throw new DeploymentException("ejb-relationship-role-name must be " +
  +               "unique in ejb-relation: ejb-relationship-role-name is " +
  +               leftName);
  +      }
  +      
  +      // verify cascade delete
  +      if(left.isCascadeDelete() && right.isMultiplicityMany()) {
  +         throw new DeploymentException("cascade-delete is only allowed in " +
  +               "ejb-relationship-role where the other role has a " +
  +               "multiplicity One");
  +      }
  +      if(right.isCascadeDelete() && left.isMultiplicityMany()) {
  +         throw new DeploymentException("cascade-delete is only allowed in " +
  +               "ejb-relationship-role where the other role has a " +
  +               "multiplicity One");
  +      }
  +   }
   }
  
  
  
  1.4       +155 -148  jboss/src/main/org/jboss/metadata/RelationshipRoleMetaData.java
  
  Index: RelationshipRoleMetaData.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/metadata/RelationshipRoleMetaData.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RelationshipRoleMetaData.java     2001/08/03 17:15:54     1.3
  +++ RelationshipRoleMetaData.java     2001/11/03 19:51:17     1.4
  @@ -14,157 +14,164 @@
    * file's ejb-relation elements.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class RelationshipRoleMetaData extends MetaData {
  -     // one is one
  -     private static int ONE = 1;
  -     // and two is many :)
  -     private static int MANY = 2;
  -     
  -     /**
  -      * Role name
  -      */
  -     private String relationshipRoleName;
  -     
  -     /**
  -      * The relation to which the role belongs.
  -      */
  -      private RelationMetaData relationMetaData;
  -     
  -     /**
  -      * Multiplicity of role, ONE or MANY.
  -      */
  -     private int multiplicity;
  -     
  -     /**
  -      * Should this entity be deleted when related entity is deleted.
  -      */
  -     private boolean cascadeDelete;
  -     
  -     /**
  -      * Name of the entity that has this role.
  -      */
  -     private String entityName;
  -     
  -     /**
  -      * Name of the entity's cmr field for this role.
  -      */
  -     private String cmrFieldName;
  -     
  -     /**
  -      * Type of the cmr field (i.e., collection or set)
  -      */
  -     private String cmrFieldType;
  +   // one is one
  +   private static int ONE = 1;
  +   // and two is many :)
  +   private static int MANY = 2;
  +   
  +   /**
  +    * Role name
  +    */
  +   private String relationshipRoleName;
  +   
  +   /**
  +    * The relation to which the role belongs.
  +    */
  +    private RelationMetaData relationMetaData;
  +   
  +   /**
  +    * Multiplicity of role, ONE or MANY.
  +    */
  +   private int multiplicity;
  +   
  +   /**
  +    * Should this entity be deleted when related entity is deleted.
  +    */
  +   private boolean cascadeDelete;
  +   
  +   /**
  +    * Name of the entity that has this role.
  +    */
  +   private String entityName;
  +   
  +   /**
  +    * Name of the entity's cmr field for this role.
  +    */
  +   private String cmrFieldName;
  +   
  +   /**
  +    * Type of the cmr field (i.e., collection or set)
  +    */
  +   private String cmrFieldType;
   
  -     public RelationshipRoleMetaData(RelationMetaData relationMetaData) {
  -             this.relationMetaData = relationMetaData;
  -     }
  -     
  -     /**
  -      * Gets the relationship role name
  -      */
  -     public String getRelationshipRoleName() {
  -             return relationshipRoleName;
  -     }
  +   public RelationshipRoleMetaData(RelationMetaData relationMetaData) {
  +      this.relationMetaData = relationMetaData;
  +   }
  +   
  +   /**
  +    * Gets the relationship role name
  +    */
  +   public String getRelationshipRoleName() {
  +      return relationshipRoleName;
  +   }
   
  -     /**
  -      * Gets the relation meta data to which the role belongs.
  -      * @returns the relation to which the relationship role belongs
  -      */
  -     public RelationMetaData getRelationMetaData() {
  -             return relationMetaData;
  -     }
  -     
  -     /**
  -      * Gets the related role's metadata
  -      */
  -     public RelationshipRoleMetaData getRelatedRoleMetaData() {
  -             return relationMetaData.getOtherRelationshipRole(this);
  -     }
  -     
  -     /**
  -      * Checks if the multiplicity is one.
  -      */
  -     public boolean isMultiplicityOne() {
  -             return multiplicity == ONE;
  -     }
  -     
  -     /**
  -      * Checks if the multiplicity is many.
  -      */
  -     public boolean isMultiplicityMany() {
  -             return multiplicity == MANY;
  -     }
  -     
  -     /**
  -      * Should this entity be deleted when related entity is deleted.
  -      */
  -     public boolean isCascadeDelete() {
  -             return cascadeDelete;
  -     }
  -     
  -     /**
  -      * Gets the name of the entity that has this role.
  -      */
  -     public String getEntityName() {
  -             return entityName;
  -     }
  -     
  -     /**
  -      * Gets the name of the entity's cmr field for this role.
  -      */
  -     public String getCMRFieldName() {
  -             return cmrFieldName;
  -     }
  -     
  -     /**
  -      * Gets the type of the cmr field (i.e., collection or set)
  -      */
  -     public String getCMRFieldType() {
  -             return cmrFieldType;
  -     }
  -     
  +   /**
  +    * Gets the relation meta data to which the role belongs.
  +    * @returns the relation to which the relationship role belongs
  +    */
  +   public RelationMetaData getRelationMetaData() {
  +      return relationMetaData;
  +   }
  +   
  +   /**
  +    * Gets the related role's metadata
  +    */
  +   public RelationshipRoleMetaData getRelatedRoleMetaData() {
  +      return relationMetaData.getOtherRelationshipRole(this);
  +   }
  +   
  +   /**
  +    * Checks if the multiplicity is one.
  +    */
  +   public boolean isMultiplicityOne() {
  +      return multiplicity == ONE;
  +   }
  +   
  +   /**
  +    * Checks if the multiplicity is many.
  +    */
  +   public boolean isMultiplicityMany() {
  +      return multiplicity == MANY;
  +   }
  +   
  +   /**
  +    * Should this entity be deleted when related entity is deleted.
  +    */
  +   public boolean isCascadeDelete() {
  +      return cascadeDelete;
  +   }
  +   
  +   /**
  +    * Gets the name of the entity that has this role.
  +    */
  +   public String getEntityName() {
  +      return entityName;
  +   }
  +   
  +   /**
  +    * Gets the name of the entity's cmr field for this role.
  +    */
  +   public String getCMRFieldName() {
  +      return cmrFieldName;
  +   }
  +   
  +   /**
  +    * Gets the type of the cmr field (i.e., collection or set)
  +    */
  +   public String getCMRFieldType() {
  +      return cmrFieldType;
  +   }
  +   
      public void importEjbJarXml (Element element) throws DeploymentException {
  -        // ejb-relationship-role-name?
  -             relationshipRoleName = getElementContent(getOptionalChild(element, 
"ejb-relationship-role-name"));
  -             
  -             // multiplicity
  -             String multiplicityString = getElementContent(getUniqueChild(element, 
"multiplicity"));
  -             if("One".equals(multiplicityString)) {
  -                     multiplicity = ONE;
  -             } else if("Many".equals(multiplicityString)) {
  -                     multiplicity = MANY;
  -             } else {
  -                     throw new DeploymentException("multiplicity should be One or 
Many but is " + multiplicityString);
  -             }
  -             
  -             // cascade-delete? 
  -             Element cascadeDeleteElement = getOptionalChild(element, 
"cascade-delete");
  -             if(cascadeDeleteElement != null) {
  -                     cascadeDelete = true;
  -             }
  -             
  -             // relationship-role-source
  -             Element relationshipRoleSourceElement = getUniqueChild(element, 
"relationship-role-source");
  -             entityName = 
getElementContent(getUniqueChild(relationshipRoleSourceElement, "ejb-name"));
  -             
  -             // cmr-field?
  -             Element cmrFieldElement = getOptionalChild(element, "cmr-field");
  -             if(cmrFieldElement != null) {
  -                     // cmr-field-name
  -                     cmrFieldName = 
getElementContent(getUniqueChild(cmrFieldElement, "cmr-field-name"));
  -                     
  -                // cmr-field-type?
  -                     Element cmrFieldTypeElement = 
getOptionalChild(cmrFieldElement, "cmr-field-type");
  -                     if(cmrFieldTypeElement != null) {
  -                             cmrFieldType = getElementContent(cmrFieldTypeElement);
  -                             if(cmrFieldType==null || 
  -                                             
(!cmrFieldType.equals("java.util.Collection") && 
  -                                                     
!cmrFieldType.equals("java.util.Set"))) {
  -                                     throw new DeploymentException("multiplicity 
should be java.util.Collection or java.util.Set but is " + cmrFieldType);
  -                             }
  -                     }
  -             }
  -     }
  +      // ejb-relationship-role-name?
  +      relationshipRoleName = 
  +            getOptionalChildContent(element, "ejb-relationship-role-name");
  +      
  +      // multiplicity
  +      String multiplicityString = 
  +            getUniqueChildContent(element, "multiplicity");
  +      if("One".equals(multiplicityString)) {
  +         multiplicity = ONE;
  +      } else if("Many".equals(multiplicityString)) {
  +         multiplicity = MANY;
  +      } else {
  +         throw new DeploymentException("multiplicity must be exactaly 'One' " +
  +               "or 'Many' but is " + multiplicityString + "; this is case " +
  +               "sensitive");
  +      }
  +      
  +      // cascade-delete? 
  +      if(getOptionalChild(element, "cascade-delete") != null) {
  +         cascadeDelete = true;
  +      }
  +      
  +      // relationship-role-source
  +      Element relationshipRoleSourceElement = 
  +            getUniqueChild(element, "relationship-role-source");
  +      entityName = 
  +            getUniqueChildContent(relationshipRoleSourceElement, "ejb-name");
  +      
  +      // cmr-field?
  +      Element cmrFieldElement = getOptionalChild(element, "cmr-field");
  +      if(cmrFieldElement != null) {
  +         // cmr-field-name
  +         cmrFieldName = 
  +               getUniqueChildContent(cmrFieldElement, "cmr-field-name");
  +         
  +         // cmr-field-type?
  +         cmrFieldType =
  +               getOptionalChildContent(cmrFieldElement, "cmr-field-type");
  +         if(cmrFieldType != null &&
  +               !cmrFieldType.equals("java.util.Collection") && 
  +               !cmrFieldType.equals("java.util.Set")) {
  +
  +            throw new DeploymentException("cmr-field-type should be " +
  +                  "java.util.Collection or java.util.Set but is " + 
  +                  cmrFieldType);
  +         }
  +      }
  +   }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to