1 19 20 package org.netbeans.modules.j2ee.ddloaders.multiview; 21 22 import org.netbeans.modules.j2ee.dd.api.ejb.CmrField; 23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbRelation; 24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbRelationshipRole; 25 import org.netbeans.modules.j2ee.dd.api.ejb.Relationships; 26 27 30 public class RelationshipHelper { 31 32 private static final String MULTIPLICITY_MANY = "Many"; 33 private static final String MULTIPLICITY_ONE = "One"; 34 35 private final EjbRelation relation; 36 37 public static class RelationshipRoleHelper { 38 39 private final EjbRelationshipRole role; 40 41 public RelationshipRoleHelper(EjbRelationshipRole role) { 42 this.role = role; 43 } 44 45 public boolean isMultiple() { 46 return MULTIPLICITY_MANY.equals(role.getMultiplicity()); 47 } 48 49 public void setMultiple(boolean multiple) { 50 role.setMultiplicity(multiple ? MULTIPLICITY_MANY : MULTIPLICITY_ONE); 51 } 52 53 public String getEjbName() { 54 return role.getRelationshipRoleSource().getEjbName(); 55 } 56 57 public void setEjbName(String ejbName) { 58 role.getRelationshipRoleSource().setEjbName(ejbName); 59 } 60 61 public String getRoleName() { 62 return role.getEjbRelationshipRoleName(); 63 } 64 65 public void setRoleName(String roleName) { 66 role.setEjbRelationshipRoleName(roleName); 67 } 68 69 public String getFieldName() { 70 CmrField field = role.getCmrField(); 71 return field == null ? null : field.getCmrFieldName(); 72 } 73 74 public String getFieldType() { 75 CmrField field = role.getCmrField(); 76 return field == null ? null : field.getCmrFieldType(); 77 } 78 79 public boolean isCascadeDelete() { 80 return role.isCascadeDelete(); 81 } 82 83 public void setCascadeDelete(boolean cascadeDelete) { 84 role.setCascadeDelete(cascadeDelete); 85 } 86 87 public CmrField getCmrField() { 88 return role.getCmrField(); 89 } 90 91 public void setCmrField(CmrField cmrField) { 92 role.setCmrField(cmrField); 93 } 94 95 public void setCmrField(String fieldName, String fieldType) { 96 CmrField field = role.getCmrField(); 97 if (field == null) { 98 role.setCmrField(field = role.newCmrField()); 99 } 100 field.setCmrFieldName(fieldName); 101 field.setCmrFieldType(fieldType); 102 } 103 104 } 105 106 public final RelationshipRoleHelper roleA; 107 public final RelationshipRoleHelper roleB; 108 109 public RelationshipHelper(EjbRelation relation) { 110 this.relation = relation; 111 roleA = new RelationshipRoleHelper(relation.getEjbRelationshipRole()); 112 roleB = new RelationshipRoleHelper(relation.getEjbRelationshipRole2()); 113 } 114 115 public RelationshipHelper(Relationships singleRelationships) { 116 relation = singleRelationships.newEjbRelation(); 117 EjbRelationshipRole roleA = newRole(); 118 relation.setEjbRelationshipRole(roleA); 119 EjbRelationshipRole roleB = newRole(); 120 relation.setEjbRelationshipRole2(roleB); 121 singleRelationships.addEjbRelation(relation); 122 this.roleA = new RelationshipRoleHelper(roleA); 123 this.roleB = new RelationshipRoleHelper(roleB); 124 } 125 126 private EjbRelationshipRole newRole() { 127 EjbRelationshipRole role = relation.newEjbRelationshipRole(); 128 role.setRelationshipRoleSource(role.newRelationshipRoleSource()); 129 return role; 130 } 131 132 public String getRelationName() { 133 return relation.getEjbRelationName(); 134 } 135 136 public void setRelationName(String relationName) { 137 relation.setEjbRelationName(relationName); 138 } 139 140 public String getDescription() { 141 return relation.getDefaultDescription(); 142 } 143 144 public void setDescription(String description) { 145 relation.setDescription(description); 146 } 147 148 } 149 | Popular Tags |