1 17 package org.alfresco.repo.dictionary; 18 19 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 20 import org.alfresco.service.cmr.dictionary.ClassDefinition; 21 import org.alfresco.service.cmr.dictionary.DictionaryException; 22 import org.alfresco.service.cmr.dictionary.ModelDefinition; 23 import org.alfresco.service.namespace.NamespacePrefixResolver; 24 import org.alfresco.service.namespace.QName; 25 26 27 32 class M2AssociationDefinition implements AssociationDefinition 33 { 34 35 private ClassDefinition classDef; 36 private M2ClassAssociation assoc; 37 private QName name; 38 private QName targetClassName; 39 private ClassDefinition targetClass; 40 private QName sourceRoleName; 41 private QName targetRoleName; 42 43 44 50 M2AssociationDefinition(ClassDefinition classDef, M2ClassAssociation assoc, NamespacePrefixResolver resolver) 51 { 52 this.classDef = classDef; 53 this.assoc = assoc; 54 55 this.name = QName.createQName(assoc.getName(), resolver); 57 this.targetClassName = QName.createQName(assoc.getTargetClassName(), resolver); 58 this.sourceRoleName = QName.createQName(assoc.getSourceRoleName(), resolver); 59 this.targetRoleName = QName.createQName(assoc.getTargetRoleName(), resolver); 60 } 61 62 @Override 63 public String toString() 64 { 65 StringBuilder sb = new StringBuilder (56); 66 sb.append("Association") 67 .append("[ class=").append(classDef) 68 .append(", name=").append(name) 69 .append(", target class=").append(targetClassName) 70 .append(", source role=").append(sourceRoleName) 71 .append(", target role=").append(targetRoleName) 72 .append("]"); 73 return sb.toString(); 74 } 75 76 77 M2ClassAssociation getM2Association() 78 { 79 return assoc; 80 } 81 82 83 void resolveDependencies(ModelQuery query) 84 { 85 if (targetClassName == null) 86 { 87 throw new DictionaryException("Target class of association " + name.toPrefixString() + " must be specified"); 88 } 89 targetClass = query.getClass(targetClassName); 90 if (targetClass == null) 91 { 92 throw new DictionaryException("Target class " + targetClassName.toPrefixString() + " of association " + name.toPrefixString() + " is not found"); 93 } 94 } 95 96 97 100 public ModelDefinition getModel() 101 { 102 return classDef.getModel(); 103 } 104 105 106 109 public QName getName() 110 { 111 return name; 112 } 113 114 115 118 public boolean isChild() 119 { 120 return (assoc instanceof M2ChildAssociation); 121 } 122 123 124 127 public String getTitle() 128 { 129 String value = M2Label.getLabel(classDef.getModel(), "association", name, "title"); 130 if (value == null) 131 { 132 value = assoc.getTitle(); 133 } 134 return value; 135 } 136 137 138 141 public String getDescription() 142 { 143 String value = M2Label.getLabel(classDef.getModel(), "association", name, "description"); 144 if (value == null) 145 { 146 value = assoc.getDescription(); 147 } 148 return value; 149 } 150 151 152 155 public boolean isProtected() 156 { 157 return assoc.isProtected(); 158 } 159 160 161 164 public ClassDefinition getSourceClass() 165 { 166 return classDef; 167 } 168 169 170 173 public QName getSourceRoleName() 174 { 175 return sourceRoleName; 176 } 177 178 179 182 public boolean isSourceMandatory() 183 { 184 return assoc.isSourceMandatory(); 185 } 186 187 188 191 public boolean isSourceMany() 192 { 193 return assoc.isSourceMany(); 194 } 195 196 197 200 public ClassDefinition getTargetClass() 201 { 202 return targetClass; 203 } 204 205 206 209 public QName getTargetRoleName() 210 { 211 return targetRoleName; 212 } 213 214 215 218 public boolean isTargetMandatory() 219 { 220 return assoc.isTargetMandatory(); 221 } 222 223 224 227 public boolean isTargetMany() 228 { 229 return assoc.isTargetMany(); 230 } 231 232 } 233 | Popular Tags |