1 26 27 package net.sourceforge.groboutils.junit.v1.iftc; 28 29 30 44 public abstract class CxFactory implements ICxFactory 45 { 46 private String id; 47 48 62 public CxFactory( String name ) 63 { 64 this( name, false ); 65 } 66 67 68 85 public CxFactory( String name, boolean addClassName ) 86 { 87 if (name == null) 88 { 89 throw new IllegalArgumentException ( 90 "factory name cannot be null." ); 91 } 92 93 if (addClassName) 97 { 98 Class c = this.getClass(); 99 String className = getOwningClassName( c ); 100 this.id = className + "-" + name; 101 } 102 else 103 { 104 this.id = name; 105 } 106 107 115 } 116 117 118 124 public String toString() 125 { 126 135 136 return this.id; 137 } 138 139 140 144 public void tearDown( Object implObject ) throws Exception 145 { 146 } 148 149 150 public abstract Object createImplObject() throws Exception ; 152 153 154 161 private String getOwningClassName( Class c ) 162 { 163 if (c == null) 164 { 165 throw new IllegalArgumentException ( "No null args." ); 166 } 167 168 Class lastOwner = c; 169 179 String className = lastOwner.getName(); 180 181 int pos = className.lastIndexOf( '$' ); 182 if (pos > 0) 183 { 184 className = className.substring( 0, pos ); 185 } 186 pos = className.lastIndexOf( '.' ); 187 if (pos > 0) 188 { 189 className = className.substring( pos+1 ); 190 } 191 return className; 192 } 193 } 194 195 | Popular Tags |