1 17 package org.alfresco.repo.dictionary; 18 19 import org.alfresco.service.cmr.dictionary.ClassDefinition; 20 import org.alfresco.service.cmr.dictionary.DictionaryException; 21 import org.alfresco.service.cmr.dictionary.ModelDefinition; 22 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 23 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 24 import org.alfresco.service.namespace.NamespacePrefixResolver; 25 import org.alfresco.service.namespace.QName; 26 27 28 33 class M2PropertyDefinition implements PropertyDefinition 34 { 35 private ClassDefinition classDef; 36 private M2Property property; 37 private QName name; 38 private QName propertyTypeName; 39 private DataTypeDefinition dataType; 40 41 42 M2PropertyDefinition(ClassDefinition classDef, M2Property m2Property, NamespacePrefixResolver resolver) 43 { 44 this.classDef = classDef; 45 this.property = m2Property; 46 47 this.name = QName.createQName(property.getName(), resolver); 49 this.propertyTypeName = QName.createQName(property.getType(), resolver); 50 } 51 52 53 M2PropertyDefinition(ClassDefinition classDef, PropertyDefinition propertyDef, M2PropertyOverride override) 54 { 55 this.classDef = classDef; 56 this.property = createOverriddenProperty(propertyDef, override); 57 this.name = propertyDef.getName(); 58 this.dataType = propertyDef.getDataType(); 59 this.propertyTypeName = this.dataType.getName(); 60 } 61 62 63 void resolveDependencies(ModelQuery query) 64 { 65 if (propertyTypeName == null) 66 { 67 throw new DictionaryException("Property type of property " + name.toPrefixString() + " must be specified"); 68 } 69 dataType = query.getDataType(propertyTypeName); 70 if (dataType == null) 71 { 72 throw new DictionaryException("Property type " + propertyTypeName.toPrefixString() + " of property " + name.toPrefixString() + " is not found"); 73 } 74 75 if (propertyTypeName.equals(DataTypeDefinition.CONTENT) && isMultiValued()) 77 { 78 throw new DictionaryException("Content properties must be single-valued"); 79 } 80 } 81 82 83 90 private M2Property createOverriddenProperty(PropertyDefinition propertyDef, M2PropertyOverride override) 91 { 92 M2Property property = new M2Property(); 93 94 String defaultValue = override.getDefaultValue(); 96 property.setDefaultValue(defaultValue == null ? propertyDef.getDefaultValue() : defaultValue); 97 98 Boolean isMandatory = override.isMandatory(); 100 if (isMandatory != null) 101 { 102 if (propertyDef.isMandatory() == true && isMandatory == false) 103 { 104 throw new DictionaryException("Cannot relax mandatory attribute of property " + propertyDef.getName().toPrefixString()); 105 } 106 } 107 property.setMandatory(isMandatory == null ? propertyDef.isMandatory() : isMandatory); 108 109 property.setDescription(propertyDef.getDescription()); 111 property.setIndexed(propertyDef.isIndexed()); 112 property.setIndexedAtomically(propertyDef.isIndexedAtomically()); 113 property.setMultiValued(propertyDef.isMultiValued()); 114 property.setProtected(propertyDef.isProtected()); 115 property.setStoredInIndex(propertyDef.isStoredInIndex()); 116 property.setTitle(propertyDef.getTitle()); 117 property.setTokenisedInIndex(propertyDef.isTokenisedInIndex()); 118 119 return property; 120 } 121 122 125 @Override 126 public String toString() 127 { 128 return getName().toString(); 129 } 130 131 134 public ModelDefinition getModel() 135 { 136 return classDef.getModel(); 137 } 138 139 142 public QName getName() 143 { 144 return name; 145 } 146 147 148 151 public String getTitle() 152 { 153 String value = M2Label.getLabel(classDef.getModel(), "property", name, "title"); 154 if (value == null) 155 { 156 value = property.getTitle(); 157 } 158 return value; 159 } 160 161 162 165 public String getDescription() 166 { 167 String value = M2Label.getLabel(classDef.getModel(), "property", name, "description"); 168 if (value == null) 169 { 170 value = property.getDescription(); 171 } 172 return value; 173 } 174 175 176 179 public String getDefaultValue() 180 { 181 return property.getDefaultValue(); 182 } 183 184 185 188 public DataTypeDefinition getDataType() 189 { 190 return dataType; 191 } 192 193 194 197 public ClassDefinition getContainerClass() 198 { 199 return classDef; 200 } 201 202 203 206 public boolean isMultiValued() 207 { 208 return property.isMultiValued(); 209 } 210 211 212 215 public boolean isMandatory() 216 { 217 return property.isMandatory(); 218 } 219 220 221 224 public boolean isProtected() 225 { 226 return property.isProtected(); 227 } 228 229 230 233 public boolean isIndexed() 234 { 235 return property.isIndexed(); 236 } 237 238 239 242 public boolean isStoredInIndex() 243 { 244 return property.isStoredInIndex(); 245 } 246 247 248 251 public boolean isIndexedAtomically() 252 { 253 return property.isIndexedAtomically(); 254 } 255 256 257 260 public boolean isTokenisedInIndex() 261 { 262 return property.isTokenisedInIndex(); 263 } 264 265 } 266 | Popular Tags |