ref #6867 extending the CdmPermissionClass enum and CdmAuthority support for sets
[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 org.apache.log4j.Logger;
12
13 import eu.etaxonomy.cdm.model.common.CdmBase;
14
15 /**
16 * see also {@link CdmBaseType}
17 *
18 * @author k.luther
19 * @author a.kohlbecker
20 * @date 06.07.2011
21 */
22 public enum CdmPermissionClass {
23 USER,
24 DESCRIPTIONBASE,
25 DESCRIPTIONELEMENTBASE,
26 TAXONBASE,
27 ALL,
28 TAXONNODE,
29 CLASSIFICATION,
30 REFERENCE,
31 TAXONNAME,
32 TEAMORPERSONBASE,
33 REGISTRATION,
34 SPECIMENOROBSERVATIONBASE,
35 SPECIMENTYPEDESIGNATION,
36 COLLECTION;
37
38
39 /**
40 * return the appropriate CdmPermissionClass for the given Object
41 *
42 * @param o
43 * @return the CdmPermissionClass or null
44 */
45 public static CdmPermissionClass getValueOf(CdmBase o){
46 return CdmPermissionClass.getValueOf(o.getClass());
47 }
48
49 /**
50 * return the appropriate CdmPermissionClass for the given Object
51 *
52 * @param o
53 * @return the CdmPermissionClass or null
54 */
55 public static CdmPermissionClass getValueOf(Class o){
56
57 CdmPermissionClass permissionClass = _valueOf(o);
58 if(permissionClass == null) {
59 Logger.getLogger(CdmPermissionClass.class).error("Permission class support for " + o + " not implemented");
60 }
61 return permissionClass;
62
63 }
64
65
66
67 /**
68 * @param o
69 * @return
70 */
71 protected static CdmPermissionClass _valueOf(Class o) {
72 try{
73 String normalizedName = o.getSimpleName().toUpperCase();
74 return CdmPermissionClass.valueOf(normalizedName);
75 } catch(IllegalArgumentException e){
76 if (CdmBase.class.isAssignableFrom(o)){
77 return _valueOf(o.getSuperclass());
78 }
79
80 }
81 return null;
82 }
83 }