View Javadoc
1   /**
2    * Copyright 2014 Internet2
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17    Copyright (C) 2004-2007 University Corporation for Advanced Internet Development, Inc.
18    Copyright (C) 2004-2007 The University Of Chicago
19  
20    Licensed under the Apache License, Version 2.0 (the "License");
21    you may not use this file except in compliance with the License.
22    You may obtain a copy of the License at
23  
24      http://www.apache.org/licenses/LICENSE-2.0
25  
26    Unless required by applicable law or agreed to in writing, software
27    distributed under the License is distributed on an "AS IS" BASIS,
28    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29    See the License for the specific language governing permissions and
30    limitations under the License.
31  */
32  
33  package edu.internet2.middleware.grouper;
34  import java.io.Serializable;
35  
36  import org.apache.commons.lang.StringUtils;
37  
38  import edu.internet2.middleware.grouper.app.loader.GrouperLoaderType;
39  import edu.internet2.middleware.grouper.util.GrouperUtil;
40  
41  /** 
42   * Field Type.
43   * <p/>
44   * @author  blair christensen.
45   * @version $Id: FieldType.java,v 1.15 2009-09-21 06:14:27 mchyzer Exp $    
46   */
47  public enum FieldType implements Serializable {
48  
49    /** */
50    ACCESS("access"),
51    
52    /** */
53    ATTRIBUTE_DEF("attributeDef"),
54    
55    /** */
56    LIST("list"),
57  
58    /** */
59    NAMING("naming");
60    
61    /**
62     * 
63     * @param type
64     * @param exceptionOnNull
65     * @return field type
66     */
67    public static FieldType valueOfIgnoreCase(String type, boolean exceptionOnNull) {
68  
69      FieldType fieldType = null;
70      
71      try {
72        fieldType = GrouperUtil.enumValueOfIgnoreCase(FieldType.class, 
73            type, false);
74      } catch (Exception e) {
75        //ignore this
76      }
77      
78      if (fieldType != null) {
79        return fieldType;
80      }
81      
82      for (FieldType localFieldType : FieldType.values()) {
83        if (StringUtils.equalsIgnoreCase(type, localFieldType.getType())) {
84          return localFieldType;
85        }
86      }
87        
88      if (exceptionOnNull) {
89        throw new RuntimeException("Cant find type: " + type);
90      }
91      
92      return null;
93      
94    }
95    
96    /**
97     * 
98     * @param type
99     * @return the type
100    */
101   public static FieldType getInstance(String type) {
102     for (FieldType fieldType : FieldType.values()) {
103       if (StringUtils.equalsIgnoreCase(type, fieldType.getType())) {
104         return fieldType;
105       }
106     }
107     throw new RuntimeException("Cant find field type: " + type);
108   }
109 
110   /**
111    * 
112    * @param theType
113    */
114   private FieldType(String theType) {
115     this.type = theType;
116   }
117   
118   /** */
119   private String type;
120 
121 
122   /**
123    * 
124    * @see java.lang.Enum#toString()
125    */
126   public String toString() {
127     return this.type;
128   } // public String toString()
129 
130   /**
131    * 
132    * @return type
133    */
134   public String getType() {
135     return type;
136   }
137 
138 }
139