1 17 package org.alfresco.repo.dictionary; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.Map ; 22 23 import org.alfresco.service.cmr.dictionary.AspectDefinition; 24 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 25 import org.alfresco.service.cmr.dictionary.ClassDefinition; 26 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 27 import org.alfresco.service.cmr.dictionary.DictionaryService; 28 import org.alfresco.service.cmr.dictionary.InvalidTypeException; 29 import org.alfresco.service.cmr.dictionary.ModelDefinition; 30 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 31 import org.alfresco.service.cmr.dictionary.TypeDefinition; 32 import org.alfresco.service.namespace.QName; 33 import org.alfresco.util.ParameterCheck; 34 35 36 41 public class DictionaryComponent implements DictionaryService 42 { 43 private DictionaryDAO dictionaryDAO; 44 45 46 48 53 public void setDictionaryDAO(DictionaryDAO dictionaryDAO) 54 { 55 this.dictionaryDAO = dictionaryDAO; 56 } 57 58 59 62 public Collection <QName> getAllModels() 63 { 64 return dictionaryDAO.getModels(); 65 } 66 67 68 71 public ModelDefinition getModel(QName model) 72 { 73 return dictionaryDAO.getModel(model); 74 } 75 76 79 public Collection <QName> getAllDataTypes() 80 { 81 Collection <QName> propertyTypes = new ArrayList <QName>(); 82 for (QName model : getAllModels()) 83 { 84 propertyTypes.addAll(getAspects(model)); 85 } 86 return propertyTypes; 87 } 88 89 90 93 public Collection <QName> getDataTypes(QName model) 94 { 95 Collection <DataTypeDefinition> propertyTypes = dictionaryDAO.getDataTypes(model); 96 Collection <QName> qnames = new ArrayList <QName>(propertyTypes.size()); 97 for (DataTypeDefinition def : propertyTypes) 98 { 99 qnames.add(def.getName()); 100 } 101 return qnames; 102 } 103 104 105 108 public Collection <QName> getAllTypes() 109 { 110 Collection <QName> types = new ArrayList <QName>(); 111 for (QName model : getAllModels()) 112 { 113 types.addAll(getTypes(model)); 114 } 115 return types; 116 } 117 118 119 122 public Collection <QName> getTypes(QName model) 123 { 124 Collection <TypeDefinition> types = dictionaryDAO.getTypes(model); 125 Collection <QName> qnames = new ArrayList <QName>(types.size()); 126 for (TypeDefinition def : types) 127 { 128 qnames.add(def.getName()); 129 } 130 return qnames; 131 } 132 133 134 137 public Collection <QName> getAllAspects() 138 { 139 Collection <QName> aspects = new ArrayList <QName>(); 140 for (QName model : getAllModels()) 141 { 142 aspects.addAll(getAspects(model)); 143 } 144 return aspects; 145 } 146 147 148 151 public Collection <QName> getAspects(QName model) 152 { 153 Collection <AspectDefinition> aspects = dictionaryDAO.getAspects(model); 154 Collection <QName> qnames = new ArrayList <QName>(aspects.size()); 155 for (AspectDefinition def : aspects) 156 { 157 qnames.add(def.getName()); 158 } 159 return qnames; 160 } 161 162 163 166 public boolean isSubClass(QName className, QName ofClassName) 167 { 168 ParameterCheck.mandatory("className", className); 170 ParameterCheck.mandatory("ofClassName", ofClassName); 171 ClassDefinition classDef = getClass(className); 172 if (classDef == null) 173 { 174 throw new InvalidTypeException(className); 175 } 176 ClassDefinition ofClassDef = getClass(ofClassName); 177 if (ofClassDef == null) 178 { 179 throw new InvalidTypeException(ofClassName); 180 } 181 182 boolean subClassOf = false; 184 if (classDef.isAspect() == ofClassDef.isAspect()) 185 { 186 while (classDef != null) 187 { 188 if (classDef.equals(ofClassDef)) 189 { 190 subClassOf = true; 191 break; 192 } 193 194 QName parentClassName = classDef.getParentName(); 196 classDef = (parentClassName == null) ? null : getClass(parentClassName); 197 } 198 } 199 return subClassOf; 200 } 201 202 203 206 public DataTypeDefinition getDataType(QName name) 207 { 208 return dictionaryDAO.getDataType(name); 209 } 210 211 212 215 public DataTypeDefinition getDataType(Class javaClass) 216 { 217 return dictionaryDAO.getDataType(javaClass); 218 } 219 220 221 224 public TypeDefinition getType(QName name) 225 { 226 return dictionaryDAO.getType(name); 227 } 228 229 230 233 public AspectDefinition getAspect(QName name) 234 { 235 return dictionaryDAO.getAspect(name); 236 } 237 238 239 242 public ClassDefinition getClass(QName name) 243 { 244 return dictionaryDAO.getClass(name); 245 } 246 247 248 251 public TypeDefinition getAnonymousType(QName type, Collection <QName> aspects) 252 { 253 return dictionaryDAO.getAnonymousType(type, aspects); 254 } 255 256 257 260 public PropertyDefinition getProperty(QName className, QName propertyName) 261 { 262 PropertyDefinition propDef = null; 263 ClassDefinition classDef = dictionaryDAO.getClass(className); 264 if (classDef != null) 265 { 266 Map <QName,PropertyDefinition> propDefs = classDef.getProperties(); 267 propDef = propDefs.get(propertyName); 268 } 269 return propDef; 270 } 271 272 273 276 public PropertyDefinition getProperty(QName propertyName) 277 { 278 return dictionaryDAO.getProperty(propertyName); 279 } 280 281 284 public AssociationDefinition getAssociation(QName associationName) 285 { 286 return dictionaryDAO.getAssociation(associationName); 287 } 288 289 } 290 | Popular Tags |