1 17 package org.alfresco.web.bean.repository; 18 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 24 import org.alfresco.service.cmr.dictionary.DictionaryService; 25 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 26 import org.alfresco.service.cmr.dictionary.TypeDefinition; 27 import org.alfresco.service.namespace.NamespaceService; 28 import org.alfresco.service.namespace.QName; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 39 public final class DataDictionary 40 { 41 private static Log logger = LogFactory.getLog(DataDictionary.class); 42 private DictionaryService dictionaryService; 43 private NamespaceService namespaceService; 44 private Map <QName, TypeDefinition> types = new HashMap <QName, TypeDefinition>(11, 1.0f); 45 46 51 public DataDictionary(DictionaryService dictionaryService) 52 { 53 this.dictionaryService = dictionaryService; 54 } 55 56 62 public TypeDefinition getTypeDef(QName type) 63 { 64 TypeDefinition typeDef = types.get(type); 65 66 if (typeDef == null) 67 { 68 typeDef = this.dictionaryService.getType(type); 69 70 if (typeDef != null) 71 { 72 types.put(type, typeDef); 73 } 74 } 75 76 return typeDef; 77 } 78 79 87 public TypeDefinition getTypeDef(QName type, Collection <QName> optionalAspects) 88 { 89 return this.dictionaryService.getAnonymousType(type, optionalAspects); 90 } 91 92 99 public PropertyDefinition getPropertyDefinition(Node node, String property) 100 { 101 PropertyDefinition propDef = null; 102 103 TypeDefinition typeDef = getTypeDef(node.getType(), node.getAspects()); 104 105 if (typeDef != null) 106 { 107 Map <QName, PropertyDefinition> properties = typeDef.getProperties(); 108 propDef = properties.get(Repository.resolveToQName(property)); 109 } 110 111 return propDef; 112 } 113 114 121 public AssociationDefinition getAssociationDefinition(Node node, String association) 122 { 123 AssociationDefinition assocDef = null; 124 125 TypeDefinition typeDef = getTypeDef(node.getType(), node.getAspects()); 126 127 if (typeDef != null) 128 { 129 Map <QName, AssociationDefinition> assocs = typeDef.getAssociations(); 130 assocDef = assocs.get(Repository.resolveToQName(association)); 131 } 132 133 return assocDef; 134 } 135 } 136 | Popular Tags |