KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > node > index > NodeIndexer


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.node.index;
18
19 import org.alfresco.model.ContentModel;
20 import org.alfresco.repo.node.NodeServicePolicies;
21 import org.alfresco.repo.policy.JavaBehaviour;
22 import org.alfresco.repo.policy.PolicyComponent;
23 import org.alfresco.repo.search.Indexer;
24 import org.alfresco.service.cmr.repository.ChildAssociationRef;
25 import org.alfresco.service.cmr.repository.NodeRef;
26 import org.alfresco.service.cmr.repository.StoreRef;
27 import org.alfresco.service.namespace.NamespaceService;
28 import org.alfresco.service.namespace.QName;
29
30 /**
31  * Handles the node policy callbacks to ensure that the node hierarchy is properly
32  * indexed.
33  *
34  * @author Derek Hulley
35  */

36 public class NodeIndexer
37         implements NodeServicePolicies.BeforeCreateStorePolicy,
38                    NodeServicePolicies.OnCreateNodePolicy,
39                    NodeServicePolicies.OnUpdateNodePolicy,
40                    NodeServicePolicies.OnDeleteNodePolicy,
41                    NodeServicePolicies.OnCreateChildAssociationPolicy,
42                    NodeServicePolicies.OnDeleteChildAssociationPolicy
43 {
44     /** the component to register the behaviour with */
45     private PolicyComponent policyComponent;
46     /** the component to index the node hierarchy */
47     private Indexer indexer;
48     
49     /**
50      * @param policyComponent used for registrations
51      */

52     public void setPolicyComponent(PolicyComponent policyComponent)
53     {
54         this.policyComponent = policyComponent;
55     }
56
57     /**
58      * @param indexer the indexer that will be index
59      */

60     public void setIndexer(Indexer indexer)
61     {
62         this.indexer = indexer;
63     }
64
65     /**
66      * Registers the policy behaviour methods
67      */

68     private void init()
69     {
70         policyComponent.bindClassBehaviour(
71                 QName.createQName(NamespaceService.ALFRESCO_URI, "beforeCreateStore"),
72                 ContentModel.TYPE_STOREROOT,
73                 new JavaBehaviour(this, "beforeCreateStore"));
74         policyComponent.bindClassBehaviour(
75                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),
76                 this,
77                 new JavaBehaviour(this, "onCreateNode"));
78         policyComponent.bindClassBehaviour(
79                 QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateNode"),
80                 this,
81                 new JavaBehaviour(this, "onUpdateNode"));
82         policyComponent.bindClassBehaviour(
83                 QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"),
84                 this,
85                 new JavaBehaviour(this, "onDeleteNode"));
86         policyComponent.bindAssociationBehaviour(
87                 QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"),
88                 this,
89                 new JavaBehaviour(this, "onCreateChildAssociation"));
90         policyComponent.bindAssociationBehaviour(
91                 QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteChildAssociation"),
92                 this,
93                 new JavaBehaviour(this, "onDeleteChildAssociation"));
94     }
95
96     public void beforeCreateStore(QName nodeTypeQName, StoreRef storeRef)
97     {
98         // indexer can perform some cleanup here, if required
99
}
100
101     public void onCreateNode(ChildAssociationRef childAssocRef)
102     {
103         indexer.createNode(childAssocRef);
104     }
105
106     public void onUpdateNode(NodeRef nodeRef)
107     {
108         indexer.updateNode(nodeRef);
109     }
110
111     public void onDeleteNode(ChildAssociationRef childAssocRef)
112     {
113         indexer.deleteNode(childAssocRef);
114     }
115
116     public void onCreateChildAssociation(ChildAssociationRef childAssocRef)
117     {
118         indexer.createChildRelationship(childAssocRef);
119     }
120
121     public void onDeleteChildAssociation(ChildAssociationRef childAssocRef)
122     {
123         indexer.deleteChildRelationship(childAssocRef);
124     }
125 }
126
Popular Tags