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 private 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 UsageEnum result = valueOf( usage ); 086 087 return result; 088 } 089 catch ( IllegalArgumentException iae ) 090 { 091 if ( "directoryOperation".equals( usage ) ) 092 { 093 return DIRECTORY_OPERATION; 094 } 095 else if ( "distributedOperation".equals( usage ) ) 096 { 097 return DISTRIBUTED_OPERATION; 098 } 099 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}