KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > executer > SpecialiseTypeActionExecuter


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.action.executer;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.repo.action.ParameterDefinitionImpl;
22 import org.alfresco.service.cmr.action.Action;
23 import org.alfresco.service.cmr.action.ParameterDefinition;
24 import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
25 import org.alfresco.service.cmr.dictionary.DictionaryService;
26 import org.alfresco.service.cmr.repository.NodeRef;
27 import org.alfresco.service.cmr.repository.NodeService;
28 import org.alfresco.service.namespace.QName;
29
30 /**
31  * Add features action executor implementation.
32  *
33  * @author Roy Wetherall
34  */

35 public class SpecialiseTypeActionExecuter extends ActionExecuterAbstractBase
36 {
37     /**
38      * Action constants
39      */

40     public static final String JavaDoc NAME = "specialise-type";
41     public static final String JavaDoc PARAM_TYPE_NAME = "type-name";
42     
43     /**
44      * The node service
45      */

46     private NodeService nodeService;
47     
48     /**
49      * The dictionary service
50      */

51     private DictionaryService dictionaryService;
52     
53     /**
54      * Set the node service
55      *
56      * @param nodeService the node service
57      */

58     public void setNodeService(NodeService nodeService)
59     {
60         this.nodeService = nodeService;
61     }
62
63     /**
64      * Set the dictionary service
65      *
66      * @param dictionaryService the dictionary service
67      */

68     public void setDictionaryService(DictionaryService dictionaryService)
69     {
70         this.dictionaryService = dictionaryService;
71     }
72     
73     /**
74      * @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
75      */

76     public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
77     {
78         if (this.nodeService.exists(actionedUponNodeRef) == true)
79         {
80             // Get the type of the node
81
QName currentType = this.nodeService.getType(actionedUponNodeRef);
82             QName destinationType = (QName)ruleAction.getParameterValue(PARAM_TYPE_NAME);
83             
84             // Ensure that we are performing a specialise
85
if (currentType.equals(destinationType) == false &&
86                 this.dictionaryService.isSubClass(destinationType, currentType) == true)
87             {
88                 // Specialise the type of the node
89
this.nodeService.setType(actionedUponNodeRef, destinationType);
90             }
91         }
92     }
93
94     /**
95      * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
96      */

97     @Override JavaDoc
98     protected void addParameterDefintions(List JavaDoc<ParameterDefinition> paramList)
99     {
100         paramList.add(new ParameterDefinitionImpl(PARAM_TYPE_NAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_TYPE_NAME)));
101     }
102
103 }
104
Popular Tags