KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > rule > ruletrigger > CreateNodeRuleTrigger


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.rule.ruletrigger;
18
19 import org.alfresco.service.cmr.dictionary.ClassDefinition;
20 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
21 import org.alfresco.service.cmr.dictionary.DictionaryService;
22 import org.alfresco.service.cmr.dictionary.PropertyDefinition;
23 import org.alfresco.service.cmr.repository.ChildAssociationRef;
24 import org.alfresco.service.namespace.QName;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 /**
29  * We use this specialised trigger for create node beaucse of a problem with the CIFS integration.
30  * <p>
31  * The create node trigger will only be fired if the object is NOT a sub-type of content.
32  *
33  * @author Roy Wetherall
34  */

35 public class CreateNodeRuleTrigger extends SingleChildAssocRefPolicyRuleTrigger
36 {
37     /**
38      * The logger
39      */

40     private static Log logger = LogFactory.getLog(CreateNodeRuleTrigger.class);
41     
42     DictionaryService dictionaryService;
43     
44     public void setDictionaryService(DictionaryService dictionaryService)
45     {
46         this.dictionaryService = dictionaryService;
47     }
48     
49     public void policyBehaviour(ChildAssociationRef childAssocRef)
50     {
51         // Only fire the rule if the node is question has no potential to contain content
52
// TODO we need to find a better way to do this .. how can this be resolved in CIFS??
53
boolean triggerRule = false;
54         QName type = this.nodeService.getType(childAssocRef.getChildRef());
55         ClassDefinition classDefinition = this.dictionaryService.getClass(type);
56         if (classDefinition != null)
57         {
58             for (PropertyDefinition propertyDefinition : classDefinition.getProperties().values())
59             {
60                 if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT) == true)
61                 {
62                     triggerRule = true;
63                     break;
64                 }
65             }
66         }
67         
68         if (triggerRule == false)
69         {
70             if (logger.isDebugEnabled() == true)
71             {
72                 logger.debug(
73                         "Create node rule trigger fired for parent node " +
74                         this.nodeService.getType(childAssocRef.getParentRef()).toString() + " " + childAssocRef.getParentRef() +
75                         " and child node " +
76                         this.nodeService.getType(childAssocRef.getChildRef()).toString() + " " + childAssocRef.getChildRef());
77             }
78             
79             triggerRules(childAssocRef.getParentRef(), childAssocRef.getChildRef());
80         }
81     }
82 }
83
Popular Tags