KickJava   Java API By Example, From Geeks To Geeks.

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


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 ClassBehaviourBinding implements BehaviourBinding
32 {
33     // The dictionary service
34
private DictionaryService dictionary;
35     
36     // The class qualified name
37
private QName classQName;
38
39     // Instance level node reference
40
private NodeRef nodeRef;
41     
42
43     /**
44      * Construct.
45      *
46      * @param dictionary the dictionary service
47      * @param nodeRef the instance level node reference
48      * @param classQName the Class qualified name
49      */

50     /*package*/ ClassBehaviourBinding(DictionaryService dictionary, NodeRef nodeRef, QName classQName)
51     {
52         this.dictionary = dictionary;
53         this.nodeRef = nodeRef;
54         this.classQName = classQName;
55     }
56     
57     /**
58      * Construct.
59      *
60      * @param dictionary the dictionary service
61      * @param classQName the Class qualified name
62      */

63     /*package*/ ClassBehaviourBinding(DictionaryService dictionary, QName classQName)
64     {
65         this(dictionary, null, classQName);
66     }
67
68     /*package*/ DictionaryService getDictionary()
69     {
70         return dictionary;
71     }
72     
73     /* (non-Javadoc)
74      * @see org.alfresco.repo.policy.BehaviourBinding#generaliseBinding()
75      */

76     public BehaviourBinding generaliseBinding()
77     {
78         BehaviourBinding generalisedBinding = null;
79         ClassDefinition classDefinition = dictionary.getClass(classQName);
80         if (classDefinition == null)
81         {
82             throw new PolicyException("Class definition " + classQName.toPrefixString() + " does not exist.");
83         }
84         
85         QName parentClassName = classDefinition.getParentName();
86         if (parentClassName != null)
87         {
88             generalisedBinding = new ClassBehaviourBinding(dictionary, parentClassName);
89         }
90         return generalisedBinding;
91     }
92     
93     /**
94      * Gets the instance level node reference
95      *
96      * @return the node reference
97      */

98     public NodeRef getNodeRef()
99     {
100         return nodeRef;
101     }
102     
103     /**
104      * Gets the class qualified name
105      *
106      * @return the class qualified name
107      */

108     public QName getClassQName()
109     {
110         return classQName;
111     }
112
113     @Override JavaDoc
114     public boolean equals(Object JavaDoc obj)
115     {
116         if (obj == null || !(obj instanceof ClassBehaviourBinding))
117         {
118             return false;
119         }
120         return classQName.equals(((ClassBehaviourBinding)obj).classQName);
121     }
122
123     @Override JavaDoc
124     public int hashCode()
125     {
126         return classQName.hashCode();
127     }
128
129     @Override JavaDoc
130     public String JavaDoc toString()
131     {
132         return "ClassBinding[class=" + classQName + "]";
133     }
134     
135 }
136
Popular Tags