KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > store > BookAclEntry


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.books.store;
17
18 import org.outerx.daisy.x10Bookstoremeta.BookAclDocument;
19 import org.outerx.daisy.x10Bookstoremeta.BookAclSubject;
20 import org.outerx.daisy.x10Bookstoremeta.BookAclAction;
21
22 /**
23  * An entry in an {@link BookAcl}. This is simply a class and not an interface,
24  * since it is just a data holder, it has no behaviour. This object is immutable.
25  */

26 public final class BookAclEntry {
27     private final BookAclSubjectType subjectType;
28     private final long subjectValue;
29     private final BookAclActionType readPermission;
30     private final BookAclActionType managePermission;
31
32     public BookAclEntry(BookAclSubjectType subjectType, long subjectValue,
33                         BookAclActionType readPermission, BookAclActionType managePermission) {
34         if (subjectType == null)
35             throw new IllegalArgumentException JavaDoc("subjectType cannot be null");
36         if (readPermission == null)
37             throw new IllegalArgumentException JavaDoc("readPermission cannot be null");
38         if (managePermission == null)
39             throw new IllegalArgumentException JavaDoc("managePermission cannot be null");
40         if (subjectType == BookAclSubjectType.EVERYONE && subjectValue != -1)
41             throw new IllegalArgumentException JavaDoc("subjectValue must be -1 if subjectType is 'everyone'");
42
43         this.subjectType = subjectType;
44         this.subjectValue = subjectValue;
45         this.readPermission = readPermission;
46         this.managePermission = managePermission;
47     }
48
49     public BookAclSubjectType getSubjectType() {
50         return subjectType;
51     }
52
53     public long getSubjectValue() {
54         return subjectValue;
55     }
56
57     public BookAclActionType getReadPermission() {
58         return readPermission;
59     }
60
61     public BookAclActionType getManagePermission() {
62         return managePermission;
63     }
64
65     public BookAclDocument.BookAcl.BookAclEntry getXml() {
66         BookAclDocument.BookAcl.BookAclEntry entryXml = BookAclDocument.BookAcl.BookAclEntry.Factory.newInstance();
67         entryXml.setSubjectType(BookAclSubject.Enum.forString(subjectType.toString()));
68         entryXml.setSubjectValue(subjectValue);
69         entryXml.setPermRead(BookAclAction.Enum.forString(readPermission.toString()));
70         entryXml.setPermManage(BookAclAction.Enum.forString(managePermission.toString()));
71         return entryXml;
72     }
73 }
74
Popular Tags