KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > permissions > impl > model > NodePermission


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.security.permissions.impl.model;
18
19 import java.util.Collections JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import org.alfresco.repo.security.permissions.NodePermissionEntry;
25 import org.alfresco.repo.security.permissions.PermissionEntry;
26 import org.alfresco.service.cmr.repository.NodeRef;
27 import org.alfresco.service.namespace.NamespacePrefixResolver;
28 import org.dom4j.Attribute;
29 import org.dom4j.Element;
30
31 /**
32  * Support to read and store the definition of node permissions
33  * @author andyh
34  */

35 public class NodePermission implements NodePermissionEntry, XMLModelInitialisable
36 {
37     // XML Constants
38

39     private static final String JavaDoc NODE_REF = "nodeRef";
40     
41     private static final String JavaDoc NODE_PERMISSION = "nodePermission";
42     
43     private static final String JavaDoc INHERIT_FROM_PARENT = "inheritFromParent";
44     
45     // Instance variables
46

47     // If null then it is the root.
48
private NodeRef nodeRef;
49     
50     private Set JavaDoc<PermissionEntry> permissionEntries = new HashSet JavaDoc<PermissionEntry>();
51     
52     private boolean inheritPermissionsFromParent;
53     
54     public NodePermission()
55     {
56         super();
57     }
58
59     public NodeRef getNodeRef()
60     {
61        return nodeRef;
62     }
63
64     public boolean inheritPermissions()
65     {
66         return inheritPermissionsFromParent;
67     }
68
69     public Set JavaDoc<PermissionEntry> getPermissionEntries()
70     {
71        return Collections.unmodifiableSet(permissionEntries);
72     }
73
74     public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
75     {
76        Attribute nodeRefAttribute = element.attribute(NODE_REF);
77        if(nodeRefAttribute != null)
78        {
79            nodeRef = new NodeRef(nodeRefAttribute.getStringValue());
80        }
81        
82        Attribute inheritFromParentAttribute = element.attribute(INHERIT_FROM_PARENT);
83        if(inheritFromParentAttribute != null)
84        {
85            inheritPermissionsFromParent = Boolean.parseBoolean(inheritFromParentAttribute.getStringValue());
86        }
87        else
88        {
89            inheritPermissionsFromParent = true;
90        }
91        
92        // Node Permissions Entry
93

94        for (Iterator JavaDoc npit = element.elementIterator(NODE_PERMISSION); npit.hasNext(); /**/)
95        {
96            Element permissionEntryElement = (Element) npit.next();
97            ModelPermissionEntry permissionEntry = new ModelPermissionEntry(nodeRef);
98            permissionEntry.initialise(permissionEntryElement, nspr, permissionModel);
99            permissionEntries.add(permissionEntry);
100        }
101         
102     }
103
104     
105     
106 }
107
Popular Tags