all test SUCCESSFUL - (concept of implicitPermission and voters discarded and disabled)
[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, DESCRIPTIONBASE, DESCRIPTIONELEMENTBASE, TAXONBASE, ALL, TAXONNODE, CLASSIFICATION;
19
20
21 /**
22 * return the appropriate CdmPermissionClass for the given Object. May return null if no matching CdmPermissionClass was found.
23 * @param s
24 * @return the CdmPermissionClass or null
25 */
26 public static CdmPermissionClass getValueOf(Object s){
27
28 String permissionClassString ;
29 if (s instanceof String){
30 permissionClassString = (String)s;
31 }else if (s instanceof CdmBase){
32 permissionClassString = s.getClass().getSimpleName().toUpperCase();
33 } else if(s instanceof Class){
34 permissionClassString = ((Class) s).getSimpleName().toUpperCase();
35 }else{
36
37 return null;
38 }
39
40 try{
41 return CdmPermissionClass.valueOf(permissionClassString);
42 }catch(IllegalArgumentException e){
43 if (s instanceof CdmBase){
44 s = s.getClass().getSuperclass();
45
46 return getValueOf(s);
47 }
48
49 }
50
51 return null;
52 }
53 }