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 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 return valueOf( usage ); 86 } 87 catch ( IllegalArgumentException iae ) 88 { 89 if ( "directoryOperation".equalsIgnoreCase( usage ) ) 90 { 91 return DIRECTORY_OPERATION; 92 } 93 else if ( "distributedOperation".equalsIgnoreCase( usage ) ) 94 { 95 return DISTRIBUTED_OPERATION; 96 } 97 else if ( "dSAOperation".equalsIgnoreCase( usage ) ) 98 { 99 return DSA_OPERATION; 100 } 101 else if ( "userApplications".equalsIgnoreCase( usage ) ) 102 { 103 return USER_APPLICATIONS; 104 } 105 else 106 { 107 return null; 108 } 109 } 110 } 111 112 113 /** 114 * Get the string representation for UsageEnum, which will be 115 * used by the AttributeType rendering 116 * @param usage The UsageEnum of which we want the rendering string 117 * @return The rendering stringe 118 */ 119 public static String render( UsageEnum usage ) 120 { 121 if ( usage == null ) 122 { 123 return "userApplications"; 124 } 125 126 switch ( usage ) 127 { 128 case DIRECTORY_OPERATION: 129 return "directoryOperation"; 130 case DISTRIBUTED_OPERATION: 131 return "distributedOperation"; 132 case DSA_OPERATION: 133 return "dSAOperation"; 134 case USER_APPLICATIONS: 135 return "userApplications"; 136 default: 137 return ""; 138 } 139 } 140 141 142 /** 143 * Get the string representation for UsageEnum, which will be 144 * used by the AttributeType rendering 145 * @return The rendering stringe 146 */ 147 public String render() 148 { 149 return render( this ); 150 } 151 }