001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.schema;
021
022
023 /**
024 * Type safe enum for an AttributeType definition's usage string. This can be
025 * take one of the following four values:
026 * <ul>
027 * <li>userApplications</li>
028 * <li>directoryOperation</li>
029 * <li>distributedOperation</li>
030 * <li>dSAOperation</li>
031 * </ul>
032 *
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 * @version $Rev: 664290 $
035 */
036 public enum UsageEnum
037 {
038 /** value for attributes with userApplications usage */
039 USER_APPLICATIONS( 0 ),
040
041 /** value for attributes with directoryOperation usage */
042 DIRECTORY_OPERATION( 1 ),
043
044 /** value for attributes with distributedOperation usage */
045 DISTRIBUTED_OPERATION( 2 ),
046
047 /** value for attributes with dSAOperation usage */
048 DSA_OPERATION( 3 );
049
050 /** Stores the integer value of each element of the enumeration */
051 private int value;
052
053 /**
054 * Private construct so no other instances can be created other than the
055 * public static constants in this class.
056 *
057 * @param value the integer value of the enumeration.
058 */
059 private UsageEnum( int value )
060 {
061 this.value = value;
062 }
063
064 /**
065 * @return The value associated with the current element.
066 */
067 public int getValue()
068 {
069 return value;
070 }
071
072 /**
073 * Gets the enumeration type for the attributeType usage string regardless
074 * of case.
075 *
076 * @param usage the usage string
077 * @return the usage enumeration type
078 */
079 public static UsageEnum getUsage( String usage )
080 {
081 try
082 {
083 UsageEnum result = valueOf( usage );
084
085 return result;
086 }
087 catch( IllegalArgumentException iae )
088 {
089 if ( "directoryOperation".equals( usage ) )
090 {
091 return DIRECTORY_OPERATION;
092 }
093 else if ( "distributedOperation".equals( usage ) )
094 {
095 return DISTRIBUTED_OPERATION;
096 }
097 else if ( "dSAOperation".equals( usage ) )
098 {
099 return DSA_OPERATION;
100 }
101 else if ( "userApplications".equals( usage ) )
102 {
103 return USER_APPLICATIONS;
104 }
105 else
106 {
107 return null;
108 }
109 }
110 }
111
112 /**
113 * Get the string representation for UsageEnum, which will be
114 * used by the AttributeType rendering
115 * @param usage The UsageEnum of which we want the rendering string
116 * @return The rendering stringe
117 */
118 public static String render( UsageEnum usage )
119 {
120 if ( usage == null)
121 {
122 return "";
123 }
124
125 switch ( usage )
126 {
127 case DIRECTORY_OPERATION : return "directoryOperation";
128 case DISTRIBUTED_OPERATION : return "distributedOperation";
129 case DSA_OPERATION : return "dSAOperation";
130 case USER_APPLICATIONS : return "userApplications";
131 default : return "";
132 }
133 }
134
135 /**
136 * Get the string representation for UsageEnum, which will be
137 * used by the AttributeType rendering
138 * @return The rendering stringe
139 */
140 public String render()
141 {
142 return render( this );
143 }
144 }