gluu
公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.credmanager.core.init.AppInitializer クラス
org.gluu.credmanager.core.init.AppInitializer の継承関係図
Inheritance graph
org.gluu.credmanager.core.init.AppInitializer 連携図
Collaboration graph

公開メンバ関数

void contextInitialized (ServletContextEvent sce)
 
void contextDestroyed (ServletContextEvent sce)
 

非公開変数類

Logger logger
 

静的非公開変数類

static final String PATCH_1 = "public ClassLoader getContextClassLoaderForName(String className);"
 
static final String PATCH_2 = "private static org.zkoss.lang.ContextClassLoaderFactory factory;"
 
static final String PATCH_3
 
static final String PATCH_4
 
static final String PATCH_5
 

詳解

This listener class can be removed when using a ZK CE version higher than 8.5.0. In this case, it suffices to uncomment the corresponding library property in file zk.xml

著者
jgomer

関数詳解

◆ contextDestroyed()

void org.gluu.credmanager.core.init.AppInitializer.contextDestroyed ( ServletContextEvent  sce)
inline
112  {
113  }

◆ contextInitialized()

void org.gluu.credmanager.core.init.AppInitializer.contextInitialized ( ServletContextEvent  sce)
inline
57  {
58 
59  //This method modifies a couple of ZK classes before they are loaded by the JVM. This is required to achieve a
60  //fix for this problem: http://tracker.zkoss.org/browse/ZK-3762
61  //In summary every cred-manager plugin is loaded in a separate Java classloader, meaning that ZK ViewModel classes
62  //bound to zuml templates won't be found in current thread's classloader unless this problem is tackled.
63  //The patching here is inspired in code of ZK 8.5.1 EE (https://github.com/zkoss/zk/tree/master/zcommon)
64 
65  //@developer: do not edit this method. You are warned :p
66  logger.trace("AppInitializer. Applying ZK classes customization");
67 
68  System.setProperty("org.zkoss.lang.contextClassLoader.class", "org.gluu.credmanager.misc.CustomClassLoader");
69  try {
70  ClassPool pool = ClassPool.getDefault();
71  pool.insertClassPath(new ClassClassPath(this.getClass()));
72 
73  logger.trace("AppInitializer. Patching org.zkoss.lang.ContextClassLoaderFactory");
74  //Patch ZK's ContextClassLoaderFactory by adding new method
75  CtClass ctLoaderFactory = pool.get("org.zkoss.lang.ContextClassLoaderFactory");
76  CtMethod ctMethod = CtMethod.make(PATCH_1, ctLoaderFactory);
77  ctLoaderFactory.addMethod(ctMethod);
78  //Load the patched interface
79  ctLoaderFactory.toClass();
80 
81  logger.trace("AppInitializer. Patching org.zkoss.lang.Classes");
82  //Patch ZK's Classes
83  CtClass ctClasses = pool.get("org.zkoss.lang.Classes");
84 
85  //Add factory field
86  CtField f = CtField.make(PATCH_2, ctClasses);
87  ctClasses.addField(f, "null");
88 
89  //Initialize field at constructor
90  CtConstructor constructor = ctClasses.getClassInitializer();
91  constructor.insertAfter(PATCH_3);
92 
93  //Add a getContextClassLoaderForName method to Classes class
94  ctMethod = CtMethod.make(PATCH_4, ctClasses);
95  ctClasses.addMethod(ctMethod);
96 
97  //Rewrite method forNameByThread
98  ctMethod = ctClasses.getDeclaredMethod("forNameByThread");
99  ctMethod.setBody(PATCH_5);
100 
101  //Load the patched class
102  ctClasses.toClass();
103 
104  logger.trace("AppInitializer. Done");
105  } catch (Exception e) {
106  logger.error(e.getMessage(), e);
107  logger.warn("AppInitializer. Failure patching. UI pages of external plugins may not work properly");
108  }
109 
110  }
static final String PATCH_3
Definition: AppInitializer.java:32
static final String PATCH_4
Definition: AppInitializer.java:35
static final String PATCH_2
Definition: AppInitializer.java:30
static final String PATCH_1
Definition: AppInitializer.java:28
Logger logger
Definition: AppInitializer.java:26
static final String PATCH_5
Definition: AppInitializer.java:41

メンバ詳解

◆ logger

Logger org.gluu.credmanager.core.init.AppInitializer.logger
private

◆ PATCH_1

final String org.gluu.credmanager.core.init.AppInitializer.PATCH_1 = "public ClassLoader getContextClassLoaderForName(String className);"
staticprivate

◆ PATCH_2

final String org.gluu.credmanager.core.init.AppInitializer.PATCH_2 = "private static org.zkoss.lang.ContextClassLoaderFactory factory;"
staticprivate

◆ PATCH_3

final String org.gluu.credmanager.core.init.AppInitializer.PATCH_3
staticprivate
初期値:
= "factory = (org.zkoss.lang.ContextClassLoaderFactory) "
+ "newInstanceByThread(org.zkoss.lang.Library.getProperty(\"org.zkoss.lang.contextClassLoader.class\"));"

◆ PATCH_4

final String org.gluu.credmanager.core.init.AppInitializer.PATCH_4
staticprivate
初期値:
= "public static ClassLoader getContextClassLoaderForName(String className) { "
+ "if (factory == null) "
+ "return Thread.currentThread().getContextClassLoader(); "
+ "return factory.getContextClassLoaderForName(className); "
+ "}"

◆ PATCH_5

final String org.gluu.credmanager.core.init.AppInitializer.PATCH_5
staticprivate
初期値:
= "{ "
+ "String clsName = toInternalForm($1); "
+ "final Class cls = org.zkoss.lang.Primitives.toClass(clsName); "
+ "if (cls != null) "
+ " return cls; "
+ "ClassLoader cl = org.zkoss.lang.Library.getProperty(\"org.zkoss.lang.contextClassLoader.class\") == null "
+ " ? Thread.currentThread().getContextClassLoader() "
+ " : getContextClassLoaderForName(clsName); "
+ "if (cl != null) "
+ " try { "
+ " return Class.forName(clsName, true, cl); "
+ " } catch (ClassNotFoundException ex) { "
+ " } "
+ "return Class.forName(clsName); "
+ "}"

このクラス詳解は次のファイルから抽出されました: