AccessDecisionVoter based acl implementation working - all test succeed, but assertio...
[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 String permissionClassString ;
28 if (s instanceof String){
29 permissionClassString = (String)s;
30 }else if (s instanceof CdmBase){
31 permissionClassString = s.getClass().getSimpleName().toUpperCase();
32 } else if(s instanceof Class){
33 permissionClassString = ((Class) s).getSimpleName().toUpperCase();
34 }else{
35
36 return null;
37 }
38 try{
39 return CdmPermissionClass.valueOf(permissionClassString);
40 }catch(IllegalArgumentException e){
41 if (s instanceof CdmBase){
42 s = s.getClass().getSuperclass();
43
44 return getValueOf(s);
45 }
46
47 }
48 return null;
49 }
50 }