KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > usermanager > GroupManagerProviderBean


1 package org.jahia.services.usermanager;
2
3 /**
4  * <p>Title: </p>
5  * <p>Description: </p>
6  * <p>Copyright: Copyright (c) 2003</p>
7  * <p>Company: </p>
8  * @author Predrag Viceic <Predrag.Viceic@ci.unil.ch>
9  * @version 1.0
10  */

11
12 import java.lang.reflect.InvocationTargetException JavaDoc;
13 import java.lang.reflect.Method JavaDoc;
14
15 public class GroupManagerProviderBean {
16
17     private String JavaDoc key;
18     private String JavaDoc className;
19     private String JavaDoc description;
20     private String JavaDoc title;
21     private boolean isReadOnly = true;
22     private JahiaGroupManagerProvider instance;
23     private boolean isDefault = false;
24     private int priority;
25
26     public GroupManagerProviderBean (String JavaDoc key,
27                                      String JavaDoc className,
28                                      String JavaDoc title,
29                                      String JavaDoc description,
30                                      boolean isDefault,
31                                      boolean isReadOnly,
32                                      int priority) {
33         this.key = key;
34         this.className = className;
35         this.description = description;
36         this.title = title;
37         this.isDefault = isDefault;
38         this.isReadOnly = isReadOnly;
39         this.priority = priority;
40     }
41
42     public String JavaDoc getKey () {
43         return key;
44     }
45
46     public void setKey (String JavaDoc key) {
47         this.key = key;
48     }
49
50     public void setClassName (String JavaDoc className) {
51         this.className = className;
52     }
53
54     public String JavaDoc getClassName () {
55         return className;
56     }
57
58     public void setDescription (String JavaDoc description) {
59         this.description = description;
60     }
61
62     public String JavaDoc getDescription () {
63         return description;
64     }
65
66     public void setTitle (String JavaDoc title) {
67         this.title = title;
68     }
69
70     public String JavaDoc getTitle () {
71         return title;
72     }
73
74     public void setIsDefault (boolean isDefault) {
75         this.isDefault = isDefault;
76     }
77
78     public boolean getIsDefault () {
79         return isDefault;
80     }
81
82     public void setIsReadOnly (boolean isReadOnly) {
83         this.isReadOnly = isReadOnly;
84     }
85
86     public boolean getIsReadOnly () {
87         return isReadOnly;
88     }
89
90     public void setPriority (int priority) {
91         this.priority = priority;
92     }
93
94     public int getPriority () {
95         return priority;
96     }
97
98     public JahiaGroupManagerProvider getInstance () {
99         if (this.instance != null) {
100             return this.instance;
101         }
102
103         if (this.className == null) {
104             return null;
105         }
106
107         try {
108             Class JavaDoc destClass = Class.forName (this.className);
109             Class JavaDoc superClass = destClass.getSuperclass ();
110             if (superClass == null) {
111                 return null;
112             }
113             if (!"org.jahia.services.usermanager.JahiaGroupManagerProvider".equals (
114                     superClass.getName ())) {
115                 // class parent is not of correct type.
116
return null;
117             }
118             Method JavaDoc getInstanceMethod = destClass.getMethod ("getInstance", null);
119             if (getInstanceMethod == null) {
120                 return null;
121             }
122             this.instance = (JahiaGroupManagerProvider) getInstanceMethod.invoke (null, null);
123
124         } catch (LinkageError JavaDoc le) {
125             le.printStackTrace ();
126             this.instance = null;
127         } catch (ClassNotFoundException JavaDoc cnfe) {
128             cnfe.printStackTrace ();
129             this.instance = null;
130         } catch (NoSuchMethodException JavaDoc nsme) {
131             nsme.printStackTrace ();
132             this.instance = null;
133         } catch (InvocationTargetException JavaDoc ite) {
134             ite.printStackTrace ();
135             this.instance = null;
136         } catch (IllegalAccessException JavaDoc iae) {
137             iae.printStackTrace ();
138             this.instance = null;
139         }
140         return this.instance;
141     }
142
143     public boolean equals (Object JavaDoc obj) {
144         if (!(obj instanceof GroupManagerProviderBean)) {
145             return false;
146         }
147         GroupManagerProviderBean right = (GroupManagerProviderBean) obj;
148         return objectEquals (getKey (), right.getKey ());
149     }
150
151     private boolean objectEquals (String JavaDoc left, String JavaDoc right) {
152         if ((left == null) && (right == null)) {
153             return true;
154         } else if ((left == null) && (right != null)) {
155             return false;
156         } else if ((left != null) && (right == null)) {
157             return false;
158         } else {
159             // we are now guaranteed that neither left or right are null so we
160
// can call the equals method safely.
161
return left.equals (right);
162         }
163     }
164 }
165
Popular Tags