KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > policy > ClassFeatureBehaviourBinding


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.policy;
18
19 import org.alfresco.service.cmr.dictionary.ClassDefinition;
20 import org.alfresco.service.cmr.dictionary.DictionaryService;
21 import org.alfresco.service.cmr.repository.NodeRef;
22 import org.alfresco.service.namespace.QName;
23
24
25 /**
26  * Behaviour binding to a Class (Type or Aspect) in the Content Model.
27  *
28  * @author David Caruana
29  *
30  */

31 /*package*/ class ClassFeatureBehaviourBinding extends ClassBehaviourBinding
32 {
33     // The feature qualified name (property or association)
34
private QName featureQName;
35     private QName activeFeatureQName;
36
37     // Wild Card feature match (match all features)
38
private static final QName ALL_FEATURES = QName.createQName("", "*");
39
40
41     /**
42      * Construct.
43      *
44      * @param dictionary the dictionary service
45      * @param nodeRef the node reference
46      * @param classQName the Class qualified name
47      * @param featureQName the Class feature (property or association) qualifed name
48      */

49     /*package*/ ClassFeatureBehaviourBinding(DictionaryService dictionary, NodeRef nodeRef, QName classQName, QName featureQName)
50     {
51         this(dictionary, nodeRef, classQName, featureQName, featureQName);
52     }
53
54     
55     /**
56      * Construct.
57      *
58      * @param dictionary the dictionary service
59      * @param classQName the Class qualified name
60      * @param featureQName the Class feature (property or association) qualifed name
61      */

62     /*package*/ ClassFeatureBehaviourBinding(DictionaryService dictionary, QName classQName, QName featureQName)
63     {
64         this(dictionary, null, classQName, featureQName, featureQName);
65     }
66
67     
68     /**
69      * Construct.
70      *
71      * @param dictionary the dictionary service
72      * @param nodeRef the node reference
73      * @param classQName the Class qualified name
74      */

75     /*package*/ ClassFeatureBehaviourBinding(DictionaryService dictionary, NodeRef nodeRef, QName classQName)
76     {
77         this(dictionary, nodeRef, classQName, ALL_FEATURES);
78     }
79
80     
81     /**
82      * Construct.
83      *
84      * @param dictionary the dictionary service
85      * @param classQName the Class qualified name
86      */

87     /*package*/ ClassFeatureBehaviourBinding(DictionaryService dictionary, QName classQName)
88     {
89         this(dictionary, null, classQName, ALL_FEATURES);
90     }
91         
92     
93     /**
94      * Construct.
95      *
96      * @param dictionary the dictionary service
97      * @param nodeRef the node reference
98      * @param classQName the Class qualified name
99      * @param featureQName the Class feature (property or association) qualifed name
100      * @param activeFeatureQName the currently active feature QName
101      */

102     private ClassFeatureBehaviourBinding(DictionaryService dictionary, NodeRef nodeRef, QName classQName, QName featureQName, QName activeFeatureQName)
103     {
104         super(dictionary, nodeRef, classQName);
105         this.featureQName = featureQName;
106         this.activeFeatureQName = activeFeatureQName;
107     }
108
109
110     /* (non-Javadoc)
111      * @see org.alfresco.repo.policy.BehaviourBinding#generaliseBinding()
112      */

113     public BehaviourBinding generaliseBinding()
114     {
115         BehaviourBinding generalisedBinding = null;
116         ClassDefinition classDefinition = getDictionary().getClass(getClassQName());
117         
118         if (activeFeatureQName.equals(ALL_FEATURES))
119         {
120             QName parentClassName = classDefinition.getParentName();
121             if (parentClassName != null)
122             {
123                 generalisedBinding = new ClassFeatureBehaviourBinding(getDictionary(), getNodeRef(), parentClassName, featureQName, featureQName);
124             }
125         }
126         else
127         {
128             generalisedBinding = new ClassFeatureBehaviourBinding(getDictionary(), getNodeRef(), getClassQName(), featureQName, ALL_FEATURES);
129         }
130         
131         return generalisedBinding;
132     }
133     
134     @Override JavaDoc
135     public boolean equals(Object JavaDoc obj)
136     {
137         if (obj == null || !(obj instanceof ClassFeatureBehaviourBinding))
138         {
139             return false;
140         }
141         return getClassQName().equals(((ClassFeatureBehaviourBinding)obj).getClassQName()) &&
142                activeFeatureQName.equals(((ClassFeatureBehaviourBinding)obj).activeFeatureQName);
143     }
144
145     @Override JavaDoc
146     public int hashCode()
147     {
148         return 37 * getClassQName().hashCode() + activeFeatureQName.hashCode();
149     }
150
151     @Override JavaDoc
152     public String JavaDoc toString()
153     {
154         return "ClassFeatureBinding[class=" + getClassQName() + ";feature=" + activeFeatureQName + "]";
155     }
156     
157 }
158
Popular Tags