KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jahia.services.usermanager;
2
3 import java.lang.reflect.InvocationTargetException JavaDoc;
4 import java.lang.reflect.Method JavaDoc;
5
6 /**
7  * <p>Title: Small bean to manage provider info </p>
8  * <p>Description: </p>
9  * <p>Copyright: Copyright (c) 2002</p>
10  * <p>Company: Jahia Inc.</p>
11  *
12  * @author Serge Huber
13  * @version 3.0
14  */

15
16 public class UserManagerProviderBean {
17
18     private String JavaDoc key;
19     private String JavaDoc className;
20     private String JavaDoc description;
21     private String JavaDoc title;
22     private boolean isReadOnly = true;
23     private JahiaUserManagerProvider instance;
24     private boolean isDefault = false;
25     private int priority = 99;
26
27     public UserManagerProviderBean (String JavaDoc key,
28                                     String JavaDoc className,
29                                     String JavaDoc title,
30                                     String JavaDoc description,
31                                     boolean isDefault,
32                                     boolean isReadOnly,
33                                     int priority) {
34         this.key = key;
35         this.className = className;
36         this.description = description;
37         this.title = title;
38         this.isDefault = isDefault;
39         this.isReadOnly = isReadOnly;
40         this.priority = priority;
41     }
42
43     public String JavaDoc getKey () {
44         return key;
45     }
46
47     public void setKey (String JavaDoc key) {
48         this.key = key;
49     }
50
51     public void setClassName (String JavaDoc className) {
52         this.className = className;
53     }
54
55     public String JavaDoc getClassName () {
56         return className;
57     }
58
59     public void setDescription (String JavaDoc description) {
60         this.description = description;
61     }
62
63     public String JavaDoc getDescription () {
64         return description;
65     }
66
67     public void setTitle (String JavaDoc title) {
68         this.title = title;
69     }
70
71     public String JavaDoc getTitle () {
72         return title;
73     }
74
75     public void setIsDefault (boolean isDefault) {
76         this.isDefault = isDefault;
77     }
78
79     public boolean getIsDefault () {
80         return isDefault;
81     }
82
83     public void setIsReadOnly (boolean isReadOnly) {
84         this.isReadOnly = isReadOnly;
85     }
86
87     public boolean getIsReadOnly () {
88         return isReadOnly;
89     }
90
91     public void setPriority (int priority) {
92         this.priority = priority;
93     }
94
95     public int getPriority () {
96         return priority;
97     }
98
99     public JahiaUserManagerProvider getInstance () {
100         if (this.instance != null) {
101             return this.instance;
102         }
103
104         if (this.className == null) {
105             return null;
106         }
107
108         try {
109             Class JavaDoc destClass = Class.forName (this.className);
110             Class JavaDoc superClass = destClass.getSuperclass ();
111             if (superClass == null) {
112                 return null;
113             }
114             if (!"org.jahia.services.usermanager.JahiaUserManagerProvider".equals (
115                     superClass.getName ())) {
116                 // class parent is not of correct type.
117
return null;
118             }
119             Method JavaDoc getInstanceMethod = destClass.getMethod ("getInstance", null);
120             if (getInstanceMethod == null) {
121                 return null;
122             }
123             this.instance = (JahiaUserManagerProvider) getInstanceMethod.invoke (null, null);
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 UserManagerProviderBean)) {
145             return false;
146         }
147         UserManagerProviderBean right = (UserManagerProviderBean) 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