1 /***
2 * Domain.java
3 *
4 * This file is part of the creme library.
5 * The creme library intends to ease the development effort of large
6 * applications by providing easy to use support classes.
7 *
8 * Copyright (C) 2003 Denis Bregeon
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * contact information: dbregeon@sourceforge.net
25 */
26 package org.jcreme.permissioning;
27
28 import java.util.Hashtable;
29
30 import org.jcreme.enumerations.Enumeration;
31
32 /***
33 * This enumeration represent the functional domains of an organization.
34 * Permissions to access certain data types are based on Domains. This ensures
35 * that the some business Domains have no access to some data if needed.
36 *
37 * @author $Author: dbregeon $
38 * @version $Revision: 1.1 $
39 */
40 public class Domain extends Enumeration {
41
42 protected static final Hashtable fromName = new Hashtable();
43
44 protected Domain(String name) {
45 super(name);
46 }
47
48 /***
49 *
50 * @param name
51 * @return
52 */
53 public static Domain get(String name) {
54 Domain result = null;
55 if (name != null) {
56 result = (Domain) fromName.get(name);
57 if (result == null) {
58 result = new Domain(name);
59 }
60 }
61 return result;
62 }
63
64 /***
65 *
66 * @param name
67 * @return
68 */
69 public static boolean contains(String name) {
70 return (name != null) && (fromName.containsKey(name));
71 }
72
73 /***
74 *
75 * @param name
76 */
77 public static void remove(String name) {
78 if (name != null) {
79 fromName.remove(name);
80 }
81 }
82
83 /***
84 * @see org.jcreme.enumerations.Enumeration#getFromName()
85 */
86 protected Hashtable getFromName() {
87 return fromName;
88 }
89
90 /***
91 *
92 * @return
93 */
94 public static Domain[] getDomains() {
95 return (Domain[]) fromName.values().toArray(new Domain[0]);
96 }
97
98 /***
99 * @return
100 */
101 public static Enumeration[] getValues() {
102 return (Enumeration[]) fromName.values().toArray(new Enumeration[0]);
103 }
104
105 }