Author: tchemit Date: 2008-12-14 18:42:16 +0000 (Sun, 14 Dec 2008) New Revision: 1081 Modified: lutinjaxx/trunk/changelog.txt lutinjaxx/trunk/jaxx-core/changelog.txt lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompilerOptions.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/ClassDescriptorLoader.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/JavaFileParser.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java lutinjaxx/trunk/maven-jaxx-plugin/changelog.txt lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java Log: add addSourcesToClassPath property to add sources directories in class-path improve classloader managment keep in DataSource objetCode fix bug when processDataBinding on a null objectCode always clean node cached values when selected it add usefull databinding method in Util Modified: lutinjaxx/trunk/changelog.txt =================================================================== --- lutinjaxx/trunk/changelog.txt 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/changelog.txt 2008-12-14 18:42:16 UTC (rev 1081) @@ -1,3 +1,5 @@ -0.7 chemit 200812?? +0.8 chemit 200812?? + +0.7 chemit 20081210 * 20081210 [chemit] use lutinutil 1.0 and lutinproject 3.2 * 20081207 [chemit] use lutinproject 3.1 \ No newline at end of file Modified: lutinjaxx/trunk/jaxx-core/changelog.txt =================================================================== --- lutinjaxx/trunk/jaxx-core/changelog.txt 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/changelog.txt 2008-12-14 18:42:16 UTC (rev 1081) @@ -1,4 +1,11 @@ 0.8 ??? 2009???? + * 20081214 [chemit] - add addSourcesToClassPath property to add sources directories in class-path + - improve classloader managment + - keep in DataSource objetCode + - fix bug when processDataBinding on a null objectCode + - always clean node cached values when selected it + - add usefull databinding method in Util + * 20081213 [chemit] - improve navigation tree node rendering with some caches - introduce a ChildBuilder to simplify building of child nodes from a collection or array Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompilerOptions.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompilerOptions.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompilerOptions.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -31,6 +31,8 @@ /** default error ui */ private Class<?> defaultErrorUI; + + private ClassLoader classLoader; /** * Returns the target directory, generally specified with the "-d" option on the command line. @@ -239,4 +241,12 @@ public Class<?> getDefaultErrorUI() { return defaultErrorUI; } + + public ClassLoader getClassLoader() { + return classLoader; + } + + public void setClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } } Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -76,7 +76,17 @@ } else { compiler.appendProcessDataBinding(" "); } - compiler.appendProcessDataBinding("if (" + TypeManager.getJavaCode(id) + ".equals($dest)) {" + JAXXCompiler.getLineSeparator() +" "+ assignment + JAXXCompiler.getLineSeparator() + " }"); + compiler.appendProcessDataBinding("if (" + TypeManager.getJavaCode(id) + ".equals($dest)) {" + JAXXCompiler.getLineSeparator()); + String objectCode = dataSource.getObjectCode(); + if (objectCode != null) { + compiler.appendProcessDataBinding(" if (" + objectCode + " != null) {" + JAXXCompiler.getLineSeparator()); + compiler.appendProcessDataBinding(" "); + } + compiler.appendProcessDataBinding(" " + assignment.trim()); + if (objectCode != null) { + compiler.appendProcessDataBinding(JAXXCompiler.getLineSeparator() + " }"); + } + compiler.appendProcessDataBinding(JAXXCompiler.getLineSeparator() + " }"); return true; } } \ No newline at end of file Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -52,6 +52,8 @@ private StringBuffer removeListenerCode = new StringBuffer(); private boolean compiled; + /** the delegate of property to be required */ + private String objectCode; /** * Creates a new data source. After creating a <code>DataSource</code>, use {@link #compile} @@ -76,6 +78,10 @@ return source; } + public String getObjectCode() { + return objectCode; + } + /** * Compiles the data source expression and listener. This method calls methods in <code>JAXXCompiler</code> * to add the Java code that performs the data source setup. Adding listeners to <code>DataSource</code> is @@ -270,8 +276,7 @@ int type = prefix.getChild(0).getId(); if (type == JavaParserTreeConstants.JJTLITERAL || type == JavaParserTreeConstants.JJTEXPRESSION) { prefix.setJavaType(prefix.getChild(0).getJavaType()); - } else - if (type == JavaParserTreeConstants.JJTNAME && expression.jjtGetNumChildren() == 1) // name with no arguments after it + } else if (type == JavaParserTreeConstants.JJTNAME && expression.jjtGetNumChildren() == 1) // name with no arguments after it { prefix.setJavaType(scanCompoundSymbol(prefix.getText().trim(), compiler.getRootObject().getObjectClass(), false, listenerId)); } @@ -393,6 +398,7 @@ } private void addListener(String dependencySymbol, String objectCode, String addCode, String removeCode) { + this.objectCode = objectCode; if (!dependencySymbols.contains(dependencySymbol)) { dependencySymbols.add(dependencySymbol); if (objectCode != null) { Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -830,21 +830,25 @@ */ public ClassLoader getClassLoader() { if (classLoader == null) { - String classPath = options.getClassPath(); - if (classPath == null) { - classPath = "."; - } - String[] paths = classPath.split(File.pathSeparator); - URL[] urls = new URL[paths.length]; - for (int i = 0; i < paths.length; i++) { - try { - urls[i] = new File(paths[i]).toURI().toURL(); + if (options.getClassLoader() != null) { + classLoader = options.getClassLoader(); + } else { + String classPath = options.getClassPath(); + if (classPath == null) { + classPath = "."; } - catch (MalformedURLException e) { - throw new RuntimeException(e); + String[] paths = classPath.split(File.pathSeparator); + URL[] urls = new URL[paths.length]; + for (int i = 0; i < paths.length; i++) { + try { + urls[i] = new File(paths[i]).toURI().toURL(); + } + catch (MalformedURLException e) { + throw new RuntimeException(e); + } } + classLoader = new URLClassLoader(urls, getClass().getClassLoader()); } - classLoader = new URLClassLoader(urls, getClass().getClassLoader()); } return classLoader; Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -85,9 +85,15 @@ if (dest.exists() && !dest.setLastModified(System.currentTimeMillis())) { log.warn("could not touch file " + dest); } - PrintWriter out = new PrintWriter(new FileWriter(dest)); - createJavaSource(out); - out.close(); + try { + PrintWriter out = new PrintWriter(new FileWriter(dest)); + createJavaSource(out); + out.close(); + } catch (RuntimeException e) { + // file could not be generated, so delete it... + dest.delete(); + throw e; + } } protected void createJavaSource(PrintWriter out) throws IOException { Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/ClassDescriptorLoader.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/ClassDescriptorLoader.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/ClassDescriptorLoader.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -39,7 +39,8 @@ public static synchronized ClassDescriptor getClassDescriptor(String className) throws ClassNotFoundException { - return getClassDescriptor(className, ClassDescriptorLoader.class.getClassLoader()); + return getClassDescriptor(className, Thread.currentThread().getContextClassLoader()); + //return getClassDescriptor(className, ClassDescriptorLoader.class.getClassLoader()); } public static synchronized ClassDescriptor getClassDescriptor(String className, ClassLoader classLoader) throws ClassNotFoundException { @@ -228,7 +229,7 @@ private static ClassDescriptor createClassDescriptorFromJavaSource(URL javaSource, ClassLoader classLoader) throws ClassNotFoundException { try { InputStream in = javaSource.openStream(); - Reader reader = new InputStreamReader(in); + Reader reader = new InputStreamReader(in,"utf-8"); ClassDescriptor result = JavaFileParser.parseJavaFile(javaSource.toString(), reader, classLoader); reader.close(); return result; Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/JavaFileParser.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/JavaFileParser.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/reflect/JavaFileParser.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -7,6 +7,8 @@ import jaxx.parser.ParseException; import jaxx.parser.SimpleNode; import jaxx.tags.TagManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import java.io.Reader; import java.lang.reflect.Modifier; @@ -17,6 +19,11 @@ // TODO: need to unify this implementation with the parsing in ScriptManager public class JavaFileParser { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(JavaFileParser.class); + + private JAXXCompiler compiler; private String className; private String packageName = null; @@ -34,7 +41,15 @@ // undefined, and doesn't report interfaces. It's safe to leave those the way they are for now, because // JAXX doesn't look at any of those for non-JAXX classes. JavaFileParser parser = new JavaFileParser(classLoader); - parser.doParse(displayName, src); + if (log.isInfoEnabled()) { + log.info("starting parsing : "+displayName); + } + try { + parser.doParse(displayName, src); + } catch (Exception e) { + log.error(e.getMessage()); + throw new RuntimeException(e); + } List<MethodDescriptor> publicMethods = parser.methods; List<FieldDescriptor> publicFields = parser.fields; Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -451,6 +451,18 @@ } /** + * Convinient method to apply more than one binding on a JAXX ui. + * + * @param src the ui to treate + * @param bindings the list of binding to process. + */ + public static void applyDataBinding(JAXXObject src, String... bindings) { + for (String binding : bindings) { + src.applyDataBinding(binding); + } + } + + /** * Convinient method to process more than one binding on a JAXX ui. * * @param src the ui to treate @@ -463,6 +475,18 @@ } /** + * Convinient method to remove more than one binding on a JAXX ui. + * + * @param src the ui to treate + * @param bindings the list of binding to process. + */ + public static void removeDataBinding(JAXXObject src, String... bindings) { + for (String binding : bindings) { + src.removeDataBinding(binding); + } + } + + /** * Convinient method to attach a bean to all validators of an JAXXObject. * <p/> * It is possible to exclude some validator to be treated. @@ -524,5 +548,5 @@ } }; } - + } Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -163,6 +163,11 @@ // now, we are free to open the ui associated with the selected node in navigation + // always clean cache on the node before all + node.cachedBean = null; + if (node.renderer != null) { + node.renderer.setRendererCachedValue(null); + } // before all, attach bean in context associated with the selected node in naivgation tree Object data = getNavigationTreeModel().getJAXXContextValue(context, path); Modified: lutinjaxx/trunk/maven-jaxx-plugin/changelog.txt =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/changelog.txt 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/maven-jaxx-plugin/changelog.txt 2008-12-14 18:42:16 UTC (rev 1081) @@ -1,4 +1,7 @@ -0.7 chemit 200812?? +0.8 chemit 200812?? + * 20081214 [chemit] - add addSourcesToClassPath property to add sources directories in class-path + +0.7 chemit 20081210 * 20081208 [chemit] - javabBean attribute use to initialize bean * 20081207 [chemit] use lutinproject 3.1 Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java =================================================================== --- lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-12-13 09:36:23 UTC (rev 1080) +++ lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-12-14 18:42:16 UTC (rev 1081) @@ -68,6 +68,14 @@ * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java" */ protected File outJava; + /** + * flag to include in compiler classpath the java sources directories (src and outJava). + * <p/> + * By default, false. + * + * @parameter expression="${jaxx.addSourcesToClassPath}" default-value="false" + */ + protected boolean addSourcesToClassPath; /** * chemin du repertoire de generation des resources. @@ -199,7 +207,6 @@ * If not given, will use the one defined in validator * * @parameter expression="${jaxx.defaultErrorUIFQN}" - * * @see jaxx.runtime.validator.BeanValidator#DEFAULT_UI_CLASS */ protected String defaultErrorUIFQN; @@ -216,6 +223,8 @@ private Class<?> defaultErrorUIClass; + protected ClassLoader cl; + protected void init() throws ClassNotFoundException { if (project != null && ("pom".equals(project.getPackaging()) || "site".equals(project.getPackaging()))) { @@ -246,6 +255,10 @@ fixCompileSourceRoots(); + if (addSourcesToClassPath) { + cl = initClassLoader(project, getLog()); + Thread.currentThread().setContextClassLoader(cl); + } DirectoryScanner ds; ds = new DirectoryScanner(); ds.setBasedir(src); @@ -312,6 +325,11 @@ result.setJaxxContextImplementorClass(jaxxContextImplementorClass); result.setExtraImports(extraImports); result.setDefaultErrorUI(defaultErrorUIClass); + if (cl!=null) { + result.setClassLoader(cl); + } + + return result; } @@ -376,26 +394,36 @@ protected URLClassLoader initClassLoader(MavenProject project, Log log) { URLClassLoader loader = null; if (project != null) { + List plugins = project.getBuildPlugins(); + + //((Plugin)project.getBuildPlugins().get(3)).getDependencies(); URLClassLoader result; try { Set<Artifact> compileClasspathElements = project.getArtifacts(); - URL[] url = new URL[compileClasspathElements.size() + 1]; + ClassLoader l = getClass().getClassLoader(); + int urlClSize = 1; + URL[] url; + if (addSourcesToClassPath) { + urlClSize+=2; + } + if (l instanceof URLClassLoader) { + urlClSize += (((URLClassLoader) l).getURLs().length); + } + url = new URL[urlClSize]; url[0] = outClass.toURI().toURL(); - int i = 1; - for (Artifact artifact : compileClasspathElements) { - File file = new File(artifact.getFile().getAbsolutePath()); - if (file.getName().endsWith(".jar")) { - url[i] = new URL("jar", "", file.toURI().toURL().toString() + "!/"); - } else { - url[i] = file.toURI().toURL(); - } - i++; + + if (l instanceof URLClassLoader) { + URL[] urls = ((URLClassLoader) l).getURLs(); + System.arraycopy(urls, 0, url, 1, urls.length); } - //ClassLoader parent = Thread.currentThread().getContextClassLoader(); + if (addSourcesToClassPath) { + url[url.length - 2] = src.toURI().toURL(); + url[url.length - 1] = outJava.toURI().toURL(); + } if (compileClasspathElements.size() == 0) { - result = new URLClassLoader(url, getClass().getClassLoader()); + result = new URLClassLoader(url, l); } else { - result = new URLClassLoader(url, getClass().getClassLoader()); + result = new URLClassLoader(url, l); } } catch (MalformedURLException eee) { throw new RuntimeException("Can't create ClassLoader for script, bad directory: " + outClass + " for reason " + eee.getMessage(), eee); @@ -404,9 +432,9 @@ } loader = result; } - if (verbose && loader != null) { + if (loader != null) { for (URL entry : loader.getURLs()) { - log.info("outClass url " + entry); + log.info("classpath : " + entry); } } return loader;