1 28 29 package org.objectweb.util.explorer.core.code.lib; 30 31 import org.objectweb.util.explorer.ExplorerUtils; 32 import org.objectweb.util.explorer.core.code.api.Code; 33 import org.objectweb.util.explorer.core.code.api.CodeConfiguration; 34 import org.objectweb.util.explorer.core.common.lib.ClassResolver; 35 import org.objectweb.util.trace.TraceSystem; 36 37 45 public class JavaCode 46 implements CodeConfiguration, Code 47 { 48 49 55 56 protected Class theClass_ = null; 57 58 64 70 protected boolean equals(JavaCode code){ 71 if(code!=null){ 72 Class codeClass = code.theClass_; 73 if(theClass_!=null && codeClass!=null){ 74 return theClass_.getName().equals(codeClass.getName()); 75 } 76 } 77 return false; 78 } 79 80 86 public void setCode(String code) { 87 try { 88 theClass_ = ClassResolver.resolve(code); 89 } catch (ClassNotFoundException e) { 90 TraceSystem.get("explorer").info(code + ": Class not found!"); 91 } 92 } 93 94 100 103 public boolean isInstanceOf(Class c){ 104 if(c!=null && theClass_!=null) 105 return c.isAssignableFrom(theClass_); 106 return false; 107 } 108 109 112 public Object createInstance() { 113 if(theClass_!=null){ 114 try { 115 return theClass_.newInstance(); 116 } catch (InstantiationException e) { 117 TraceSystem.get("explorer").info(e.getMessage()); 118 } catch (IllegalAccessException e) { 119 TraceSystem.get("explorer").info(e.getMessage()); 120 } 121 } 122 return null; 123 } 124 125 131 135 public boolean equals(Object o){ 136 if(o!=null && o instanceof JavaCode){ 137 return equals((JavaCode)o); 138 } 139 return false; 140 } 141 142 146 public String toString(){ 147 return "JavaCode[class=" + 148 ExplorerUtils.toString(theClass_) + "]"; 149 } 150 151 } 152 | Popular Tags |