KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.alfresco.service.cmr.dictionary.AssociationDefinition;
20 import org.alfresco.service.cmr.dictionary.ClassDefinition;
21 import org.alfresco.service.cmr.dictionary.DictionaryException;
22 import org.alfresco.service.cmr.dictionary.ModelDefinition;
23 import org.alfresco.service.namespace.NamespacePrefixResolver;
24 import org.alfresco.service.namespace.QName;
25
26
27 /**
28  * Compiled Association Definition.
29  *
30  * @author David Caruana
31  */

32 /*package*/ class M2AssociationDefinition implements AssociationDefinition
33 {
34
35     private ClassDefinition classDef;
36     private M2ClassAssociation assoc;
37     private QName name;
38     private QName targetClassName;
39     private ClassDefinition targetClass;
40     private QName sourceRoleName;
41     private QName targetRoleName;
42     
43     
44     /**
45      * Construct
46      *
47      * @param m2Association association definition
48      * @return the definition
49      */

50     /*package*/ M2AssociationDefinition(ClassDefinition classDef, M2ClassAssociation assoc, NamespacePrefixResolver resolver)
51     {
52         this.classDef = classDef;
53         this.assoc = assoc;
54         
55         // Resolve names
56
this.name = QName.createQName(assoc.getName(), resolver);
57         this.targetClassName = QName.createQName(assoc.getTargetClassName(), resolver);
58         this.sourceRoleName = QName.createQName(assoc.getSourceRoleName(), resolver);
59         this.targetRoleName = QName.createQName(assoc.getTargetRoleName(), resolver);
60     }
61     
62     @Override JavaDoc
63     public String JavaDoc toString()
64     {
65         StringBuilder JavaDoc sb = new StringBuilder JavaDoc(56);
66         sb.append("Association")
67           .append("[ class=").append(classDef)
68           .append(", name=").append(name)
69           .append(", target class=").append(targetClassName)
70           .append(", source role=").append(sourceRoleName)
71           .append(", target role=").append(targetRoleName)
72           .append("]");
73         return sb.toString();
74     }
75
76     
77     /*package*/ M2ClassAssociation getM2Association()
78     {
79         return assoc;
80     }
81
82
83     /*package*/ void resolveDependencies(ModelQuery query)
84     {
85         if (targetClassName == null)
86         {
87             throw new DictionaryException("Target class of association " + name.toPrefixString() + " must be specified");
88         }
89         targetClass = query.getClass(targetClassName);
90         if (targetClass == null)
91         {
92             throw new DictionaryException("Target class " + targetClassName.toPrefixString() + " of association " + name.toPrefixString() + " is not found");
93         }
94     }
95     
96
97     /* (non-Javadoc)
98      * @see org.alfresco.service.cmr.dictionary.AssociationDefinition#getModel()
99      */

100     public ModelDefinition getModel()
101     {
102         return classDef.getModel();
103     }
104
105
106     /* (non-Javadoc)
107      * @see org.alfresco.repo.dictionary.AssociationDefinition#getName()
108      */

109     public QName getName()
110     {
111         return name;
112     }
113
114     
115     /* (non-Javadoc)
116      * @see org.alfresco.repo.dictionary.AssociationDefinition#isChild()
117      */

118     public boolean isChild()
119     {
120         return (assoc instanceof M2ChildAssociation);
121     }
122
123
124     /* (non-Javadoc)
125      * @see org.alfresco.repo.dictionary.AssociationDefinition#getTitle()
126      */

127     public String JavaDoc getTitle()
128     {
129         String JavaDoc value = M2Label.getLabel(classDef.getModel(), "association", name, "title");
130         if (value == null)
131         {
132             value = assoc.getTitle();
133         }
134         return value;
135     }
136
137
138     /* (non-Javadoc)
139      * @see org.alfresco.repo.dictionary.AssociationDefinition#getDescription()
140      */

141     public String JavaDoc getDescription()
142     {
143         String JavaDoc value = M2Label.getLabel(classDef.getModel(), "association", name, "description");
144         if (value == null)
145         {
146             value = assoc.getDescription();
147         }
148         return value;
149     }
150
151
152     /* (non-Javadoc)
153      * @see org.alfresco.repo.dictionary.AssociationDefinition#isProtected()
154      */

155     public boolean isProtected()
156     {
157         return assoc.isProtected();
158     }
159
160
161     /* (non-Javadoc)
162      * @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceClass()
163      */

164     public ClassDefinition getSourceClass()
165     {
166         return classDef;
167     }
168
169
170     /* (non-Javadoc)
171      * @see org.alfresco.repo.dictionary.AssociationDefinition#getSourceRoleName()
172      */

173     public QName getSourceRoleName()
174     {
175         return sourceRoleName;
176     }
177
178
179     /* (non-Javadoc)
180      * @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMandatory()
181      */

182     public boolean isSourceMandatory()
183     {
184         return assoc.isSourceMandatory();
185     }
186
187
188     /* (non-Javadoc)
189      * @see org.alfresco.repo.dictionary.AssociationDefinition#isSourceMany()
190      */

191     public boolean isSourceMany()
192     {
193         return assoc.isSourceMany();
194     }
195
196
197     /* (non-Javadoc)
198      * @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetClass()
199      */

200     public ClassDefinition getTargetClass()
201     {
202         return targetClass;
203     }
204
205
206     /* (non-Javadoc)
207      * @see org.alfresco.repo.dictionary.AssociationDefinition#getTargetRoleName()
208      */

209     public QName getTargetRoleName()
210     {
211         return targetRoleName;
212     }
213
214
215     /* (non-Javadoc)
216      * @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMandatory()
217      */

218     public boolean isTargetMandatory()
219     {
220         return assoc.isTargetMandatory();
221     }
222
223
224     /* (non-Javadoc)
225      * @see org.alfresco.repo.dictionary.AssociationDefinition#isTargetMany()
226      */

227     public boolean isTargetMany()
228     {
229         return assoc.isTargetMany();
230     }
231
232 }
233
Popular Tags