merging in git branch 'methodSecurityExpressions' and resolving conflict in SecurityT...
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / hibernate / permission / CdmPermissionClass.java
1 /**
2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.persistence.hibernate.permission;
10
11 import eu.etaxonomy.cdm.model.common.CdmBase;
12
13 /**
14 * @author k.luther
15 * @date 06.07.2011
16 */
17 public enum CdmPermissionClass {
18 USER,
19 DESCRIPTIONBASE,
20 DESCRIPTIONELEMENTBASE,
21 TAXONBASE,
22 ALL,
23 TAXONNODE,
24 CLASSIFICATION;
25
26
27 /**
28 * return the appropriate CdmPermissionClass for the given Object. May return null if no matching CdmPermissionClass was found.
29 * @param s
30 * @return the CdmPermissionClass or null
31 */
32 public static CdmPermissionClass getValueOf(Object s){
33
34 String permissionClassString ;
35 if (s instanceof String){
36 permissionClassString = (String)s;
37 }else if (s instanceof CdmBase){
38 permissionClassString = s.getClass().getSimpleName().toUpperCase();
39 } else if(s instanceof Class){
40 permissionClassString = ((Class) s).getSimpleName().toUpperCase();
41 }else{
42
43 return null;
44 }
45
46 try{
47 return CdmPermissionClass.valueOf(permissionClassString);
48 }catch(IllegalArgumentException e){
49 if (s instanceof CdmBase){
50 s = s.getClass().getSuperclass();
51
52 return getValueOf(s);
53 }
54
55 }
56
57 return null;
58 }
59 }