001:/*
002: * The contents of this file are subject to the Sapient Public License
003: * Version 1.0 (the "License"); you may not use this file except in compliance
004: * with the License. You may obtain a copy of the License at
005: * http://carbon.sf.net/License.html.
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is The Carbon Component Framework.
012: *
013: * The Initial Developer of the Original Code is Sapient Corporation
014: *
015: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016: */
017:
018:package org.sape.carbon.services.security.management.rdbms;
019:
020:
021:
022:import java.io.ObjectStreamException;
023:import java.io.Serializable;
024:
025:import org.sape.carbon.core.util.enum.BaseEnum;
026:import org.sape.carbon.core.util.enum.EnumNotFoundException;
027:
028:/**
029: * Enumeration object for the two main types of principals.
030: *
031: * <p>
032: * Principals are unique indentifiers for entities. The two major types
033: * of entities in a system are users and groups. In the java
034: * environment, checking to see if objects implement the Group interface
035: * is an easy way to check. In the default database implementation an
036: * enumeration is needed in the mapping table.
037: * </p>
038: *
039: * @author $Author: dvoet $ $Date: 2003/05/05 21:21:35 $
040: * @version $Revision: 1.6 $
041: *
042: * @since carbon 1.2
043: */
044:public final class PrincipalTypeEnum extends BaseEnum
045: implements Serializable {
046: /** User. */
047: public static final PrincipalTypeEnum USER =
048: new PrincipalTypeEnum("user", 1);
049:
050: /** Group. */
051: public static final PrincipalTypeEnum GROUP =
052: new PrincipalTypeEnum("group", 2);
053:
054: /**
055: * Constructs a enumeration of type <code>PrincipalTypeEnum</code>.
056: *
057: * @param name the string name of the enumeration type
058: * @param ordinal the ordinal number for the enumeration type
059: */
060: private PrincipalTypeEnum(String name, int ordinal) {
061: super (PrincipalTypeEnum.class, name, ordinal);
062: }
063:
064: /**
065: * Strongly typed enum retriever.
066: *
067: * @param name string name of the enumeration to retreive
068: *
069: * @return the enumeration for the name
070: *
071: * @throws PrincipalTypeEnumNotFoundException indicates there is no
072: * enumeration represented by the given name
073: */
074: public static final PrincipalTypeEnum getByName(String name)
075: throws PrincipalTypeEnumNotFoundException {
076: PrincipalTypeEnum scope =
077: (PrincipalTypeEnum) BaseEnum.getByName(
078: name, PrincipalTypeEnum.class);
079:
080: if (scope == null) {
081: throw new PrincipalTypeEnumNotFoundException(
082: PrincipalTypeEnum.class, name);
083: }
084:
085: return scope;
086: }
087:
088: /**
089: * Strongly typed enum retriever.
090: *
091: * @param ordinal ordinal of the enumeration to retreive
092: *
093: * @return the enumeration for the ordinal
094: *
095: * @throws PrincipalTypeEnumNotFoundException indicates there is no
096: * enumeration represented by the given ordinal
097: */
098: public static final PrincipalTypeEnum getByOrdinal(int ordinal)
099: throws PrincipalTypeEnumNotFoundException {
100: PrincipalTypeEnum scope =
101: (PrincipalTypeEnum) BaseEnum.getByOrdinal(
102: ordinal, PrincipalTypeEnum.class);
103:
104: if (scope == null) {
105: throw new PrincipalTypeEnumNotFoundException(
106: PrincipalTypeEnum.class,
107: new Integer(ordinal).toString());
108: }
109:
110: return scope;
111: }
112:
113: /**
114: * Overrides part of serialization to return a reference to an
115: * enumeration instance that is managed by the Enumeration Subsystem.
116: * This will always return the SAME object instance for any single
117: * enum instance and is what allows the "==" operator to be used for
118: * comparisons.
119: *
120: * @return the object instance that should be resolved by this class
121: *
122: * @throws ObjectStreamException when there is a failure to resolve
123: * the streamed object due to a format or read io exception
124: */
125: final Object readResolve() throws ObjectStreamException {
126: return super .getByOrdinal(this .ordinal, this .getClass());
127: }
128:
129: /**
130: * This class is a typesafe retriever exception for an enumeration.
131: */
132: public static class PrincipalTypeEnumNotFoundException
133: extends EnumNotFoundException {
134: /**
135: * Constructor for LifecycleStateEnumNotFoundException.
136: *
137: * @param sourceClass the source object generating the exception
138: * @param name the name/ordinal being searched for
139: */
140: public PrincipalTypeEnumNotFoundException(
141: Class sourceClass, String name) {
142: super(sourceClass, name);
143: }
144: }
145:}
|