001 package railo.runtime.cfx.customtag; 002 003 import railo.runtime.cfx.CFXTagException; 004 import railo.runtime.reflection.Reflector; 005 006 import com.allaire.cfx.CustomTag; 007 008 /** 009 * 010 */ 011 public final class JavaCFXTagClass implements CFXTagClass { 012 013 private String name; 014 private String strClass; 015 private Class clazz; 016 private boolean readOnly=false; 017 018 019 public JavaCFXTagClass(String name, String strClass) { 020 name=name.toLowerCase(); 021 if(name.startsWith("cfx_"))name=name.substring(4); 022 this.name=name; 023 this.strClass=strClass; 024 } 025 private JavaCFXTagClass(String name, String strClass, Class clazz,boolean readOnly) { 026 027 this.name=name; 028 this.strClass=strClass; 029 this.clazz=clazz; 030 this.readOnly=readOnly; 031 } 032 033 /** 034 * @see railo.runtime.cfx.customtag.CFXTagClass#newInstance() 035 */ 036 public CustomTag newInstance() throws CFXTagException { 037 try { 038 return _newInstance(); 039 } catch (Throwable e) { 040 throw new CFXTagException(e); 041 } 042 } 043 044 /** 045 * create and return an new CustomTag Object 046 * @throws ClassNotFoundException 047 * @see railo.runtime.cfx.customtag.CFXTagClass#newInstance() 048 */ 049 public CustomTag _newInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException { 050 051 Object o=getClazz().newInstance(); 052 return (CustomTag)o; 053 } 054 /** 055 * @return Returns the clazz. 056 * @throws ClassNotFoundException 057 */ 058 public Class<CustomTag> getClazz() throws ClassNotFoundException { 059 if(clazz==null) { 060 clazz=this.getClass().getClassLoader().loadClass(strClass); 061 } 062 return clazz; 063 } 064 065 /** 066 * @return Returns the name. 067 */ 068 public String getName() { 069 return name; 070 } 071 /** 072 * @return Returns the strClass. 073 */ 074 public String getStrClass() { 075 return strClass; 076 } 077 078 /** 079 * @see railo.runtime.cfx.customtag.CFXTagClass#isReadOnly() 080 */ 081 public boolean isReadOnly() { 082 return readOnly; 083 } 084 085 /** 086 * @see railo.runtime.cfx.customtag.CFXTagClass#cloneReadOnly() 087 */ 088 public CFXTagClass cloneReadOnly() { 089 return new JavaCFXTagClass(name,strClass,clazz,true); 090 } 091 /** 092 * @see railo.runtime.cfx.customtag.CFXTagClass#getDisplayType() 093 */ 094 public String getDisplayType() { 095 return "Java"; 096 } 097 /** 098 * @see railo.runtime.cfx.customtag.CFXTagClass#getSourceName() 099 */ 100 public String getSourceName() { 101 return strClass; 102 } 103 104 /** 105 * @see railo.runtime.cfx.customtag.CFXTagClass#isValid() 106 */ 107 public boolean isValid() { 108 try { 109 return Reflector.isInstaneOf(getClazz(),CustomTag.class); 110 } 111 catch (ClassNotFoundException e) { 112 return false; 113 } 114 } 115 }