KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javax.jcr.RepositoryException;
24
25 import org.alfresco.jcr.session.SessionImpl;
26 import org.alfresco.model.ContentModel;
27 import org.alfresco.service.cmr.repository.NodeRef;
28 import org.alfresco.service.namespace.QName;
29
30
31 /**
32  * Responsible for mapping Alfresco Classes to JCR Types / Mixins and vice versa.
33  *
34  * @author David Caruana
35  */

36 public class ClassMap
37 {
38     /** Map of Alfresco Class to JCR Class */
39     private static Map JavaDoc<QName, QName> JCRToAlfresco = new HashMap JavaDoc<QName, QName>();
40     static
41     {
42         JCRToAlfresco.put(NodeTypeImpl.MIX_REFERENCEABLE, ContentModel.ASPECT_REFERENCEABLE);
43         JCRToAlfresco.put(NodeTypeImpl.MIX_LOCKABLE, ContentModel.ASPECT_LOCKABLE);
44         JCRToAlfresco.put(NodeTypeImpl.MIX_VERSIONABLE, ContentModel.ASPECT_VERSIONABLE);
45     }
46
47     /** Map of JCR Class to Alfresco Class */
48     private static Map JavaDoc<QName, QName> AlfrescoToJCR = new HashMap JavaDoc<QName, QName>();
49     static
50     {
51         AlfrescoToJCR.put(ContentModel.ASPECT_REFERENCEABLE, NodeTypeImpl.MIX_REFERENCEABLE);
52         AlfrescoToJCR.put(ContentModel.ASPECT_LOCKABLE, NodeTypeImpl.MIX_LOCKABLE);
53         AlfrescoToJCR.put(ContentModel.ASPECT_VERSIONABLE, NodeTypeImpl.MIX_VERSIONABLE);
54     }
55
56     /** Map of JCR to Alfresco "Add Aspect" Behaviours */
57     private static Map JavaDoc<QName, AddMixin> addMixin = new HashMap JavaDoc<QName, AddMixin>();
58     static
59     {
60         addMixin.put(ContentModel.ASPECT_VERSIONABLE, new VersionableMixin());
61     }
62     
63     /** Map of JCR to Alfresco "Remove Aspect" Behaviours */
64     private static Map JavaDoc<QName, RemoveMixin> removeMixin = new HashMap JavaDoc<QName, RemoveMixin>();
65     static
66     {
67         removeMixin.put(ContentModel.ASPECT_VERSIONABLE, new VersionableMixin());
68     }
69
70     
71     /**
72      * Convert an Alfresco Class to a JCR Type
73      *
74      * @param jcrType JCR Type
75      * @return Alfresco Class
76      * @throws RepositoryException
77      */

78     public static QName convertTypeToClass(QName jcrType)
79     {
80         return JCRToAlfresco.get(jcrType);
81     }
82
83     /**
84      * Convert an Alfresco Class to a JCR Type
85      *
86      * @param alfrescoClass Alfresco Class
87      * @return JCR Type
88      * @throws RepositoryException
89      */

90     public static QName convertClassToType(QName alfrescoClass)
91     {
92         return JCRToAlfresco.get(alfrescoClass);
93     }
94
95     /**
96      * Get 'Add Mixin' JCR behaviour
97      *
98      * @param alfrescoClass
99      * @return AddMixin behaviour
100      */

101     public static AddMixin getAddMixin(QName alfrescoClass)
102     {
103         return addMixin.get(alfrescoClass);
104     }
105     
106     /**
107      * Get 'Remove Mixin' JCR behaviour
108      *
109      * @param alfrescoClass
110      * @return RemoveMixin behaviour
111      */

112     public static RemoveMixin getRemoveMixin(QName alfrescoClass)
113     {
114         return removeMixin.get(alfrescoClass);
115     }
116     
117     /**
118      * Add Mixin Behaviour
119      *
120      * Encapsulates mapping of JCR behaviour to Alfresco
121      */

122     public interface AddMixin
123     {
124         public Map JavaDoc<QName, Serializable JavaDoc> preAddMixin(SessionImpl session, NodeRef nodeRef);
125         public void postAddMixin(SessionImpl session, NodeRef nodeRef);
126     }
127
128     /**
129      * Remove Mixin Behaviour
130      *
131      * Encapsulates mapping of JCR behaviour to Alfresco
132      */

133     public interface RemoveMixin
134     {
135         public void preRemoveMixin(SessionImpl session, NodeRef nodeRef);
136         public void postRemoveMixin(SessionImpl session, NodeRef nodeRef);
137     }
138     
139 }
140
Popular Tags