KickJava   Java API By Example, From Geeks To Geeks.

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


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.service.namespace.NamespacePrefixResolver;
25 import org.alfresco.service.namespace.QName;
26 import org.dom4j.Attribute;
27 import org.dom4j.Element;
28
29 /**
30  * Store and read the definition of a permission set
31  * @author andyh
32  */

33 public class PermissionSet implements XMLModelInitialisable
34 {
35     private static final String JavaDoc TYPE = "type";
36     private static final String JavaDoc PERMISSION_GROUP = "permissionGroup";
37     private static final String JavaDoc PERMISSION = "permission";
38     private static final String JavaDoc EXPOSE = "expose";
39     private static final String JavaDoc EXPOSE_ALL = "all";
40     //private static final String EXPOSE_SELECTED = "selected";
41

42     
43     private QName qname;
44     
45     private boolean exposeAll;
46     
47     private Set JavaDoc<PermissionGroup> permissionGroups = new HashSet JavaDoc<PermissionGroup>();
48     
49     private Set JavaDoc<Permission> permissions = new HashSet JavaDoc<Permission>();
50     
51     public PermissionSet()
52     {
53         super();
54     }
55     
56     public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
57     {
58         qname = QName.createQName(element.attributeValue(TYPE), nspr);
59         
60         Attribute exposeAttribute = element.attribute(EXPOSE);
61         if(exposeAttribute != null)
62         {
63             exposeAll = exposeAttribute.getStringValue().equalsIgnoreCase(EXPOSE_ALL);
64         }
65         else
66         {
67             exposeAll = true;
68         }
69         
70         for(Iterator JavaDoc pgit = element.elementIterator(PERMISSION_GROUP); pgit.hasNext(); /**/)
71         {
72             Element permissionGroupElement = (Element)pgit.next();
73             PermissionGroup permissionGroup = new PermissionGroup(qname);
74             permissionGroup.initialise(permissionGroupElement, nspr, permissionModel);
75             permissionGroups.add(permissionGroup);
76         }
77         
78         for(Iterator JavaDoc pit = element.elementIterator(PERMISSION); pit.hasNext(); /**/)
79         {
80             Element permissionElement = (Element)pit.next();
81             Permission permission = new Permission(qname);
82             permission.initialise(permissionElement, nspr, permissionModel);
83             permissions.add(permission);
84         }
85         
86     }
87
88     public Set JavaDoc<PermissionGroup> getPermissionGroups()
89     {
90         return Collections.unmodifiableSet(permissionGroups);
91     }
92
93     public Set JavaDoc<Permission> getPermissions()
94     {
95         return Collections.unmodifiableSet(permissions);
96     }
97
98     public QName getQName()
99     {
100         return qname;
101     }
102
103     public boolean exposeAll()
104     {
105         return exposeAll;
106     }
107     
108     
109
110 }
111
Popular Tags