KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > configuration > ConfigurableServiceImpl


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.configuration;
18
19 import java.util.List JavaDoc;
20
21 import org.alfresco.model.ContentModel;
22 import org.alfresco.service.cmr.repository.ChildAssociationRef;
23 import org.alfresco.service.cmr.repository.NodeRef;
24 import org.alfresco.service.cmr.repository.NodeService;
25 import org.alfresco.service.namespace.RegexQNamePattern;
26
27 /**
28  * @author Roy Wetherall
29  */

30 public class ConfigurableServiceImpl implements ConfigurableService
31 {
32     private NodeService nodeService;
33     
34     public void setNodeService(NodeService nodeService)
35     {
36         this.nodeService = nodeService;
37     }
38
39     public boolean isConfigurable(NodeRef nodeRef)
40     {
41         return this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_CONFIGURABLE);
42     }
43
44     public void makeConfigurable(NodeRef nodeRef)
45     {
46         if (isConfigurable(nodeRef) == false)
47         {
48             // First apply the aspect
49
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_CONFIGURABLE, null);
50             
51             // Next create and add the configurations folder
52
this.nodeService.createNode(
53                     nodeRef,
54                     ContentModel.ASSOC_CONFIGURATIONS,
55                     ContentModel.ASSOC_CONFIGURATIONS,
56                     ContentModel.TYPE_CONFIGURATIONS);
57         }
58     }
59     
60     public NodeRef getConfigurationFolder(NodeRef nodeRef)
61     {
62         NodeRef result = null;
63         if (isConfigurable(nodeRef) == true)
64         {
65             List JavaDoc<ChildAssociationRef> assocs = this.nodeService.getChildAssocs(
66                     nodeRef,
67                     RegexQNamePattern.MATCH_ALL,
68                     ContentModel.ASSOC_CONFIGURATIONS);
69             if (assocs.size() != 0)
70             {
71                 ChildAssociationRef assoc = assocs.get(0);
72                 result = assoc.getChildRef();
73             }
74         }
75         return result;
76     }
77
78 }
79
Popular Tags