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 */ 020package org.apache.directory.api.ldap.model.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 */ 035public enum UsageEnum 036{ 037 /** value for attributes with userApplications usage */ 038 USER_APPLICATIONS(0), 039 040 /** value for attributes with directoryOperation usage */ 041 DIRECTORY_OPERATION(1), 042 043 /** value for attributes with distributedOperation usage */ 044 DISTRIBUTED_OPERATION(2), 045 046 /** value for attributes with dSAOperation usage */ 047 DSA_OPERATION(3); 048 049 /** Stores the integer value of each element of the enumeration */ 050 private int value; 051 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 UsageEnum( int value ) 060 { 061 this.value = value; 062 } 063 064 065 /** 066 * @return The value associated with the current element. 067 */ 068 public int getValue() 069 { 070 return value; 071 } 072 073 074 /** 075 * Gets the enumeration type for the attributeType usage string regardless 076 * of case. 077 * 078 * @param usage the usage string 079 * @return the usage enumeration type 080 */ 081 public static UsageEnum getUsage( String usage ) 082 { 083 try 084 { 085 return valueOf( usage ); 086 } 087 catch ( IllegalArgumentException iae ) 088 { 089 if ( "directoryOperation".equalsIgnoreCase( usage ) ) 090 { 091 return DIRECTORY_OPERATION; 092 } 093 else if ( "distributedOperation".equalsIgnoreCase( usage ) ) 094 { 095 return DISTRIBUTED_OPERATION; 096 } 097 else if ( "dSAOperation".equalsIgnoreCase( usage ) ) 098 { 099 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}