1 22 package org.jboss.metadata; 23 24 import java.util.Iterator ; 25 26 import org.w3c.dom.Element ; 27 import org.jboss.deployment.DeploymentException; 28 29 37 public class RelationMetaData extends MetaData 38 { 39 private String description; 40 private String displayName; 41 42 private String relationName; 43 44 48 private RelationshipRoleMetaData left; 49 50 54 private RelationshipRoleMetaData right; 55 56 public String getDescription() 57 { 58 return description; 59 } 60 61 public void setDescription(String description) 62 { 63 this.description = description; 64 } 65 66 public String getDisplayName() 67 { 68 return displayName; 69 } 70 71 public void setDisplayName(String displayName) 72 { 73 this.displayName = displayName; 74 } 75 76 80 public String getRelationName() 81 { 82 return relationName; 83 } 84 85 public void setRelationName(String name) 86 { 87 relationName = name; 88 if( relationName != null && relationName.length() == 0 ) 89 relationName = null; 90 } 91 92 96 public RelationshipRoleMetaData getLeftRelationshipRole() 97 { 98 return left; 99 } 100 101 public void setLeftRelationshipRole(RelationshipRoleMetaData left) 102 { 103 this.left = left; 104 } 105 106 110 public RelationshipRoleMetaData getRightRelationshipRole() 111 { 112 return right; 113 } 114 115 public void setRightRelationshipRole(RelationshipRoleMetaData left) 116 { 117 this.right = left; 118 } 119 120 public RelationshipRoleMetaData getOtherRelationshipRole(RelationshipRoleMetaData role) 121 { 122 if (left == role) 123 { 124 return right; 125 } 126 else if (right == role) 127 { 128 return left; 129 } 130 else 131 { 132 throw new IllegalArgumentException ("Specified role is not the left " 133 + "or right role. role=" + role); 134 } 135 } 136 137 public void importEjbJarXml(Element element) throws DeploymentException 138 { 139 relationName = getOptionalChildContent(element, "ejb-relation-name"); 141 if ("".equals(relationName)) 142 { 143 relationName = null; 144 } 145 146 Iterator iter = getChildrenByTagName(element, "ejb-relationship-role"); 148 if (iter.hasNext()) 149 { 150 left = new RelationshipRoleMetaData(this); 151 left.importEjbJarXml((Element ) iter.next()); 152 } else 153 { 154 throw new DeploymentException("Expected 2 ejb-relationship-role " 155 + "roles but found none"); 156 } 157 158 if (iter.hasNext()) 160 { 161 right = new RelationshipRoleMetaData(this); 162 right.importEjbJarXml((Element ) iter.next()); 163 } else 164 { 165 throw new DeploymentException("Expected 2 ejb-relationship-role " 166 + "but only found one"); 167 } 168 169 if (iter.hasNext()) 171 { 172 throw new DeploymentException("Expected only 2 ejb-relationship-" 173 + "role but found more then 2"); 174 } 175 176 if (relationName == null) 179 { 180 setDefaultRelationName(); 183 } 184 185 String leftName = left.getRelationshipRoleName(); 187 String rightName = right.getRelationshipRoleName(); 188 if (leftName != null && leftName.equals(rightName)) 189 { 190 throw new DeploymentException("ejb-relationship-role-name must be " 191 + "unique in ejb-relation: ejb-relationship-role-name is " 192 + leftName); 193 } 194 195 if (left.isCascadeDelete() && right.isMultiplicityMany()) 197 { 198 throw new DeploymentException("cascade-delete is only allowed in " 199 + "ejb-relationship-role where the other role has a " 200 + "multiplicity One"); 201 } 202 if (right.isCascadeDelete() && left.isMultiplicityMany()) 203 { 204 throw new DeploymentException("cascade-delete is only allowed in " 205 + "ejb-relationship-role where the other role has a " 206 + "multiplicity One"); 207 } 208 } 209 210 public void setDefaultRelationName() 211 { 212 relationName = left.getEntityName() 213 + (left.getCMRFieldName() == null ? "" : "_" 214 + left.getCMRFieldName()) 215 + "-" 216 + right.getEntityName() 217 + (right.getCMRFieldName() == null ? "" : "_" 218 + right.getCMRFieldName()); 219 } 220 } 221 | Popular Tags |