1 17 package org.alfresco.jcr.dictionary; 18 19 import javax.jcr.Value; 20 import javax.jcr.nodetype.NodeType; 21 import javax.jcr.nodetype.PropertyDefinition; 22 import javax.jcr.version.OnParentVersionAction; 23 24 import org.alfresco.jcr.item.ValueImpl; 25 import org.alfresco.jcr.item.property.JCRMixinTypesProperty; 26 import org.alfresco.jcr.item.property.JCRPrimaryTypeProperty; 27 import org.alfresco.model.ContentModel; 28 import org.alfresco.service.cmr.dictionary.ClassDefinition; 29 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 30 31 36 public class PropertyDefinitionImpl implements PropertyDefinition 37 { 38 39 private NodeTypeManagerImpl typeManager; 40 41 42 private org.alfresco.service.cmr.dictionary.PropertyDefinition propDef; 43 44 45 50 public PropertyDefinitionImpl(NodeTypeManagerImpl typeManager, org.alfresco.service.cmr.dictionary.PropertyDefinition propDef) 51 { 52 this.typeManager = typeManager; 53 this.propDef = propDef; 54 } 55 56 59 public int getRequiredType() 60 { 61 if (propDef.getName().equals(ContentModel.PROP_CONTENT)) 63 { 64 return DataTypeMap.convertDataTypeToPropertyType(DataTypeDefinition.CONTENT); 65 } 66 return DataTypeMap.convertDataTypeToPropertyType(propDef.getDataType().getName()); 67 } 68 69 72 public String [] getValueConstraints() 73 { 74 return new String [] {}; 75 } 76 77 80 public Value[] getDefaultValues() 81 { 82 String defaultValue = propDef.getDefaultValue(); 83 if (defaultValue == null) 84 { 85 return null; 86 } 87 return new Value[] { new ValueImpl(typeManager.getSession(), getRequiredType(), defaultValue) }; 88 } 89 90 93 public boolean isMultiple() 94 { 95 return propDef.isMultiValued(); 96 } 97 98 101 public NodeType getDeclaringNodeType() 102 { 103 ClassDefinition declaringClass = propDef.getContainerClass(); 104 return typeManager.getNodeTypeImpl(declaringClass.getName()); 105 } 106 107 110 public String getName() 111 { 112 return propDef.getName().toPrefixString(typeManager.getNamespaceService()); 113 } 114 115 118 public boolean isAutoCreated() 119 { 120 return isMandatory(); 121 } 122 123 126 public boolean isMandatory() 127 { 128 return propDef.isMandatory(); 129 } 130 131 134 public int getOnParentVersion() 135 { 136 if (propDef.getName().equals(JCRPrimaryTypeProperty.PROPERTY_NAME) || 138 propDef.getName().equals(JCRMixinTypesProperty.PROPERTY_NAME)) 139 { 140 return OnParentVersionAction.COMPUTE; 141 } 142 143 return OnParentVersionAction.INITIALIZE; 145 } 146 147 150 public boolean isProtected() 151 { 152 return propDef.isProtected(); 153 } 154 155 } 156 | Popular Tags |