1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.schema; 21 22 23 /** 24 * Type safe enum for an AttributeType definition's usage string. This can be 25 * take one of the following four values: 26 * <ul> 27 * <li>userApplications</li> 28 * <li>directoryOperation</li> 29 * <li>distributedOperation</li> 30 * <li>dSAOperation</li> 31 * </ul> 32 * 33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 34 */ 35 public enum UsageEnum 36 { 37 /** value for attributes with userApplications usage */ 38 USER_APPLICATIONS(0), 39 40 /** value for attributes with directoryOperation usage */ 41 DIRECTORY_OPERATION(1), 42 43 /** value for attributes with distributedOperation usage */ 44 DISTRIBUTED_OPERATION(2), 45 46 /** value for attributes with dSAOperation usage */ 47 DSA_OPERATION(3); 48 49 /** Stores the integer value of each element of the enumeration */ 50 private int value; 51 52 53 /** 54 * Private construct so no other instances can be created other than the 55 * public static constants in this class. 56 * 57 * @param value the integer value of the enumeration. 58 */ 59 private UsageEnum( int value ) 60 { 61 this.value = value; 62 } 63 64 65 /** 66 * @return The value associated with the current element. 67 */ 68 public int getValue() 69 { 70 return value; 71 } 72 73 74 /** 75 * Gets the enumeration type for the attributeType usage string regardless 76 * of case. 77 * 78 * @param usage the usage string 79 * @return the usage enumeration type 80 */ 81 public static UsageEnum getUsage( String usage ) 82 { 83 try 84 { 85 UsageEnum result = valueOf( usage ); 86 87 return result; 88 } 89 catch ( IllegalArgumentException iae ) 90 { 91 if ( "directoryOperation".equals( usage ) ) 92 { 93 return DIRECTORY_OPERATION; 94 } 95 else if ( "distributedOperation".equals( usage ) ) 96 { 97 return DISTRIBUTED_OPERATION; 98 } 99 else if ( "dSAOperation".equals( usage ) ) 100 { 101 return DSA_OPERATION; 102 } 103 else if ( "userApplications".equals( usage ) ) 104 { 105 return USER_APPLICATIONS; 106 } 107 else 108 { 109 return null; 110 } 111 } 112 } 113 114 115 /** 116 * Get the string representation for UsageEnum, which will be 117 * used by the AttributeType rendering 118 * @param usage The UsageEnum of which we want the rendering string 119 * @return The rendering stringe 120 */ 121 public static String render( UsageEnum usage ) 122 { 123 if ( usage == null ) 124 { 125 return "userApplications"; 126 } 127 128 switch ( usage ) 129 { 130 case DIRECTORY_OPERATION: 131 return "directoryOperation"; 132 case DISTRIBUTED_OPERATION: 133 return "distributedOperation"; 134 case DSA_OPERATION: 135 return "dSAOperation"; 136 case USER_APPLICATIONS: 137 return "userApplications"; 138 default: 139 return ""; 140 } 141 } 142 143 144 /** 145 * Get the string representation for UsageEnum, which will be 146 * used by the AttributeType rendering 147 * @return The rendering stringe 148 */ 149 public String render() 150 { 151 return render( this ); 152 } 153 }