KickJava   Java API By Example, From Geeks To Geeks.

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


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.PermissionReference;
25 import org.alfresco.repo.security.permissions.impl.AbstractPermissionReference;
26 import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl;
27 import org.alfresco.service.namespace.NamespacePrefixResolver;
28 import org.alfresco.service.namespace.QName;
29 import org.dom4j.Attribute;
30 import org.dom4j.Element;
31
32 /**
33  * Support to read and store the defintion of permission groups.
34  *
35  * @author andyh
36  */

37 public class PermissionGroup extends AbstractPermissionReference implements XMLModelInitialisable
38 {
39     // XML Constants
40

41     private static final String JavaDoc NAME = "name";
42     
43     private static final String JavaDoc EXTENDS = "extends";
44
45     private static final String JavaDoc ALLOW_FULL_CONTOL = "allowFullControl";
46
47     private static final String JavaDoc INCLUDE_PERMISSION_GROUP = "includePermissionGroup";
48
49     private static final String JavaDoc PERMISSION_GROUP = "permissionGroup";
50
51     private static final String JavaDoc TYPE = "type";
52     
53     private static final String JavaDoc EXPOSE = "expose";
54     
55     private static final String JavaDoc REQUIRES_TYPE = "requiresType";
56
57     private String JavaDoc name;
58     
59     private QName type;
60     
61     private boolean extendz;
62
63     private boolean isExposed;
64     
65     private boolean allowFullControl;
66
67     private QName container;
68
69     private Set JavaDoc<PermissionReference> includedPermissionGroups = new HashSet JavaDoc<PermissionReference>();
70
71     private boolean requiresType;
72
73     public PermissionGroup(QName container)
74     {
75         super();
76         this.container = container;
77     }
78
79     public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel)
80     {
81         // Name
82
name = element.attributeValue(NAME);
83         // Allow full control
84
Attribute att = element.attribute(ALLOW_FULL_CONTOL);
85         if (att != null)
86         {
87             allowFullControl = Boolean.parseBoolean(att.getStringValue());
88         }
89         else
90         {
91             allowFullControl = false;
92         }
93         
94         att = element.attribute(REQUIRES_TYPE);
95         if (att != null)
96         {
97             requiresType = Boolean.parseBoolean(att.getStringValue());
98         }
99         else
100         {
101             requiresType = true;
102         }
103         
104         att = element.attribute(EXTENDS);
105         if (att != null)
106         {
107             extendz = Boolean.parseBoolean(att.getStringValue());
108         }
109         else
110         {
111             extendz = false;
112         }
113         
114         att = element.attribute(EXPOSE);
115         if (att != null)
116         {
117             isExposed = Boolean.parseBoolean(att.getStringValue());
118         }
119         else
120         {
121             isExposed = true;
122         }
123         
124         att = element.attribute(TYPE);
125         if (att != null)
126         {
127             type = QName.createQName(att.getStringValue(),nspr);
128         }
129         else
130         {
131             type = null;
132         }
133         
134         // Include permissions defined for other permission groups
135

136         for (Iterator JavaDoc ipgit = element.elementIterator(INCLUDE_PERMISSION_GROUP); ipgit.hasNext(); /**/)
137         {
138             QName qName;
139             Element includePermissionGroupElement = (Element) ipgit.next();
140             Attribute typeAttribute = includePermissionGroupElement.attribute(TYPE);
141             if (typeAttribute != null)
142             {
143                 qName = QName.createQName(typeAttribute.getStringValue(), nspr);
144             }
145             else
146             {
147                 qName = container;
148             }
149             String JavaDoc refName = includePermissionGroupElement.attributeValue(PERMISSION_GROUP);
150             PermissionReference permissionReference = new PermissionReferenceImpl(qName, refName);
151             includedPermissionGroups.add(permissionReference);
152         }
153     }
154
155     public Set JavaDoc<PermissionReference> getIncludedPermissionGroups()
156     {
157         return Collections.unmodifiableSet(includedPermissionGroups);
158     }
159
160     public String JavaDoc getName()
161     {
162         return name;
163     }
164
165     public boolean isAllowFullControl()
166     {
167         return allowFullControl;
168     }
169
170     public QName getQName()
171     {
172         return container;
173     }
174
175     public boolean isExtends()
176     {
177         return extendz;
178     }
179
180     public QName getTypeQName()
181     {
182         return type;
183     }
184
185     public boolean isExposed()
186     {
187         return isExposed;
188     }
189     
190     
191     public boolean isTypeRequired()
192     {
193         return requiresType;
194     }
195 }
196
Popular Tags