Merge branch 'release/4.8.0'
[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.CdmBaseType;
12 import eu.etaxonomy.cdm.model.common.CdmBase;
13
14 /**
15 * see also {@link CdmBaseType}
16 *
17 * @author k.luther
18 * @author a.kohlbecker
19 * @date 06.07.2011
20 */
21 public enum CdmPermissionClass {
22 USER,
23 DESCRIPTIONBASE,
24 DESCRIPTIONELEMENTBASE,
25 TAXONBASE,
26 ALL,
27 TAXONNODE,
28 CLASSIFICATION,
29 REFERENCE,
30 TAXONNAME,
31 TEAMORPERSONBASE;
32
33 /**
34 * return the appropriate CdmPermissionClass for the given Object
35 *
36 * @param o
37 * @return the CdmPermissionClass or null
38 */
39 public static CdmPermissionClass getValueOf(CdmBase o){
40 return CdmPermissionClass.getValueOf(o.getClass());
41 }
42
43
44
45 /**
46 * return the appropriate CdmPermissionClass for the given Object
47 *
48 * @param o
49 * @return the CdmPermissionClass or null
50 */
51 public static CdmPermissionClass getValueOf(Class o){
52
53 try{
54 return CdmPermissionClass.valueOf(o.getSimpleName().toUpperCase());
55 } catch(IllegalArgumentException e){
56 if (CdmBase.class.isAssignableFrom(o)){
57 return getValueOf(o.getSuperclass());
58 }
59
60 }
61
62 return null;
63 }
64 }