KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > jaas > principal > GroupListImpl


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.jaas.principal;
14
15 import info.magnolia.cms.security.auth.GroupList;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.commons.lang.builder.ToStringBuilder;
23 import org.apache.commons.lang.builder.ToStringStyle;
24
25
26 /**
27  * @author Sameer Charles $Id: GroupListImpl.java 6341 2006-09-12 09:18:27Z philipp $
28  */

29 public class GroupListImpl implements GroupList {
30
31     /**
32      * Stable serialVersionUID.
33      */

34     private static final long serialVersionUID = 222L;
35
36     /**
37      * default name for this principal
38      */

39     protected static final String JavaDoc DEFAULT_NAME = "groups";
40
41     /**
42      * properties
43      */

44     protected String JavaDoc name;
45
46     /**
47      * list of names
48      */

49     protected Collection JavaDoc list;
50
51     public GroupListImpl() {
52         this.list = new ArrayList JavaDoc();
53     }
54
55     /**
56      * Get name given to this principal
57      * @return name
58      */

59     public String JavaDoc getName() {
60         if (StringUtils.isEmpty(this.name)) {
61             return DEFAULT_NAME;
62         }
63         return this.name;
64     }
65
66     /**
67      * Set principal name
68      * @param name
69      */

70     public void setName(String JavaDoc name) {
71         this.name = name;
72     }
73
74     /**
75      * Add a name to the list
76      * @param name
77      */

78     public void add(String JavaDoc name) {
79         this.list.add(name);
80     }
81
82     /**
83      * Gets list of roles as string
84      * @return roles
85      */

86     public Collection JavaDoc getList() {
87         return this.list;
88     }
89
90     /**
91      * Checks if the name exist in this list
92      * @param name
93      */

94     public boolean has(String JavaDoc name) {
95         Iterator JavaDoc listIterator = this.list.iterator();
96         while (listIterator.hasNext()) {
97             String JavaDoc roleName = (String JavaDoc) listIterator.next();
98             if (StringUtils.equalsIgnoreCase(name, roleName)) {
99                 return true;
100             }
101         }
102         return false;
103     }
104
105     /**
106      * @see java.lang.Object#toString()
107      */

108     public String JavaDoc toString() {
109         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("name", this.name).append(
110             "list",
111             this.list).toString();
112     }
113 }
114
Popular Tags