KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > jcr > dictionary > PropertyDefinitionImpl


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

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 /**
32  * Alfresco implementation of a JCR Property Definition
33  *
34  * @author David Caruana
35  */

36 public class PropertyDefinitionImpl implements PropertyDefinition
37 {
38     /** Session */
39     private NodeTypeManagerImpl typeManager;
40     
41     /** Alfresco Property Definition */
42     private org.alfresco.service.cmr.dictionary.PropertyDefinition propDef;
43     
44     
45     /**
46      * Construct
47      *
48      * @param propDef Alfresco Property Definition
49      */

50     public PropertyDefinitionImpl(NodeTypeManagerImpl typeManager, org.alfresco.service.cmr.dictionary.PropertyDefinition propDef)
51     {
52         this.typeManager = typeManager;
53         this.propDef = propDef;
54     }
55
56     /* (non-Javadoc)
57      * @see javax.jcr.nodetype.PropertyDefinition#getRequiredType()
58      */

59     public int getRequiredType()
60     {
61         // TODO: Switch on data type
62
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     /* (non-Javadoc)
70      * @see javax.jcr.nodetype.PropertyDefinition#getValueConstraints()
71      */

72     public String JavaDoc[] getValueConstraints()
73     {
74         return new String JavaDoc[] {};
75     }
76
77     /* (non-Javadoc)
78      * @see javax.jcr.nodetype.PropertyDefinition#getDefaultValues()
79      */

80     public Value[] getDefaultValues()
81     {
82         String JavaDoc 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     /* (non-Javadoc)
91      * @see javax.jcr.nodetype.PropertyDefinition#isMultiple()
92      */

93     public boolean isMultiple()
94     {
95         return propDef.isMultiValued();
96     }
97
98     /* (non-Javadoc)
99      * @see javax.jcr.nodetype.ItemDefinition#getDeclaringNodeType()
100      */

101     public NodeType getDeclaringNodeType()
102     {
103         ClassDefinition declaringClass = propDef.getContainerClass();
104         return typeManager.getNodeTypeImpl(declaringClass.getName());
105     }
106
107     /* (non-Javadoc)
108      * @see javax.jcr.nodetype.ItemDefinition#getName()
109      */

110     public String JavaDoc getName()
111     {
112         return propDef.getName().toPrefixString(typeManager.getNamespaceService());
113     }
114     
115     /* (non-Javadoc)
116      * @see javax.jcr.nodetype.ItemDefinition#isAutoCreated()
117      */

118     public boolean isAutoCreated()
119     {
120         return isMandatory();
121     }
122
123     /* (non-Javadoc)
124      * @see javax.jcr.nodetype.ItemDefinition#isMandatory()
125      */

126     public boolean isMandatory()
127     {
128         return propDef.isMandatory();
129     }
130
131     /* (non-Javadoc)
132      * @see javax.jcr.nodetype.ItemDefinition#getOnParentVersion()
133      */

134     public int getOnParentVersion()
135     {
136         // TODO: There's no equivalent in Alfresco, so hard code for now
137
if (propDef.getName().equals(JCRPrimaryTypeProperty.PROPERTY_NAME) ||
138             propDef.getName().equals(JCRMixinTypesProperty.PROPERTY_NAME))
139         {
140             return OnParentVersionAction.COMPUTE;
141         }
142         
143         // TODO: Check this
144
return OnParentVersionAction.INITIALIZE;
145     }
146
147     /* (non-Javadoc)
148      * @see javax.jcr.nodetype.ItemDefinition#isProtected()
149      */

150     public boolean isProtected()
151     {
152         return propDef.isProtected();
153     }
154
155 }
156
Popular Tags