KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > dictionary > M2AnonymousTypeDefinition


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.repo.dictionary;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.alfresco.service.cmr.dictionary.AspectDefinition;
27 import org.alfresco.service.cmr.dictionary.AssociationDefinition;
28 import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
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.NamespaceService;
33 import org.alfresco.service.namespace.QName;
34
35
36 /**
37  * Compiled anonymous type definition.
38  *
39  * @author David Caruana
40  *
41  */

42 /*package*/ class M2AnonymousTypeDefinition implements TypeDefinition
43 {
44     private TypeDefinition type;
45     private Map JavaDoc<QName,PropertyDefinition> properties = new HashMap JavaDoc<QName,PropertyDefinition>();
46     private Map JavaDoc<QName,AssociationDefinition> associations = new HashMap JavaDoc<QName,AssociationDefinition>();
47     private Map JavaDoc<QName,ChildAssociationDefinition> childassociations = new HashMap JavaDoc<QName,ChildAssociationDefinition>();
48     
49
50     /**
51      * Construct
52      *
53      * @param type the primary type
54      * @param aspects the aspects to combine with the type
55      */

56     /*package*/ M2AnonymousTypeDefinition(TypeDefinition type, Collection JavaDoc<AspectDefinition> aspects)
57     {
58         this.type = type;
59         
60         // Combine features of type and aspects
61
properties.putAll(type.getProperties());
62         associations.putAll(type.getAssociations());
63         childassociations.putAll(type.getChildAssociations());
64         for (AspectDefinition aspect : aspects)
65         {
66             properties.putAll(aspect.getProperties());
67             associations.putAll(aspect.getAssociations());
68             childassociations.putAll(aspect.getChildAssociations());
69         }
70     }
71
72     /* (non-Javadoc)
73      * @see org.alfresco.service.cmr.dictionary.ClassDefinition#getModel()
74      */

75     public ModelDefinition getModel()
76     {
77         return type.getModel();
78     }
79     
80     /* (non-Javadoc)
81      * @see org.alfresco.repo.dictionary.TypeDefinition#getDefaultAspects()
82      */

83     public List JavaDoc<AspectDefinition> getDefaultAspects()
84     {
85         return type.getDefaultAspects();
86     }
87
88     
89     /* (non-Javadoc)
90      * @see org.alfresco.repo.dictionary.ClassDefinition#getName()
91      */

92     public QName getName()
93     {
94         return QName.createQName(NamespaceService.DICTIONARY_MODEL_1_0_URI, "anonymous#" + type.getName().getLocalName());
95     }
96
97     
98     /* (non-Javadoc)
99      * @see org.alfresco.repo.dictionary.ClassDefinition#getTitle()
100      */

101     public String JavaDoc getTitle()
102     {
103         return type.getTitle();
104     }
105
106     
107     /* (non-Javadoc)
108      * @see org.alfresco.repo.dictionary.ClassDefinition#getDescription()
109      */

110     public String JavaDoc getDescription()
111     {
112         return type.getDescription();
113     }
114
115     
116     /* (non-Javadoc)
117      * @see org.alfresco.repo.dictionary.ClassDefinition#getParentName()
118      */

119     public QName getParentName()
120     {
121         return type.getParentName();
122     }
123
124     
125     /* (non-Javadoc)
126      * @see org.alfresco.repo.dictionary.ClassDefinition#isAspect()
127      */

128     public boolean isAspect()
129     {
130         return type.isAspect();
131     }
132
133     
134     /* (non-Javadoc)
135      * @see org.alfresco.repo.dictionary.ClassDefinition#getProperties()
136      */

137     public Map JavaDoc<QName, PropertyDefinition> getProperties()
138     {
139         return Collections.unmodifiableMap(properties);
140     }
141     
142     /**
143      * @see org.alfresco.service.cmr.dictionary.ClassDefinition#getDefaultValues()
144      */

145     public Map JavaDoc<QName, Serializable JavaDoc> getDefaultValues()
146     {
147         Map JavaDoc<QName, Serializable JavaDoc> result = new HashMap JavaDoc<QName, Serializable JavaDoc>(5);
148         
149         for(Map.Entry JavaDoc<QName, PropertyDefinition> entry : properties.entrySet())
150         {
151             PropertyDefinition propertyDefinition = entry.getValue();
152             String JavaDoc defaultValue = propertyDefinition.getDefaultValue();
153             if (defaultValue != null)
154             {
155                 result.put(entry.getKey(), defaultValue);
156             }
157         }
158         
159         return Collections.unmodifiableMap(result);
160     }
161
162     
163     /* (non-Javadoc)
164      * @see org.alfresco.repo.dictionary.ClassDefinition#getAssociations()
165      */

166     public Map JavaDoc<QName, AssociationDefinition> getAssociations()
167     {
168         return Collections.unmodifiableMap(associations);
169     }
170
171
172     /* (non-Javadoc)
173      * @see org.alfresco.service.cmr.dictionary.ClassDefinition#isContainer()
174      */

175     public boolean isContainer()
176     {
177         return !childassociations.isEmpty();
178     }
179
180     
181     /* (non-Javadoc)
182      * @see org.alfresco.repo.dictionary.ClassDefinition#getChildAssociations()
183      */

184     public Map JavaDoc<QName, ChildAssociationDefinition> getChildAssociations()
185     {
186         return Collections.unmodifiableMap(childassociations);
187     }
188
189 }
190
Popular Tags