KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > modules > iBatis_2_2_0 > object > config > IBatisChangeApplicatorSpec


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package org.terracotta.modules.iBatis_2_2_0.object.config;
6
7 import org.terracotta.modules.iBatis_2_2_0.object.dna.impl.IBatisAccessPlanInstance;
8
9 import com.tc.object.config.ChangeApplicatorSpec;
10
11 public class IBatisChangeApplicatorSpec implements ChangeApplicatorSpec {
12   private final static String JavaDoc IBATIS_ACCESS_PLAN_APPLICATOR_CLASS_NAME = "org.terracotta.modules.iBatis_2_2_0.object.applicator.IBatisAccessPlanApplicator";
13
14   private final ClassLoader JavaDoc classLoader;
15
16   public IBatisChangeApplicatorSpec(ClassLoader JavaDoc classLoader) {
17     this.classLoader = classLoader;
18   }
19
20   public Class JavaDoc getChangeApplicator(Class JavaDoc clazz) {
21     String JavaDoc changeApplicatorClassName = null;
22     if (isIBatisAccessPlan(clazz)) {
23       changeApplicatorClassName = IBATIS_ACCESS_PLAN_APPLICATOR_CLASS_NAME;
24     }
25     if (changeApplicatorClassName != null) {
26       try {
27         if (classLoader == null) {
28           return Class.forName(changeApplicatorClassName);
29         } else {
30           return Class.forName(changeApplicatorClassName, false, classLoader);
31         }
32       } catch (Exception JavaDoc e) {
33         throw new AssertionError JavaDoc(e);
34       }
35     }
36     return null;
37   }
38
39   public static boolean isIBatisAccessPlan(Class JavaDoc clazz) {
40     if (IBatisAccessPlanInstance.class.getName().equals(clazz.getName())) { return true; }
41     Class JavaDoc superclass = clazz.getSuperclass();
42     if (superclass == null) { return false; }
43     if (superclass.getName().equals("com.ibatis.sqlmap.engine.accessplan.BaseAccessPlan")) { return true; }
44     return false;
45
46   }
47 }
48
Popular Tags