KickJava   Java API By Example, From Geeks To Geeks.

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


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

37 public class AddFeaturesActionExecuter extends ActionExecuterAbstractBase
38 {
39     /**
40      * Action constants
41      */

42     public static final String JavaDoc NAME = "add-features";
43     public static final String JavaDoc PARAM_ASPECT_NAME = "aspect-name";
44     public static final String JavaDoc PARAM_ASPECT_PROPERTIES = "aspect_properties";
45     
46     /**
47      * The node service
48      */

49     private NodeService nodeService;
50     
51     /**
52      * Set the node service
53      *
54      * @param nodeService the node service
55      */

56     public void setNodeService(NodeService nodeService)
57     {
58         this.nodeService = nodeService;
59     }
60     
61     /**
62      * Adhoc properties are allowed for this executor
63      */

64     @Override JavaDoc
65     protected boolean getAdhocPropertiesAllowed()
66     {
67         return true;
68     }
69
70     /**
71      * @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
72      */

73     public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
74     {
75         if (this.nodeService.exists(actionedUponNodeRef) == true)
76         {
77             Map JavaDoc<QName, Serializable JavaDoc> properties = new HashMap JavaDoc<QName, Serializable JavaDoc>();
78             QName aspectQName = null;
79             
80             Map JavaDoc<String JavaDoc, Serializable JavaDoc> paramValues = ruleAction.getParameterValues();
81             for (Map.Entry JavaDoc<String JavaDoc, Serializable JavaDoc> entry : paramValues.entrySet())
82             {
83                 if (entry.getKey().equals(PARAM_ASPECT_NAME) == true)
84                 {
85                     aspectQName = (QName)entry.getValue();
86                 }
87                 else
88                 {
89                     // Must be an adhoc property
90
QName propertyQName = QName.createQName(entry.getKey());
91                     Serializable JavaDoc propertyValue = entry.getValue();
92                     properties.put(propertyQName, propertyValue);
93                 }
94             }
95             
96             // Add the aspect
97
this.nodeService.addAspect(actionedUponNodeRef, aspectQName, properties);
98         }
99     }
100
101     /**
102      * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
103      */

104     @Override JavaDoc
105     protected void addParameterDefintions(List JavaDoc<ParameterDefinition> paramList)
106     {
107         paramList.add(new ParameterDefinitionImpl(PARAM_ASPECT_NAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASPECT_NAME)));
108     }
109
110 }
111
Popular Tags