You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClassLoaderWeavingAdaptor.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*******************************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Alexandre Vasseur initial implementation
  11. * David Knibb weaving context enhancments
  12. *******************************************************************************/
  13. package org.aspectj.weaver.loadtime;
  14. import org.aspectj.asm.IRelationship;
  15. import org.aspectj.bridge.IMessage;
  16. import org.aspectj.bridge.ISourceLocation;
  17. import org.aspectj.bridge.Message;
  18. import org.aspectj.bridge.MessageUtil;
  19. import org.aspectj.util.LangUtil;
  20. import org.aspectj.weaver.ICrossReferenceHandler;
  21. import org.aspectj.weaver.ResolvedType;
  22. import org.aspectj.weaver.UnresolvedType;
  23. import org.aspectj.weaver.World;
  24. import org.aspectj.weaver.bcel.BcelWeaver;
  25. import org.aspectj.weaver.bcel.BcelWorld;
  26. import org.aspectj.weaver.bcel.Utility;
  27. import org.aspectj.weaver.bcel.BcelObjectType;
  28. import org.aspectj.weaver.loadtime.definition.Definition;
  29. import org.aspectj.weaver.loadtime.definition.DocumentParser;
  30. import org.aspectj.weaver.patterns.PatternParser;
  31. import org.aspectj.weaver.patterns.TypePattern;
  32. import org.aspectj.weaver.tools.GeneratedClassHandler;
  33. import org.aspectj.weaver.tools.WeavingAdaptor;
  34. import java.io.File;
  35. import java.io.InputStream;
  36. import java.io.IOException;
  37. import java.net.URL;
  38. import java.util.ArrayList;
  39. import java.util.Enumeration;
  40. import java.util.HashMap;
  41. import java.util.Iterator;
  42. import java.util.List;
  43. import java.util.Properties;
  44. import java.util.StringTokenizer;
  45. /**
  46. * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
  47. */
  48. public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
  49. private final static String AOP_XML = "META-INF/aop.xml";
  50. private List m_dumpTypePattern = new ArrayList();
  51. private List m_includeTypePattern = new ArrayList();
  52. private List m_excludeTypePattern = new ArrayList();
  53. private List m_includeStartsWith = new ArrayList();
  54. private List m_excludeStartsWith = new ArrayList();
  55. private List m_aspectExcludeTypePattern = new ArrayList();
  56. private List m_aspectExcludeStartsWith = new ArrayList();
  57. private List m_aspectIncludeTypePattern = new ArrayList();
  58. private List m_aspectIncludeStartsWith = new ArrayList();
  59. private StringBuffer namespace;
  60. private IWeavingContext weavingContext;
  61. public ClassLoaderWeavingAdaptor(final ClassLoader loader, IWeavingContext wContext) {
  62. this.weavingContext = wContext;
  63. }
  64. void initialize(final ClassLoader loader, IWeavingContext wContext) {
  65. //super(null);// at this stage we don't have yet a generatedClassHandler to define to the VM the closures
  66. this.generatedClassHandler = new GeneratedClassHandler() {
  67. /**
  68. * Callback when we need to define a Closure in the JVM
  69. *
  70. * @param name
  71. * @param bytes
  72. */
  73. public void acceptClass(String name, byte[] bytes) {
  74. try {
  75. if (shouldDump(name.replace('/', '.'))) {
  76. Aj.dump(name, bytes);
  77. }
  78. } catch (Throwable throwable) {
  79. throwable.printStackTrace();
  80. }
  81. Aj.defineClass(loader, name, bytes);// could be done lazily using the hook
  82. }
  83. };
  84. if(wContext==null){
  85. weavingContext = new DefaultWeavingContext(loader);
  86. }else{
  87. weavingContext = wContext ;
  88. }
  89. bcelWorld = new BcelWorld(
  90. loader, messageHandler, new ICrossReferenceHandler() {
  91. public void addCrossReference(ISourceLocation from, ISourceLocation to, IRelationship.Kind kind, boolean runtimeTest) {
  92. ;// for tools only
  93. }
  94. }
  95. );
  96. // //TODO this AJ code will call
  97. // //org.aspectj.apache.bcel.Repository.setRepository(this);
  98. // //ie set some static things
  99. // //==> bogus as Bcel is expected to be
  100. // org.aspectj.apache.bcel.Repository.setRepository(new ClassLoaderRepository(loader));
  101. weaver = new BcelWeaver(bcelWorld);
  102. // register the definitions
  103. registerDefinitions(weaver, loader);
  104. // AV - see #113511 - not sure it is good to skip message handler
  105. if (enabled) {
  106. messageHandler = bcelWorld.getMessageHandler();
  107. // after adding aspects
  108. weaver.prepareForWeave();
  109. }
  110. }
  111. /**
  112. * Load and cache the aop.xml/properties according to the classloader visibility rules
  113. *
  114. * @param weaver
  115. * @param loader
  116. */
  117. private void registerDefinitions(final BcelWeaver weaver, final ClassLoader loader) {
  118. try {
  119. MessageUtil.info(messageHandler, "register classloader " + getClassLoaderName(loader));
  120. //TODO av underoptimized: we will parse each XML once per CL that see it
  121. List definitions = new ArrayList();
  122. //TODO av dev mode needed ? TBD -Daj5.def=...
  123. if (ClassLoader.getSystemClassLoader().equals(loader)) {
  124. String file = System.getProperty("aj5.def", null);
  125. if (file != null) {
  126. MessageUtil.info(messageHandler, "using (-Daj5.def) " + file);
  127. definitions.add(DocumentParser.parse((new File(file)).toURL()));
  128. }
  129. }
  130. String resourcePath = System.getProperty("org.aspectj.weaver.loadtime.configuration",AOP_XML);
  131. StringTokenizer st = new StringTokenizer(resourcePath,";");
  132. while(st.hasMoreTokens()){
  133. Enumeration xmls = weavingContext.getResources(st.nextToken());
  134. // System.out.println("? registerDefinitions: found-aop.xml=" + xmls.hasMoreElements() + ", loader=" + loader);
  135. while (xmls.hasMoreElements()) {
  136. URL xml = (URL) xmls.nextElement();
  137. MessageUtil.info(messageHandler, "using " + xml.getFile());
  138. definitions.add(DocumentParser.parse(xml));
  139. }
  140. }
  141. // still go thru if definitions is empty since we will configure
  142. // the default message handler in there
  143. registerOptions(weaver, loader, definitions);
  144. // AV - see #113511
  145. if (!definitions.isEmpty()) {
  146. registerAspectExclude(weaver, loader, definitions);
  147. registerAspectInclude(weaver, loader, definitions);
  148. registerAspects(weaver, loader, definitions);
  149. registerIncludeExclude(weaver, loader, definitions);
  150. registerDump(weaver, loader, definitions);
  151. } else {
  152. enabled = false;// will allow very fast skip in shouldWeave()
  153. info("no configuration found. Disabling weaver for class loader " + getClassLoaderName(loader));
  154. }
  155. } catch (Exception e) {
  156. weaver.getWorld().getMessageHandler().handleMessage(
  157. new Message("Register definition failed", IMessage.WARNING, e, null)
  158. );
  159. }
  160. }
  161. private String getClassLoaderName (ClassLoader loader) {
  162. return weavingContext.getClassLoaderName();
  163. }
  164. /**
  165. * Configure the weaver according to the option directives
  166. * TODO av - don't know if it is that good to reuse, since we only allow a small subset of options in LTW
  167. *
  168. * @param weaver
  169. * @param loader
  170. * @param definitions
  171. */
  172. private void registerOptions(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
  173. StringBuffer allOptions = new StringBuffer();
  174. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  175. Definition definition = (Definition) iterator.next();
  176. allOptions.append(definition.getWeaverOptions()).append(' ');
  177. }
  178. Options.WeaverOption weaverOption = Options.parse(allOptions.toString(), loader, messageHandler);
  179. // configure the weaver and world
  180. // AV - code duplicates AspectJBuilder.initWorldAndWeaver()
  181. World world = weaver.getWorld();
  182. world.setMessageHandler(weaverOption.messageHandler);
  183. world.setXlazyTjp(weaverOption.lazyTjp);
  184. world.setXHasMemberSupportEnabled(weaverOption.hasMember);
  185. world.setPinpointMode(weaverOption.pinpoint);
  186. weaver.setReweavableMode(weaverOption.notReWeavable);
  187. world.setXnoInline(weaverOption.noInline);
  188. // AMC - autodetect as per line below, needed for AtAjLTWTests.testLTWUnweavable
  189. world.setBehaveInJava5Way(LangUtil.is15VMOrGreater());
  190. //-Xlintfile: first so that lint wins
  191. if (weaverOption.lintFile != null) {
  192. InputStream resource = null;
  193. try {
  194. resource = loader.getResourceAsStream(weaverOption.lintFile);
  195. Exception failure = null;
  196. if (resource != null) {
  197. try {
  198. Properties properties = new Properties();
  199. properties.load(resource);
  200. world.getLint().setFromProperties(properties);
  201. } catch (IOException e) {
  202. failure = e;
  203. }
  204. }
  205. if (failure != null || resource == null) {
  206. world.getMessageHandler().handleMessage(new Message(
  207. "Cannot access resource for -Xlintfile:"+weaverOption.lintFile,
  208. IMessage.WARNING,
  209. failure,
  210. null));
  211. }
  212. } finally {
  213. try { resource.close(); } catch (Throwable t) {;}
  214. }
  215. }
  216. if (weaverOption.lint == null) {
  217. bcelWorld.getLint().loadDefaultProperties();
  218. bcelWorld.getLint().adviceDidNotMatch.setKind(IMessage.INFO);
  219. } else {
  220. if (weaverOption.lint.equals("default")) {//FIXME should be AjBuildConfig.AJLINT_DEFAULT but yetanother deps..
  221. bcelWorld.getLint().loadDefaultProperties();
  222. } else {
  223. bcelWorld.getLint().setAll(weaverOption.lint);
  224. }
  225. }
  226. //TODO proceedOnError option
  227. }
  228. private void registerAspectExclude(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
  229. String fastMatchInfo = null;
  230. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  231. Definition definition = (Definition) iterator.next();
  232. for (Iterator iterator1 = definition.getAspectExcludePatterns().iterator(); iterator1.hasNext();) {
  233. String exclude = (String) iterator1.next();
  234. TypePattern excludePattern = new PatternParser(exclude).parseTypePattern();
  235. m_aspectExcludeTypePattern.add(excludePattern);
  236. fastMatchInfo = looksLikeStartsWith(exclude);
  237. if (fastMatchInfo != null) {
  238. m_aspectExcludeStartsWith.add(fastMatchInfo);
  239. }
  240. }
  241. }
  242. }
  243. private void registerAspectInclude(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
  244. String fastMatchInfo = null;
  245. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  246. Definition definition = (Definition) iterator.next();
  247. for (Iterator iterator1 = definition.getAspectIncludePatterns().iterator(); iterator1.hasNext();) {
  248. String include = (String) iterator1.next();
  249. TypePattern includePattern = new PatternParser(include).parseTypePattern();
  250. m_aspectIncludeTypePattern.add(includePattern);
  251. fastMatchInfo = looksLikeStartsWith(include);
  252. if (fastMatchInfo != null) {
  253. m_aspectIncludeStartsWith.add(fastMatchInfo);
  254. }
  255. }
  256. }
  257. }
  258. /**
  259. * Register the aspect, following include / exclude rules
  260. *
  261. * @param weaver
  262. * @param loader
  263. * @param definitions
  264. */
  265. private void registerAspects(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
  266. //TODO: the exclude aspect allow to exclude aspect defined upper in the CL hierarchy - is it what we want ??
  267. // if not, review the getResource so that we track which resource is defined by which CL
  268. //iterate aspectClassNames
  269. //exclude if in any of the exclude list
  270. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  271. Definition definition = (Definition) iterator.next();
  272. for (Iterator aspects = definition.getAspectClassNames().iterator(); aspects.hasNext();) {
  273. String aspectClassName = (String) aspects.next();
  274. if (acceptAspect(aspectClassName)) {
  275. info("register aspect " + aspectClassName);
  276. ResolvedType aspect = weaver.addLibraryAspect(aspectClassName);
  277. //generate key for SC
  278. if(namespace==null){
  279. namespace=new StringBuffer(aspectClassName);
  280. }else{
  281. namespace = namespace.append(";"+aspectClassName);
  282. }
  283. }
  284. }
  285. }
  286. //iterate concreteAspects
  287. //exclude if in any of the exclude list - note that the user defined name matters for that to happen
  288. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  289. Definition definition = (Definition) iterator.next();
  290. for (Iterator aspects = definition.getConcreteAspects().iterator(); aspects.hasNext();) {
  291. Definition.ConcreteAspect concreteAspect = (Definition.ConcreteAspect) aspects.next();
  292. if (acceptAspect(concreteAspect.name)) {
  293. ConcreteAspectCodeGen gen = new ConcreteAspectCodeGen(concreteAspect, weaver.getWorld());
  294. if (!gen.validate()) {
  295. error("Concrete-aspect '"+concreteAspect.name+"' could not be registered");
  296. break;
  297. }
  298. this.generatedClassHandler.acceptClass(
  299. concreteAspect.name,
  300. gen.getBytes()
  301. );
  302. ResolvedType aspect = weaver.addLibraryAspect(concreteAspect.name);
  303. //generate key for SC
  304. if(namespace==null){
  305. namespace=new StringBuffer(concreteAspect.name);
  306. }else{
  307. namespace = namespace.append(";"+concreteAspect.name);
  308. }
  309. }
  310. }
  311. }
  312. }
  313. /**
  314. * Register the include / exclude filters
  315. * We duplicate simple patterns in startWith filters that will allow faster matching without ResolvedType
  316. *
  317. * @param weaver
  318. * @param loader
  319. * @param definitions
  320. */
  321. private void registerIncludeExclude(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
  322. String fastMatchInfo = null;
  323. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  324. Definition definition = (Definition) iterator.next();
  325. for (Iterator iterator1 = definition.getIncludePatterns().iterator(); iterator1.hasNext();) {
  326. String include = (String) iterator1.next();
  327. TypePattern includePattern = new PatternParser(include).parseTypePattern();
  328. m_includeTypePattern.add(includePattern);
  329. fastMatchInfo = looksLikeStartsWith(include);
  330. if (fastMatchInfo != null) {
  331. m_includeStartsWith.add(fastMatchInfo);
  332. }
  333. }
  334. for (Iterator iterator1 = definition.getExcludePatterns().iterator(); iterator1.hasNext();) {
  335. String exclude = (String) iterator1.next();
  336. TypePattern excludePattern = new PatternParser(exclude).parseTypePattern();
  337. m_excludeTypePattern.add(excludePattern);
  338. fastMatchInfo = looksLikeStartsWith(exclude);
  339. if (fastMatchInfo != null) {
  340. m_excludeStartsWith.add(fastMatchInfo);
  341. }
  342. }
  343. }
  344. }
  345. /**
  346. * Checks if the type pattern can be handled as a startswith check
  347. *
  348. * TODO AV - enhance to support "char.sss" ie FQN direclty (match iff equals)
  349. * we could also add support for "*..*charss" endsWith style?
  350. *
  351. * @param typePattern
  352. * @return null if not possible, or the startWith sequence to test against
  353. */
  354. private String looksLikeStartsWith(String typePattern) {
  355. if (typePattern.indexOf('@') >= 0
  356. || typePattern.indexOf('+') >= 0
  357. || typePattern.indexOf(' ') >= 0
  358. || typePattern.charAt(typePattern.length()-1) != '*') {
  359. return null;
  360. }
  361. // now must looks like with "charsss..*" or "cha.rss..*" etc
  362. // note that "*" and "*..*" won't be fast matched
  363. // and that "charsss.*" will not neither
  364. int length = typePattern.length();
  365. if (typePattern.endsWith("..*") && length > 3) {
  366. if (typePattern.indexOf("..") == length-3 // no ".." before last sequence
  367. && typePattern.indexOf('*') == length-1) { // no "*" before last sequence
  368. return typePattern.substring(0, length-2).replace('$', '.');
  369. // ie "charsss." or "char.rss." etc
  370. }
  371. }
  372. return null;
  373. }
  374. /**
  375. * Register the dump filter
  376. *
  377. * @param weaver
  378. * @param loader
  379. * @param definitions
  380. */
  381. private void registerDump(final BcelWeaver weaver, final ClassLoader loader, final List definitions) {
  382. for (Iterator iterator = definitions.iterator(); iterator.hasNext();) {
  383. Definition definition = (Definition) iterator.next();
  384. for (Iterator iterator1 = definition.getDumpPatterns().iterator(); iterator1.hasNext();) {
  385. String dump = (String) iterator1.next();
  386. TypePattern pattern = new PatternParser(dump).parseTypePattern();
  387. m_dumpTypePattern.add(pattern);
  388. }
  389. }
  390. }
  391. protected boolean accept(String className, byte[] bytes) {
  392. // avoid ResolvedType if not needed
  393. if (m_excludeTypePattern.isEmpty() && m_includeTypePattern.isEmpty()) {
  394. return true;
  395. }
  396. // still try to avoid ResolvedType if we have simple patterns
  397. String fastClassName = className.replace('/', '.').replace('$', '.');
  398. for (int i = 0; i < m_excludeStartsWith.size(); i++) {
  399. if (fastClassName.startsWith((String)m_excludeStartsWith.get(i))) {
  400. return false;
  401. }
  402. }
  403. boolean fastAccept = false;//defaults to false if no fast include
  404. for (int i = 0; i < m_includeStartsWith.size(); i++) {
  405. fastAccept = fastClassName.startsWith((String)m_includeStartsWith.get(i));
  406. if (fastAccept) {
  407. break;
  408. }
  409. }
  410. if (fastAccept) {
  411. return true;
  412. }
  413. // needs further analysis
  414. // TODO AV - needs refactoring
  415. // during LTW this calling resolve at that stage is BAD as we do have the bytecode from the classloader hook
  416. // but still go thru resolve that will do a getResourcesAsStream on disk
  417. // this is also problematic for jit stub which are not on disk - as often underlying infra
  418. // does returns null or some other info for getResourceAsStream (f.e. WLS 9 CR248491)
  419. // Instead I parse the given bytecode. But this also means it will be parsed again in
  420. // new WeavingClassFileProvider() from WeavingAdaptor.getWovenBytes()...
  421. BcelObjectType bct = ((BcelWorld)weaver.getWorld()).addSourceObjectType(Utility.makeJavaClass(null, bytes));
  422. ResolvedType classInfo = bct.getResolvedTypeX();//BAD: weaver.getWorld().resolve(UnresolvedType.forName(className), true);
  423. //exclude are "AND"ed
  424. for (Iterator iterator = m_excludeTypePattern.iterator(); iterator.hasNext();) {
  425. TypePattern typePattern = (TypePattern) iterator.next();
  426. if (typePattern.matchesStatically(classInfo)) {
  427. // exclude match - skip
  428. return false;
  429. }
  430. }
  431. //include are "OR"ed
  432. boolean accept = true;//defaults to true if no include
  433. for (Iterator iterator = m_includeTypePattern.iterator(); iterator.hasNext();) {
  434. TypePattern typePattern = (TypePattern) iterator.next();
  435. accept = typePattern.matchesStatically(classInfo);
  436. if (accept) {
  437. break;
  438. }
  439. // goes on if this include did not match ("OR"ed)
  440. }
  441. return accept;
  442. }
  443. //FIXME we don't use include/exclude of others aop.xml
  444. //this can be nice but very dangerous as well to change that
  445. private boolean acceptAspect(String aspectClassName) {
  446. // avoid ResolvedType if not needed
  447. if (m_aspectExcludeTypePattern.isEmpty() && m_aspectIncludeTypePattern.isEmpty()) {
  448. return true;
  449. }
  450. // still try to avoid ResolvedType if we have simple patterns
  451. // EXCLUDE: if one match then reject
  452. String fastClassName = aspectClassName.replace('/', '.').replace('.', '$');
  453. for (int i = 0; i < m_aspectExcludeStartsWith.size(); i++) {
  454. if (fastClassName.startsWith((String)m_aspectExcludeStartsWith.get(i))) {
  455. return false;
  456. }
  457. }
  458. //INCLUDE: if one match then accept
  459. for (int i = 0; i < m_aspectIncludeStartsWith.size(); i++) {
  460. if (fastClassName.startsWith((String)m_aspectIncludeStartsWith.get(i))) {
  461. return true;
  462. }
  463. }
  464. // needs further analysis
  465. ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(aspectClassName), true);
  466. //exclude are "AND"ed
  467. for (Iterator iterator = m_aspectExcludeTypePattern.iterator(); iterator.hasNext();) {
  468. TypePattern typePattern = (TypePattern) iterator.next();
  469. if (typePattern.matchesStatically(classInfo)) {
  470. // exclude match - skip
  471. return false;
  472. }
  473. }
  474. //include are "OR"ed
  475. boolean accept = true;//defaults to true if no include
  476. for (Iterator iterator = m_aspectIncludeTypePattern.iterator(); iterator.hasNext();) {
  477. TypePattern typePattern = (TypePattern) iterator.next();
  478. accept = typePattern.matchesStatically(classInfo);
  479. if (accept) {
  480. break;
  481. }
  482. // goes on if this include did not match ("OR"ed)
  483. }
  484. return accept;
  485. }
  486. public boolean shouldDump(String className) {
  487. // avoid ResolvedType if not needed
  488. if (m_dumpTypePattern.isEmpty()) {
  489. return false;
  490. }
  491. //TODO AV - optimize for className.startWith only
  492. ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(className), true);
  493. //dump
  494. for (Iterator iterator = m_dumpTypePattern.iterator(); iterator.hasNext();) {
  495. TypePattern typePattern = (TypePattern) iterator.next();
  496. if (typePattern.matchesStatically(classInfo)) {
  497. // dump match
  498. return true;
  499. }
  500. }
  501. return false;
  502. }
  503. /*
  504. * shared classes methods
  505. */
  506. /**
  507. * @return Returns the key.
  508. */
  509. public String getNamespace() {
  510. if(namespace==null) return "";
  511. else return new String(namespace);
  512. }
  513. /**
  514. * Check to see if any classes are stored in the generated classes cache.
  515. * Then flush the cache if it is not empty
  516. * @return true if a class has been generated and is stored in the cache
  517. */
  518. public boolean generatedClassesExist(){
  519. if(generatedClasses.size()>0) {
  520. return true;
  521. }
  522. return false;
  523. }
  524. /**
  525. * Flush the generated classes cache
  526. */
  527. public void flushGeneratedClasses(){
  528. generatedClasses = new HashMap();
  529. }
  530. }