implementing global PUBLISH role, also introducing the interface IPublishable; solves...
[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 * @author a.kohlbecker
16 * @date 06.07.2011
17 */
18 public enum CdmPermissionClass {
19 USER,
20 DESCRIPTIONBASE,
21 DESCRIPTIONELEMENTBASE,
22 TAXONBASE,
23 ALL,
24 TAXONNODE,
25 CLASSIFICATION;
26
27
28 /**
29 * return the appropriate CdmPermissionClass for the given Object. May return null if no matching CdmPermissionClass was found.
30 * @param s
31 * @return the CdmPermissionClass or null
32 */
33 public static CdmPermissionClass getValueOf(Object s){
34
35 String permissionClassString ;
36 if (s instanceof String){
37 permissionClassString = (String)s;
38 }else if (s instanceof CdmBase){
39 permissionClassString = s.getClass().getSimpleName().toUpperCase();
40 } else if(s instanceof Class){
41 permissionClassString = ((Class) s).getSimpleName().toUpperCase();
42 }else{
43
44 return null;
45 }
46
47 try{
48 return CdmPermissionClass.valueOf(permissionClassString);
49 }catch(IllegalArgumentException e){
50 if (s instanceof CdmBase){
51 s = s.getClass().getSuperclass();
52
53 return getValueOf(s);
54 }
55
56 }
57
58 return null;
59 }
60 }