1 package org.jahia.services.usermanager; 2 3 import java.lang.reflect.InvocationTargetException ; 4 import java.lang.reflect.Method ; 5 6 15 16 public class UserManagerProviderBean { 17 18 private String key; 19 private String className; 20 private String description; 21 private String 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 key, 28 String className, 29 String title, 30 String 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 getKey () { 44 return key; 45 } 46 47 public void setKey (String key) { 48 this.key = key; 49 } 50 51 public void setClassName (String className) { 52 this.className = className; 53 } 54 55 public String getClassName () { 56 return className; 57 } 58 59 public void setDescription (String description) { 60 this.description = description; 61 } 62 63 public String getDescription () { 64 return description; 65 } 66 67 public void setTitle (String title) { 68 this.title = title; 69 } 70 71 public String 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 destClass = Class.forName (this.className); 110 Class superClass = destClass.getSuperclass (); 111 if (superClass == null) { 112 return null; 113 } 114 if (!"org.jahia.services.usermanager.JahiaUserManagerProvider".equals ( 115 superClass.getName ())) { 116 return null; 118 } 119 Method getInstanceMethod = destClass.getMethod ("getInstance", null); 120 if (getInstanceMethod == null) { 121 return null; 122 } 123 this.instance = (JahiaUserManagerProvider) getInstanceMethod.invoke (null, null); 124 } catch (LinkageError le) { 125 le.printStackTrace (); 126 this.instance = null; 127 } catch (ClassNotFoundException cnfe) { 128 cnfe.printStackTrace (); 129 this.instance = null; 130 } catch (NoSuchMethodException nsme) { 131 nsme.printStackTrace (); 132 this.instance = null; 133 } catch (InvocationTargetException ite) { 134 ite.printStackTrace (); 135 this.instance = null; 136 } catch (IllegalAccessException iae) { 137 iae.printStackTrace (); 138 this.instance = null; 139 } 140 return this.instance; 141 } 142 143 public boolean equals (Object 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 left, String 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 return left.equals (right); 162 } 163 } 164 165 } | Popular Tags |