1 22 package org.jboss.metadata; 23 24 import org.w3c.dom.Element ; 25 import org.jboss.deployment.DeploymentException; 26 27 34 public class RelationshipRoleMetaData extends MetaData { 35 private static int ONE = 1; 37 private static int MANY = 2; 39 40 43 private String relationshipRoleName; 44 45 48 private RelationMetaData relationMetaData; 49 50 53 private int multiplicity; 54 55 58 private boolean cascadeDelete; 59 60 63 private String entityName; 64 65 68 private String cmrFieldName; 69 70 73 private String cmrFieldType; 74 75 public RelationshipRoleMetaData(RelationMetaData relationMetaData) { 76 this.relationMetaData = relationMetaData; 77 } 78 79 82 public String getRelationshipRoleName() { 83 return relationshipRoleName; 84 } 85 86 90 public RelationMetaData getRelationMetaData() { 91 return relationMetaData; 92 } 93 94 97 public RelationshipRoleMetaData getRelatedRoleMetaData() { 98 return relationMetaData.getOtherRelationshipRole(this); 99 } 100 101 104 public boolean isMultiplicityOne() { 105 return multiplicity == ONE; 106 } 107 108 111 public boolean isMultiplicityMany() { 112 return multiplicity == MANY; 113 } 114 115 118 public boolean isCascadeDelete() { 119 return cascadeDelete; 120 } 121 122 125 public String getEntityName() { 126 return entityName; 127 } 128 129 132 public String getCMRFieldName() { 133 return cmrFieldName; 134 } 135 136 139 public String getCMRFieldType() { 140 return cmrFieldType; 141 } 142 143 public void setRelationshipRoleName(String relationshipRoleName) 144 { 145 this.relationshipRoleName = relationshipRoleName; 146 } 147 148 public void setMultiplicity(String multiplicity) 149 { 150 if("One".equals(multiplicity)) 151 { 152 this.multiplicity = ONE; 153 } 154 else if("Many".equals(multiplicity)) 155 { 156 this.multiplicity = MANY; 157 } 158 else 159 { 160 throw new IllegalStateException ("multiplicity must be exactaly 'One' " + 161 "or 'Many' but is " + multiplicity + "; this is case " + 162 "sensitive"); 163 } 164 } 165 166 public void setCascadeDelete(boolean cascadeDelete) 167 { 168 this.cascadeDelete = cascadeDelete; 169 } 170 171 public void setEntityName(String entityName) 172 { 173 this.entityName = entityName; 174 } 175 176 public void setCmrFieldName(String cmrFieldName) 177 { 178 this.cmrFieldName = cmrFieldName; 179 } 180 181 public void setCmrFieldType(String cmrFieldType) 182 { 183 this.cmrFieldType = cmrFieldType; 184 } 185 186 public void importEjbJarXml (Element element) throws DeploymentException { 187 relationshipRoleName = 189 getOptionalChildContent(element, "ejb-relationship-role-name"); 190 191 String multiplicityString = 193 getUniqueChildContent(element, "multiplicity"); 194 if("One".equals(multiplicityString)) { 195 multiplicity = ONE; 196 } else if("Many".equals(multiplicityString)) { 197 multiplicity = MANY; 198 } else { 199 throw new DeploymentException("multiplicity must be exactaly 'One' " + 200 "or 'Many' but is " + multiplicityString + "; this is case " + 201 "sensitive"); 202 } 203 204 if(getOptionalChild(element, "cascade-delete") != null) { 206 cascadeDelete = true; 207 } 208 209 Element relationshipRoleSourceElement = 211 getUniqueChild(element, "relationship-role-source"); 212 entityName = 213 getUniqueChildContent(relationshipRoleSourceElement, "ejb-name"); 214 215 Element cmrFieldElement = getOptionalChild(element, "cmr-field"); 217 if(cmrFieldElement != null) { 218 cmrFieldName = 220 getUniqueChildContent(cmrFieldElement, "cmr-field-name"); 221 222 cmrFieldType = 224 getOptionalChildContent(cmrFieldElement, "cmr-field-type"); 225 if(cmrFieldType != null && 226 !cmrFieldType.equals("java.util.Collection") && 227 !cmrFieldType.equals("java.util.Set")) { 228 229 throw new DeploymentException("cmr-field-type should be " + 230 "java.util.Collection or java.util.Set but is " + 231 cmrFieldType); 232 } 233 } 234 235 if(relationshipRoleName == null) 237 { 238 relationshipRoleName = entityName + (cmrFieldName == null ? "" : "_" + cmrFieldName); 239 } 240 } 241 } 242 | Popular Tags |