[Buix-commits] r1500 - in trunk/guix-compiler/src/main/java/org/nuiton/guix: . databinding generator model parser tags
Author: kmorin Date: 2009-07-22 15:06:26 +0200 (Wed, 22 Jul 2009) New Revision: 1500 Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java Removed: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java Log: Removed the general taghandlers (I kept the one useful for the tests) Generation of the binding after the generation of the non-dynamic code : I made a copy of GuixLauncher working with DataBinding and DataSource classes, but it seems to be working without Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -22,19 +22,8 @@ //~--- non-JDK imports -------------------------------------------------------- import org.nuiton.guix.tags.ApplicationHandler; -import org.nuiton.guix.tags.ButtonHandler; -import org.nuiton.guix.tags.CellHandler; -import org.nuiton.guix.tags.LabelHandler; -import org.nuiton.guix.tags.MenuBarHandler; -import org.nuiton.guix.tags.MenuHandler; -import org.nuiton.guix.tags.MenuItemHandler; -import org.nuiton.guix.tags.RowHandler; -import org.nuiton.guix.tags.TableHandler; import org.nuiton.guix.tags.PanelHandler; -import org.nuiton.guix.tags.TabPanelHandler; import org.nuiton.guix.tags.TagManager; -import org.nuiton.guix.tags.TextFieldHandler; -import org.nuiton.guix.tags.ToggleButtonHandler; /** * Initialize the application @@ -44,18 +33,7 @@ public class GuixInitializer { public static void initialize() { TagManager.registerGuixClassHandler("Application", ApplicationHandler.class); - TagManager.registerGuixClassHandler("Table", TableHandler.class); - TagManager.registerGuixClassHandler("Row", RowHandler.class); - TagManager.registerGuixClassHandler("Cell", CellHandler.class); TagManager.registerGuixClassHandler("Panel", PanelHandler.class); - TagManager.registerGuixClassHandler("Button", ButtonHandler.class); - TagManager.registerGuixClassHandler("TextField", TextFieldHandler.class); - TagManager.registerGuixClassHandler("Label", LabelHandler.class); - TagManager.registerGuixClassHandler("ToggleButton", ToggleButtonHandler.class); - TagManager.registerGuixClassHandler("TabPanel", TabPanelHandler.class); - TagManager.registerGuixClassHandler("MenuBar", MenuBarHandler.class); - TagManager.registerGuixClassHandler("Menu", MenuHandler.class); - TagManager.registerGuixClassHandler("MenuItem", MenuItemHandler.class); } } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -21,6 +21,9 @@ import org.nuiton.guix.compiler.GuixCompiler; import java.io.File; import java.io.PrintWriter; +import java.io.StringReader; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -28,10 +31,16 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.generator.Generator; import org.nuiton.guix.generator.GuixGenerator; +import org.nuiton.guix.generator.JavaArgument; +import org.nuiton.guix.generator.JavaField; +import org.nuiton.guix.generator.JavaFile; +import org.nuiton.guix.generator.JavaMethod; import org.nuiton.guix.model.ClassDescriptor; import org.nuiton.guix.model.GuixModelObject; +import org.nuiton.guix.parser.JavaParser; +import org.nuiton.guix.parser.JavaParserTreeConstants; +import org.nuiton.guix.parser.SimpleNode; import org.nuiton.guix.tags.TagManager; import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlSerializer; @@ -61,6 +70,7 @@ protected List<ClassDescriptor> classDescriptors = new ArrayList<ClassDescriptor>(); private List<File> compiledFiles = new ArrayList<File>(); + private Map<GuixGenerator,JavaFile> generatedFiles = new HashMap<GuixGenerator,JavaFile>(); protected int compilerCount; private File targetDirectory; private String rootPackage; @@ -204,7 +214,7 @@ for (GuixModelObject mo : rootModelObjects.keySet()) { try { - Generator gen = (GuixGenerator) generatorClass.newInstance(); + GuixGenerator gen = (GuixGenerator) generatorClass.newInstance(); gen.setDestDir(destDir); gen.setGmo(mo); gen.setLastModification(rootModelObjects.get(mo)); @@ -212,7 +222,7 @@ gen.setSerializer(serializer); gen.setClasses(Arrays.asList(classNames)); gen.setLauncherName(launcherName); - gen.generate(); + generatedFiles.put(gen,gen.generate()); } catch (InstantiationException eee) { if(log.isErrorEnabled()) @@ -222,11 +232,124 @@ if(log.isErrorEnabled()) log.error(eee); } - catch (NullPointerException eee) { - if(log.isErrorEnabled()) - log.error(eee); - eee.printStackTrace(); + } + for(GuixGenerator gen : generatedFiles.keySet()) { + int dataSourceNumber = 0; + StringBuffer dbCreation = new StringBuffer(); + StringBuffer dbDeletion = new StringBuffer(); + StringBuffer dbProcess = new StringBuffer(); + JavaFile jf = generatedFiles.get(gen); + for(String field : gen.getBindingsToGenerate().keySet()) { + for(String attr : gen.getBindingsToGenerate().get(field).keySet()) { + dbCreation.append(dbCreation.length() != 0 ? "else if(\"" : "if(\"").append(field) + .append(".").append(attr) + .append("\".equals(_binding)) {\n"); + dbDeletion.append(dbDeletion.length() != 0 ? "else if(\"" : "if(\"").append(field) + .append(".").append(attr) + .append("\".equals(_binding)) {\n"); + dbProcess.append(dbProcess.length() != 0 ? "else if(\"" : "if(\"").append(field) + .append(".").append(attr) + .append("\".equals(_binding)) {\n") + .append(field).append(".set") + .append(Character.toUpperCase(attr.charAt(0))) + .append(attr.substring(1)) + .append("("); + List<String[]> bindings = new ArrayList<String[]>(); + JavaParser p = new JavaParser(new StringReader(gen.getBindingsToGenerate().get(field).get(attr))); + //start parsing + while (!p.Line()) { + SimpleNode node = p.popNode(); + if (node != null) { + for(String s : browseNode(node)) { + List<String> l = new ArrayList<String>(); + int parOuvertes = 0; + StringBuffer read = new StringBuffer(); + for(char c : s.toCharArray()) { + if(c == '(') { + parOuvertes++; + read.append(c); + } + else if(c == ')') { + parOuvertes--; + read.append(c); + } + else if(c == '.') { + if(parOuvertes == 0) { + l.add(read.toString()); + read = new StringBuffer(); + } + else { + read.append(c); + } + } + else { + read.append(c); + } + } + l.add(read.toString()); + bindings.add(l.toArray(new String[l.size()])); + } + } + } + List<Class> listeners = new ArrayList<Class>(); + for(String[] binding : bindings) { + StringBuffer methodToInvoke = new StringBuffer(); + StringBuffer oldBinding = new StringBuffer(); + for(String s : binding) { + log.info("old : " + s); + methodToInvoke.append(s.replaceAll("\\W", "")); + oldBinding.append(s).append("."); + } + oldBinding.setLength(oldBinding.length() - 1); + listeners.addAll(gen.generateBindings(dbCreation, dbDeletion, null, jf, null, binding, 0, null, methodToInvoke.toString(), generatedFiles)); + //JavaArgument[] args = new JavaArgument[]{new JavaArgument(parameterType.getName(), "event")}; + StringBuffer newBinding = new StringBuffer(); + for(String s : binding) { + log.info("new : " + s); + newBinding.append(s).append("."); + } + newBinding.setLength(newBinding.length() - 1); + log.info(gen.getBindingsToGenerate().get(field).get(attr) + " : " + oldBinding + " - " + newBinding.toString()); + gen.getBindingsToGenerate().get(field) + .put(attr, gen.getBindingsToGenerate().get(field).get(attr).replace(oldBinding.toString(), newBinding.toString())); + + if (jf.getMethod("onChangeFrom" + methodToInvoke, /*args*/null) == null) { + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "onChangeFrom" + methodToInvoke.toString(), /*args*/null, null, /*"_DataSource" + dataSourceNumber + ".propertyChange(null);"*/"processDataBinding(\"" + field + "." + attr + "\");", null)); + } + else { + jf.getMethod("onChangeFrom" + methodToInvoke.toString(), /*args*/null).appendBodyCode(/*"_DataSource" + dataSourceNumber + ".propertyChange(null);"*/"processDataBinding(\"" + field + "." + attr + "\");", "\n"); + } + } + dbCreation.append("}\n"); + dbDeletion.append("}\n"); + dbProcess.append(gen.getBindingsToGenerate().get(field).get(attr)) + .append(");\n}\n"); + if(listeners != null) { + //jf.addField(new JavaField(Modifier.PRIVATE, "java.beans.PropertyChangeListener", "_DataSource" + dataSourceNumber, "new org.nuiton.guix.runtime.DataBindingListener(this,\"" + field + "." + attr + "\")", null, null)); + jf.getMethod("initDataBinding", null).appendBodyCode("applyDataBinding(\"" + field + "." + attr + "\");", "\n"); + for(Class listener : listeners) { + final List<Method> listenerMethods = Arrays.asList(listener.getMethods()); + Class parameterType = listenerMethods.get(0).getParameterTypes()[0]; + } + } + dataSourceNumber++; + } } + if(generatedFiles.get(jf.getSuperClass()) != null) { + dbCreation.append("else {\nsuper.applyDataBinding(_binding);\n" + + "return;\n}"); + dbDeletion.append("\nelse {\nsuper.removeDataBinding(_binding);\n}\n"); + } + dbCreation.append("\nprocessDataBinding(_binding);"); + dbProcess.insert(0, "if (activeBindings.contains(_binding)) {\n" + + "return;\n}\n" + + "activeBindings.add(_binding);\ntry{\n"); + dbProcess.append("\n} finally {\nactiveBindings.remove(_binding);\n}\n"); + jf.addField(new JavaField(Modifier.PRIVATE, "java.util.List<String>", "activeBindings", "new java.util.ArrayList<String>()", "List of the active bindings", null), false); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbCreation.toString(), null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbDeletion.toString(), null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbProcess.toString(), null)); + gen.saveFiles(); } serializer.endTag("", "beans"); serializer.endDocument(); @@ -251,6 +374,7 @@ } } + /** * Registers a ClassDescriptor * @@ -305,4 +429,17 @@ } return classDescriptors.get(i); } + + private List<String> browseNode(SimpleNode node) { + List<String> result = new ArrayList<String>(); + for(int i = 0 ; i < node.jjtGetNumChildren() ; i++) { + if(node.getChild(i).getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION + && !node.getChild(i).getText().trim().startsWith("(") + && !node.getChild(i).getText().trim().startsWith("\"")) { + result.add(node.getChild(i).getText().trim()); + } + result.addAll(browseNode(node.getChild(i))); + } + return result; + } } Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java (rev 0) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher1.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -0,0 +1,372 @@ +/** + * *##% guix-compiler + * Copyright (C) 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ +package org.nuiton.guix; + +import java.beans.BeanInfo; +import java.beans.PropertyChangeListener; +import org.nuiton.guix.compiler.GuixCompiler; +import java.io.File; +import java.io.PrintWriter; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EventListener; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.guix.generator.Generator; +import org.nuiton.guix.generator.GuixGenerator; +import org.nuiton.guix.generator.JavaArgument; +import org.nuiton.guix.generator.JavaField; +import org.nuiton.guix.generator.JavaFile; +import org.nuiton.guix.generator.JavaMethod; +import org.nuiton.guix.model.ClassDescriptor; +import org.nuiton.guix.model.GuixModelObject; +import org.nuiton.guix.tags.TagHandler; +import org.nuiton.guix.tags.TagManager; +import org.xmlpull.v1.XmlPullParserFactory; +import org.xmlpull.v1.XmlSerializer; + +/** + * Launch Guix files compilation + * + * @author morin + */ +public class GuixLauncher1 { + + /** log */ + protected static final Log log = LogFactory.getLog(GuixLauncher1.class); + /** original list of files to compile */ + protected final File[] files; + /** original list of classes to compile */ + protected final String[] classNames; + /** Files to be treated while compilation. */ + protected List<File> guixFiles = new ArrayList<File>(); + /** Class names corresponding to the files in the guixFiles list. */ + protected List<String> guixFileClassNames = new ArrayList<String>(); + /** Maps the root GuixModelObjects being compiled to the compiler instance + * handling the compilation. */ + protected Map<GuixModelObject, Long> rootModelObjects = + new HashMap<GuixModelObject, Long>(); + /** CLassDescriptor met during the compilation */ + protected List<ClassDescriptor> classDescriptors = + new ArrayList<ClassDescriptor>(); + private List<File> compiledFiles = new ArrayList<File>(); + private Map<GuixGenerator,JavaFile> generatedFiles = new HashMap<GuixGenerator,JavaFile>(); + protected int compilerCount; + private File targetDirectory; + private String rootPackage; + private String mainClass; + private Class generatorClass; + private String launcherName; + + /** + * Constructor + * + * @param files the files to compile + */ + public GuixLauncher1(File[] files, File targetDirectory, String rootPackage, + File baseDir, String mainClass, Class generatorClass, String launcherName) { + // Set up a simple configuration that logs on the console. + this.files = files; + this.targetDirectory = targetDirectory; + this.rootPackage = rootPackage != null ? rootPackage : ""; + if (files != null) { + classNames = new String[files.length]; + for (int i = 0; i < files.length; i++) { + String path = files[i].getAbsolutePath(); + if (baseDir != null) { + classNames[i] = rootPackage + "." + path.substring(baseDir.getAbsolutePath().length() + 1, + path.lastIndexOf('.')).replace(File.separatorChar, '.'); + } + else { + classNames[i] = path.substring(0, path.lastIndexOf('.')); + } + } + } + else { + classNames = null; + } + this.mainClass = mainClass != null ? mainClass : ""; + this.launcherName = launcherName != null ? launcherName : "Main"; + this.generatorClass = generatorClass; + } + + /** + * Compiled a set of files. + * + * @return <code>true</code> if compilation succeeds, + * <code>false</code> otherwise + */ + public synchronized boolean compile() { + compilerCount = 0; + File destDir = targetDirectory; + if (files != null) { + if (log.isInfoEnabled()) { + log.info("Start compiling"); + } + guixFiles.addAll(Arrays.asList(files)); + guixFileClassNames.addAll(Arrays.asList(classNames)); + boolean success = true; + + try { + assert guixFiles.size() == guixFileClassNames.size(); + + for (int i = 0; i < guixFiles.size(); i++) { + File file = guixFiles.get(i); + String className = guixFileClassNames.get(i); + + //if we have not compiled the file yet + if (!compiledFiles.contains(file)) { + if (log.isInfoEnabled()) { + log.info("Compiling class " + className); + } + compiledFiles.add(file); + + String classPackage; + if (targetDirectory != null) { + int dotPos = className.lastIndexOf("."); + if (dotPos != -1) { + destDir = new File(targetDirectory, className.substring(0, dotPos).replace('.', File.separatorChar)); + classPackage = className.substring(0, dotPos); + } + else { + destDir = new File(targetDirectory, className); + classPackage = className; + } + if (!destDir.exists() && !destDir.mkdirs()) { + if (log.isWarnEnabled()) { + log.warn("couldn't create directory " + destDir); + } + continue; + } + } + else { + destDir = file.getParentFile(); + classPackage = destDir.getAbsolutePath().replace(File.separatorChar, '.'); + } + //compile the file + // GuixCompiler compiler = new GuixCompiler(file, this, classPackage); + GuixCompiler compiler = null; + + GuixModelObject rootModelObject = compiler.compile(); + rootModelObjects.put(rootModelObject, compiler.getLastModification()); + + if (compiler.isFailed()) { + success = false; + } + } + else { + if (log.isWarnEnabled()) { + log.warn(file.getName() + " has already been compiled."); + } + } + } + + if (success) { + int i = 0; + while (success && i < classDescriptors.size()) { + success = (classDescriptors.get(i).getPackageName() != null || TagManager.getGuixClassHandler(classDescriptors.get(i).getName()) != null); + i++; + } + if (!success) { + if (log.isErrorEnabled()) { + log.error("The class '" + classDescriptors.get(--i).getName() + "' has no package."); + } + } + } + + if (generatorClass != null) { + //creates the XML serializer for the spring conf + XmlPullParserFactory factory = + XmlPullParserFactory.newInstance( + System.getProperty(XmlPullParserFactory.PROPERTY_NAME), + null); + XmlSerializer serializer = factory.newSerializer(); + + File config = new File(targetDirectory,"config.xml"); + + serializer.setOutput(new PrintWriter(config)); + serializer.startDocument("UTF-8", null); + serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n"); + serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "\t"); + serializer.text("\n"); + serializer.docdecl(" beans SYSTEM \"http://www.springframework.org/dtd/spring-beans.dtd\""); + serializer.text("\n"); + serializer.startTag("", "beans"); + + for (GuixModelObject mo : rootModelObjects.keySet()) { + try { + GuixGenerator gen = (GuixGenerator) generatorClass.newInstance(); + gen.setDestDir(destDir); + gen.setGmo(mo); + gen.setLastModification(rootModelObjects.get(mo)); + gen.setMainClass((mo.getClassDescriptor().getPackageName() + "." + mo.getClassDescriptor().getName()).equals(mainClass)); + gen.setSerializer(serializer); + gen.setClasses(Arrays.asList(classNames)); + gen.setLauncherName(launcherName); + generatedFiles.put(gen,gen.generate()); + } + catch (InstantiationException eee) { + if(log.isErrorEnabled()) + log.error(eee); + } + catch (IllegalAccessException eee) { + if(log.isErrorEnabled()) + log.error(eee); + } + } + for(GuixGenerator gen : generatedFiles.keySet()) { + int dataSourceNumber = 0; + StringBuffer dbCreation = new StringBuffer(); + StringBuffer dbDeletion = new StringBuffer(); + StringBuffer dbProcess = new StringBuffer(); + JavaFile jf = generatedFiles.get(gen); + for(String field : gen.getBindingsToGenerate().keySet()) { + for(String attr : gen.getBindingsToGenerate().get(field).keySet()) { + dbCreation.append(dbCreation.length() != 0 ? "else if(\"" : "if(\"").append(field) + .append(".").append(attr) + .append("\".equals(_binding)) {\n"); + dbDeletion.append(dbDeletion.length() != 0 ? "else if(\"" : "if(\"").append(field) + .append(".").append(attr) + .append("\".equals(_binding)) {\n"); + dbProcess.append(dbProcess.length() != 0 ? "else if(\"" : "if(\"").append(field) + .append(".").append(attr) + .append("\".equals(_binding)) {\n") + .append(field).append(".set") + .append(Character.toUpperCase(attr.charAt(0))) + .append(attr.substring(1)) + .append("("); + String[] binding = gen.getBindingsToGenerate().get(field).get(attr).split("\\s*\\.\\s*"); + String methodToInvoke = gen.getBindingsToGenerate().get(field).get(attr).replaceAll("\\W", ""); + List<Class> listeners = gen.generateBindings(dbCreation, dbDeletion, null, jf, null,null, 0, null, methodToInvoke, generatedFiles); + dbCreation.append("}\n"); + dbDeletion.append("}\n"); + dbProcess.append(");\n}\n"); + if(listeners != null) { + jf.addField(new JavaField(Modifier.PRIVATE, "java.beans.PropertyChangeListener", "_DataSource" + dataSourceNumber, "new org.nuiton.guix.runtime.DataBindingListener(this,\"" + field + "." + attr + "\")", null, null)); + jf.getMethod("initDataBinding", null).appendBodyCode("applyDataBinding(\"" + field + "." + attr + "\");", "\n"); + for(Class listener : listeners) { + final List<Method> listenerMethods = Arrays.asList(listener.getMethods()); + Class parameterType = listenerMethods.get(0).getParameterTypes()[0]; + JavaArgument[] args = new JavaArgument[]{new JavaArgument(parameterType.getName(), "event")}; + if (jf.getMethod("onChangeFrom" + methodToInvoke, args) == null) { + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "onChangeFrom" + methodToInvoke, args, null, "_DataSource" + dataSourceNumber + ".propertyChange(null);", null)); + } + else { + jf.getMethod("onChangeFrom" + methodToInvoke, args).appendBodyCode("_DataSource" + dataSourceNumber + ".propertyChange(null);", "\n"); + } + } + } + dataSourceNumber++; + } + } + if(generatedFiles.get(jf.getSuperClass()) != null) { + dbCreation.append("else {\nsuper.applyDataBinding(_binding);\n" + + "return;\n}"); + dbDeletion.append("\nelse {\nsuper.removeDataBinding(_binding);\n}\n"); + } + dbCreation.append("\nprocessDataBinding(_binding);"); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbCreation.toString(), null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbDeletion.toString(), null)); + jf.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "_binding")}, null, dbProcess.toString(), null)); + gen.saveFiles(); + } + serializer.endTag("", "beans"); + serializer.endDocument(); + } + else { + if(log.isWarnEnabled()) { + log.warn("No generation language given"); + } + } + } + catch (Throwable e) { + e.printStackTrace(); + return false; + } + return success; + } + else { + if (log.isWarnEnabled()) { + log.warn("No file to compile"); + } + return true; + } + } + + + /** + * Registers a ClassDescriptor + * + * @param classDescriptor the ClassDescripor to register + * @return false if another ClassDescriptor with the same classname + * and package has a different script or superclass + */ + public ClassDescriptor registerClassDescriptor(ClassDescriptor classDescriptor) { + if (classDescriptor == null || classDescriptor.getName() == null) { + return null; + } + int i = 0; + while (i < classDescriptors.size() && (!classDescriptors.get(i).getName().equals(classDescriptor.getName()) || (classDescriptors.get(i).getPackageName() != null && classDescriptor.getPackageName() != null && !classDescriptors.get(i).getPackageName().equals(classDescriptor.getPackageName())))) { + i++; + } + //if the ClassDescriptor does not exist + if (i >= classDescriptors.size()) { + classDescriptors.add(classDescriptor); + if (log.isDebugEnabled()) { + log.debug("new ClassDescriptor " + classDescriptor + " inserted"); + } + return classDescriptor; + } + classDescriptors.get(i).setPackageName(classDescriptor.getPackageName()); + if (classDescriptor.getScript() != null) { + if (classDescriptors.get(i).getScript() == null) { + classDescriptors.get(i).setScript(classDescriptor.getScript()); + if (log.isDebugEnabled()) { + log.debug("add script to ClassDescriptor " + classDescriptor); + } + } + else if (!classDescriptors.get(i).getScript().equals(classDescriptor.getScript())) { + if (log.isDebugEnabled()) { + log.error("ClassDescriptor " + classDescriptor + " script already defined and different !"); + } + return null; + } + } + if (classDescriptor.getSuperClass() != null) { + if (classDescriptors.get(i).getSuperClass() == null) { + classDescriptors.get(i).setSuperClass(classDescriptor.getSuperClass()); + if (log.isDebugEnabled()) { + log.debug("add superclass to ClassDescriptor " + classDescriptor); + } + } + else if (!classDescriptors.get(i).getSuperClass().equals(classDescriptor.getSuperClass())) { + if (log.isErrorEnabled()) { + log.error("ClassDescriptor " + classDescriptor + " superclass already defined and different !"); + } + return null; + } + } + return classDescriptors.get(i); + } +} Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/BindingUtils.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -88,24 +88,25 @@ expression.append(escapeJavaString(stringValue.substring(lastPos))); expression.append('"'); } - - StringBuffer el = new StringBuffer(); - Pattern p = Pattern .compile("\\.(get|is)([A-Z])([a-zA-Z0-9]*)\\(\\)"); - Matcher m = p.matcher(expression.toString()); - int mEnd = 0; - if(m.find()) { - do { - el.append(expression.toString().substring(mEnd, m.start())) - .append("."); - mEnd = m.end(); - el.append(m.group(2).toLowerCase()) - .append(m.group(3)); - } while (m.find()); - } - else { - el.append(expression.toString()); - } - return el.toString().length() > 0 ? el.toString().substring(0, el.toString().length()) : el.toString(); +// +// StringBuffer el = new StringBuffer(); +// Pattern p = Pattern .compile("\\.(get|is)([A-Z])([a-zA-Z0-9]*)\\(\\)"); +// Matcher m = p.matcher(expression.toString()); +// int mEnd = 0; +// if(m.find()) { +// do { +// el.append(expression.toString().substring(mEnd, m.start())) +// .append("."); +// mEnd = m.end(); +// el.append(m.group(2).toLowerCase()) +// .append(m.group(3)); +// } while (m.find()); +// } +// else { +// el.append(expression.toString()); +// } +// return el.toString().length() > 0 ? el.toString().substring(0, el.toString().length()) : el.toString(); + return expression.toString(); } return null; } Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java (rev 0) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataBinding.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -0,0 +1,92 @@ +/* + * Copyright 2006 Ethan Nicholas. All rights reserved. + * Use is subject to license terms. + */ +package org.nuiton.guix.databinding; + +import org.nuiton.guix.CompilerException; +import org.nuiton.guix.compiler.GuixCompiler; + +/** + * Represents a data binding in a JAXX file. <code>DataBinding</code> uses {@link DataSource} to + * track changes to a source expression and update the destination. + */ +public class DataBinding { + private String id; + + /** The DatSource which tracks source expression changes. */ + private DataSource dataSource; + + /** The data binding destination in the form <code><id>.<propertyName></code>. */ + private String dest; + + /** + * A Java snippet which will cause the destination property to be updated with the current value of + * the binding. + */ + private String assignment; + + /** The current <code>GuixCompiler</code>. */ + private GuixCompiler compiler; + + + /** + * Creates a new data binding. + * + * @param source the Java source code for the data binding expression + * @param dest the data binding destination in the form <code><id>.<propertyName></code> + * @param assignment Java snippet which will cause the destination property to be updated with the current value of the binding + * @param compiler the current <code>JAXXCompiler</code> + */ + public DataBinding(String source, String dest, String assignment, GuixCompiler compiler) { + this.id = dest; + this.dataSource = new DataSource(id, source); + this.dest = dest; + this.assignment = assignment; + this.compiler = compiler; + } + + + public String getId() { + return id; + } + + + /** + * Compiles the data binding expression. This method calls methods in <code>JAXXCompiler</code> + * to add the Java code that performs the data binding setup. + * + * @param quickNoDependencies true to optimize bindings with no dependencies by simply running them at startup time + * @return <code>true</code> if the expression has dependencies, <code>false</code> otherwise + * @throws CompilerException if a compilation error occurs + */ +// public boolean compile(boolean quickNoDependencies) throws CompilerException { +// // DataSource.compile handles all of the listener additions +// boolean result = dataSource.compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + TypeManager.getJavaCode(id) + ")"); +// +// if (!result && quickNoDependencies) { +// if (!dest.endsWith(".layout")) // layout is specially handled early in the chain +// { +// compiler.appendInitDataBindings(assignment + JAXXCompiler.getLineSeparator()); +// } +// return false; // no dependencies, just a static expression +// } +// if (compiler.haveProcessDataBinding()) { +// compiler.appendProcessDataBinding(" else "); +// } else { +// compiler.appendProcessDataBinding(" "); +// } +// 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 Added: trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java (rev 0) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/databinding/DataSource.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -0,0 +1,460 @@ +/* + * Copyright 2006 Ethan Nicholas. All rights reserved. + * Use is subject to license terms. + */ +package org.nuiton.guix.databinding; + +import java.beans.Introspector; +import java.beans.PropertyChangeListener; +import java.io.StringReader; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.guix.CompilerException; +import org.nuiton.guix.UnsupportedAttributeException; +import org.nuiton.guix.generator.JavaField; +import org.nuiton.guix.parser.JavaParser; +import org.nuiton.guix.parser.JavaParserConstants; +import org.nuiton.guix.parser.JavaParserTreeConstants; +import org.nuiton.guix.parser.SimpleNode; +import org.nuiton.guix.tags.DefaultTagHandler; +import org.nuiton.guix.tags.TagHandler; +import org.nuiton.guix.tags.TagManager; + +/** + * Represents a Java expression which fires a <code>PropertyChangeEvent</code> when it can be + * determined that its value may have changed. Events are fired on a "best effort" basis, and events + * may either be fired too often (the value has not actually changed) or not often enough (the value + * changed but no event was fired). + */ +public class DataSource { + private class NULL { + } // type attached to "null" constants in parsed expressions + + private Log log = LogFactory.getLog(DataSource.class); + + private String id; + + /** The Java source code for the expression. */ + private String source; + + /** The current <code>JAXXCompiler</code>. */ + //private JAXXCompiler compiler; + + /** List of symbols which this data source expression depends on. */ + private List<String> dependencySymbols = new ArrayList<String>(); + + private StringBuffer addListenerCode = new StringBuffer(); + 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} + * to cause it to function at runtime. + * + * @param id the DataSource's id + * @param source the Java source code for the data source expression + * @param compiler the current <code>JAXXCompiler</code> + */ + public DataSource(String id, String source) { + this.id = id; + this.source = source; + } + + + public String getId() { + return id; + } + + public String getSource() { + 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 + * slightly more complicated than with ordinary classes, because <code>DataSource</code> only exists at compile + * time. You must pass in a Java expression which evaluates to a <code>PropertyChangeListener</code>; this + * expression will be compiled and evaluated at runtime to yield the <code>DataSource's</code> listener. + * + * @param propertyChangeListenerCode Java code snippet which evaluates to a <code>PropertyChangeListener</code> + * @return <code>true</code> if the expression has dependencies, <code>false</code> otherwise + * @throws CompilerException if a compilation error occurs + */ +// public boolean compile(String propertyChangeListenerCode) throws CompilerException { +// if (compiled) { +// throw new IllegalStateException(this + " has already been compiled"); +// } +// String id = ""; +// JavaParser p = new JavaParser(new StringReader(source + ";")); +// while (!p.Line()) { +// SimpleNode node = p.popNode(); +// scanNode(node, id); +// } +// +// if (dependencySymbols.size() > 0) { +// //TC 20081108 prefer add a real JavaField instead of raw code +// //compiler.appendBodyCode("private PropertyChangeListener " + id + " = " + propertyChangeListenerCode + ";\n"); +// compiler.addSimpleField(new JavaField(Modifier.PRIVATE, PropertyChangeListener.class.getName(), id, propertyChangeListenerCode)); +// } +// +// compileListeners(); +// compiled = true; +// +// return dependencySymbols.size() > 0; +// } +// +// /** @return a list of symbols on which this data source depends. */ +// public Collection<String> getDependencies() { +// return Collections.unmodifiableList(dependencySymbols); +// } +// +// /** +// * Examines a node to identify any dependencies it contains. +// * +// * @param node node to scan +// * @param listenerId id of listener +// * @throws jaxx.CompilerException ? +// */ +// private void scanNode(SimpleNode node, String listenerId) throws CompilerException { +// switch (node.getId()) { +// case JavaParserTreeConstants.JJTMETHODDECLARATION: +// break; +// case JavaParserTreeConstants.JJTFIELDDECLARATION: +// break; +// +// default: +// int count = node.jjtGetNumChildren(); +// for (int i = 0; i < count; i++) { +// scanNode(node.getChild(i), listenerId); +// } +// determineNodeType(node, listenerId); +// } +// } +// +// private Class determineLiteralType(SimpleNode node) { +// assert node.getId() == JavaParserTreeConstants.JJTLITERAL; +// if (node.jjtGetNumChildren() == 1) { +// int id = node.getChild(0).getId(); +// if (id == JavaParserTreeConstants.JJTBOOLEANLITERAL) { +// return boolean.class; +// } +// if (id == JavaParserTreeConstants.JJTNULLLITERAL) { +// return null; +// } +// throw new RuntimeException("Expected BooleanLiteral or NullLiteral, found " + JavaParserTreeConstants.jjtNodeName[id]); +// } +// int id = node.firstToken.kind; +// switch (id) { +// case JavaParserConstants.INTEGER_LITERAL: +// if (node.firstToken.image.toLowerCase().endsWith("l")) { +// return long.class; +// } +// return int.class; +// case JavaParserConstants.CHARACTER_LITERAL: +// return char.class; +// case JavaParserConstants.FLOATING_POINT_LITERAL: +// if (node.firstToken.image.toLowerCase().endsWith("f")) { +// return float.class; +// } +// return double.class; +// case JavaParserConstants.STRING_LITERAL: +// return String.class; +// default: +// throw new RuntimeException("Expected literal token, found " + JavaParserConstants.tokenImage[id]); +// } +// } +// +// /** +// * Scans through a compound symbol (foo.bar.baz) to identify and track all trackable pieces of it. +// * +// * @param symbol symbol to scan +// * @param contextClass current class context +// * @param isMethod flag to search a method +// * @param listenerId id of the listener +// * @return the type of the symbol (or null if it could not be determined). +// */ +// private Class scanCompoundSymbol(String symbol, Class contextClass, boolean isMethod, String listenerId) { +// String[] tokens = symbol.split("\\s*\\.\\s*"); +// StringBuffer currentSymbol = new StringBuffer(); +// StringBuffer tokensSeenSoFar = new StringBuffer(); +// boolean accepted; // if this ends up false, it means we weren't able to figure out +// // which object the method is being invoked on +// boolean recognizeClassNames = true; +// for (int j = 0; j < tokens.length - (isMethod ? 1 : 0); j++) { +// accepted = false; +// +// if (tokensSeenSoFar.length() > 0) { +// tokensSeenSoFar.append('.'); +// } +// tokensSeenSoFar.append(tokens[j]); +// if (currentSymbol.length() > 0) { +// currentSymbol.append('.'); +// } +// currentSymbol.append(tokens[j]); +// +// if (currentSymbol.indexOf(".") == -1) { +// String memberName = currentSymbol.toString(); +// CompiledObject object = compiler.getCompiledObject(memberName); +// if (object != null) { +// contextClass = object.getObjectClass(); +// currentSymbol.setLength(0); +// accepted = true; +// recognizeClassNames = false; +// } else { +// try { +// FieldDescriptor field = contextClass.getFieldDescriptor(memberName); +// trackMemberIfPossible(tokensSeenSoFar.toString(), contextClass, field.getName(), false, listenerId); +// contextClass = field.getType(); +// currentSymbol.setLength(0); +// accepted = true; +// recognizeClassNames = false; +// } +// catch (NoSuchFieldException e) { +// if (j == 0 || j == 1 && tokens[0].equals(compiler.getRootObject().getId())) { // still in root context +// FieldDescriptor[] newFields = compiler.getScriptFields(); +// for (FieldDescriptor newField : newFields) { +// if (newField.getName().equals(memberName)) { +// addListener(tokensSeenSoFar.toString(), +// null, +// "addPropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(), +// "removePropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator()); +// contextClass = newField.getType(); +// assert contextClass != null : "script field '" + memberName + "' is defined, but has type null"; +// currentSymbol.setLength(0); +// accepted = true; +// recognizeClassNames = false; +// break; +// } +// } +// } +// } +// } +// } +// if (currentSymbol.length() > 0 && recognizeClassNames) { +// contextClass = TagManager.resolveClass(currentSymbol.toString(), compiler); +// if (contextClass != null) { +// currentSymbol.setLength(0); +// //accepted = true; +// //recognizeClassNames = false; +// // TODO: for now we don't handle statics +// return null; +// } +// } +// if (!accepted) { +// return null; +// } +// } +// +// return contextClass; +// } +// +// /** +// * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which +// * can be tracked. +// * +// * @param expression the node to scan +// * @param listenerId id of the listener +// * @return the class descriptor of the return type or null +// */ +// private Class determineExpressionType(SimpleNode expression, String listenerId) { +// assert expression.getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION; +// SimpleNode prefix = expression.getChild(0); +// if (prefix.jjtGetNumChildren() == 1) { +// 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 +// { +// prefix.setJavaType(scanCompoundSymbol(prefix.getText().trim(), compiler.getRootObject().getObjectClass(), false, listenerId)); +// } +// } +// +// if (expression.jjtGetNumChildren() == 1) { +// return prefix.getJavaType(); +// } +// +// Class contextClass = prefix.getJavaType(); +// if (contextClass == null) { +// contextClass = compiler.getRootObject().getObjectClass(); +// } +// String lastNode = prefix.getText().trim(); +// +// for (int i = 1; i < expression.jjtGetNumChildren(); i++) { +// SimpleNode suffix = expression.getChild(i); +// if (suffix.jjtGetNumChildren() == 1 && suffix.getChild(0).getId() == JavaParserTreeConstants.JJTARGUMENTS) { +// if (suffix.getChild(0).jjtGetNumChildren() == 0) { // at the moment only no-argument methods are trackable +// contextClass = scanCompoundSymbol(lastNode, contextClass, true, listenerId); +// if (contextClass == null) { +// return null; +// } +// int dotPos = lastNode.lastIndexOf("."); +// String objectCode = dotPos == -1 ? "" : lastNode.substring(0, dotPos); +// for (int j = i - 2; j >= 0; j--) { +// objectCode = expression.getChild(j).getText() + objectCode; +// } +// if (objectCode.length() == 0) { +// objectCode = compiler.getRootObject().getJavaCode(); +// } +// String methodName = lastNode.substring(dotPos + 1).trim(); +// try { +// MethodDescriptor method = contextClass.getMethodDescriptor(methodName); +// trackMemberIfPossible(objectCode, contextClass, method.getName(), true, listenerId); +// return method.getReturnType(); +// } +// catch (NoSuchMethodException e) { +// // happens for methods defined in the current JAXX file via scripts +// String propertyName = null; +// if (methodName.startsWith("is")) { +// propertyName = Introspector.decapitalize(methodName.substring("is".length())); +// } else if (methodName.startsWith("get")) { +// propertyName = Introspector.decapitalize(methodName.substring("get".length())); +// } +// if (propertyName != null) { +// MethodDescriptor[] newMethods = compiler.getScriptMethods(); +// for (MethodDescriptor newMethod : newMethods) { +// if (newMethod.getName().equals(methodName)) { +// addListener(compiler.getRootObject().getId(), +// null, +// "addPropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(), +// "removePropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator()); +// contextClass = newMethod.getReturnType(); +// break; +// } +// } +// } +// } +// } +// } +// lastNode = suffix.getText().trim(); +// if (lastNode.startsWith(".")) { +// lastNode = lastNode.substring(1); +// } +// } +// +// return null; +// } +// +//// private void trackMemberIfPossible(String objectCode, Class objectClass, String memberName, boolean method, String listenerId) { +//// if (objectClass.isInterface()) // might be technically possible to track in some cases, but for now +//// { +//// return; // we can't create a DefaultObjectHandler for interfaces +//// } +//// +//// TagHandler handler = (TagHandler)TagManager.getGuixClassHandler(objectClass.getName()).newInstance(); +//// try { +//// if (handler.isMemberBound(memberName)) { +//// addListener(objectCode + "." + memberName + (method ? "()" : ""), +//// objectCode, +//// handler.getAddMemberListenerCode(objectCode, id, memberName, listenerId, compiler), +//// handler.getRemoveMemberListenerCode(objectCode, id, memberName, listenerId, compiler)); +//// } +//// } +//// catch (UnsupportedAttributeException e) { +//// // ignore -- this is thrown for methods like toString(), for which there is no tracking and +//// // no setting support +//// } +//// } +// +// /** +// * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which +// * can be tracked. +// * +// * @param node node to scan +// * @param listenerId the listener id +// */ +// private void determineNodeType(SimpleNode node, String listenerId) { +// Class type = null; +// if (node.jjtGetNumChildren() == 1) { +// type = node.getChild(0).getJavaType(); +// } +// switch (node.getId()) { +// case JavaParserTreeConstants.JJTCLASSORINTERFACETYPE: +// type = Class.class; +// break; +// case JavaParserTreeConstants.JJTPRIMARYEXPRESSION: +// type = determineExpressionType(node, listenerId); +// break; +// case JavaParserTreeConstants.JJTLITERAL: +// type = determineLiteralType(node); +// break; +// case JavaParserTreeConstants.JJTCASTEXPRESSION: +// try { +// type = Class.forName(node.getChild(0).getText()); +// } +// catch (ClassNotFoundException eee) { +// if(log.isErrorEnabled()) { +// log.error(eee); +// } +// } +// break; +// } +// node.setJavaType(type); +// } +// +// private void addListener(String dependencySymbol, String objectCode, String addCode, String removeCode) { +// this.objectCode = objectCode; +// if (!dependencySymbols.contains(dependencySymbol)) { +// dependencySymbols.add(dependencySymbol); +// if (objectCode != null) { +// addListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator()); +// addListenerCode.append(" "); +// } +// addListenerCode.append(" ").append(addCode); +// if (objectCode != null) { +// addListenerCode.append(" ").append("}"); +// } +// +// if (objectCode != null) { +// removeListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator()); +// removeListenerCode.append(" "); +// } +// removeListenerCode.append(" ").append(removeCode); +// if (objectCode != null) { +// removeListenerCode.append(" }"); +// } +// } +// } +// +// private void compileListeners() { +// String javaCodeId = TypeManager.getJavaCode(id); +// if (addListenerCode.length() > 0) { +// if (compiler.haveApplyDataBinding()) { +// compiler.appendApplyDataBinding(" else "); +// } +// compiler.appendApplyDataBinding("if (" + javaCodeId + ".equals($binding)) {" + JAXXCompiler.getLineSeparator()); +// compiler.appendApplyDataBinding(" " + addListenerCode + JAXXCompiler.getLineSeparator()); +// compiler.appendApplyDataBinding("}"); +// //if (compiler.applyDataBinding.length() > 0) +// // compiler.applyDataBinding.append("else "); +// //compiler.applyDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator()); +// //compiler.applyDataBinding.append(" ").append(addListenerCode).append(JAXXCompiler.getLineSeparator()); +// //compiler.applyDataBinding.append("}").append(JAXXCompiler.getLineSeparator()); +// } +// +// if (removeListenerCode.length() > 0) { +// if (compiler.haveRemoveDataBinding()) { +// compiler.appendRemoveDataBinding(" else "); +// } +// compiler.appendRemoveDataBinding("if (" + javaCodeId + ".equals($binding)) {" + JAXXCompiler.getLineSeparator()); +// compiler.appendRemoveDataBinding(" " + removeListenerCode + JAXXCompiler.getLineSeparator()); +// compiler.appendRemoveDataBinding("}"); +// //if (compiler.removeDataBinding.length() > 0) +// // compiler.removeDataBinding.append("else "); +// //compiler.removeDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator()); +// //compiler.removeDataBinding.append(" ").append(removeListenerCode).append(JAXXCompiler.getLineSeparator()); +// //compiler.removeDataBinding.append("}").append(JAXXCompiler.getLineSeparator()); +// } +// } +} Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/Generator.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -31,7 +31,7 @@ */ public interface Generator { - public void generate(); + public JavaFile generate(); public File getDestDir(); Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/GuixGenerator.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -20,8 +20,11 @@ package org.nuiton.guix.generator; import java.io.File; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.nuiton.guix.model.GuixModelObject; +import org.nuiton.guix.tags.TagHandler; import org.xmlpull.v1.XmlSerializer; /** @@ -45,8 +48,10 @@ protected List<String> classes = null; /** Name to give to the generated launcher*/ protected String launcherName = null; + /** */ + protected Map<String,Map<String, String>> bindings2Generate = new HashMap<String,Map<String, String>>(); - public abstract void generate(); + public abstract JavaFile generate(); public File getDestDir() { return destDir; @@ -104,4 +109,16 @@ this.launcherName = launcherName; } + public Map<String,Map<String, String>> getBindingsToGenerate() { + return bindings2Generate; + } + + public void setBindingsToGenerate(Map<String,Map<String, String>> bindings2Generate) { + this.bindings2Generate = bindings2Generate; + } + + public abstract void saveFiles(); + + public abstract List<Class> generateBindings(StringBuffer dbCreation, StringBuffer dbDeletion, TagHandler prevTh, JavaFile jf, + Class clazz, String[] binding, int i, List<String> alreadyChecked, String methodToInvoke, Map<GuixGenerator,JavaFile> generatedFiles); } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaField.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -20,6 +20,7 @@ import java.lang.reflect.Modifier; import java.util.Comparator; +import org.nuiton.guix.tags.TagHandler; /** * Represents a field in a Java source file being generated for output. <code>JavaFields</code> are created @@ -32,6 +33,7 @@ private String name; private String initializer; private String javaDoc; + private TagHandler tagHandler; /** @@ -44,10 +46,23 @@ * @param name the field's name */ public JavaField(int modifiers, String type, String name, String javaDoc) { - this(modifiers, type, name, null, javaDoc); + this(modifiers, type, name, null, javaDoc, null); } + /** + * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the + * constants from {@link java.lang.reflect.Modifier}, and the <code>type</code> of the field should be + * represented as it would appear in Java source code. + * + * @param modifiers the modifier keywords that should appear as part of the field's declaration + * @param type the type of the field as it would appear in Java source code + * @param name the field's name + */ + public JavaField(int modifiers, String type, String name, String javaDoc, TagHandler tagHanlder) { + this(modifiers, type, name, null, javaDoc, tagHanlder); + } + /** * Constructs a new <code>JavaField</code>. The <code>modifiers</code> parameter is a bit mask of the * constants from <code>java.lang.reflect.Modifier</code>, and the <code>type</code> of the field should be @@ -60,12 +75,13 @@ * @param name the field's name * @param initializer the initial value of the field, as it would appear in Java source code */ - public JavaField(int modifiers, String type, String name, String initializer, String javaDoc) { + public JavaField(int modifiers, String type, String name, String initializer, String javaDoc, TagHandler tagHandler) { this.modifiers = modifiers; this.type = type; this.name = name; this.initializer = initializer; this.javaDoc = javaDoc; + this.tagHandler = tagHandler; } @@ -100,7 +116,11 @@ return type; } + public TagHandler getTagHandler() { + return tagHandler; + } + /** * Returns the Java source code for this field. * Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFile.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -27,6 +27,8 @@ import java.util.EnumMap; import java.util.List; import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * A Java source file being generated for output. Once the class is completely initialized, use the @@ -156,6 +158,30 @@ return methods.toArray(new JavaMethod[methods.size()]); } + public JavaMethod getMethod(String methodName, JavaArgument[] args) { + for(JavaMethod method : methods) { + if(method.getName().equals(methodName)) { + if(method.getArguments() == null && args == null) { + return method; + } + else if (method.getArguments().length == args.length) { + boolean samesame = true; + for(int i = 0 ; i < args.length ; i++) { + if(!args[i].getName().equals(method.getArguments()[i].getName()) + || !args[i].getType().equals(method.getArguments()[i].getType())) { + samesame = false; + break; + } + } + if(samesame) { + return method; + } + } + } + } + return null; + } + public void addField(JavaField field) { addField(field, false); } @@ -190,31 +216,48 @@ return fields.toArray(new JavaField[fields.size()]); } + public JavaField getField(String fieldName) { + for(JavaField field : fields) { + if(field.getName().equals(fieldName)) { + return field; + } + } + return null; + } - public static String addIndentation(String source, int indentation, String lineSeparator) { - return indent(source, indentation, false, lineSeparator); + + public static String addIndentation(String source, String lineSeparator) { + return indent(source, false, lineSeparator); } - public static String setIndentation(String source, int indentation, String lineSeparator) { - return indent(source, indentation, true, lineSeparator); + public static String setIndentation(String source, String lineSeparator) { + return indent(source, true, lineSeparator); } - public static String indent(String source, int indentation, boolean trim, String lineSeparator) { + public static String indent(String source, boolean trim, String lineSeparator) { if (trim) { source = source.trim(); } - char[] spaces = new char[indentation]; - Arrays.fill(spaces, ' '); + char[] spaces = new char[1]; + Arrays.fill(spaces, '\t'); StringBuffer result = new StringBuffer(); String[] lines = source.split(System.getProperty("line.separator") + "|\n"); for (int i = 0; i < lines.length; i++) { if (i > 0) { result.append(lineSeparator); } + if(lines[i].equals(lines[i].trim()) && (lines[i].trim().startsWith("}") || lines[i].trim().endsWith("}"))) { + spaces = new char[spaces.length - 1]; + Arrays.fill(spaces, '\t'); + } result.append(spaces); result.append(trim ? lines[i].trim() : lines[i]); + if(lines[i].equals(lines[i].trim()) && lines[i].trim().endsWith("{")) { + spaces = new char[spaces.length + 1]; + Arrays.fill(spaces, '\t'); + } } return result.toString(); } @@ -226,32 +269,31 @@ public String getClassBody(String lineSeparator) { - StringBuffer result = new StringBuffer(); + StringBuffer result = new StringBuffer("\t"); if (classType != INTERFACE && fields.size() > 0) { java.util.Collections.sort(fields); // sort fields for (JavaField field : fields) { - result.append(addIndentation(field.toString(lineSeparator), 4, lineSeparator)); - result.append(lineSeparator); + result.append(field.toString(lineSeparator)); } result.append(lineSeparator); } if (rawBodyCode.length() > 0) { - result.append(addIndentation("/* begin raw body code */\n", 4, lineSeparator)); + result.append("/* begin raw body code */\n"); String s = rawBodyCode.toString(); if (!s.startsWith(lineSeparator)) { result.append(lineSeparator); } - result.append(addIndentation(s, 4, lineSeparator)); + result.append(s); result.append(lineSeparator); - result.append(addIndentation("/* end raw body code */", 4, lineSeparator)); - result.append(lineSeparator); + result.append("/* end raw body code */"); + result.append(lineSeparator).append(lineSeparator); } for (JavaFile innerClass : innerClasses) { - result.append(addIndentation(innerClass.toString(), 4, lineSeparator)); + result.append(innerClass.toString()); result.append(lineSeparator).append(lineSeparator); } @@ -263,7 +305,11 @@ } map.clear(); - return result.toString(); + Pattern p = Pattern.compile("\\n"); + //System.out.println(result.toString()); + Matcher m = p.matcher(result.toString()); + return m.replaceAll("\n\t"); + } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -98,7 +98,7 @@ * Fills and saves the generated file * @param out the file to record */ - protected void saveFile(File out) { + public void saveFile(File out) { FileWriter fw = null; try { fw = new FileWriter(out); Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaMethod.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -27,6 +27,8 @@ import java.util.EnumSet; import java.util.Iterator; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Represents a method in a Java source file being generated for output. <code>JavaMethods</code> are created @@ -240,7 +242,7 @@ if (bodyCode != null) { result.append(" {"); result.append(lineSeparator); - String formattedBodyCode = JavaFile.addIndentation(bodyCode.toString().trim(), 4, lineSeparator); + String formattedBodyCode = JavaFile.addIndentation(bodyCode.toString().trim(), lineSeparator); if (formattedBodyCode.length() > 0) { result.append(formattedBodyCode); result.append(lineSeparator); @@ -408,10 +410,10 @@ if (methods.isEmpty()) { return; } - buffer.append(JavaFile.addIndentation(header, 4, lineSeparator)); + buffer.append(header); buffer.append(lineSeparator).append(lineSeparator); for (JavaMethod method : methods) { - buffer.append(JavaFile.addIndentation(method.toString(lineSeparator), 4, lineSeparator)); + buffer.append(method.toString(lineSeparator)); buffer.append(lineSeparator).append(lineSeparator); } } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -18,6 +18,7 @@ */ package org.nuiton.guix.model; +import org.nuiton.guix.tags.TagHandler; /** * Descriptor of a class found in the guix files. @@ -94,5 +95,3 @@ } } - -//~ Formatted by Jindent --- http://www.jindent.com Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/SimpleNode.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -10,7 +10,7 @@ protected Node[] children; public Token firstToken; protected int id; - private ClassDescriptor javaType; + private Class javaType; public Token lastToken; protected Node parent; protected JavaParser parser; @@ -44,11 +44,11 @@ return (SimpleNode) parent; } - public ClassDescriptor getJavaType() { + public Class getJavaType() { return javaType; } - public void setJavaType(ClassDescriptor javaType) { + public void setJavaType(Class javaType) { this.javaType = javaType; } Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ApplicationHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,20 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class ApplicationHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public ApplicationHandler() { - - } -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ButtonHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,20 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class ButtonHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public ButtonHandler() { - - } -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/CellHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,173 +0,0 @@ -/** - * *##% guix-compiler-swing - * Copyright (C) 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ -package org.nuiton.guix.tags; - -import org.nuiton.guix.model.AttributeDescriptor; -import org.nuiton.guix.model.GuixModelObject; - -/** - * Represents a cell of a table - * - * @author kevin - */ -public abstract class CellHandler extends TableHandler { - - /** id of the object contained by the cell */ - private String id = null; - /** number of columns of the cell */ - private int columns = 1; - /** number of rows of the cell */ - private int rows = 1; - /** index of the row */ - private int row = -1; - /** index of the column */ - private int column = -1; - - /** - * Constructor - */ - public CellHandler() { - - } - - /** - * Constructor - * - * @param cell the GuixModelObject which represents the cell - */ - public CellHandler(GuixModelObject cell) { - assert cell.getChildren().size() == 1; - id = cell.getChildren().get(0).getId(); - for (AttributeDescriptor attr : cell.getAttributeDescriptors()) { - if (attr.getName().equals("columns")) { - columns = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("column")) { - column = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("rows")) { - rows = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("weightx")) { - weightx = Double.valueOf(attr.getValue()); - } - else if (attr.getName().equals("weighty")) { - weighty = Double.valueOf(attr.getValue()); - } - else if (attr.getName().equals("ipadx")) { - ipadx = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("ipady")) { - ipady = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("halign")) { - horizontalAlignment = getHalign(attr.getValue()); - } - else if (attr.getName().equals("valign")) { - verticalAlignment = getValign(attr.getValue()); - } - else if (attr.getName().equals("fill")) { - fill = attr.getValue(); - } - else if (attr.getName().equals("insets")) { - insets = attr.getValue(); - } - } - } - - /** - * Constructor - * - * @param cell the GuixModelObject which represents the cell - * @param row the row which contains the cell - */ - public CellHandler(GuixModelObject cell, RowHandler row) { - this(cell); - //if the attributes that the row contains too have not been defined by the user within the cell, - //but have been defined in the row (or the table), set them - if (horizontalAlignment == null) { - horizontalAlignment = row.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : row.getHorizontalAlignment(); - } - if (verticalAlignment == null) { - verticalAlignment = row.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : row.getVerticalAlignment(); - } - if (fill == null) { - fill = row.getFill() == null ? TableHandler.DEFAULT_FILL : row.getFill(); - } - if (insets == null) { - insets = row.getInsets() == null ? TableHandler.DEFAULT_INSETS : row.getInsets(); - } - if (ipadx == null) { - ipadx = row.getIpadx() == null ? TableHandler.DEFAULT_IPADX : row.getIpadx(); - } - if (ipady == null) { - ipady = row.getIpady() == null ? TableHandler.DEFAULT_IPADY : row.getIpady(); - } - if (weightx == null) { - weightx = row.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : row.getWeightx(); - } - if (weighty == null) { - weighty = row.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : row.getWeighty(); - } - if(this.row == -1) { - this.row = row.getRow() < 0 ? -1 : row.getRow(); - } - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public int getColumn() { - return column; - } - - public void setColumn(int column) { - this.column = column; - } - - public int getColumns() { - return columns; - } - - public void setColumns(int columns) { - this.columns = columns; - } - - public int getRow() { - return row; - } - - public void setRow(int row) { - this.row = row; - } - - public int getRows() { - return rows; - } - - public void setRows(int rows) { - this.rows = rows; - } - -} Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -4,6 +4,18 @@ */ package org.nuiton.guix.tags; +import java.beans.BeanInfo; +import java.beans.EventSetDescriptor; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.MethodDescriptor; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; +import org.nuiton.guix.UnsupportedAttributeException; /** * @@ -11,4 +23,248 @@ */ public abstract class DefaultTagHandler implements TagHandler { + protected Map<String,String> attrMap = new HashMap<String,String>(); + + /** Maps property names to their respective ProxyEventInfos. */ + private Map<String, ProxyEventInfo> eventInfos; + + /** The JAXXBeanInfo for the beanClass. */ + protected BeanInfo beanInfo; + + /** Maps property names to their respective JAXXPropertyDescriptors. */ + private Map<String, PropertyDescriptor> properties; + + /** Maps event names to their respective JAXXEventSetDescriptors. */ + private Map<String, EventSetDescriptor> events; + + /** + * Encapsulates information about a "proxy event handler", which is an event handler that + * fires PropertyChangeEvents when it is triggered. ProxyEventInfos simplify the data binding + * system by allowing all dependencies to fire the same kind of event even if they would + * normally throw something else, like <code>DocumentEvent</code>. + */ + private class ProxyEventInfo { + /** The name of the method or field being proxied, e.g. "getText". */ + String memberName; + + /** The "actual" event listener for the property in question, e.g. DocumentListener. */ + Class listenerClass; + + /** + * In cases where a different object (such as a model) is more directly responsible for + * managing the property, this is the name of the property where that object can be + * found, e.g. "document" (which is turned into a call to "getDocument()"). This property + * is also treated as a dependency of the data binding expression, and any updates to it + * (assuming it is bound) will cause the listener to be removed from the old value and + * attached to the new value, and the data binding to be processed. + */ + String modelName; + + /** The name of the method used to add the "native" event listener, e.g. "addDocumentListener". */ + String addMethod; + + /** The name of the method used to remove the "native" event listener, e.g. "removeDocumentListener". */ + String removeMethod; + } + + /** + * Performs introspection on the beanClass and stores the results. + * + * @throws java.beans.IntrospectionException + * TODO + */ + protected void init() throws IntrospectionException { + if (beanInfo == null) { + // perform introspection & cache the results + beanInfo = Introspector.getBeanInfo(getClassToGenerate()); + + PropertyDescriptor[] propertiesArray = beanInfo.getPropertyDescriptors(); + properties = new HashMap<String, PropertyDescriptor>(); + for (int i = propertiesArray.length - 1; i >= 0; i--) { + properties.put(propertiesArray[i].getName(), propertiesArray[i]); + } + + EventSetDescriptor[] eventsArray = beanInfo.getEventSetDescriptors(); + events = new HashMap<String, EventSetDescriptor>(); + for (int i = eventsArray.length - 1; i >= 0; i--) { + Method[] methods = eventsArray[i].getListenerMethods(); + for (Method method : methods) { + events.put(method.getName(), eventsArray[i]); + } + } + + configureProxyEventInfo(); + } + } + + /** + * Configures the event handling for members which do not fire <code>PropertyChangeEvent</code> when + * modified. The default implementation does nothing. Subclasses should override this method to call + * <code>addProxyEventInfo</code> for each member which requires special handling. + */ + protected void configureProxyEventInfo() { + + } + + + /** + * Configures a proxy event handler which fires <code>PropertyChangeEvents</code> when a non-bound + * member is updated. This is necessary for all fields (which cannot be bound) and for methods that are + * not bound property <code>get</code> methods. The proxy event handler will attach the specified kind + * of listener to the class and fire a <code>PropertyChangeEvent</code> whenever the listener receives + * any kind of event. + * <p/> + * Even though this method can theoretically be applied to fields (in addition to methods), it would be an + * unusual situation in which that would actually work -- as fields cannot fire events when modified, it would + * be difficult to have a listener that was always notified when a field value changed. + * + * @param memberName the name of the field or method being proxied + * @param listenerClass the type of listener which receives events when the field or method is updated + */ + public void addProxyEventInfo(String memberName, Class listenerClass) { + addProxyEventInfo(memberName, listenerClass, null); + } + + + /** + * Configures a proxy event handler which fires <code>PropertyChangeEvents</code> when a non-bound + * member is updated. This is necessary for all fields (which cannot be bound) and for methods that are + * not bound property <code>get</code> methods. This variant attaches a listener to a property of the + * object (such as <code>model</code>) and not the object itself, which is useful when there is a model + * that is the "real" container of the information. The proxy event handler will attach the specified kind + * of listener to the property's value (retrieved using the property's <code>get</code> method) and fire + * a <code>PropertyChangeEvent</code> whenever the listener receives any kind of event. + * <p/> + * If the property is itself bound (typically the case with models), any updates to the property's value will + * cause the listener to be removed from the old property value and reattached to the new property value, + * as well as cause a <code>PropertyChangeEvent</code> to be fired. + * <p/> + * Even though this method can theoretically be applied to fields (in addition to methods), it would be an + * unusual situation in which that would actually work -- as fields cannot fire events when modified, it would + * be difficult to have a listener that was always notified when a field value changed. + * + * @param memberName the name of the field or method being proxied + * @param listenerClass the type of listener which receives events when the field or method is updated + * @param modelName the JavaBeans-style name of the model property + */ + public void addProxyEventInfo(String memberName, Class listenerClass, String modelName) { + String listenerName = listenerClass.getName(); + listenerName = listenerName.substring(listenerName.lastIndexOf(".") + 1); + addProxyEventInfo(memberName, listenerClass, modelName, "add" + listenerName, "remove" + listenerName); + } + + /** + * Configures a proxy event handler which fires <code>PropertyChangeEvents</code> when a non-bound + * member is updated. This is necessary for all fields (which cannot be bound) and for methods that are + * not bound property <code>get</code> methods. This variant attaches a listener to a property of the + * object (such as <code>model</code>) and not the object itself, which is useful when there is a model + * that is the "real" container of the information. The proxy event handler will attach the specified kind + * of listener to the property's value (retrieved using the property's <code>get</code> method) and fire + * a <code>PropertyChangeEvent</code> whenever the listener receives any kind of event. + * <p/> + * If the property is itself bound (typically the case with models), any updates to the property's value will + * cause the listener to be removed from the old property value and reattached to the new property value, + * as well as cause a <code>PropertyChangeEvent</code> to be fired. + * <p/> + * This variant of <code>addProxyEventInfo</code> allows the names of the methods that add and remove + * the event listener to be specified, in cases where the names are not simply <code>add<listenerClassName></code> + * and <code>remove<listenerClassName></code>. + * <p/> + * Even though this method can theoretically be applied to fields (in addition to methods), it would be an + * unusual situation in which that would actually work -- as fields cannot fire events when modified, it would + * be difficult to have a listener that was always notified when a field value changed. + * + * @param memberName the name of the field or method being proxied + * @param listenerClass the type of listener which receives events when the field or method is updated + * @param modelName the JavaBeans-style name of the model property + * @param addMethod add method name + * @param removeMethod remove method name + */ + public void addProxyEventInfo(String memberName, Class listenerClass, + String modelName, String addMethod, String removeMethod) { + ProxyEventInfo info = new ProxyEventInfo(); + info.memberName = memberName; + info.listenerClass = listenerClass; + info.modelName = modelName; + info.addMethod = addMethod; + info.removeMethod = removeMethod; + if (eventInfos == null) { + eventInfos = new HashMap<String, ProxyEventInfo>(); + } + eventInfos.put(memberName, info); + } + + @Override + public boolean hasEventInfosAboutMethod(String methodName) { + return eventInfos != null && eventInfos.get(methodName) != null; + } + + @Override + public Class getEventInfosListenerClass(String methodName) { + return eventInfos.get(methodName) != null ? eventInfos.get(methodName).listenerClass : null; + } + + @Override + public String getEventInfosAddListenerMethodName(String methodName) { + return eventInfos.get(methodName) != null ? eventInfos.get(methodName).addMethod : null; + } + + @Override + public String getEventInfosRemoveListenerMethodName(String methodName) { + return eventInfos.get(methodName) != null ? eventInfos.get(methodName).removeMethod : null; + } + + @Override + public String getEventInfosModelName(String methodName) { + return eventInfos.get(methodName) != null ? eventInfos.get(methodName).modelName : null; + } + + @Override + public String getAttrToGenerate(String attr) { + return attrMap.get(attr); + } + + /** + * @param name ? + * @return <code>true</code> if the named member is <i>bound</i> (fires <code>PropertyChangeEvent</code> + * when modified). Members are either fields (represented by the simple name of the field) or <code>get/is</code> + * methods (represented by the simple name of the method, <b>not</b> the simplified JavaBeans-style name). + * Methods which are not actually bound in their native class, but for which proxy events have been + * configured (such as <code>JTextField.getText</code>, return <code>true</code>. + * @throws jaxx.UnsupportedAttributeException + * ? + */ + @Override + public boolean isMemberBound(String member) throws UnsupportedAttributeException { + try { + init(); + } catch (IntrospectionException e) { + throw new RuntimeException(e); + } + + if (eventInfos != null && eventInfos.containsKey(member)) { + return true; + } + + if (member.equals("getClass")) { + return false; + } + + String propertyName = null; + if (member.startsWith("get")) { + propertyName = Introspector.decapitalize(member.substring("get".length())); + } else if (member.startsWith("is")) { + propertyName = Introspector.decapitalize(member.substring("is".length())); + } + PropertyDescriptor property = propertyName != null ? properties.get(propertyName) : null; + if (property != null) { + return property.isBound(); + } + try { + Field field = getClassToGenerate().getField(member); + return Modifier.isFinal(field.getModifiers()); // final fields might as well be considered bound -- they can't be modified anyway + } catch (NoSuchFieldException e) { + throw new UnsupportedAttributeException("cannot find property '" + member + "' of " + getClassToGenerate()); + } + } } Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/LabelHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class LabelHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public LabelHandler() { - - } - -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuBarHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class MenuBarHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public MenuBarHandler() { - - } - -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class MenuHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public MenuHandler() { - - } - -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/MenuItemHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class MenuItemHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public MenuItemHandler() { - - } - -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/PanelHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,20 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class PanelHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public PanelHandler() { - - } -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/RowHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,122 +0,0 @@ -/** - * *##% guix-compiler-swing - * Copyright (C) 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ -package org.nuiton.guix.tags; - -import org.nuiton.guix.model.AttributeDescriptor; -import org.nuiton.guix.model.GuixModelObject; - -/** - * Represents a row of a table - * - * @author kevin - */ -public abstract class RowHandler extends TableHandler { - - /** index of the row */ - private int row = -1; - - /** - * Constructor - */ - public RowHandler() { - - } - - /** - * Constructor - * - * @param row the GuixModelObject which represents the row - */ - public RowHandler(GuixModelObject row) { - for (AttributeDescriptor attr : row.getAttributeDescriptors()) { - if (attr.getName().equals("row")) { - this.row = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("weightx")) { - weightx = Double.valueOf(attr.getValue()); - } - else if (attr.getName().equals("weighty")) { - weighty = Double.valueOf(attr.getValue()); - } - else if (attr.getName().equals("ipadx")) { - ipadx = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("ipady")) { - ipady = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("halign")) { - horizontalAlignment = getHalign(attr.getValue()); - } - else if (attr.getName().equals("valign")) { - verticalAlignment = getValign(attr.getValue()); - } - else if (attr.getName().equals("fill")) { - fill = attr.getValue(); - } - else if (attr.getName().equals("insets")) { - insets = attr.getValue(); - } - } - } - - /** - * Constructor - * - * @param row the GuixModelObject which represents the row - * @param table the table which contains the row - */ - public RowHandler(GuixModelObject row, TableHandler table) { - this(row); - //if the attributes that the table contains too have not been defined by the user within the row, - //but have been defined in the table, set them - if (horizontalAlignment == null) { - horizontalAlignment = table.getHorizontalAlignment() == null ? TableHandler.DEFAULT_HORIZONTAL_ALIGNMENT : table.getHorizontalAlignment(); - } - if (verticalAlignment == null) { - verticalAlignment = table.getVerticalAlignment() == null ? TableHandler.DEFAULT_VERTICAL_ALIGNMENT : table.getVerticalAlignment(); - } - if (fill == null) { - fill = table.getFill() == null ? TableHandler.DEFAULT_FILL : table.getFill(); - } - if (insets == null) { - insets = table.getInsets() == null ? TableHandler.DEFAULT_INSETS : table.getInsets(); - } - if (ipadx == null) { - ipadx = table.getIpadx() == null ? TableHandler.DEFAULT_IPADX : table.getIpadx(); - } - if (ipady == null) { - ipady = table.getIpady() == null ? TableHandler.DEFAULT_IPADY : table.getIpady(); - } - if (weightx == null) { - weightx = table.getWeightx() == null ? TableHandler.DEFAULT_WEIGHTX : table.getWeightx(); - } - if (weighty == null) { - weighty = table.getWeighty() == null ? TableHandler.DEFAULT_WEIGHTY : table.getWeighty(); - } - } - - public int getRow() { - return row; - } - - public void setRow(int row) { - this.row = row; - } - -} Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -90,6 +90,7 @@ * with the same name as the class */ public StyleSheet autoDetectStyleFile(File styleFile) throws IOException { + selectors = new ArrayList<Selector>(); return processStylesheet(loadStyleFile(styleFile)); } @@ -109,6 +110,7 @@ public StyleSheet compileStyle(XmlPullParser xpp, File styleFile) throws IOException, XmlPullParserException { StyleSheet result = null; StringBuffer style = new StringBuffer(); + selectors = new ArrayList<Selector>(); if ((styleFile != null) && styleFile.exists()) { style.append(loadStyleFile(styleFile)); @@ -150,7 +152,6 @@ * which rules will be applied to */ protected Selector processSelector(SimpleNode selector) { - // chack if it is a selector if (selector.getId() != CSSParserTreeConstants.JJTSELECTOR) { throw new IllegalArgumentException("argument node is not a Selector"); Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TabPanelHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,20 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class TabPanelHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public TabPanelHandler() { - - } -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TableHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,202 +0,0 @@ -/** - * *##% guix-compiler-swing - * Copyright (C) 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ -package org.nuiton.guix.tags; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.model.AttributeDescriptor; -import org.nuiton.guix.model.GuixModelObject; - -/** - * Represents a table - * - * @author kevin - */ -public abstract class TableHandler extends DefaultTagHandler { - - private static Log log = LogFactory.getLog(TableHandler.class); - - protected enum VerticalAlignment { - - ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM - } - protected enum HorizontalAlignment { - - ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_DEFAULT - } - public static final String DEFAULT_INSETS = "3, 3, 3, 3"; - public static final HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT = HorizontalAlignment.ALIGN_DEFAULT; - public static final VerticalAlignment DEFAULT_VERTICAL_ALIGNMENT = VerticalAlignment.ALIGN_TOP; - public static final String DEFAULT_FILL = "java.awt.GridBagConstraints.BOTH"; - public static final Integer DEFAULT_IPADX = 1; - public static final Integer DEFAULT_IPADY = 1; - public static final Double DEFAULT_WEIGHTX = 0.0; - public static final Double DEFAULT_WEIGHTY = 0.0; - protected Double weightx = null; - protected Double weighty = null; - protected Integer ipadx = null; - protected Integer ipady = null; - protected HorizontalAlignment horizontalAlignment = null; - protected VerticalAlignment verticalAlignment = null; - protected String fill = null; - protected String insets = null; - - /** - * Constructor - */ - public TableHandler() { - } - - /** - * Constructor - * - * @param table the GuixModelObject which represents the table - */ - public TableHandler(GuixModelObject table) { - - for (AttributeDescriptor attr : table.getAttributeDescriptors()) { - if (attr.getName().equals("weightx")) { - weightx = Double.valueOf(attr.getValue()); - } - else if (attr.getName().equals("weighty")) { - weighty = Double.valueOf(attr.getValue()); - } - else if (attr.getName().equals("ipadx")) { - ipadx = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("ipady")) { - ipady = Integer.valueOf(attr.getValue()); - } - else if (attr.getName().equals("halign")) { - horizontalAlignment = getHalign(attr.getValue()); - if (horizontalAlignment == null) { - if (log.isErrorEnabled()) { - log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue()); - } - horizontalAlignment = HorizontalAlignment.ALIGN_DEFAULT; - } - } - else if (attr.getName().equals("valign")) { - verticalAlignment = getValign(attr.getValue()); - if (verticalAlignment == null) { - if (log.isErrorEnabled()) { - log.error(table.getId() + "'s halign attribute has a wrong value : " + attr.getValue()); - } - verticalAlignment = VerticalAlignment.ALIGN_TOP; - } - } - else if (attr.getName().equals("fill")) { - fill = attr.getValue(); - } - else if (attr.getName().equals("insets")) { - insets = attr.getValue(); - } - } - } - - public HorizontalAlignment getHorizontalAlignment() { - return horizontalAlignment; - } - - public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) { - this.horizontalAlignment = horizontalAlignment; - } - - public VerticalAlignment getVerticalAlignment() { - return verticalAlignment; - } - - public void setVerticalAlignment(VerticalAlignment verticalAlignment) { - this.verticalAlignment = verticalAlignment; - } - - public String getFill() { - return fill; - } - - public void setFill(String fill) { - this.fill = fill; - } - - public String getInsets() { - return insets; - } - - public void setInsets(String insets) { - this.insets = insets; - } - - public Integer getIpadx() { - return ipadx; - } - - public void setIpadx(Integer ipadx) { - this.ipadx = ipadx; - } - - public Integer getIpady() { - return ipady; - } - - public void setIpady(Integer ipady) { - this.ipady = ipady; - } - - public Double getWeightx() { - return weightx; - } - - public void setWeightx(Double weightx) { - this.weightx = weightx; - } - - public Double getWeighty() { - return weighty; - } - - public void setWeighty(Double weighty) { - this.weighty = weighty; - } - - public HorizontalAlignment getHalign(String halign) { - if (halign.equalsIgnoreCase("left")) { - return HorizontalAlignment.ALIGN_LEFT; - } - if (halign.equalsIgnoreCase("right")) { - return HorizontalAlignment.ALIGN_RIGHT; - } - if (halign.equalsIgnoreCase("center")) { - return HorizontalAlignment.ALIGN_CENTER; - } - return null; - } - - public VerticalAlignment getValign(String valign) { - if (valign.equalsIgnoreCase("top")) { - return VerticalAlignment.ALIGN_TOP; - } - if (valign.equalsIgnoreCase("bottom")) { - return VerticalAlignment.ALIGN_BOTTOM; - } - if (valign.equalsIgnoreCase("middle")) { - return VerticalAlignment.ALIGN_MIDDLE; - } - return null; - } -} Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -12,4 +12,18 @@ public interface TagHandler { public Class getClassToGenerate(); + + public String getAttrToGenerate(String attr); + + public boolean hasEventInfosAboutMethod(String methodName); + + public Class getEventInfosListenerClass(String methodName); + + public String getEventInfosAddListenerMethodName(String methodName); + + public String getEventInfosRemoveListenerMethodName(String methodName); + + public String getEventInfosModelName(String methodName); + + public boolean isMemberBound(String member); } Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TextFieldHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,21 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class TextFieldHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public TextFieldHandler() { - - } - -} Deleted: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java 2009-07-22 13:03:32 UTC (rev 1499) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ToggleButtonHandler.java 2009-07-22 13:06:26 UTC (rev 1500) @@ -1,20 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.nuiton.guix.tags; - -/** - * - * @author kevin - */ -public abstract class ToggleButtonHandler extends DefaultTagHandler { - - /** - * Constructor - */ - public ToggleButtonHandler() { - - } -}
participants (1)
-
kmorin@users.labs.libre-entreprise.org