Buix-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- 1440 discussions
r1365 - in guix/trunk/guix-compiler/src: main/java/org/nuiton/guix main/java/org/nuiton/guix/compiler main/java/org/nuiton/guix/model main/java/org/nuiton/guix/tags main/resources test test/java/org/nuiton/guix test/java/org/nuiton/guix/compiler test/java/org/nuiton/guix/tags
by kmorinīŧ users.labs.libre-entreprise.org 29 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 29 Apr '09
29 Apr '09
Author: kmorin
Date: 2009-04-29 15:41:14 +0000 (Wed, 29 Apr 2009)
New Revision: 1365
Added:
guix/trunk/guix-compiler/src/main/resources/log4j.properties
guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java
guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/
guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java
guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/tags/
guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/tags/TagManagerTest.java
guix/trunk/guix-compiler/src/test/test.guix
Modified:
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java
Log:
log + test unitaires
+ corrections des bugs d?\195?\169couverts grace aux tests unitaires
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-04-29 08:06:47 UTC (rev 1364)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -9,11 +9,11 @@
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.guix.model.ClassDescriptor;
import org.nuiton.guix.model.GuixModelObject;
import org.nuiton.guix.model.Rule;
@@ -30,7 +30,7 @@
public class GuixLauncher {
/** log */
- Logger log = Logger.getLogger(GuixLauncher.class);
+ protected static final Log log = LogFactory.getLog(GuixLauncher.class);
/** original list of files to compile */
protected final File[] files;
/** original list of classes to compile */
@@ -49,19 +49,34 @@
private List<File> compiledFiles = new ArrayList<File>();
protected int compilerCount;
private File targetDirectory;
+ private String rootPackage;
/**
* Constructor
*
* @param files the files to compile
*/
- public GuixLauncher(File[] files, File targetDirectory) {
+ public GuixLauncher(File[] files, File targetDirectory, String rootPackage,
+ File baseDir) {
// Set up a simple configuration that logs on the console.
this.files = files;
this.targetDirectory = targetDirectory;
- classNames = new String[files.length];
- for (int i = 0; i < files.length; i++) {
- classNames[i] = files[i].getName().substring(0, files[i].getName().lastIndexOf('.'));
+ if(rootPackage != null)
+ this.rootPackage = rootPackage;
+ else
+ this.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;
}
}
@@ -73,185 +88,204 @@
*/
public synchronized boolean compile() {
compilerCount = 0;
- guixFiles.addAll(Arrays.asList(files));
- guixFileClassNames.addAll(Arrays.asList(classNames));
- boolean success = true;
+ File destDir = targetDirectory;
+ if (files != null) {
+ guixFiles.addAll(Arrays.asList(files));
+ guixFileClassNames.addAll(Arrays.asList(classNames));
+ boolean success = true;
+
+ try {
+ assert guixFiles.size() == guixFileClassNames.size();
- try {
- assert guixFiles.size() == guixFileClassNames.size();
+ for (int i = 0; i < guixFiles.size(); i++) {
+ File file = guixFiles.get(i);
+ String className = guixFileClassNames.get(i);
- 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);
- //if we have not compiled the file yet
- if (!compiledFiles.contains(file)) {
- log.info("Compiling class " + className);
- compiledFiles.add(file);
-
- File destDir = targetDirectory;
- if (destDir != null) {
- int dotPos = className.lastIndexOf(".");
- if (dotPos != -1) {
- destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
+ 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 = new File(destDir, className);
+ destDir = file.getParentFile();
+ classPackage = destDir.getAbsolutePath().replace(File.separatorChar,'.');
}
- if (!destDir.exists() && !destDir.mkdirs()) {
- log.warn("couldn't create directory " + destDir);
- continue;
+ //compile the file
+ GuixCompiler compiler = new GuixCompiler(file, this, classPackage);
+
+ GuixModelObject rootModelObject = compiler.compile();
+ rootModelObjects.put(rootModelObject, compiler);
+
+ if (compiler.isFailed()) {
+ success = false;
}
} else {
- destDir = file.getParentFile();
+ if (log.isWarnEnabled()) {
+ log.warn(file.getName() + " has already been compiled.");
+ }
}
- //compile the file
- GuixCompiler compiler = new GuixCompiler(
- file.getParentFile(), file, className, this);
+ }
- GuixModelObject rootModelObject = compiler.compile();
- rootModelObjects.put(rootModelObject, compiler);
-
- if (compiler.isFailed()) {
- success = false;
+ if (success) {
+ int i = 0;
+ while (success && i < classDescriptors.size()) {
+ success = (classDescriptors.get(i++).getPackageName() != null);
}
- } else {
- log.warn(file.getName() + " has already been compiled.");
+ if (!success) {
+ if (log.isErrorEnabled()) {
+ log.error("The class '" + classDescriptors.get(--i).getName() + "' has no package.");
+ }
+ }
}
- }
+ if (success || true) {
+ XmlPullParserFactory factory =
+ XmlPullParserFactory.newInstance(
+ System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
+ null);
- if (success) {
- int i = 0;
- while (success && i < classDescriptors.size()) {
- success = (classDescriptors.get(i++).getPackageName() != null);
- }
- if (!success) {
- log.error("The class '" + classDescriptors.get(--i).getName() + "' has no package.");
- }
- }
- if (success || true) {
- XmlPullParserFactory factory =
- XmlPullParserFactory.newInstance(
- System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
- null);
-
- for (GuixModelObject mo : rootModelObjects.keySet()) {
- File f = new File(targetDirectory, mo.getClassDescriptor().getName() + "ModelTree.xml");
- log.info(mo.getClassDescriptor().getName() + " last modification : "
- + new Date(rootModelObjects.get(mo).getLastModification()));
-
- if (rootModelObjects.get(mo).getLastModification() > f.lastModified()) {
- log.info("Generation of " + mo.getClassDescriptor().getName());
- if (!f.exists()) {
- f.createNewFile();
+ for (GuixModelObject mo : rootModelObjects.keySet()) {
+ File f = new File(destDir, mo.getClassDescriptor().getName() + "ModelTree.xml");
+ if (log.isInfoEnabled()) {
+ log.info(mo.getClassDescriptor().getName() + " last modification : " + new Date(rootModelObjects.get(mo).getLastModification()));
}
- XmlSerializer serializer = factory.newSerializer();
- XmlSerializer cssSerializer = factory.newSerializer();
+ if (rootModelObjects.get(mo).getLastModification() > f.lastModified()) {
+ if (log.isInfoEnabled()) {
+ log.info("Generation of " + mo.getClassDescriptor().getName());
+ }
+ if (!f.exists()) {
+ f.createNewFile();
+ }
+ XmlSerializer serializer = factory.newSerializer();
+ XmlSerializer cssSerializer = factory.newSerializer();
- serializer.setOutput(new PrintWriter(f));
- 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.setOutput(new PrintWriter(f));
+ 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");
- cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
- cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "\t");
+ cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "\t");
- writeModelTree(serializer, mo, cssSerializer);
+ writeModelTree(serializer, mo, cssSerializer, destDir);
- serializer.endDocument();
+ serializer.endDocument();
+ } else if (log.isWarnEnabled()) {
+ log.warn(mo.getClassDescriptor().getName() + " has already been generated and is up to date.");
+ }
}
- else {
- log.warn(mo.getClassDescriptor().getName() + " has already been generated and is up to date.");
- }
+
+ /*// pass 2
+ if (!nextStep(LifeCycle.compile_second_pass, success)) {
+ return false;
}
- /*// pass 2
- if (!nextStep(LifeCycle.compile_second_pass, success)) {
- return false;
- }
+ assert guixFiles.size() == guixFileClassNames.size();
+ List<File> jaxxFilesClone = new ArrayList<File>(guixFiles);
+ for (String className : guixFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ if (log.isDebugEnabled()) {
+ log.debug("runInitializers for " + className);
+ }
+ if (!compiler.isFailed()) {
+ compiler.runInitializers();
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("compile second pass for " + className);
+ }
+ compiler.compileSecondPass();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (log.isDebugEnabled()) {
+ log.debug("done with result [" + !compiler.isFailed() + "] for " + className);
+ }
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ if (!jaxxFilesClone.equals(guixFiles)) {
+ throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + guixFiles + ")");
+ }
- assert guixFiles.size() == guixFileClassNames.size();
- List<File> jaxxFilesClone = new ArrayList<File>(guixFiles);
- for (String className : guixFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass");
- addProfileTime(compiler, currentPass.name() + "_start");
- if (log.isDebugEnabled()) {
- log.debug("runInitializers for " + className);
- }
- if (!compiler.isFailed()) {
- compiler.runInitializers();
- }
- if (log.isDebugEnabled()) {
- log.debug("compile second pass for " + className);
- }
- compiler.compileSecondPass();
- addProfileTime(compiler, currentPass.name() + "_end");
- if (log.isDebugEnabled()) {
- log.debug("done with result [" + !compiler.isFailed() + "] for " + className);
- }
- if (compiler.isFailed()) {
- success = false;
- }
- }
- if (!jaxxFilesClone.equals(guixFiles)) {
- throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + guixFiles + ")");
- }
+ // stylesheet application
+ if (!nextStep(LifeCycle.stylesheet_pass, success)) {
+ return false;
+ }
+ assert guixFiles.size() == guixFileClassNames.size();
+ for (String className : guixFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compiler.applyStylesheets();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
- // stylesheet application
- if (!nextStep(LifeCycle.stylesheet_pass, success)) {
- return false;
- }
- assert guixFiles.size() == guixFileClassNames.size();
- for (String className : guixFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application");
- addProfileTime(compiler, currentPass.name() + "_start");
- compiler.applyStylesheets();
- addProfileTime(compiler, currentPass.name() + "_end");
- if (compiler.isFailed()) {
- success = false;
- }
- }
+ // code generation
+ if (!nextStep(LifeCycle.generate_pass, success)) {
+ return false;
+ }
+ assert guixFiles.size() == guixFileClassNames.size();
+ List<Generator> generators = new ArrayList<Generator>();
+ for (Generator generator : ServiceLoader.load(Generator.class)) {
+ generators.add(generator);
+ }
+ for (String className : guixFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compiler.generateCode(generators);
+ addProfileTime(compiler, currentPass.name() + "_end");
+ //compiler.generateCode();
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
- // code generation
- if (!nextStep(LifeCycle.generate_pass, success)) {
- return false;
- }
- assert guixFiles.size() == guixFileClassNames.size();
- List<Generator> generators = new ArrayList<Generator>();
- for (Generator generator : ServiceLoader.load(Generator.class)) {
- generators.add(generator);
- }
- for (String className : guixFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation");
- addProfileTime(compiler, currentPass.name() + "_start");
- compiler.generateCode(generators);
- addProfileTime(compiler, currentPass.name() + "_end");
- //compiler.generateCode();
- if (compiler.isFailed()) {
- success = false;
- }
- }
+ if (options.isProfile()) {
+ // profile pass (only if succes compile)
+ if (!nextStep(LifeCycle.profile_pass, success)) {
+ return false;
+ }
+ StringBuilder buffer = profiler.computeProfileReport();
+ log.info(buffer.toString());
+ }
- if (options.isProfile()) {
- // profile pass (only if succes compile)
- if (!nextStep(LifeCycle.profile_pass, success)) {
- return false;
+ return report(success);
+
+ //FIXME : deal better the exception treatment...
+ } catch (CompilerException e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ return false;*/
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ return false;
}
- StringBuilder buffer = profiler.computeProfileReport();
- log.info(buffer.toString());
+ return success;
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn("No file to compile");
}
-
- return report(success);
-
- //FIXME : deal better the exception treatment...
- } catch (CompilerException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return false;*/
- }
- } catch (Throwable e) {
- e.printStackTrace();
- return false;
+ return true;
}
- return success;
}
/**
@@ -264,11 +298,11 @@
* @throws java.io.IOException
*/
private void writeModelTree(XmlSerializer serializer, GuixModelObject mo,
- XmlSerializer cssSerializer) throws IOException {
+ XmlSerializer cssSerializer, File destDir) throws IOException {
if (!mo.getStyleSheets().isEmpty()) {
int i = 0;
for (StyleSheet styleSheet : mo.getStyleSheets()) {
- File ss = new File(targetDirectory, mo.getClassDescriptor().getName() + i++ + "SS.xml");
+ File ss = new File(destDir, mo.getClassDescriptor().getName() + i++ + "SS.xml");
cssSerializer.setOutput(new FileWriter(ss));
cssSerializer.startTag("", "rules");
for (Rule rule : styleSheet.getRules()) {
@@ -338,16 +372,15 @@
serializer.endTag("", "script");
serializer.startTag("", "superclass");
if (mo.getClassDescriptor().getSuperClass() != null) {
- serializer.text(mo.getClassDescriptor().getSuperClass().getPackageName() + "." + mo.getClassDescriptor().getSuperClass().getName());
+ serializer.text(mo.getClassDescriptor().getSuperClass().toString());
}
serializer.endTag("", "superclass");
serializer.endTag("", "class");
for (GuixModelObject child : mo.getChildren()) {
- writeModelTree(serializer, child, cssSerializer);
+ writeModelTree(serializer, child, cssSerializer, destDir);
}
-
serializer.endTag("", "Object");
}
@@ -360,26 +393,47 @@
* and package has a different script or superclass
*/
public boolean registerClassDescriptor(ClassDescriptor classDescriptor) {
+ if(classDescriptor == null || classDescriptor.getName() == null)
+ return false;
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())))) {
+ 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 true;
}
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 false;
}
}
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 false;
}
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-04-29 08:06:47 UTC (rev 1364)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -1,4 +1,3 @@
-
package org.nuiton.guix.compiler;
import org.nuiton.guix.GuixLauncher;
@@ -7,7 +6,8 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.ClassDescriptor;
import org.nuiton.guix.model.GuixModelObject;
@@ -26,14 +26,15 @@
*/
public class GuixCompiler {
+ /** log */
+ protected static final Log log = LogFactory.getLog(GuixCompiler.class);
/** Flag to detec if an error occurs while compiling guix file */
protected boolean failed;
/** Directory containing the guix files */
private File baseDir;
/** Guix file to compile */
private File src;
- /** Name of the class to produce */
- private String outputClassName;
+ private String srcPackage;
/** GuixLauncher instance which launched this compiler */
private GuixLauncher launcher;
private StyleHandler styleHandler = new StyleHandler();
@@ -49,18 +50,20 @@
/**
* Creates a new GuixCompiler.
*
- * @param baseDir classpath location
- * @param src location of file to compile
- * @param outputClassName the out file name
- * @param launcher the launcher of the compiler
+ * @param src location of file to compile
+ * @param launcher the launcher of the compiler
*/
- public GuixCompiler(File baseDir, File src, String outputClassName,
- GuixLauncher launcher) {
- this.baseDir = baseDir;
+ public GuixCompiler(File src, GuixLauncher launcher, String srcPackage) {
this.src = src;
- this.outputClassName = outputClassName;
this.launcher = launcher;
- lastModification = src.lastModified();
+ if(srcPackage != null)
+ this.srcPackage = srcPackage;
+ else
+ this.srcPackage = "";
+ if (src != null) {
+ baseDir = src.getParentFile();
+ lastModification = src.lastModified();
+ }
}
/**
@@ -69,73 +72,81 @@
* @return the root of the model
*/
public GuixModelObject compile() {
- try {
- //Creation of the Xml parser
- XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
- factory.setNamespaceAware(true);
- XmlPullParser xpp = factory.newPullParser();
- xpp.setInput(new FileReader(src));
- //Start parsing
- if (xpp.getEventType() == XmlPullParser.START_DOCUMENT) {
- //javaDoc of the class to create
- StringBuffer doc = new StringBuffer();
- do {
- xpp.nextToken();
- if (xpp.getEventType() == XmlPullParser.COMMENT) {
- doc.append(xpp.getText());
+ if (src != null && launcher != null) {
+ try {
+ //Creation of the Xml parser
+ XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
+ factory.setNamespaceAware(true);
+ XmlPullParser xpp = factory.newPullParser();
+ xpp.setInput(new FileReader(src));
+ //Start parsing
+ if (xpp.getEventType() == XmlPullParser.START_DOCUMENT) {
+ //javaDoc of the class to create
+ StringBuffer doc = new StringBuffer();
+ do {
+ xpp.nextToken();
+ if (xpp.getEventType() == XmlPullParser.COMMENT) {
+ doc.append(xpp.getText());
+ }
+ } while (xpp.getEventType() != XmlPullParser.START_TAG);
+ //resolve the package of teh superclass
+ String tagNameSpace = xpp.getNamespace();
+ String tagName;
+ if (xpp.getName().lastIndexOf('.') >= 0) {
+ tagName = xpp.getName().substring(xpp.getName().lastIndexOf('.') + 1);
+ } else {
+ tagName = xpp.getName();
}
- } while (xpp.getEventType() != XmlPullParser.START_TAG);
- //resolve the package of teh superclass
- String tagNameSpace = xpp.getNamespace();
- String tagName = xpp.getName();
- String tagPackageName = resolvePackageName(tagNameSpace, tagName);
- //creation of the root GuixModelObject
- rootMO = new GuixModelObject(xpp.getAttributeValue("", "id"), doc.toString(), xpp.getAttributeValue("", "styleClass"));
- //the class name is the name of the file minus the extension
- String className = src.getName().substring(0, src.getName().lastIndexOf('.'));
- String classPackageName = src.getPath().replace('/', '.').substring(src.getPath().lastIndexOf("src/main/java/") + 14, src.getPath().lastIndexOf('/'));
- rootMO.setClassDescriptor(new ClassDescriptor(className, classPackageName));
- rootMO.getClassDescriptor().setSuperClass(new ClassDescriptor(tagName, tagPackageName));
- rootMO.setAttributeDescriptors(getAttributes(xpp));
- rootMO.setChildren(new ArrayList<GuixModelObject>());
+ String tagPackageName = resolvePackageName(tagNameSpace, xpp.getName());
+ //creation of the root GuixModelObject
+ rootMO = new GuixModelObject(xpp.getAttributeValue("", "id"), doc.toString(), xpp.getAttributeValue("", "styleClass"));
+ //the class name is the name of the file minus the extension
+ String className = src.getName().substring(0, src.getName().lastIndexOf('.'));
+ rootMO.setClassDescriptor(new ClassDescriptor(className, srcPackage));
+ rootMO.getClassDescriptor().setSuperClass(new ClassDescriptor(tagName, tagPackageName));
+ rootMO.setAttributeDescriptors(getAttributes(xpp));
+ rootMO.setChildren(new ArrayList<GuixModelObject>());
- //add the stylesheet of the CSS file with the same name as the Guix file
- File styleFile = new File(baseDir, className + ".css");
- if(styleFile.exists()) {
- StyleSheet ss = styleHandler.autoDetectStyleFile(styleFile);
- rootMO.getStyleSheets().add(ss);
- lastModification = Math.max(lastModification,styleFile.lastModified());
- }
+ //add the stylesheet of the CSS file with the same name as the Guix file
+ File styleFile = new File(src.getParentFile(), className + ".css");
+ if (styleFile.exists()) {
+ StyleSheet ss = styleHandler.autoDetectStyleFile(styleFile);
+ rootMO.getStyleSheets().add(ss);
+ lastModification = Math.max(lastModification, styleFile.lastModified());
+ }
- StringBuffer script = new StringBuffer();
- //add the script in the .script file with the same name as the Guix file
- File scriptFile = new File(baseDir, className + ".script");
- if(scriptFile.exists()) {
- script.append(scriptHandler.loadScriptFile(scriptFile));
- lastModification = Math.max(lastModification, scriptFile.lastModified());
- }
+ StringBuffer script = new StringBuffer();
+ //add the script in the .script file with the same name as the Guix file
+ File scriptFile = new File(src.getParentFile(), className + ".script");
+ if (scriptFile.exists()) {
+ script.append(scriptHandler.loadScriptFile(scriptFile));
+ lastModification = Math.max(lastModification, scriptFile.lastModified());
+ }
- //reach the next START_TAG
- do {
- xpp.nextToken();
- } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
- //if not eof
- if (xpp.getEventType() == XmlPullParser.START_TAG) {
- //compile the rest of the file
- script.append(compile(xpp, rootMO, doc.toString()));
+ //reach the next START_TAG
+ do {
+ xpp.nextToken();
+ } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ //if not eof
+ if (xpp.getEventType() == XmlPullParser.START_TAG) {
+ //compile the rest of the file
+ script.append(compile(xpp, rootMO, doc.toString()));
+ }
+ //all the script tags have been recorded
+ rootMO.getClassDescriptor().setScript(script.toString());
+ //register the root ClassDescriptor
+ failed = !launcher.registerClassDescriptor(rootMO.getClassDescriptor());
+ return rootMO;
}
- //all the script tags have been recorded
- rootMO.getClassDescriptor().setScript(script.toString());
- //register the root ClassDescriptor
- failed = !launcher.registerClassDescriptor(rootMO.getClassDescriptor());
- return rootMO;
+ } catch (XmlPullParserException ex) {
+ if(log.isErrorEnabled())
+ log.error(ex);
+ } catch (IOException ex) {
+ if(log.isErrorEnabled())
+ log.error(ex);
}
- failed = true;
- } catch (XmlPullParserException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).error(ex);
- } catch (IOException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).error(ex);
}
+ failed = true;
return null;
}
@@ -149,7 +160,7 @@
* @param javaDoc the comments above the tag, to add to its javaDoc
* @return the scripts already discovered while parsing the file
*/
- private StringBuffer compile(final XmlPullParser xpp, GuixModelObject previousMO,
+ protected StringBuffer compile(final XmlPullParser xpp, GuixModelObject previousMO,
String javaDoc) {
StringBuffer result = new StringBuffer();
@@ -168,15 +179,16 @@
}
//creates a new stylesheet
StyleSheet ss = styleHandler.compileStyle(xpp, styleFile);
- if(ss != null)
+ if (ss != null) {
rootMO.getStyleSheets().add(ss);
- if (styleFile != null && styleFile.exists())
+ }
+ if (styleFile != null && styleFile.exists()) {
lastModification = Math.max(lastModification, styleFile.lastModified());
-
+ }
+
//the parent is still the same
prev = previousMO;
- }
- //if the tag is a script tag
+ } //if the tag is a script tag
else if (xpp.getName() != null && xpp.getName().equals("script")) {
File scriptFile = null;
//the name of the file to load
@@ -187,26 +199,23 @@
}
//add the script to the result
result.append(scriptHandler.compileScript(xpp, scriptFile));
- if (scriptFile != null && scriptFile.exists()) {
+ if (scriptFile != null && scriptFile.exists()) {
lastModification = Math.max(lastModification, scriptFile.lastModified());
}
//the parent is still the same
prev = previousMO;
- }
- //if the tag is a class tag
+ } //if the tag is a class tag
else {
String tagNameSpace = xpp.getNamespace();
String tagPackageName = resolvePackageName(tagNameSpace, xpp.getName());
String tagName;
//if the name of the tag is the fully-qualified class name
- if(xpp.getName().lastIndexOf('.') >= 0) {
+ if (xpp.getName().lastIndexOf('.') >= 0) {
tagName = xpp.getName().substring(xpp.getName().lastIndexOf('.') + 1);
- }
- else {
+ } else {
tagName = xpp.getName();
}
- tagNameSpace = tagPackageName + ".*";
//create the GuixModelObject representing the tag
GuixModelObject mo = new GuixModelObject(xpp.getAttributeValue("", "id"),
javaDoc, xpp.getAttributeValue("", "styleClass"));
@@ -218,7 +227,6 @@
//register the ClassDescriptor
failed = !launcher.registerClassDescriptor(mo.getClassDescriptor());
-
if (!failed) {
//parse the children of the tag
prev = mo;
@@ -231,21 +239,23 @@
//add the comment to the doc of the next tag
doc.append(xpp.getText());
}
- } while (xpp.getEventType() != XmlPullParser.START_TAG
- && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ } else {
+ return null;
}
- else
- return null;
}
+
//if not eof
if (xpp.getEventType() == XmlPullParser.START_TAG) {
//compile the rest of the document
result.append(compile(xpp, prev, doc.toString()));
}
} catch (XmlPullParserException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).error(ex);
+ if(log.isErrorEnabled())
+ log.error(ex);
} catch (IOException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).error(ex);
+ if(log.isErrorEnabled())
+ log.error(ex);
}
return result;
}
@@ -265,16 +275,15 @@
packageName = tagNameSpace.substring(0, tagNameSpace.length() - 2);
}
//if the name of the tag is the fully qualified class name
- if(tagName.lastIndexOf('.') >= 0) {
- if(packageName == null) {
+ if (tagName.lastIndexOf('.') >= 0) {
+ if (packageName == null) {
packageName = tagName.substring(0, tagName.lastIndexOf('.'));
- }
- else {
+ } else {
packageName += tagName.substring(0, tagName.lastIndexOf('.'));
}
}
//if nor the namespace nor the fully qualified class name is defined
- if(packageName == null) {
+ if (packageName == null) {
String fullClassName = TagManager.resolveClassName(tagName);
packageName = (fullClassName == null) ? null : fullClassName.substring(0, fullClassName.lastIndexOf('.'));
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java 2009-04-29 08:06:47 UTC (rev 1364)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -38,5 +38,9 @@
public void setValue(String value) {
this.value = value;
}
+
+ public String toString() {
+ return name + " : " + value;
+ }
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-04-29 08:06:47 UTC (rev 1364)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -60,4 +60,8 @@
public void setSuperClass(ClassDescriptor superClass) {
this.superClass = superClass;
}
+
+ public String toString() {
+ return (packageName != null) ? packageName + "." + name : name;
+ }
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-29 08:06:47 UTC (rev 1364)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -11,7 +11,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.log4j.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.guix.css.CSSParser;
import org.nuiton.guix.css.CSSParserConstants;
import org.nuiton.guix.css.CSSParserTreeConstants;
@@ -30,6 +31,8 @@
*/
public class StyleHandler {
+ /** log */
+ protected static final Log log = LogFactory.getLog(TagManager.class);
/** List of the selectors */
private List<Selector> selectors = new ArrayList<Selector>();
@@ -92,8 +95,8 @@
do {
switch (xpp.getEventType()) {
case XmlPullParser.START_TAG:
- Logger.getLogger(StyleHandler.class)
- .warn("<style> tag may not contain child elements: " + xpp.getName());
+ if(log.isWarnEnabled())
+ log.warn("<style> tag may not contain child elements: " + xpp.getName());
break;
case XmlPullParser.TEXT:
break;// fall through
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-04-29 08:06:47 UTC (rev 1364)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -1,19 +1,11 @@
package org.nuiton.guix.tags;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Manages tags of the .guix files.
@@ -21,7 +13,6 @@
public class TagManager {
/** log */
protected static final Log log = LogFactory.getLog(TagManager.class);
-
/**
* Namespace for Guix's non-class tags, such as <Button;>. The namespace normally does not
* need to be specified but can be used to resolve ambiguities.
@@ -35,7 +26,7 @@
private static Map<String, Boolean> classExistenceCache = new HashMap<String, Boolean>();
/** List of the Guix classes such as <Button;> */
- private static List<String> guixClasses = new ArrayList<String>();
+ protected static List<String> guixClasses = new ArrayList<String>();
private TagManager() { /* not instantiable */ }
@@ -249,7 +240,6 @@
return resolveClassName(name.substring(0, name.length() - 2)) + "[]";
if (name.indexOf("<") != -1)
name = name.substring(0, name.indexOf("<")); // strip off generic types
-
name = name.intern();
if (name.equals("boolean") || name.equals("byte") || name.equals("short") || name.equals("int") ||
name.equals("long") || name.equals("float") || name.equals("double") || name.equals("char"))
@@ -258,6 +248,10 @@
if (guixClasses.contains(name)) {
return GUIX_NAMESPACE.substring(0, GUIX_NAMESPACE.lastIndexOf('*')) + name;
}
+ //if the name of the tag is the fully qualified class name
+ if(name.lastIndexOf('.') >= 0) {
+ return name;
+ }
return null;
}
Added: guix/trunk/guix-compiler/src/main/resources/log4j.properties
===================================================================
--- guix/trunk/guix-compiler/src/main/resources/log4j.properties (rev 0)
+++ guix/trunk/guix-compiler/src/main/resources/log4j.properties 2009-04-29 15:41:14 UTC (rev 1365)
@@ -0,0 +1,9 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%F : %M] %m%n
+
+#log4j.logger.org.codelutin.i18n=ERROR
+log4j.logger.org.nuiton.guix=DEBUG
Added: guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java
===================================================================
--- guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java (rev 0)
+++ guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/GuixLauncherTest.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -0,0 +1,77 @@
+package org.nuiton.guix;
+
+import java.io.File;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.nuiton.guix.model.ClassDescriptor;
+
+/**
+ * Tests the methods of the GuixLauncher class
+ *
+ * @author morin
+ */
+public class GuixLauncherTest {
+
+ /**
+ * Tests the method compile
+ */
+ @Test
+ public void compileTest() {
+ GuixInitializer.initialize();
+
+ GuixLauncher gl = new GuixLauncher(null,null,null,null);
+ assertTrue(gl.files == null || gl.classNames.length == gl.files.length);
+ assertTrue(gl.compile());
+ assertTrue(gl.files == null || gl.rootModelObjects.size() == gl.files.length);
+
+ File f = new File("src/test/test.guix");
+ File f2 = new File(f.getAbsolutePath());
+ File dir = new File("target/test");
+ File dir2 = new File(dir.getAbsolutePath());
+ gl = new GuixLauncher(new File[]{f2},dir2,"org.nuiton.guix",f2.getParentFile());
+ assertTrue(gl.files == null || gl.classNames.length == gl.files.length);
+ assertTrue(gl.compile());
+ }
+
+ /**
+ * Tests the method registerClassDescriptor
+ */
+ @Test
+ public void registerClassDescriptorTest() {
+ GuixLauncher gl = new GuixLauncher(null,null,null,null);
+ assertFalse(gl.registerClassDescriptor(null));
+ assertFalse(gl.registerClassDescriptor(new ClassDescriptor(null, null)));
+
+ ClassDescriptor cd = new ClassDescriptor("name", "package");
+ assertTrue(gl.registerClassDescriptor(cd));
+ cd.setSuperClass(new ClassDescriptor("super", "package"));
+ assertTrue(gl.registerClassDescriptor(cd)
+ && gl.classDescriptors.get(0).getSuperClass() != null);
+ assertTrue(gl.registerClassDescriptor(cd)
+ && gl.classDescriptors.size() == 1);
+
+ ClassDescriptor cd2 = new ClassDescriptor("name", "package");
+ cd2.setSuperClass(new ClassDescriptor("super2", "package"));
+ assertFalse(gl.registerClassDescriptor(cd2));
+
+ ClassDescriptor cd3 = new ClassDescriptor("name", "package");
+ cd3.setScript("script");
+ assertTrue(gl.registerClassDescriptor(cd3)
+ && gl.classDescriptors.size() == 1);
+
+ ClassDescriptor cd4 = new ClassDescriptor("name", "package");
+ cd4.setScript("script2");
+ assertFalse(gl.registerClassDescriptor(cd4));
+
+ assertTrue(gl.registerClassDescriptor(new ClassDescriptor("name", null))
+ && gl.classDescriptors.size() == 1);
+ assertTrue(gl.registerClassDescriptor(new ClassDescriptor("test", null))
+ && gl.classDescriptors.size() == 2);
+ assertTrue(gl.registerClassDescriptor(new ClassDescriptor("test", null))
+ && gl.classDescriptors.size() == 2);
+ }
+}
+
Added: guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java
===================================================================
--- guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java (rev 0)
+++ guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/compiler/GuixCompilerTest.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -0,0 +1,38 @@
+package org.nuiton.guix.compiler;
+
+import java.io.File;
+import org.junit.Test;
+import org.nuiton.guix.GuixLauncher;
+import static org.junit.Assert.*;
+
+/**
+ * Tests the GuixCompiler class
+ *
+ * @author morin
+ */
+public class GuixCompilerTest {
+
+ @Test
+ public void compileTest() {
+ File f = new File("src/test/test.guix");
+ File f2 = new File(f.getAbsolutePath());
+ GuixLauncher gl = new GuixLauncher(new File[]{f2}, null,
+ "org.nuiton.guix",f2.getParentFile());
+
+ GuixCompiler gc = new GuixCompiler(null, null,null);
+ assertNull(gc.compile());
+
+ gc = new GuixCompiler(null, gl, null);
+ assertNull(gc.compile());
+
+ gc = new GuixCompiler(f, null, null);
+ assertNull(gc.compile());
+
+ gc = new GuixCompiler(f2, gl, null);
+ assertNotNull(gc.compile());
+
+ gc = new GuixCompiler(f2, gl, "test.compiler");
+ assertNotNull(gc.compile());
+ }
+
+}
Added: guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/tags/TagManagerTest.java
===================================================================
--- guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/tags/TagManagerTest.java (rev 0)
+++ guix/trunk/guix-compiler/src/test/java/org/nuiton/guix/tags/TagManagerTest.java 2009-04-29 15:41:14 UTC (rev 1365)
@@ -0,0 +1,34 @@
+package org.nuiton.guix.tags;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * Tests the methods of the TagManager class
+ *
+ * @author morin
+ */
+public class TagManagerTest {
+
+ /**
+ * Tests the method resolveClassName
+ */
+ @Test
+ public void resolveClassNameTest() {
+ assertTrue(TagManager.resolveClassName("test.test.test[]").equals("test.test.test[]"));
+ assertNull(TagManager.resolveClassName("test"));
+ assertNotNull(TagManager.resolveClassName("boolean"));
+ assertNotNull(TagManager.resolveClassName("byte"));
+ assertNotNull(TagManager.resolveClassName("short"));
+ assertNotNull(TagManager.resolveClassName("int"));
+ assertNotNull(TagManager.resolveClassName("long"));
+ assertNotNull(TagManager.resolveClassName("float"));
+ assertNotNull(TagManager.resolveClassName("double"));
+ assertNotNull(TagManager.resolveClassName("char"));
+ for(String clazz : TagManager.guixClasses) {
+ assertNotNull(TagManager.resolveClassName(clazz));
+ }
+ }
+}
Added: guix/trunk/guix-compiler/src/test/test.guix
===================================================================
--- guix/trunk/guix-compiler/src/test/test.guix (rev 0)
+++ guix/trunk/guix-compiler/src/test/test.guix 2009-04-29 15:41:14 UTC (rev 1365)
@@ -0,0 +1,4 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<org.nuiton.guix.Test>
+ <Panel />
+</org.nuiton.guix.Test>
1
0
29 Apr '09
Author: tchemit
Date: 2009-04-29 08:06:47 +0000 (Wed, 29 Apr 2009)
New Revision: 1364
Modified:
guix/trunk/guix-maven-plugin/pom.xml
Log:
les versions de dependances doivent etre gerees via le dependenciesManagment et non directement dans les dependances
Modified: guix/trunk/guix-maven-plugin/pom.xml
===================================================================
--- guix/trunk/guix-maven-plugin/pom.xml 2009-04-29 08:05:44 UTC (rev 1363)
+++ guix/trunk/guix-maven-plugin/pom.xml 2009-04-29 08:06:47 UTC (rev 1364)
@@ -77,7 +77,6 @@
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
- <version>2.1</version>
</dependency>
</dependencies>
@@ -127,8 +126,8 @@
<!-- ************************************************************* -->
<scm>
<connection>${maven.scm.connection.child}</connection>
- <!--developerConnection>${maven.scm.developerConnection.child}</developerConnection>
- <url>${maven.scm.url.child}</url-->
+ <developerConnection>${maven.scm.developerConnection.child}</developerConnection>
+ <url>${maven.scm.url.child}</url>
</scm>
</project>
1
0
Author: tchemit
Date: 2009-04-29 08:05:44 +0000 (Wed, 29 Apr 2009)
New Revision: 1363
Modified:
guix/trunk/pom.xml
Log:
quelques modifs sur le pom :
- pas de dependence direct dans super-pom
- utilisation doxia plutot que jrst-plugin
- bump versions
Modified: guix/trunk/pom.xml
===================================================================
--- guix/trunk/pom.xml 2009-04-27 16:13:24 UTC (rev 1362)
+++ guix/trunk/pom.xml 2009-04-29 08:05:44 UTC (rev 1363)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
- <version>3.4</version>
+ <version>3.5.3</version>
</parent>
<groupId>org.nuiton.guix</groupId>
@@ -21,14 +21,14 @@
<module>guix-compiler</module>
<module>guix-maven-plugin</module>
<module>guix-test</module>
- </modules>
+ </modules>
- <dependencies>
+ <!--dependencies>
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>lutinutil</artifactId>
</dependency>
- </dependencies>
+ </dependencies-->
<dependencyManagement>
<dependencies>
@@ -83,14 +83,14 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
- <version>2.0.4</version>
+ <version>${maven.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <version>2.0.4</version>
+ <version>${maven.version}</version>
<scope>compile</scope>
</dependency>
@@ -137,10 +137,11 @@
<labs.project>buix</labs.project>
<!-- libs version -->
- <lutinutil.version>1.0.3</lutinutil.version>
+ <lutinutil.version>1.0.4</lutinutil.version>
<guix.version>${project.version}</guix.version>
- <i18n.version>0.10</i18n.version>
- <lutinpluginutil.version>0.3</lutinpluginutil.version>
+ <i18n.version>0.11</i18n.version>
+ <lutinpluginutil.version>0.4</lutinpluginutil.version>
+ <maven.version>2.0.10</maven.version>
</properties>
<build>
@@ -160,38 +161,25 @@
<version>2.4.3</version>
</plugin>
+ <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <configuration>
+ <locales>fr</locales>
+ <siteDirectory>src/site</siteDirectory>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>doxia-module-jrst</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</pluginManagement>
<plugins>
- <!--plugin>
- <groupId>org.codelutin.guix</groupId>
- <artifactId>guix-maven-plugin</artifactId>
- <version>${project.version}</version>
- </plugin-->
-
- <!-- Always process jrst files, but only called on pre-site phase -->
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jrst-plugin</artifactId>
- <version>0.8.4</version>
- <configuration>
- <directoryIn>${maven.src.dir}/site</directoryIn>
- <directoryOut>${maven.site.gen.dir}</directoryOut>
- <defaultLocale>fr</defaultLocale>
- <inputEncoding>${project.build.sourceEncoding}</inputEncoding>
- <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
- </configuration>
- <executions>
- <execution>
- <phase>pre-site</phase>
- <goals>
- <goal>jrst</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
1
0
r1362 - guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
27 Apr '09
Author: kmorin
Date: 2009-04-27 16:13:24 +0000 (Mon, 27 Apr 2009)
New Revision: 1362
Modified:
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
Log:
javadoc
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-27 16:08:18 UTC (rev 1361)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-27 16:13:24 UTC (rev 1362)
@@ -185,7 +185,6 @@
Selector selector = processSelector(selectorNode);
ruleSelectors.add(selector);
//records the selector if it has not been recorded yet
- //to add each selector only once in the StyleSheet
if (!selectorRecorded(selector)) {
selectors.add(selector);
}
@@ -246,9 +245,10 @@
}
/**
- *
- * @param newSelector
- * @return
+ * Checks if a new Selector has already been recorded or not
+ * We chack it to add each selector only once in the StyleSheet
+ * @param newSelector the Selector to check
+ * @return true if the Selector has already been recorded
*/
private boolean selectorRecorded(Selector newSelector) {
for (Selector selector : selectors) {
1
0
r1361 - in guix/trunk/guix-test: . src/main/java/org/nuiton/guix/demo
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
27 Apr '09
Author: kmorin
Date: 2009-04-27 16:08:18 +0000 (Mon, 27 Apr 2009)
New Revision: 1361
Added:
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/JButton.css
Modified:
guix/trunk/guix-test/pom.xml
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
Log:
- Config des dossiers des fichiers Guix et du dossier de destination dans le pom.xml
Modified: guix/trunk/guix-test/pom.xml
===================================================================
--- guix/trunk/guix-test/pom.xml 2009-04-27 16:07:40 UTC (rev 1360)
+++ guix/trunk/guix-test/pom.xml 2009-04-27 16:08:18 UTC (rev 1361)
@@ -43,6 +43,9 @@
<groupId>org.nuiton.guix</groupId>
<artifactId>guix-maven-plugin</artifactId>
<version>${project.version}</version>
+ <configuration>
+ <guixFilesDir>/home/morin/NetBeansProjects/guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/</guixFilesDir>
+ </configuration>
<executions>
<execution>
<phase>compile</phase>
Modified: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css 2009-04-27 16:07:40 UTC (rev 1360)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css 2009-04-27 16:08:18 UTC (rev 1361)
@@ -1,10 +1,5 @@
-#display:{
- object . getText( ) . startsWith( "-" )
-}
-
+#display:{object . getText( ) . startsWith( "-" )}
{
-foreground: red
-
-;
+ foreground: red;
}
Modified: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-04-27 16:07:40 UTC (rev 1360)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-04-27 16:08:18 UTC (rev 1361)
@@ -116,9 +116,9 @@
</swing:JTree>
</swing:JScrollPane>
<java.awt.CardLayout id='cardLayout'/>
-
+<script source="scriptFile.script" />
<Panel id='preview' layout='{cardLayout}'>
- <jaxx.EmptyDemo id='emptyDemo' constraints='emptyDemo.getLabel()'/>
+ <EmptyDemo id='emptyDemo' constraints='emptyDemo.getLabel()'/>
<JButtonDemo id='buttonDemo' constraints='buttonDemo.getLabel()'/>
<JCheckBoxDemo id='checkBoxDemo' constraints='checkBoxDemo.getLabel()'/>
<JCheckBoxMenuItemDemo id='checkBoxMenuItemDemo' constraints='checkBoxMenuItemDemo.getLabel()'/>
Added: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/JButton.css
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/JButton.css (rev 0)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/JButton.css 2009-04-27 16:08:18 UTC (rev 1361)
@@ -0,0 +1,30 @@
+JButton {
+ font-size: 18;
+ width: 80;
+ height: 35;
+}
+
+JButton.digit {
+ foreground: blue;
+}
+
+JButton#dot {
+ font-size: 20;
+}
+
+JButton.operator {
+ font-size: 16;
+ foreground: #009900;
+}
+
+JButton.clear {
+ foreground: red;
+}
+
+JButton:mouseover {
+ font-weight: bold;
+}
+
+JButton.operator:mouseover {
+ font-weight: normal;
+}
1
0
r1360 - in guix/trunk/guix-maven-plugin/src/main: java/org/nuiton/guix resources
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
27 Apr '09
Author: kmorin
Date: 2009-04-27 16:07:40 +0000 (Mon, 27 Apr 2009)
New Revision: 1360
Added:
guix/trunk/guix-maven-plugin/src/main/resources/log4j.properties
Modified:
guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java
Log:
- Ajout de la config de log4j
- Config des dossiers des fichiers Guix et du dossier de destination dans le pom.xml
Modified: guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java
===================================================================
--- guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-04-27 16:06:15 UTC (rev 1359)
+++ guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-04-27 16:07:40 UTC (rev 1360)
@@ -1,20 +1,67 @@
package org.nuiton.guix;
+import java.io.File;
+import java.util.ArrayList;
+import org.apache.log4j.Logger;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
+ * Launches the program
*
* @author morin
* @goal testMojo
*/
public class GuixMojo extends AbstractMojo
{
-
+ /**
+ * Directory of the files to compile.
+ * @parameter expression="${guixFilesDir}"
+ * @required
+ */
+ private String guixFilesDir;
+
+ /**
+ * Directory of the generated files.
+ * @parameter expression="${generatedFilesDestination}" default-value="generatedFiles"
+ */
+ private String targetDirectory;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
GuixInitializer.initialize();
- GuixLauncher gcl = new GuixLauncher();
+ File guixFilesDir = new File(this.guixFilesDir);
+ File targetDirectory = new File(this.targetDirectory);
+
+ if(!targetDirectory.exists())
+ targetDirectory.mkdirs();
+
+ if(guixFilesDir.exists() && guixFilesDir.isDirectory()) {
+ ArrayList<File> guixFiles = goDeeperInto(guixFilesDir);
+
+ GuixLauncher gcl = new GuixLauncher(guixFiles.toArray(new File[guixFiles.size()]),targetDirectory);
+ boolean result = gcl.compile();
+
+ if(result)
+ Logger.getLogger(GuixMojo.class).info("Compilation succeeded !");
+ else
+ Logger.getLogger(GuixMojo.class).error("Compilation failed...");
+ }
}
+
+ private ArrayList<File> goDeeperInto(File dir) {
+ Logger.getLogger(GuixMojo.class).debug("goind deeper into " + dir.getPath());
+ ArrayList<File> result = new ArrayList<File>();
+ for(File f : dir.listFiles()) {
+ if(f.isDirectory() && !f.isHidden()) {
+ result.addAll(goDeeperInto(f));
+ }
+ else if(f.getName().endsWith(".guix")) {
+ Logger.getLogger(GuixMojo.class).debug("found " + f.getName());
+ result.add(f);
+ }
+ }
+ return result;
+ }
}
Added: guix/trunk/guix-maven-plugin/src/main/resources/log4j.properties
===================================================================
--- guix/trunk/guix-maven-plugin/src/main/resources/log4j.properties (rev 0)
+++ guix/trunk/guix-maven-plugin/src/main/resources/log4j.properties 2009-04-27 16:07:40 UTC (rev 1360)
@@ -0,0 +1,9 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%F : %M] %m%n
+
+#log4j.logger.org.codelutin.i18n=ERROR
+log4j.logger.org.nuiton.guix=DEBUG
1
0
r1359 - in guix/trunk/guix-compiler/src/main/java/org/nuiton/guix: . compiler model tags
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 27 Apr '09
27 Apr '09
Author: kmorin
Date: 2009-04-27 16:06:15 +0000 (Mon, 27 Apr 2009)
New Revision: 1359
Modified:
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java
Log:
- JavaDoc
- v?\195?\169rification de date de derniere modification avant de g?\195?\169n?\195?\169rer une classe
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/CompilerException.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,12 +1,7 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
package org.nuiton.guix;
/** Thrown by the compiler when an error occurs. */
public class CompilerException extends RuntimeException {
- private static final long serialVersionUID = -9099889519671482440L;
/** Creates a new <code>ParseException</code>. */
public CompilerException() {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,13 +1,10 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.guix;
import org.nuiton.guix.tags.TagManager;
/**
+ * Initialize the application
*
* @author morin
*/
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,7 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.guix;
import java.io.IOException;
@@ -11,13 +7,13 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Logger;
import org.nuiton.guix.model.ClassDescriptor;
import org.nuiton.guix.model.GuixModelObject;
import org.nuiton.guix.model.Rule;
@@ -34,8 +30,7 @@
public class GuixLauncher {
/** log */
- /* protected static final Log log =
- LogFactory.getLog(GuixLauncher.class);*/
+ Logger log = Logger.getLogger(GuixLauncher.class);
/** original list of files to compile */
protected final File[] files;
/** original list of classes to compile */
@@ -44,23 +39,30 @@
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 names of classes being compiled to the compiler instance
+ /** Maps the root GuixModelObjects being compiled to the compiler instance
* handling the compilation. */
- protected Map<String, GuixCompiler> compilers =
- new HashMap<String, GuixCompiler>();
- /** ModelObjects which are root of files */
- protected List<GuixModelObject> rootModelObjects = new ArrayList<GuixModelObject>();
+ protected Map<GuixModelObject, GuixCompiler> rootModelObjects =
+ new HashMap<GuixModelObject, GuixCompiler>();
/** CLassDescriptor met during the compilation */
protected List<ClassDescriptor> classDescriptors =
new ArrayList<ClassDescriptor>();
private List<File> compiledFiles = new ArrayList<File>();
protected int compilerCount;
- private File targetDirectory = new File("destination");
+ private File targetDirectory;
- public GuixLauncher() {
- files = new File[]{new File("/home/morin/NetBeansProjects/guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix")};
- classNames = new String[]{"GuixDemo"};
- compile();
+ /**
+ * Constructor
+ *
+ * @param files the files to compile
+ */
+ public GuixLauncher(File[] files, File targetDirectory) {
+ // Set up a simple configuration that logs on the console.
+ this.files = files;
+ this.targetDirectory = targetDirectory;
+ classNames = new String[files.length];
+ for (int i = 0; i < files.length; i++) {
+ classNames[i] = files[i].getName().substring(0, files[i].getName().lastIndexOf('.'));
+ }
}
/**
@@ -70,232 +72,240 @@
* <code>false</code> otherwise
*/
public synchronized boolean compile() {
- //reset(); // just to be safe...
compilerCount = 0;
guixFiles.addAll(Arrays.asList(files));
guixFileClassNames.addAll(Arrays.asList(classNames));
+ boolean success = true;
+
try {
- boolean success = true;
+ assert guixFiles.size() == guixFileClassNames.size();
- // pass 1
- /*if (!nextStep(LifeCycle.compile_first_pass, success)) {
- return false;
- }*/
- boolean compiled;
- do {
- compiled = false;
- assert guixFiles.size() == guixFileClassNames.size();
- // clone it so it can safely be modified while we're iterating
- Iterator<File> filesIterator =
- new ArrayList<File>(guixFiles).iterator();
- Iterator<String> classNamesIterator =
- new ArrayList<String>(guixFileClassNames).iterator();
+ for (int i = 0; i < guixFiles.size(); i++) {
+ File file = guixFiles.get(i);
+ String className = guixFileClassNames.get(i);
- while (filesIterator.hasNext()) {
+ //if we have not compiled the file yet
+ if (!compiledFiles.contains(file)) {
+ log.info("Compiling class " + className);
+ compiledFiles.add(file);
- File file = filesIterator.next();
- String className = classNamesIterator.next();
- /*if (log.isDebugEnabled()) {
- log.debug("compile first pass for " + className);
- }*/
- if (!compiledFiles.contains(file)) {
- compiled = true;
- compiledFiles.add(file);
-
- File destDir = targetDirectory;
- if (destDir != null) {
- int dotPos = className.lastIndexOf(".");
- if (dotPos != -1) {
- destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
- }
- if (!destDir.exists() && !destDir.mkdirs()) {
- //log.warn("couldn't create directory " + destDir);
- System.out.println("couldn't create directory " + destDir);
- continue;
- }
+ File destDir = targetDirectory;
+ if (destDir != null) {
+ int dotPos = className.lastIndexOf(".");
+ if (dotPos != -1) {
+ destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
} else {
- //destDir = file.getParentFile();
+ destDir = new File(destDir, className);
}
- GuixCompiler compiler = new GuixCompiler(
- file.getParentFile(), file, className, this);
- //addProfileTime(compiler, currentPass.name() + "_start");
- compilers.put(className, compiler);
- GuixModelObject rootModelObject = compiler.compile();
- rootModelObjects.add(rootModelObject);
- //addProfileTime(compiler, currentPass.name() + "_end");
- //assert !symbolTables.values().contains(compiler.getSymbolTable()) : "symbolTable is already registered";
- //symbolTables.put(file, compiler.getSymbolTable());
- if (compiler.isFailed()) {
- success = false;
+ if (!destDir.exists() && !destDir.mkdirs()) {
+ log.warn("couldn't create directory " + destDir);
+ continue;
}
+ } else {
+ destDir = file.getParentFile();
}
- }
+ //compile the file
+ GuixCompiler compiler = new GuixCompiler(
+ file.getParentFile(), file, className, this);
- } while (compiled);
+ GuixModelObject rootModelObject = compiler.compile();
+ rootModelObjects.put(rootModelObject, compiler);
- XmlPullParserFactory factory =
- XmlPullParserFactory.newInstance(
- System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
- null);
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ } else {
+ log.warn(file.getName() + " has already been compiled.");
+ }
+ }
- for (GuixModelObject mo : rootModelObjects) {
-
- File f = new File(targetDirectory,mo.getClassDescriptor().getName() + "ModelTree.xml");
- if (!f.exists()) {
- f.createNewFile();
+ if (success) {
+ int i = 0;
+ while (success && i < classDescriptors.size()) {
+ success = (classDescriptors.get(i++).getPackageName() != null);
}
- System.out.println(f.getAbsolutePath());
+ if (!success) {
+ log.error("The class '" + classDescriptors.get(--i).getName() + "' has no package.");
+ }
+ }
+ if (success || true) {
+ XmlPullParserFactory factory =
+ XmlPullParserFactory.newInstance(
+ System.getProperty(XmlPullParserFactory.PROPERTY_NAME),
+ null);
- XmlSerializer serializer = factory.newSerializer();
- XmlSerializer cssSerializer = factory.newSerializer();
+ for (GuixModelObject mo : rootModelObjects.keySet()) {
+ File f = new File(targetDirectory, mo.getClassDescriptor().getName() + "ModelTree.xml");
+ log.info(mo.getClassDescriptor().getName() + " last modification : "
+ + new Date(rootModelObjects.get(mo).getLastModification()));
+
+ if (rootModelObjects.get(mo).getLastModification() > f.lastModified()) {
+ log.info("Generation of " + mo.getClassDescriptor().getName());
+ if (!f.exists()) {
+ f.createNewFile();
+ }
+ XmlSerializer serializer = factory.newSerializer();
+ XmlSerializer cssSerializer = factory.newSerializer();
- serializer.setOutput(new PrintWriter(f));
- 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.setOutput(new PrintWriter(f));
+ 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");
- cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
- cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "\t");
+ cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ cssSerializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "\t");
- writeModelTree(serializer, mo, cssSerializer);
+ writeModelTree(serializer, mo, cssSerializer);
- serializer.endDocument();
+ serializer.endDocument();
+ }
+ else {
+ log.warn(mo.getClassDescriptor().getName() + " has already been generated and is up to date.");
+ }
+ }
+
+ /*// pass 2
+ if (!nextStep(LifeCycle.compile_second_pass, success)) {
+ return false;
}
- /*// pass 2
- if (!nextStep(LifeCycle.compile_second_pass, success)) {
- return false;
- }
+ assert guixFiles.size() == guixFileClassNames.size();
+ List<File> jaxxFilesClone = new ArrayList<File>(guixFiles);
+ for (String className : guixFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ if (log.isDebugEnabled()) {
+ log.debug("runInitializers for " + className);
+ }
+ if (!compiler.isFailed()) {
+ compiler.runInitializers();
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("compile second pass for " + className);
+ }
+ compiler.compileSecondPass();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (log.isDebugEnabled()) {
+ log.debug("done with result [" + !compiler.isFailed() + "] for " + className);
+ }
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
+ if (!jaxxFilesClone.equals(guixFiles)) {
+ throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + guixFiles + ")");
+ }
- assert guixFiles.size() == guixFileClassNames.size();
- List<File> jaxxFilesClone = new ArrayList<File>(guixFiles);
- for (String className : guixFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during second pass");
- addProfileTime(compiler, currentPass.name() + "_start");
- if (log.isDebugEnabled()) {
- log.debug("runInitializers for " + className);
- }
- if (!compiler.isFailed()) {
- compiler.runInitializers();
- }
- if (log.isDebugEnabled()) {
- log.debug("compile second pass for " + className);
- }
- compiler.compileSecondPass();
- addProfileTime(compiler, currentPass.name() + "_end");
- if (log.isDebugEnabled()) {
- log.debug("done with result [" + !compiler.isFailed() + "] for " + className);
- }
- if (compiler.isFailed()) {
- success = false;
- }
- }
- if (!jaxxFilesClone.equals(guixFiles)) {
- throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + guixFiles + ")");
- }
+ // stylesheet application
+ if (!nextStep(LifeCycle.stylesheet_pass, success)) {
+ return false;
+ }
+ assert guixFiles.size() == guixFileClassNames.size();
+ for (String className : guixFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compiler.applyStylesheets();
+ addProfileTime(compiler, currentPass.name() + "_end");
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
- // stylesheet application
- if (!nextStep(LifeCycle.stylesheet_pass, success)) {
- return false;
- }
- assert guixFiles.size() == guixFileClassNames.size();
- for (String className : guixFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during stylesheet application");
- addProfileTime(compiler, currentPass.name() + "_start");
- compiler.applyStylesheets();
- addProfileTime(compiler, currentPass.name() + "_end");
- if (compiler.isFailed()) {
- success = false;
- }
- }
+ // code generation
+ if (!nextStep(LifeCycle.generate_pass, success)) {
+ return false;
+ }
+ assert guixFiles.size() == guixFileClassNames.size();
+ List<Generator> generators = new ArrayList<Generator>();
+ for (Generator generator : ServiceLoader.load(Generator.class)) {
+ generators.add(generator);
+ }
+ for (String className : guixFileClassNames) {
+ JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation");
+ addProfileTime(compiler, currentPass.name() + "_start");
+ compiler.generateCode(generators);
+ addProfileTime(compiler, currentPass.name() + "_end");
+ //compiler.generateCode();
+ if (compiler.isFailed()) {
+ success = false;
+ }
+ }
- // code generation
- if (!nextStep(LifeCycle.generate_pass, success)) {
- return false;
- }
- assert guixFiles.size() == guixFileClassNames.size();
- List<Generator> generators = new ArrayList<Generator>();
- for (Generator generator : ServiceLoader.load(Generator.class)) {
- generators.add(generator);
- }
- for (String className : guixFileClassNames) {
- JAXXCompiler compiler = getCompiler(className, "Internal error: could not find compiler for " + className + " during code generation");
- addProfileTime(compiler, currentPass.name() + "_start");
- compiler.generateCode(generators);
- addProfileTime(compiler, currentPass.name() + "_end");
- //compiler.generateCode();
- if (compiler.isFailed()) {
- success = false;
- }
- }
+ if (options.isProfile()) {
+ // profile pass (only if succes compile)
+ if (!nextStep(LifeCycle.profile_pass, success)) {
+ return false;
+ }
+ StringBuilder buffer = profiler.computeProfileReport();
+ log.info(buffer.toString());
+ }
- if (options.isProfile()) {
- // profile pass (only if succes compile)
- if (!nextStep(LifeCycle.profile_pass, success)) {
- return false;
- }
- StringBuilder buffer = profiler.computeProfileReport();
- log.info(buffer.toString());
- }
+ return report(success);
- return report(success);
-
- //FIXME : deal better the exception treatment...
- } catch (CompilerException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return false;*/
-
+ //FIXME : deal better the exception treatment...
+ } catch (CompilerException e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ return false;*/
+ }
} catch (Throwable e) {
e.printStackTrace();
return false;
- } finally {
- compilerCount = compilers.size();
- //TC - 20081018 only reset when no error was detected
- //if (options.isResetAfterCompile() && errorCount == 0) {
- // reset();
- //}
- return false;
}
+ return success;
}
+ /**
+ * Temporary
+ * Writes the model in an Xml file
+ *
+ * @param serializer
+ * @param mo
+ * @param cssSerializer
+ * @throws java.io.IOException
+ */
private void writeModelTree(XmlSerializer serializer, GuixModelObject mo,
XmlSerializer cssSerializer) throws IOException {
- if(!mo.getStyleSheets().isEmpty()) {
+ if (!mo.getStyleSheets().isEmpty()) {
int i = 0;
- for(StyleSheet styleSheet : mo.getStyleSheets()) {
- File ss = new File(targetDirectory,mo.getClassDescriptor().getName() + i++ + "SS.xml");
+ for (StyleSheet styleSheet : mo.getStyleSheets()) {
+ File ss = new File(targetDirectory, mo.getClassDescriptor().getName() + i++ + "SS.xml");
cssSerializer.setOutput(new FileWriter(ss));
cssSerializer.startTag("", "rules");
- for(Rule rule : styleSheet.getRules()) {
+ for (Rule rule : styleSheet.getRules()) {
cssSerializer.startTag("", "rule");
cssSerializer.startTag("", "selectors");
- for(Selector selector : rule.getSelectors()) {
+ for (Selector selector : rule.getSelectors()) {
cssSerializer.startTag("", "selector");
cssSerializer.startTag("", "javaClassName");
- if(selector.getJavaClassName() != null)
+ if (selector.getJavaClassName() != null) {
cssSerializer.text(selector.getJavaClassName());
+ }
cssSerializer.endTag("", "javaClassName");
cssSerializer.startTag("", "styleClass");
- if(selector.getStyleClass() != null)
+ if (selector.getStyleClass() != null) {
cssSerializer.text(selector.getStyleClass());
+ }
cssSerializer.endTag("", "styleClass");
cssSerializer.startTag("", "pseudoClass");
- if(selector.getPseudoClass() != null)
+ if (selector.getPseudoClass() != null) {
cssSerializer.text(selector.getPseudoClass());
+ }
cssSerializer.endTag("", "pseudoClass");
cssSerializer.startTag("", "id");
- if(selector.getId() != null)
+ if (selector.getId() != null) {
cssSerializer.text(selector.getId());
+ }
cssSerializer.endTag("", "id");
cssSerializer.endTag("", "selector");
}
cssSerializer.endTag("", "selectors");
cssSerializer.startTag("", "properties");
- for(Entry entry : rule.getProperties().entrySet()) {
- cssSerializer.startTag("", (String)entry.getKey());
- if(entry.getValue() != null)
- cssSerializer.text((String)entry.getValue());
- cssSerializer.endTag("", (String)entry.getKey());
+ for (Entry entry : rule.getProperties().entrySet()) {
+ cssSerializer.startTag("", (String) entry.getKey());
+ if (entry.getValue() != null) {
+ cssSerializer.text((String) entry.getValue());
+ }
+ cssSerializer.endTag("", (String) entry.getKey());
}
cssSerializer.endTag("", "properties");
cssSerializer.endTag("", "rule");
@@ -342,6 +352,13 @@
}
+ /**
+ * 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 boolean registerClassDescriptor(ClassDescriptor classDescriptor) {
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())))) {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedAttributeException.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,16 +1,9 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
package org.nuiton.guix;
/**
- * Thrown by <code>TagHandler</code> when an unsupported attribute is encountered.
- *
- * @see jaxx.tags.TagHandler
+ * Thrown when an unsupported attribute is encountered.
*/
public class UnsupportedAttributeException extends CompilerException {
- private static final long serialVersionUID = -6919583037172920343L;
/** Creates a new <code>UnsupportedAttributeException</code>. */
public UnsupportedAttributeException() {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/UnsupportedTagException.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,12 +1,7 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
package org.nuiton.guix;
/** Thrown by the compiler when an unregistered tag is encountered. */
public class UnsupportedTagException extends CompilerException {
- private static final long serialVersionUID = 3199732135804426699L;
/** Creates a new <code>UnsupportedTagException</code>. */
public UnsupportedTagException() {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,14 +1,13 @@
package org.nuiton.guix.compiler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.nuiton.guix.GuixLauncher;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.log4j.Logger;
import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.ClassDescriptor;
import org.nuiton.guix.model.GuixModelObject;
@@ -41,6 +40,8 @@
private ScriptHandler scriptHandler = new ScriptHandler();
/** Root of the model */
private GuixModelObject rootMO;
+ /** */
+ private long lastModification;
/*------------------------------------------------------------------------*/
/*-- Constructor methods -------------------------------------------------*/
@@ -59,6 +60,7 @@
this.src = src;
this.outputClassName = outputClassName;
this.launcher = launcher;
+ lastModification = src.lastModified();
}
/**
@@ -96,12 +98,23 @@
rootMO.getClassDescriptor().setSuperClass(new ClassDescriptor(tagName, tagPackageName));
rootMO.setAttributeDescriptors(getAttributes(xpp));
rootMO.setChildren(new ArrayList<GuixModelObject>());
+
//add the stylesheet of the CSS file with the same name as the Guix file
- StyleSheet ss = styleHandler.autoDetectStyleFile(baseDir.getPath(), outputClassName);
- rootMO.getStyleSheets().add(ss);
+ File styleFile = new File(baseDir, className + ".css");
+ if(styleFile.exists()) {
+ StyleSheet ss = styleHandler.autoDetectStyleFile(styleFile);
+ rootMO.getStyleSheets().add(ss);
+ lastModification = Math.max(lastModification,styleFile.lastModified());
+ }
+
StringBuffer script = new StringBuffer();
//add the script in the .script file with the same name as the Guix file
- script.append(scriptHandler.autoDetectScriptFile(baseDir.getPath(), outputClassName));
+ File scriptFile = new File(baseDir, className + ".script");
+ if(scriptFile.exists()) {
+ script.append(scriptHandler.loadScriptFile(scriptFile));
+ lastModification = Math.max(lastModification, scriptFile.lastModified());
+ }
+
//reach the next START_TAG
do {
xpp.nextToken();
@@ -119,9 +132,9 @@
}
failed = true;
} catch (XmlPullParserException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
+ Logger.getLogger(GuixCompiler.class.getName()).error(ex);
} catch (IOException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
+ Logger.getLogger(GuixCompiler.class.getName()).error(ex);
}
return null;
}
@@ -146,17 +159,37 @@
try {
//if the tag is a style tag
if (xpp.getName() != null && xpp.getName().equals("style")) {
+ File styleFile = null;
+ //the name of the file to load
+ String source = xpp.getAttributeValue("", "source");
+ //if the source attribute is specified
+ if (source != null) {
+ styleFile = new File(baseDir, source.replace('/', File.separatorChar));
+ }
//creates a new stylesheet
- StyleSheet ss = styleHandler.compileStyle(xpp, baseDir.getPath());
- rootMO.getStyleSheets().add(ss);
+ StyleSheet ss = styleHandler.compileStyle(xpp, styleFile);
+ if(ss != null)
+ rootMO.getStyleSheets().add(ss);
+ if (styleFile != null && styleFile.exists())
+ lastModification = Math.max(lastModification, styleFile.lastModified());
+
//the parent is still the same
-
prev = previousMO;
}
//if the tag is a script tag
else if (xpp.getName() != null && xpp.getName().equals("script")) {
+ File scriptFile = null;
+ //the name of the file to load
+ String source = xpp.getAttributeValue("", "source");
+ //if the source attribute is specified
+ if (source != null) {
+ scriptFile = new File(baseDir, source.replace('/', File.separatorChar));
+ }
//add the script to the result
- result.append(scriptHandler.compileScript(xpp, baseDir.getPath()));
+ result.append(scriptHandler.compileScript(xpp, scriptFile));
+ if (scriptFile != null && scriptFile.exists()) {
+ lastModification = Math.max(lastModification, scriptFile.lastModified());
+ }
//the parent is still the same
prev = previousMO;
}
@@ -210,9 +243,9 @@
result.append(compile(xpp, prev, doc.toString()));
}
} catch (XmlPullParserException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
+ Logger.getLogger(GuixCompiler.class.getName()).error(ex);
} catch (IOException ex) {
- Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
+ Logger.getLogger(GuixCompiler.class.getName()).error(ex);
}
return result;
}
@@ -275,4 +308,8 @@
public boolean isFailed() {
return failed;
}
+
+ public long getLastModification() {
+ return lastModification;
+ }
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/AttributeDescriptor.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,18 +1,23 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package org.nuiton.guix.model;
/**
+ * Descriptor of tag attributes
*
* @author morin
*/
public class AttributeDescriptor {
+
+ /** Name of the attribute */
private String name;
+ /** Value of the attribute */
private String value;
+ /**
+ * Constructor
+ *
+ * @param name name of the attribute
+ * @param value value of the attribute
+ */
public AttributeDescriptor(String name, String value) {
this.name = name;
this.value = value;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,21 +1,29 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package org.nuiton.guix.model;
/**
+ * Descriptor of a class found in the guix files.
*
* @author morin
*/
public class ClassDescriptor {
+ /** Name of the class */
private String name;
+ /** Package of the class (must ends with '.*')*/
private String packageName;
+ /** Script declared in the guix file.
+ * Available only for the root GuixModelObject class.*/
private String script;
- private ClassDescriptor superClass;
+ /** Superclass of the class
+ * Available only for the root GuixModelObject class.*/
+ private ClassDescriptor superClass;
+ /**
+ * Constructor
+ *
+ * @param name name of the class
+ * @param packageName name of the package
+ */
public ClassDescriptor(String name, String packageName){
this.name = name;
this.packageName = packageName;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,4 +1,3 @@
-
package org.nuiton.guix.model;
import java.util.ArrayList;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Rule.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,8 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package org.nuiton.guix.model;
import java.util.ArrayList;
@@ -11,12 +6,16 @@
import java.util.List;
/**
+ * Representation of a rule of a CSS file
*
* @author morin
*/
public class Rule {
+ /** Properties of the rule :
+ * Maps the name of the property to its value.*/
private Map<String,String> properties = new HashMap<String,String>();
+ /** Selectors which the rule is applied to */
private List<Selector> selectors = new ArrayList<Selector>();
public Map<String, String> getProperties() {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/Selector.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,14 +1,10 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
package org.nuiton.guix.model;
import java.util.ArrayList;
import java.util.List;
/**
+ * Represents a selector of a CSS file
*
* @author morin
*/
@@ -19,12 +15,29 @@
public static final int ALWAYS_APPLIES_INHERIT_ONLY = 3;
public static final int ALWAYS_APPLIES = 4;
+ /** Class which rules are applied to
+ * e.g. Label */
private String javaClassName;
+ /** Styleclass which rules are applied to
+ * e.g. .bold */
private String styleClass;
+ /** Pseudoclass which rules are applied to
+ * e.g. :hover */
private String pseudoClass;
+ /** Id of the object which rules are applied to
+ * e.g. #label5 */
private String id;
+ /** List of the rules applied to the selector */
private List<Rule> rules = new ArrayList<Rule>();
+ /**
+ * Constructor
+ *
+ * @param javaClassName class which rules are applied to
+ * @param styleClass styleclass which rules are applied to
+ * @param pseudoClass pseudoclass which rules are applied to
+ * @param id id of the object which rules are applied to
+ */
public Selector(String javaClassName, String styleClass, String pseudoClass, String id) {
this.javaClassName = javaClassName;
this.styleClass = styleClass;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/StyleSheet.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,7 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.guix.model;
@@ -9,12 +5,16 @@
import java.util.List;
/**
+ * Represantation of a stylesheet file
*
* @author morin
*/
public class StyleSheet {
+ /** Rules of the stylesheet */
private List<Rule> rules = new ArrayList<Rule>();
+
+ /** Selectors which at least one of the rules is applied to */
private List<Selector> selectors = new ArrayList<Selector>();
public List<Rule> getRules() {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,12 +1,9 @@
package org.nuiton.guix.tags;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -24,7 +21,7 @@
* @return the content of the script file
* @throws java.io.IOException if an error occurs while reading scriptFile
*/
- private String loadScriptFile(File scriptFile) throws IOException {
+ public String loadScriptFile(File scriptFile) throws IOException {
StringWriter scriptBuffer = new StringWriter();
FileReader in = new FileReader(scriptFile);
char[] readBuffer = new char[2048];
@@ -36,23 +33,6 @@
}
/**
- * Loads the file with the name of the class
- * and get the content of the file.
- *
- * @param baseDir the directory of the compiled guix file
- * @param className the name of the file to load
- * @return the content of the file
- * @throws IOException if an error occurs while reading the file
- * with the same name as the class
- */
- public String autoDetectScriptFile(String baseDir, String className)
- throws IOException {
- File scriptFile = null;
- scriptFile = new File(baseDir, className + ".script");
- return loadScriptFile(scriptFile);
- }
-
- /**
* Parse the <code>script</code> tag.
*
* @param xpp the parser referencing the style tag
@@ -62,21 +42,12 @@
* @throws IOException
* @throws XmlPullParserException
*/
- public String compileScript(XmlPullParser xpp, String baseDir)
+ public String compileScript(XmlPullParser xpp, File scriptFile)
throws IOException, XmlPullParserException {
StringBuffer script = new StringBuffer();
- File scriptFile = null;
- //the name of the file to load
- String source = xpp.getAttributeValue("", "source");
-
- //if the source attribute is specified
- if (source != null) {
- scriptFile = new File(baseDir, source.replace('/', File.separatorChar));
- }
- if (scriptFile != null && scriptFile.exists()) {
+ if(scriptFile != null && scriptFile.exists())
script.append(loadScriptFile(scriptFile));
- }
xpp.nextToken();
if (xpp.getEventType() == XmlPullParser.CDSECT) {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -11,8 +11,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.apache.log4j.Logger;
import org.nuiton.guix.css.CSSParser;
import org.nuiton.guix.css.CSSParserConstants;
import org.nuiton.guix.css.CSSParserTreeConstants;
@@ -65,9 +64,7 @@
* @throws IOException if an error occurs while reading the file
* with the same name as the class
*/
- public StyleSheet autoDetectStyleFile(String baseDir, String className) throws FileNotFoundException, IOException {
- File styleFile = null;
- styleFile = new File(baseDir, className + ".css");
+ public StyleSheet autoDetectStyleFile(File styleFile) throws IOException {
return processStylesheet(loadStyleFile(styleFile));
}
@@ -84,28 +81,19 @@
* @throws org.xmlpull.v1.XmlPullParserException if an error occurs
* while parsing the guix file
*/
- public StyleSheet compileStyle(XmlPullParser xpp, String baseDir) throws IOException, XmlPullParserException {
- File styleFile = null;
+ public StyleSheet compileStyle(XmlPullParser xpp, File styleFile) throws IOException, XmlPullParserException {
StyleSheet result = null;
- //the name of the file to load
- String source = xpp.getAttributeValue("", "source");
- //if a file is specified
- if (source != null) {
- styleFile = new File(baseDir, source.replace('/', File.separatorChar));
- }
StringBuffer style = new StringBuffer();
-
- if (styleFile != null && styleFile.exists()) {
+ if(styleFile != null && styleFile.exists())
style.append(loadStyleFile(styleFile));
- }
xpp.nextToken();
do {
switch (xpp.getEventType()) {
case XmlPullParser.START_TAG:
- Logger.getLogger(StyleHandler.class.getName()).log(Level.WARNING,
- "<style> tag may not contain child elements: " + xpp.getName());
+ Logger.getLogger(StyleHandler.class)
+ .warn("<style> tag may not contain child elements: " + xpp.getName());
break;
case XmlPullParser.TEXT:
break;// fall through
@@ -115,8 +103,11 @@
break;
}
} while ((xpp.getEventType() != XmlPullParser.END_TAG) && (!xpp.getName().equals("style")));
+
+ //analyze the content of the CSS
result = processStylesheet(style.toString());
+ //reaches next START_TAG
do {
xpp.nextToken();
} while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
@@ -126,11 +117,14 @@
}
/**
+ * Analyses a selector node
*
- * @param selector
- * @return
+ * @param selector the selector node to analyse
+ * @return a Selector with the class, styleclass, pseudoclass and/or id
+ * 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");
}
@@ -142,21 +136,25 @@
for (int i = 0; i < selector.jjtGetNumChildren(); i++) {
SimpleNode child = selector.getChild(i);
switch (child.getId()) {
+ //class
case CSSParserTreeConstants.JJTJAVACLASS:
if (!child.getText().trim().equals("*")) {
javaClassName = child.getText();
}
break;
+ //styleclass
case CSSParserTreeConstants.JJTCLASS:
styleClass = child.getText().substring(1);
break;
+ //pseudoclass
case CSSParserTreeConstants.JJTPSEUDOCLASS:
pseudoClass = child.getText().substring(1);
break;
+ //id
case CSSParserTreeConstants.JJTID:
id = child.getText().substring(1);
break;
-
+ //error if other
default:
throw new IllegalStateException("unexpected child of Selector node, type=" + child.getId());
}
@@ -166,29 +164,35 @@
}
/**
+ * Analyses a CSS rule
*
- * @param ruleNode
- * @return
+ * @param ruleNode the CSSParser node containing the rule to analyse
+ * @return a Rule containing the properties and the selectors of the rule
*/
protected Rule processRule(SimpleNode ruleNode) {
-
+ //checks if it is a rule
if (ruleNode.getId() != CSSParserTreeConstants.JJTRULE) {
throw new IllegalArgumentException("argument node is not a Rule");
}
+
SimpleNode selectorsNode = ruleNode.getChild(0);
assert selectorsNode.getId() == CSSParserTreeConstants.JJTSELECTORS : "expected node to be of type Selectors";
List<Selector> ruleSelectors = new ArrayList<Selector>();
+ //analyses each selector
for (int i = 0; i < selectorsNode.jjtGetNumChildren(); i++) {
SimpleNode selectorNode = selectorsNode.getChild(i);
Selector selector = processSelector(selectorNode);
ruleSelectors.add(selector);
+ //records the selector if it has not been recorded yet
+ //to add each selector only once in the StyleSheet
if (!selectorRecorded(selector)) {
selectors.add(selector);
}
}
Map<String, String> properties = new HashMap<String, String>();
+ //records the properties
for (int i = 1; i < ruleNode.jjtGetNumChildren(); i++) {
SimpleNode declarationNode = ruleNode.getChild(i);
if (declarationNode.getId() == CSSParserTreeConstants.JJTDECLARATION) {
@@ -201,8 +205,8 @@
properties.put(key, value);
}
}
- Rule rule;
- rule = new Rule();
+ //creates the new rule
+ Rule rule = new Rule();
rule.setSelectors(ruleSelectors);
for (Selector selector : ruleSelectors) {
selector.getRules().add(rule);
@@ -212,11 +216,13 @@
}
/**
+ * Analyses the CSS
*
- * @param stylesheetText
- * @return
+ * @param stylesheetText the content of the CSS file or the style tag
+ * @return the StyleSheet containing the rules of the CSS file or the style tag
*/
protected StyleSheet processStylesheet(String stylesheetText) {
+ //parses the CSS
CSSParser p = new CSSParser(new StringReader(stylesheetText));
SimpleNode node;
try {
@@ -224,14 +230,16 @@
} catch (ParseException ex) {
throw ex;
}
+
List<Rule> rules = new ArrayList<Rule>();
+ //analyses each rule
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
SimpleNode ruleNode = node.getChild(i);
Rule rule = processRule(ruleNode);
rules.add(rule);
}
- StyleSheet styleSheet;
- styleSheet = new StyleSheet();
+
+ StyleSheet styleSheet = new StyleSheet();
styleSheet.setRules(rules);
styleSheet.setSelectors(selectors);
return styleSheet;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-04-24 15:39:17 UTC (rev 1358)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-04-27 16:06:15 UTC (rev 1359)
@@ -1,7 +1,3 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
package org.nuiton.guix.tags;
import java.util.logging.Level;
@@ -19,13 +15,15 @@
import java.util.Map;
import java.util.Set;
-/** Manages TagHandlers, including automatically compiling .jaxx files corresponding to class tags. */
+/**
+ * Manages tags of the .guix files.
+ */
public class TagManager {
/** log */
protected static final Log log = LogFactory.getLog(TagManager.class);
/**
- * Namespace for JAXX's non-class tags, such as <script;>. The namespace normally does not
+ * Namespace for Guix's non-class tags, such as <Button;>. The namespace normally does not
* need to be specified but can be used to resolve ambiguities.
*/
public static final String GUIX_NAMESPACE = "org.nuiton.guix.*";
@@ -33,59 +31,13 @@
/** Maps simple tag names to their default namespaces (package names). */
private static Map<String, String> defaultNamespaces = new HashMap<String, String>();
- /** Maps qualified tag names to the TagHandlers responsible for processing them. */
- //private static Map<QName, TagHandler> registeredTags = new HashMap<QName, TagHandler>();
-
/** Keeps track of whether or not named classes exist. */
private static Map<String, Boolean> classExistenceCache = new HashMap<String, Boolean>();
- /** */
+ /** List of the Guix classes such as <Button;> */
private static List<String> guixClasses = new ArrayList<String>();
- /**
- * Maps bean classes to their TagHandler classes. The mapping is to TagHandler classes, rather than to
- * TagHandler instances, because subclasses of the bean class should be handled by the same TagHandler
- * (assuming no more specific mappings exist), which requires creating a new instance of the TagHandler.
- */
- //private static ClassMap<Class<? extends TagHandler>> registeredBeans = new ClassMap<Class<? extends TagHandler>>();
- // still targeting 1.4, so I can't use javax.xml.namespace.QName
- private static class QName {
- private String namespaceURI;
- private String localPart;
-
- public QName(String namespaceURI, String localPart) {
- if (localPart == null)
- throw new NullPointerException();
- this.namespaceURI = namespaceURI;
- this.localPart = localPart;
- }
-
-
- public String getNamespaceURI() {
- return namespaceURI;
- }
-
-
- public String getLocalPart() {
- return localPart;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == null || !(o instanceof QName))
- return false;
- QName qname = (QName) o;
- return qname.getNamespaceURI().equals(getNamespaceURI()) && qname.getLocalPart().equals(getLocalPart());
- }
-
- @Override
- public int hashCode() {
- return (namespaceURI != null ? namespaceURI.hashCode() : 0) ^ getLocalPart().hashCode();
- }
- }
-
-
private TagManager() { /* not instantiable */ }
@@ -253,7 +205,12 @@
}
}*/
-
+ /**
+ * Tests if a class exists
+ *
+ * @param className name of the class we want to know if it exists
+ * @return true if the class exists
+ */
private static boolean classExists(String className) {
if (classExistenceCache.containsKey(className)) {
return classExistenceCache.get(className);
@@ -276,40 +233,6 @@
return found;
}
-
- /*private static String determinePackage(String simpleClassName, String defaultPackage) {
- String namespace = null;
- Set<String> classes = compiler.getImportedClasses();
- for (String className : classes) { // search class imports (e.g. import java.util.Date;)
- if (className.equals(simpleClassName) || className.endsWith("." + simpleClassName)) {
- namespace = className.substring(0, className.lastIndexOf(".") + 1) + "*";
- }
- }
- if (namespace == null) { // search package imports (e.g. import java.util.*;)
- Set<String> searchList = compiler.getImportedPackages();
- if (defaultPackage != null) {
- if (!defaultPackage.endsWith("*")) {
- throw new IllegalArgumentException("defaultPackage must end in '*', found '" + defaultPackage + "'");
- }
- if (classExists(defaultPackage.substring(0, defaultPackage.length() - 1) + simpleClassName)) {
- return defaultPackage;
- }
- }
- for (String currentPackage : searchList) {
- String className = currentPackage + simpleClassName;
- if (classExists(className)) {
- if (namespace != null) { // we've already found the same name in another package
- //compiler.reportError("symbol '" + simpleClassName + "' is ambiguous, found matching classes " + namespace.substring(0, namespace.length() - 1) + simpleClassName + " and " + currentPackage + simpleClassName + ". Use fully-qualified name to disambiguate.");
- return null;
- }
- namespace = currentPackage + "*";
- }
- }
- }
-
- return namespace;
- }*/
-
/**
* Resolves a simple class name (like <code>Object</code> or <code>String</code>) to its fully-qualified name. Inner
* classes should be represented as they would appear in Java source code (e.g. JPopupMenu.Separator). Fully-qualified names,
@@ -338,16 +261,4 @@
return null;
}
-
- /*public static ClassDescriptor resolveClass(String className, JAXXCompiler compiler) {
- try {
- className = resolveClassName(className, compiler);
- if (className == null)
- return null;
- return ClassDescriptorLoader.getClassDescriptor(className, compiler.getClassLoader());
- }
- catch (ClassNotFoundException e) {
- return null;
- }
- }*/
}
\ No newline at end of file
1
0
r1358 - in guix/trunk/guix-test/src/main/java/org/nuiton/guix: . demo
by kmorinīŧ users.labs.libre-entreprise.org 24 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 24 Apr '09
24 Apr '09
Author: kmorin
Date: 2009-04-24 15:39:17 +0000 (Fri, 24 Apr 2009)
New Revision: 1358
Added:
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.script
guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/scriptFile.script
Log:
Ajout de fichiers test
Added: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css (rev 0)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.css 2009-04-24 15:39:17 UTC (rev 1358)
@@ -0,0 +1,10 @@
+#display:{
+ object . getText( ) . startsWith( "-" )
+}
+
+{
+foreground: red
+
+;
+}
+
Added: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix (rev 0)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix 2009-04-24 15:39:17 UTC (rev 1358)
@@ -0,0 +1,149 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<Application title="JAXX Demo" width='1024' height='800' xmlns:swing='javax.swing.*'>
+ <script><![CDATA[
+
+org.codelutin.i18n.I18n.init();
+
+void $afterCompleteSetup() {
+ try { jaxx.runtime.SwingUtil.initNimbusLoookAndFeel(); } catch (Exception e) { log.error(e.getMessage(), e); }
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ int i=0;
+ while( i < list.getRowCount()) {
+ list.expandRow(i++);
+ }
+ }
+ });
+}
+
+]]></script>
+
+ <style><![CDATA[
+#table {
+ border: { BorderFactory . createEmptyBorder( 4, 4, 4, 4 )
+}
+
+;
+font-face:
+
+"Trebuchet MS"
+;
+}
+
+#display {
+ background: #BCE5AD;
+ opaque: true;
+ horizontalAlignment: right;
+ border: { BorderFactory . createBevelBorder( BevelBorder . LOWERED )
+}
+
+;
+font-size:
+
+22
+;
+font-weight: bold
+
+;
+}
+]]></style>
+ <swing:JSplitPane>
+ <!--JSplitPane dividerLocation='200'-->
+ <swing:JScrollPane>
+ <swing:JTree id='list' showsRootHandles='true'
+ onValueChanged='cardLayout.show(preview, list.getSelectionValue() instanceof DemoPanel ? ((DemoPanel) list.getSelectionValue()).getLabel() : emptyDemo.getLabel())'
+ cellRenderer='{new javax.swing.tree.DefaultTreeCellRenderer() {
+ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
+ if (value instanceof DemoPanel)
+ value = ((DemoPanel) value).getLabel();
+ return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
+ }
+ }
+ }'>
+ <item value="Components">
+ <item value='Buttons'>
+ <item value='{buttonDemo}'/>
+ <item value='{checkBoxDemo}'/>
+ <item value='{radioButtonDemo}'/>
+ <item value='{toggleButtonDemo}'/>
+ </item>
+
+ <item value='Form elements'>
+ <item value='Text'>
+ <item value='{passwordFieldDemo}'/>
+ <item value='{textFieldDemo}'/>
+ <item value='{textAreaDemo}'/>
+ </item>
+
+ <item value='{comboBoxDemo}'/>
+ <item value='{listDemo}'/>
+ <item value='{sliderDemo}'/>
+ <item value='{spinnerDemo}'/>
+ </item>
+
+ <item value='Layout components'>
+ <item value='{splitPaneDemo}'/>
+ </item>
+
+ <item value='Menus'>
+ <item value='{menuItemDemo}'/>
+ <item value='{checkBoxMenuItemDemo}'/>
+ <item value='{radioButtonMenuItemDemo}'/>
+ </item>
+
+ <item value='Windows'>
+ <item value='{dialogDemo}'/>
+ </item>
+
+ <item value='{progressBarDemo}'/>
+
+ </item>
+
+ <item value='{labelStyleDemo}'/>
+
+ <item value='{counterDemo}'/>
+ <item value='{calculatorDemo}'/>
+
+ <item value='New features'>
+ <item value='Validation'>
+ <item value='{validationDemo1}'/>
+ <item value='{validationDemo2}'/>
+ </item>
+ <item value='{dataBindingDemo}'/>
+ <item value='{boxedDecoratorDemo}'/>
+ </item>
+ </swing:JTree>
+ </swing:JScrollPane>
+ <java.awt.CardLayout id='cardLayout'/>
+
+ <Panel id='preview' layout='{cardLayout}'>
+ <jaxx.EmptyDemo id='emptyDemo' constraints='emptyDemo.getLabel()'/>
+ <JButtonDemo id='buttonDemo' constraints='buttonDemo.getLabel()'/>
+ <JCheckBoxDemo id='checkBoxDemo' constraints='checkBoxDemo.getLabel()'/>
+ <JCheckBoxMenuItemDemo id='checkBoxMenuItemDemo' constraints='checkBoxMenuItemDemo.getLabel()'/>
+ <JComboBoxDemo id='comboBoxDemo' constraints='comboBoxDemo.getLabel()'/>
+ <JDialogDemo id='dialogDemo' constraints='dialogDemo.getLabel()'/>
+ <JListDemo id='listDemo' constraints='listDemo.getLabel()'/>
+ <JMenuItemDemo id='menuItemDemo' constraints='menuItemDemo.getLabel()'/>
+ <JPasswordFieldDemo id='passwordFieldDemo' constraints='passwordFieldDemo.getLabel()'/>
+ <JProgressBarDemo id='progressBarDemo' constraints='progressBarDemo.getLabel()'/>
+ <JSliderDemo id='sliderDemo' constraints='sliderDemo.getLabel()'/>
+ <JSpinnerDemo id='spinnerDemo' constraints='spinnerDemo.getLabel()'/>
+ <JSplitPaneDemo id='splitPaneDemo' constraints='splitPaneDemo.getLabel()'/>
+ <JRadioButtonDemo id='radioButtonDemo' constraints='radioButtonDemo.getLabel()'/>
+ <JRadioButtonMenuItemDemo id='radioButtonMenuItemDemo' constraints='radioButtonMenuItemDemo.getLabel()'/>
+ <JToggleButtonDemo id='toggleButtonDemo' constraints='toggleButtonDemo.getLabel()'/>
+ <JTextFieldDemo id='textFieldDemo' constraints='textFieldDemo.getLabel()'/>
+ <JTextAreaDemo id='textAreaDemo' constraints='textAreaDemo.getLabel()'/>
+ <ValidationListDemo id='validationDemo1' constraints='validationDemo1.getLabel()'/>
+ <ValidationTableDemo id='validationDemo2' constraints='validationDemo2.getLabel()'/>
+ <BeanDataBindingDemo id='dataBindingDemo' constraints='dataBindingDemo.getLabel()'/>
+ <LabelStyleDemo id='labelStyleDemo' constraints='labelStyleDemo.getLabel()'/>
+ <CounterDemo id='counterDemo' constraints='counterDemo.getLabel()'/>
+ <CalculatorDemo id='calculatorDemo' constraints='calculatorDemo.getLabel()'/>
+ <BoxedDecoratorDemo id='boxedDecoratorDemo' constraints='boxedDecoratorDemo.getLabel()'/>
+ </Panel>
+ <style source="JButton.css" />
+ </swing:JSplitPane>
+</Application>
Added: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.script
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.script (rev 0)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.script 2009-04-24 15:39:17 UTC (rev 1358)
@@ -0,0 +1,3 @@
+public void testSameName() {
+ System.out.println("load the script file with the same name");
+}
Added: guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/scriptFile.script
===================================================================
--- guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/scriptFile.script (rev 0)
+++ guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/scriptFile.script 2009-04-24 15:39:17 UTC (rev 1358)
@@ -0,0 +1,3 @@
+public void testOtherName() {
+ System.out.println("load the script file with a specified name");
+}
1
0
r1357 - guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix
by kmorinīŧ users.labs.libre-entreprise.org 24 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 24 Apr '09
24 Apr '09
Author: kmorin
Date: 2009-04-24 15:38:51 +0000 (Fri, 24 Apr 2009)
New Revision: 1357
Modified:
guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java
Log:
Initialisation du compiler au lancement
Modified: guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java
===================================================================
--- guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-04-24 15:37:46 UTC (rev 1356)
+++ guix/trunk/guix-maven-plugin/src/main/java/org/nuiton/guix/GuixMojo.java 2009-04-24 15:38:51 UTC (rev 1357)
@@ -14,6 +14,7 @@
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ GuixInitializer.initialize();
GuixLauncher gcl = new GuixLauncher();
}
}
1
0
r1356 - in guix/trunk/guix-compiler/src/main/java/org/nuiton/guix: . compiler css model parser tags
by kmorinīŧ users.labs.libre-entreprise.org 24 Apr '09
by kmorinīŧ users.labs.libre-entreprise.org 24 Apr '09
24 Apr '09
Author: kmorin
Date: 2009-04-24 15:37:46 +0000 (Fri, 24 Apr 2009)
New Revision: 1356
Added:
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java
Modified:
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jj
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jjt
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Java1.5.jjt
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java
Log:
Parsing des fichiers CSS et des fichiers scripts
Added: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java (rev 0)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixInitializer.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -0,0 +1,24 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.nuiton.guix;
+
+import org.nuiton.guix.tags.TagManager;
+
+/**
+ *
+ * @author morin
+ */
+public class GuixInitializer {
+
+ public static void initialize() {
+ TagManager.registerGuixClasse("Button");
+ TagManager.registerGuixClasse("Panel");
+ TagManager.registerGuixClasse("Label");
+ TagManager.registerGuixClasse("CheckBox");
+ TagManager.registerGuixClasse("ComboBox");
+ TagManager.registerGuixClasse("Application");
+ }
+}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -58,8 +58,8 @@
private File targetDirectory = new File("destination");
public GuixLauncher() {
- files = new File[]{new File("/home/morin/NetBeansProjects/jaxx-gwt/trunk/jaxx-example/src/main/java/jaxx/demo/CalculatorDemo.jaxx")};
- classNames = new String[]{"CalculatorDemo"};
+ files = new File[]{new File("/home/morin/NetBeansProjects/guix/trunk/guix-test/src/main/java/org/nuiton/guix/demo/GuixDemo.guix")};
+ classNames = new String[]{"GuixDemo"};
compile();
}
@@ -140,7 +140,7 @@
for (GuixModelObject mo : rootModelObjects) {
- File f = new File(mo.getClassDescriptor().getName() + "ModelTree.xml");
+ File f = new File(targetDirectory,mo.getClassDescriptor().getName() + "ModelTree.xml");
if (!f.exists()) {
f.createNewFile();
}
@@ -261,8 +261,9 @@
private void writeModelTree(XmlSerializer serializer, GuixModelObject mo,
XmlSerializer cssSerializer) throws IOException {
if(!mo.getStyleSheets().isEmpty()) {
+ int i = 0;
for(StyleSheet styleSheet : mo.getStyleSheets()) {
- File ss = new File(mo.getClassDescriptor().getName() + "SS");
+ File ss = new File(targetDirectory,mo.getClassDescriptor().getName() + i++ + "SS.xml");
cssSerializer.setOutput(new FileWriter(ss));
cssSerializer.startTag("", "rules");
for(Rule rule : styleSheet.getRules()) {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/compiler/GuixCompiler.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -1,17 +1,14 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+
package org.nuiton.guix.compiler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.nuiton.guix.GuixLauncher;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Stack;
import org.nuiton.guix.model.AttributeDescriptor;
import org.nuiton.guix.model.ClassDescriptor;
import org.nuiton.guix.model.GuixModelObject;
@@ -24,174 +21,257 @@
import org.xmlpull.v1.XmlPullParserFactory;
/**
- * Compiles Guix files into Java classes
+ * Compiles Guix files into model tree
*
* @author morin
*/
public class GuixCompiler {
- /** flag to detec if an error occurs while compiling jaxx file */
+ /** Flag to detec if an error occurs while compiling guix file */
protected boolean failed;
- /** Used for error reporting purposes,
- * so we can report the right source file. */
- protected Stack<File> sourceFiles = new Stack<File>();
- /** XML parser of src file. */
+ /** Directory containing the guix files */
private File baseDir;
+ /** Guix file to compile */
private File src;
+ /** Name of the class to produce */
private String outputClassName;
- private GuixLauncher launchor;
+ /** GuixLauncher instance which launched this compiler */
+ private GuixLauncher launcher;
private StyleHandler styleHandler = new StyleHandler();
private ScriptHandler scriptHandler = new ScriptHandler();
-
+ /** Root of the model */
+ private GuixModelObject rootMO;
+
/*------------------------------------------------------------------------*/
/*-- Constructor methods -------------------------------------------------*/
/*------------------------------------------------------------------------*/
/**
* Creates a new GuixCompiler.
*
- * @param baseDir classpath location
- * @param src location of file to compile
- * @param outputClassName the out file name
+ * @param baseDir classpath location
+ * @param src location of file to compile
+ * @param outputClassName the out file name
+ * @param launcher the launcher of the compiler
*/
public GuixCompiler(File baseDir, File src, String outputClassName,
- GuixLauncher launchor) {
+ GuixLauncher launcher) {
this.baseDir = baseDir;
this.src = src;
- sourceFiles.push(src);
this.outputClassName = outputClassName;
- this.launchor = launchor;
+ this.launcher = launcher;
}
- public GuixModelObject compile()
- throws FileNotFoundException, IOException, XmlPullParserException {
- //try {
- XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
- System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
- factory.setNamespaceAware(true);
- XmlPullParser xpp = factory.newPullParser();
- xpp.setInput(new FileReader(src));
-
- if (xpp.getEventType() == XmlPullParser.START_DOCUMENT) {
- StringBuffer doc = new StringBuffer();
- do {
- xpp.nextToken();
- if(xpp.getEventType() == XmlPullParser.COMMENT)
- doc.append(xpp.getText());
- } while(xpp.getEventType() != XmlPullParser.START_TAG);
-
- String nameSpace = xpp.getNamespace();
- String localName = xpp.getName();
- String packageName =
- resolvePackageName(nameSpace, localName);
-
- GuixModelObject root = new GuixModelObject(xpp.getAttributeValue("", "id"),
- doc.toString(),xpp.getAttributeValue("", "styleClass"));
- String className = src.getName().substring(0, src.getName().lastIndexOf('.'));
- String classPackageName = src.getPath().replace('/', '.')
- .substring(src.getPath().lastIndexOf("src/main/java/") + 14,
- src.getPath().lastIndexOf('/'));
- root.setClassDescriptor(new ClassDescriptor(className,classPackageName));
- root.getClassDescriptor().setSuperClass(new ClassDescriptor(
- localName, packageName));
- root.setAttributeDescriptors(getAttributes(xpp));
- root.setChildren(new ArrayList<GuixModelObject>());
-
- do {
- xpp.nextToken();
- } while(xpp.getEventType() != XmlPullParser.START_TAG);
-
- while(xpp.getName().equals("script")
- ||xpp.getName().equals("style")) {
- if(xpp.getName().equals("script")) {
- root.getClassDescriptor().setScript(
- scriptHandler.compileScript(xpp));
+ /**
+ * Compiles the guix file
+ *
+ * @return the root of the model
+ */
+ public GuixModelObject compile() {
+ try {
+ //Creation of the Xml parser
+ XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
+ factory.setNamespaceAware(true);
+ XmlPullParser xpp = factory.newPullParser();
+ xpp.setInput(new FileReader(src));
+ //Start parsing
+ if (xpp.getEventType() == XmlPullParser.START_DOCUMENT) {
+ //javaDoc of the class to create
+ StringBuffer doc = new StringBuffer();
+ do {
+ xpp.nextToken();
+ if (xpp.getEventType() == XmlPullParser.COMMENT) {
+ doc.append(xpp.getText());
+ }
+ } while (xpp.getEventType() != XmlPullParser.START_TAG);
+ //resolve the package of teh superclass
+ String tagNameSpace = xpp.getNamespace();
+ String tagName = xpp.getName();
+ String tagPackageName = resolvePackageName(tagNameSpace, tagName);
+ //creation of the root GuixModelObject
+ rootMO = new GuixModelObject(xpp.getAttributeValue("", "id"), doc.toString(), xpp.getAttributeValue("", "styleClass"));
+ //the class name is the name of the file minus the extension
+ String className = src.getName().substring(0, src.getName().lastIndexOf('.'));
+ String classPackageName = src.getPath().replace('/', '.').substring(src.getPath().lastIndexOf("src/main/java/") + 14, src.getPath().lastIndexOf('/'));
+ rootMO.setClassDescriptor(new ClassDescriptor(className, classPackageName));
+ rootMO.getClassDescriptor().setSuperClass(new ClassDescriptor(tagName, tagPackageName));
+ rootMO.setAttributeDescriptors(getAttributes(xpp));
+ rootMO.setChildren(new ArrayList<GuixModelObject>());
+ //add the stylesheet of the CSS file with the same name as the Guix file
+ StyleSheet ss = styleHandler.autoDetectStyleFile(baseDir.getPath(), outputClassName);
+ rootMO.getStyleSheets().add(ss);
+ StringBuffer script = new StringBuffer();
+ //add the script in the .script file with the same name as the Guix file
+ script.append(scriptHandler.autoDetectScriptFile(baseDir.getPath(), outputClassName));
+ //reach the next START_TAG
+ do {
+ xpp.nextToken();
+ } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ //if not eof
+ if (xpp.getEventType() == XmlPullParser.START_TAG) {
+ //compile the rest of the file
+ script.append(compile(xpp, rootMO, doc.toString()));
}
-
- if(xpp.getName().equals("style")) {
- StyleSheet ss = styleHandler.compileStyle(xpp, baseDir.getPath());
- root.getStyleSheets().add(ss);
- }
+ //all the script tags have been recorded
+ rootMO.getClassDescriptor().setScript(script.toString());
+ //register the root ClassDescriptor
+ failed = !launcher.registerClassDescriptor(rootMO.getClassDescriptor());
+ return rootMO;
}
- failed = launchor.registerClassDescriptor(root.getClassDescriptor());
-
- if (xpp.getEventType() == XmlPullParser.START_TAG) {
- compile(xpp,root,doc.toString());
- }
-
- return root;
+ failed = true;
+ } catch (XmlPullParserException ex) {
+ Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
}
- failed = true;
return null;
- //}
}
/*------------------------------------------------------------------------*/
/*-- Compile methods -----------------------------------------------------*/
/*------------------------------------------------------------------------*/
- private void compile(final XmlPullParser xpp, GuixModelObject previousMO,
- String javaDoc) throws IOException, XmlPullParserException {
+ /**
+ *
+ * @param xpp the parser referencing the tag
+ * @param previousMO the <code>GuixModelObject</code> parent of the tag
+ * @param javaDoc the comments above the tag, to add to its javaDoc
+ * @return the scripts already discovered while parsing the file
+ */
+ private StringBuffer compile(final XmlPullParser xpp, GuixModelObject previousMO,
+ String javaDoc) {
- String nameSpace = xpp.getNamespace();
- String localName = xpp.getName();
- String packageName = resolvePackageName(nameSpace, localName);
+ StringBuffer result = new StringBuffer();
+ StringBuffer doc = new StringBuffer();
+ GuixModelObject prev;
- nameSpace = packageName + ".*";
- GuixModelObject mo = new GuixModelObject(xpp.getAttributeValue("","id"),
- javaDoc,xpp.getAttributeValue("", "styleClass"));
- mo.setParent(previousMO);
- mo.setClassDescriptor(new ClassDescriptor(localName, packageName));
- previousMO.getChildren().add(mo);
- mo.setChildren(new ArrayList<GuixModelObject>());
-
- failed = !launchor.registerClassDescriptor(mo.getClassDescriptor());
-
- if(!failed) {
- GuixModelObject prev = mo;
- StringBuffer doc = new StringBuffer();
- do {
- xpp.nextToken();
-
- if (xpp.getEventType() == XmlPullParser.END_TAG) {
- prev = prev.getParent();
+ try {
+ //if the tag is a style tag
+ if (xpp.getName() != null && xpp.getName().equals("style")) {
+ //creates a new stylesheet
+ StyleSheet ss = styleHandler.compileStyle(xpp, baseDir.getPath());
+ rootMO.getStyleSheets().add(ss);
+ //the parent is still the same
+
+ prev = previousMO;
+ }
+ //if the tag is a script tag
+ else if (xpp.getName() != null && xpp.getName().equals("script")) {
+ //add the script to the result
+ result.append(scriptHandler.compileScript(xpp, baseDir.getPath()));
+ //the parent is still the same
+ prev = previousMO;
+ }
+ //if the tag is a class tag
+ else {
+ String tagNameSpace = xpp.getNamespace();
+ String tagPackageName = resolvePackageName(tagNameSpace, xpp.getName());
+ String tagName;
+ //if the name of the tag is the fully-qualified class name
+ if(xpp.getName().lastIndexOf('.') >= 0) {
+ tagName = xpp.getName().substring(xpp.getName().lastIndexOf('.') + 1);
}
- else if(xpp.getEventType() == XmlPullParser.COMMENT)
- doc.append(xpp.getText());
- else if(xpp.getName() != null && xpp.getName().equals("style")) {
- StyleSheet ss = styleHandler.compileStyle(xpp, baseDir.getPath());
- prev.getStyleSheets().add(ss);
+ else {
+ tagName = xpp.getName();
}
- } while (xpp.getEventType() != XmlPullParser.START_TAG
- && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ tagNameSpace = tagPackageName + ".*";
+ //create the GuixModelObject representing the tag
+ GuixModelObject mo = new GuixModelObject(xpp.getAttributeValue("", "id"),
+ javaDoc, xpp.getAttributeValue("", "styleClass"));
+ mo.setParent(previousMO);
+ mo.setClassDescriptor(new ClassDescriptor(tagName, tagPackageName));
+ mo.setChildren(new ArrayList<GuixModelObject>());
+ //add this GuixModelObject to the children of the parent
+ previousMO.getChildren().add(mo);
+
+ //register the ClassDescriptor
+ failed = !launcher.registerClassDescriptor(mo.getClassDescriptor());
+
+ if (!failed) {
+ //parse the children of the tag
+ prev = mo;
+ do {
+ xpp.nextToken();
+ //if the tag has no children
+ if (xpp.getEventType() == XmlPullParser.END_TAG) {
+ prev = prev.getParent();
+ } else if (xpp.getEventType() == XmlPullParser.COMMENT) {
+ //add the comment to the doc of the next tag
+ doc.append(xpp.getText());
+ }
+ } while (xpp.getEventType() != XmlPullParser.START_TAG
+ && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ }
+ else
+ return null;
+ }
+ //if not eof
if (xpp.getEventType() == XmlPullParser.START_TAG) {
- compile(xpp, prev,doc.toString());
+ //compile the rest of the document
+ result.append(compile(xpp, prev, doc.toString()));
}
+ } catch (XmlPullParserException ex) {
+ Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ Logger.getLogger(GuixCompiler.class.getName()).log(Level.SEVERE, null, ex);
}
+ return result;
}
- private String resolvePackageName(String nameSpace, String localName) {
- // resolve class tags into fully-qualified class name
- String packageName;
- if (nameSpace != null && nameSpace.endsWith("*")) {
- packageName = nameSpace.substring(0, nameSpace.length() - 2);
- } else {
- String fullClassName = TagManager.resolveClassName(localName);
- packageName = (fullClassName == null) ? null : fullClassName
- .substring(0, fullClassName.lastIndexOf('.'));
+ /**
+ * Resolve the package name of the tag using the namespace
+ * and the name of the tag.
+ *
+ * @param tagNameSpace namespace of the tag
+ * @param tagName name of the tag
+ * @return the name of the package of the tag
+ */
+ private String resolvePackageName(String tagNameSpace, String tagName) {
+ String packageName = null;
+ //if there is a namespace
+ if (tagNameSpace != null && tagNameSpace.endsWith("*")) {
+ packageName = tagNameSpace.substring(0, tagNameSpace.length() - 2);
}
+ //if the name of the tag is the fully qualified class name
+ if(tagName.lastIndexOf('.') >= 0) {
+ if(packageName == null) {
+ packageName = tagName.substring(0, tagName.lastIndexOf('.'));
+ }
+ else {
+ packageName += tagName.substring(0, tagName.lastIndexOf('.'));
+ }
+ }
+ //if nor the namespace nor the fully qualified class name is defined
+ if(packageName == null) {
+ String fullClassName = TagManager.resolveClassName(tagName);
+ packageName = (fullClassName == null) ? null : fullClassName.substring(0, fullClassName.lastIndexOf('.'));
+ }
return packageName;
}
+ /**
+ * Transforms the attributes of a tag
+ * into a list of <code>AttributeDescriptor</code>s.
+ *
+ * @param xpp the parser referencing a tag.
+ * @return the list of <code>AttributeDescriptor</code>s corresponding
+ * to the attributes of the tag.
+ */
private List<AttributeDescriptor> getAttributes(XmlPullParser xpp) {
List<AttributeDescriptor> result = new ArrayList<AttributeDescriptor>();
- for(int i = 0 ; i < xpp.getAttributeCount() ; i++) {
- if(!xpp.getAttributeName(i).equals("id"))
+ for (int i = 0; i < xpp.getAttributeCount(); i++) {
+ if (!xpp.getAttributeName(i).equals("id")) {
result.add(new AttributeDescriptor(
- xpp.getAttributeName(i),xpp.getAttributeValue(i)));
+ xpp.getAttributeName(i), xpp.getAttributeValue(i)));
+ }
}
return result;
}
+ /**
+ * Return if the compilation failed.
+ *
+ * @return true if the compilation failed
+ */
public boolean isFailed() {
return failed;
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jj
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jj 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jj 2009-04-24 15:37:46 UTC (rev 1356)
@@ -9,11 +9,11 @@
// fan of the LGPL, unfortunately that won't work.
options {
STATIC = false;
- JDK_VERSION = "1.4";
+ JDK_VERSION = "1.6";
}
PARSER_BEGIN(CSSParser)
-package jaxx.css;
+package org.nuiton.guix.css;
public class CSSParser/*@bgen(jjtree)*/implements CSSParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
protected JJTCSSParserState jjtree = new JJTCSSParserState();
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jjt
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jjt 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/css/CSS.jjt 2009-04-24 15:37:46 UTC (rev 1356)
@@ -8,12 +8,12 @@
// fan of the LGPL, unfortunately that won't work.
options {
STATIC = false;
- JDK_VERSION = "1.4";
+ JDK_VERSION = "1.6";
NODE_SCOPE_HOOK = true;
}
PARSER_BEGIN(CSSParser)
-package jaxx.css;
+package org.nuiton.guix.css;
public class CSSParser {
public SimpleNode popNode() {
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/model/GuixModelObject.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -1,7 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.nuiton.guix.model;
@@ -9,20 +5,38 @@
import java.util.List;
/**
+ * Base object to represent the model of the guix files
*
* @author morin
*/
public class GuixModelObject {
+ /** The id of the object */
private String id;
+ /** The component containing the object */
private GuixModelObject parent;
+ /** The children that the object contains */
private List<GuixModelObject> children = new ArrayList<GuixModelObject>();
+ /** The descriptor the class of the object */
private ClassDescriptor classDescriptor;
- private List<AttributeDescriptor> attributeDescriptors = new ArrayList<AttributeDescriptor>();
+ /** The descriptor of the attributes of the object */
+ private List<AttributeDescriptor> attributeDescriptors
+ = new ArrayList<AttributeDescriptor>();
+ /** The stylesheets associated to the object
+ * (in case the object is a root model object) */
private List<StyleSheet> styleSheets = new ArrayList<StyleSheet>();
+ /** The javaDoc of the object */
private String javadoc;
+ /** The style class of the object */
private String styleClass;
+ /**
+ * Constructor
+ *
+ * @param id the id of the object
+ * @param javadoc the javadoc of the object
+ * @param styleClass the styleclass of the object
+ */
public GuixModelObject(String id, String javadoc, String styleClass) {
this.id = id;
this.javadoc = javadoc;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Java1.5.jjt
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Java1.5.jjt 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/parser/Java1.5.jjt 2009-04-24 15:37:46 UTC (rev 1356)
@@ -33,7 +33,7 @@
JAVA_UNICODE_ESCAPE = true;
ERROR_REPORTING = false;
STATIC = false;
- JDK_VERSION = "1.4";
+ JDK_VERSION = "1.6";
NODE_SCOPE_HOOK=true;
}
@@ -1083,27 +1083,27 @@
<EOF> {
return true;
}
-|
+|
LOOKAHEAD(BlockStatement())
BlockStatement() {
return false;
- }
-|
- LOOKAHEAD(Modifiers() [ TypeParameters() ] [ ResultType() ] <IDENTIFIER> FormalParameters() [ "throws" NameList() ] "{")
+ }
+|
+ LOOKAHEAD(Modifiers() [ TypeParameters() ] [ ResultType() ] <IDENTIFIER> FormalParameters() [ "throws" NameList() ] "{")
ClassOrInterfaceBodyDeclaration(false) {
return false;
}
-|
- LOOKAHEAD(ClassOrInterfaceBodyDeclaration(false))
+|
+ LOOKAHEAD(ClassOrInterfaceBodyDeclaration(false))
ClassOrInterfaceBodyDeclaration(false) {
return false;
}
|
- LOOKAHEAD(Expression())
- Expression() {
- return false;
- }
-|
+ LOOKAHEAD(Expression())
+ Expression() {
+ return false;
+ }
+|
ImportDeclaration() {
return false;
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -1,10 +1,10 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
package org.nuiton.guix.tags;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xmlpull.v1.XmlPullParser;
@@ -13,31 +13,82 @@
/**
* Handles the <code><script></code> tag.
*
- * @author Ethan Nicholas
+ * @author morin
*/
public class ScriptHandler {
- public String compileScript(XmlPullParser xpp) {
- try {
- String script = null;
+ /**
+ * Loads the content of a script file
+ *
+ * @param scriptFile the file to load
+ * @return the content of the script file
+ * @throws java.io.IOException if an error occurs while reading scriptFile
+ */
+ private String loadScriptFile(File scriptFile) throws IOException {
+ StringWriter scriptBuffer = new StringWriter();
+ FileReader in = new FileReader(scriptFile);
+ char[] readBuffer = new char[2048];
+ int c;
+ while ((c = in.read(readBuffer)) > 0) {
+ scriptBuffer.write(readBuffer, 0, c);
+ }
+ return scriptBuffer.toString();
+ }
+
+ /**
+ * Loads the file with the name of the class
+ * and get the content of the file.
+ *
+ * @param baseDir the directory of the compiled guix file
+ * @param className the name of the file to load
+ * @return the content of the file
+ * @throws IOException if an error occurs while reading the file
+ * with the same name as the class
+ */
+ public String autoDetectScriptFile(String baseDir, String className)
+ throws IOException {
+ File scriptFile = null;
+ scriptFile = new File(baseDir, className + ".script");
+ return loadScriptFile(scriptFile);
+ }
+
+ /**
+ * Parse the <code>script</code> tag.
+ *
+ * @param xpp the parser referencing the style tag
+ * @param baseDir the directory of the compiled guix file
+ * @return the content of the file specified by the <code>source</code> attribute
+ * or the script between the script tags
+ * @throws IOException
+ * @throws XmlPullParserException
+ */
+ public String compileScript(XmlPullParser xpp, String baseDir)
+ throws IOException, XmlPullParserException {
+
+ StringBuffer script = new StringBuffer();
+ File scriptFile = null;
+ //the name of the file to load
+ String source = xpp.getAttributeValue("", "source");
+
+ //if the source attribute is specified
+ if (source != null) {
+ scriptFile = new File(baseDir, source.replace('/', File.separatorChar));
+ }
+ if (scriptFile != null && scriptFile.exists()) {
+ script.append(loadScriptFile(scriptFile));
+ }
+
+ xpp.nextToken();
+ if (xpp.getEventType() == XmlPullParser.CDSECT) {
+ script.append(xpp.getText());
+ }
+ while ((xpp.getEventType() != XmlPullParser.END_TAG) || (!xpp.getName().equals("script"))) {
xpp.nextToken();
- if (xpp.getEventType() == XmlPullParser.CDSECT) {
- script = xpp.getText();
- }
- while ((xpp.getEventType() != XmlPullParser.END_TAG) || (!xpp.getName().equals("script"))) {
- xpp.nextToken();
- }
- do {
- xpp.nextToken();
- } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
- return script;
- } catch (XmlPullParserException ex) {
- Logger.getLogger(ScriptHandler.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(ScriptHandler.class.getName()).log(Level.SEVERE, null, ex);
}
- finally {
- return null;
- }
+ do {
+ xpp.nextToken();
+ } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+
+ return script.toString();
}
}
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -1,7 +1,4 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
+
package org.nuiton.guix.tags;
import java.io.File;
@@ -14,6 +11,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.nuiton.guix.css.CSSParser;
import org.nuiton.guix.css.CSSParserConstants;
import org.nuiton.guix.css.CSSParserTreeConstants;
@@ -28,74 +27,113 @@
/**
* Handles the <code><style></code> tag.
*
- * @author Ethan Nicholas
+ * @author morin
*/
public class StyleHandler {
+ /** List of the selectors */
private List<Selector> selectors = new ArrayList<Selector>();
+ /**
+ * Loads the content of a file.
+ *
+ * @param styleFile the file to load
+ * @return the content of the file
+ * @throws java.io.FileNotFoundException if styleFile does not exist
+ * @throws java.io.IOException if an error occurs while reading styleFile
+ */
+ private String loadStyleFile(File styleFile) throws FileNotFoundException, IOException {
+ StringWriter styleBuffer = new StringWriter();
+ FileReader in = new FileReader(styleFile);
+ char[] readBuffer = new char[2048];
+ int c;
+ while ((c = in.read(readBuffer)) > 0) {
+ styleBuffer.write(readBuffer, 0, c);
+ }
+ return styleBuffer.toString();
+ }
+
+ /**
+ * Load the file with the name of the class
+ * and creates a <code>StyleSheet</code> with the content of the file.
+ *
+ * @param baseDir the directory of the compiled guix file
+ * @param className the name of the file to load
+ * @return a <code>StyleSheet</code> containing the content of the file
+ * @throws FileNotFoundException if the file with the same name as the class
+ * does not exist
+ * @throws IOException if an error occurs while reading the file
+ * with the same name as the class
+ */
+ public StyleSheet autoDetectStyleFile(String baseDir, String className) throws FileNotFoundException, IOException {
+ File styleFile = null;
+ styleFile = new File(baseDir, className + ".css");
+ return processStylesheet(loadStyleFile(styleFile));
+ }
+
+ /**
+ * Load the file specified by the <code>source</code> attribute
+ * or the code between the style tags
+ * and creates a <code>StyleSheet</code> with this content.
+ *
+ * @param xpp the parser referencing the style tag
+ * @param baseDir the directory of the compiled guix file
+ * @return a <code>StyleSheet</code> containing the content of the file
+ * @throws java.io.IOException if an error occurs while reading
+ * the file specified by the <code>source</code> attribute
+ * @throws org.xmlpull.v1.XmlPullParserException if an error occurs
+ * while parsing the guix file
+ */
public StyleSheet compileStyle(XmlPullParser xpp, String baseDir) throws IOException, XmlPullParserException {
- boolean source = false;
+ File styleFile = null;
StyleSheet result = null;
- for (int i = 0; i < xpp.getAttributeCount(); i++) {
- String name = xpp.getAttributeName(i);
- String attrValue = xpp.getAttributeValue(i);
- if (name.equals("source")) {
- source = true;
- File styleFile = new File(baseDir, attrValue.replace('/', File.separatorChar));
- StringWriter styleBuffer = new StringWriter();
- try {
- FileReader in = new FileReader(styleFile);
- char[] readBuffer = new char[2048];
- int c;
- while ((c = in.read(readBuffer)) > 0)
- styleBuffer.write(readBuffer, 0, c);
- }
- catch (FileNotFoundException e) {
- //compiler.reportError(
- System.out.println("stylesheet file not found: " + styleFile);
- }
- result = processStylesheet(styleBuffer.toString());
- /*compiler.getSourceFiles().push(styleFile);
- compiler.registerStylesheet(processStylesheet(styleBuffer.toString()));
- compiler.getSourceFiles().pop();*/
- }/* else
- if (!name.startsWith("xmlns") && !JAXXCompiler.JAXX_INTERNAL_NAMESPACE.equals(attribute.getNamespaceURI()))
- throw new UnsupportedAttributeException(name);*/
+ //the name of the file to load
+ String source = xpp.getAttributeValue("", "source");
+
+ //if a file is specified
+ if (source != null) {
+ styleFile = new File(baseDir, source.replace('/', File.separatorChar));
}
+ StringBuffer style = new StringBuffer();
- StringBuffer style = new StringBuffer();
+ if (styleFile != null && styleFile.exists()) {
+ style.append(loadStyleFile(styleFile));
+ }
+
+ xpp.nextToken();
do {
- xpp.nextToken();
switch (xpp.getEventType()) {
case XmlPullParser.START_TAG:
- /*compiler.reportError*/System.out.println("<style> tag may not contain child elements: ");// + tag);
+ Logger.getLogger(StyleHandler.class.getName()).log(Level.WARNING,
+ "<style> tag may not contain child elements: " + xpp.getName());
break;
- case XmlPullParser.TEXT: break;// fall through
+ case XmlPullParser.TEXT:
+ break;// fall through
case XmlPullParser.CDSECT:
+ style.append(xpp.getText());
xpp.nextToken();
- style.append(xpp.getText());
break;
}
- } while((xpp.getEventType() != XmlPullParser.END_TAG)
- && (!xpp.getName().equals("style")));
-
- String styleString = style.toString().trim();
- if (styleString.length() > 0) {
- if (source)
- /*compiler.reportError*/System.out.println("<style> tag has both a source attribute and an inline stylesheet");
- //compiler.registerStylesheet(processStylesheet(style.toString()));
- }
+ } while ((xpp.getEventType() != XmlPullParser.END_TAG) && (!xpp.getName().equals("style")));
+ result = processStylesheet(style.toString());
+
do {
xpp.nextToken();
- } while(xpp.getEventType() != XmlPullParser.START_TAG
- && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+ } while (xpp.getEventType() != XmlPullParser.START_TAG && xpp.getEventType() != XmlPullParser.END_DOCUMENT);
+
return result;
+
}
+ /**
+ *
+ * @param selector
+ * @return
+ */
protected Selector processSelector(SimpleNode selector) {
- if (selector.getId() != CSSParserTreeConstants.JJTSELECTOR)
+ if (selector.getId() != CSSParserTreeConstants.JJTSELECTOR) {
throw new IllegalArgumentException("argument node is not a Selector");
+ }
String javaClassName = null;
String styleClass = null;
String pseudoClass = null;
@@ -105,8 +143,9 @@
SimpleNode child = selector.getChild(i);
switch (child.getId()) {
case CSSParserTreeConstants.JJTJAVACLASS:
- if (!child.getText().trim().equals("*"))
+ if (!child.getText().trim().equals("*")) {
javaClassName = child.getText();
+ }
break;
case CSSParserTreeConstants.JJTCLASS:
styleClass = child.getText().substring(1);
@@ -122,11 +161,15 @@
throw new IllegalStateException("unexpected child of Selector node, type=" + child.getId());
}
}
-
+
return new Selector(javaClassName, styleClass, pseudoClass, id);
}
-
+ /**
+ *
+ * @param ruleNode
+ * @return
+ */
protected Rule processRule(SimpleNode ruleNode) {
if (ruleNode.getId() != CSSParserTreeConstants.JJTRULE) {
@@ -140,11 +183,12 @@
SimpleNode selectorNode = selectorsNode.getChild(i);
Selector selector = processSelector(selectorNode);
ruleSelectors.add(selector);
- if(!selectorRecorded(selector))
+ if (!selectorRecorded(selector)) {
selectors.add(selector);
+ }
}
- Map<String,String> properties = new HashMap<String,String>();
+ Map<String, String> properties = new HashMap<String, String>();
for (int i = 1; i < ruleNode.jjtGetNumChildren(); i++) {
SimpleNode declarationNode = ruleNode.getChild(i);
if (declarationNode.getId() == CSSParserTreeConstants.JJTDECLARATION) {
@@ -160,14 +204,18 @@
Rule rule;
rule = new Rule();
rule.setSelectors(ruleSelectors);
- for(Selector selector : ruleSelectors) {
+ for (Selector selector : ruleSelectors) {
selector.getRules().add(rule);
}
rule.setProperties(properties);
return rule;
}
-
+ /**
+ *
+ * @param stylesheetText
+ * @return
+ */
protected StyleSheet processStylesheet(String stylesheetText) {
CSSParser p = new CSSParser(new StringReader(stylesheetText));
SimpleNode node;
@@ -189,8 +237,13 @@
return styleSheet;
}
+ /**
+ *
+ * @param newSelector
+ * @return
+ */
private boolean selectorRecorded(Selector newSelector) {
- for(Selector selector : selectors) {
+ for (Selector selector : selectors) {
boolean areJavaClassNamesNull = newSelector.getJavaClassName() == null && selector.getJavaClassName() == null;
boolean areJavaClassNamesNotNull = newSelector.getJavaClassName() != null && selector.getJavaClassName() != null;
boolean areStyleClassesNull = newSelector.getStyleClass() == null && selector.getStyleClass() == null;
@@ -199,14 +252,8 @@
boolean arePseudoClassesNotNull = newSelector.getPseudoClass() != null && selector.getPseudoClass() != null;
boolean areIdsNull = newSelector.getId() == null && selector.getId() == null;
boolean areIdsNotNull = newSelector.getId() != null && selector.getId() != null;
- if((areJavaClassNamesNull || (areJavaClassNamesNotNull
- && newSelector.getJavaClassName().equals(selector.getJavaClassName())))
- && (areStyleClassesNull || (areStyleClassesNotNull
- && newSelector.getStyleClass().equals(selector.getStyleClass())))
- && (arePseudoClassesNull || (arePseudoClassesNotNull
- && newSelector.getPseudoClass().equals(selector.getPseudoClass())))
- && (areIdsNull || (areIdsNotNull && newSelector.getId().equals(selector.getId())))) {
- return true;
+ if ((areJavaClassNamesNull || (areJavaClassNamesNotNull && newSelector.getJavaClassName().equals(selector.getJavaClassName()))) && (areStyleClassesNull || (areStyleClassesNotNull && newSelector.getStyleClass().equals(selector.getStyleClass()))) && (arePseudoClassesNull || (arePseudoClassesNotNull && newSelector.getPseudoClass().equals(selector.getPseudoClass()))) && (areIdsNull || (areIdsNotNull && newSelector.getId().equals(selector.getId())))) {
+ return true;
}
}
return false;
Modified: guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java
===================================================================
--- guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-04-21 15:57:24 UTC (rev 1355)
+++ guix/trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-04-24 15:37:46 UTC (rev 1356)
@@ -13,7 +13,9 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -26,7 +28,7 @@
* Namespace for JAXX's non-class tags, such as <script;>. The namespace normally does not
* need to be specified but can be used to resolve ambiguities.
*/
- public static final String JAXX_NAMESPACE = "http://www.jaxxframework.org/";
+ public static final String GUIX_NAMESPACE = "org.nuiton.guix.*";
/** Maps simple tag names to their default namespaces (package names). */
private static Map<String, String> defaultNamespaces = new HashMap<String, String>();
@@ -37,6 +39,9 @@
/** Keeps track of whether or not named classes exist. */
private static Map<String, Boolean> classExistenceCache = new HashMap<String, Boolean>();
+ /** */
+ private static List<String> guixClasses = new ArrayList<String>();
+
/**
* Maps bean classes to their TagHandler classes. The mapping is to TagHandler classes, rather than to
* TagHandler instances, because subclasses of the bean class should be handled by the same TagHandler
@@ -142,6 +147,13 @@
}
}
+ /**
+ *
+ * @param className
+ */
+ public static void registerGuixClasse(String className) {
+ guixClasses.add(className);
+ }
/**
* Registers a <code>TagHandler</code> for a tag. When a tag with the given name and namespace
@@ -319,82 +331,11 @@
if (name.equals("boolean") || name.equals("byte") || name.equals("short") || name.equals("int") ||
name.equals("long") || name.equals("float") || name.equals("double") || name.equals("char"))
return name;
-
- String result = null;
- String originalName = name;
- String defaultNamespace = null;
- if (defaultNamespaces.containsKey(name)) {
- defaultNamespace = defaultNamespaces.get(name);
- if (defaultNamespace == null) { // defaultNamespaces map contains a null value, which is put there to indicate ambiguity
- //compiler.reportError("class '" + name + "' is ambiguous; specify fully-qualified name (package and class) to disambiguate");
- return null;
- }
+
+ if (guixClasses.contains(name)) {
+ return GUIX_NAMESPACE.substring(0, GUIX_NAMESPACE.lastIndexOf('*')) + name;
}
- if (defaultNamespace != null && defaultNamespace.endsWith("*")) {
- result = defaultNamespace.substring(0, defaultNamespace.length() - 1) + name;
- }
-
- /*if (result == null) {
- // Inner class names (like JPopupMenu.Separator) present a special challenge. The name before the dot might be
- // a package name, or it might be a class name. If it's a class name, it might be fully qualified, or it might
- // not. And it's also not actually the correct name of the class, as far as the JVM is concerned -- the correct
- // name uses a dollar sign instead of a dot (javax.swing.JPopupMenu$Separator). And there could be more than
- // one inner class -- it's possible to have com.mycompany.Outer$Inner$Innerer$Innerest.
- //
- // The basic strategy is to start by treating the part before the last dot as a package name, as that is by far
- // the most likely case. If we don't find the class there, change the last dot to a dollar sign and try again.
- // Suppose we have the tag <com.mycompany.Outer.Inner.Innerer.Innerest/>, matching the class above. Resolution
- // proceeds like this:
- // com.mycompany.Outer.Inner.Innerer.* : Innerest
- // com.mycompany.Outer.Inner.* : Innerer$Innerest
- // com.mycompany.Outer.* : Inner$Innerer$Innerest
- // com.mycompany.* : Outer$Inner$Innerer$Innerest
- // And at this point we have a match with the class Outer$Inner$Innerer$Innerest in package com.mycompany.
- int dotPos = originalName.lastIndexOf('.');
- for (; ;) {
- String namespace = dotPos != -1 ? originalName.substring(0, dotPos) + ".*" : "*";
- name = originalName.substring(dotPos + 1).replace('.', '$');
- String packageName = determinePackage(name, namespace);
- if (packageName != null) {
- assert packageName.endsWith("*");
- if (packageName.equals(namespace) || namespace.equals("*")) {
- // check for an alias (like javax.swing.JComboBox actually being jaxx.runtime.swing.JAXXComboBox)
- TagHandler handler = registeredTags.get(new QName(namespace, name));
- if (handler != null) { // determine alias by looking at handler
- ClassDescriptor alias = ((DefaultObjectHandler) handler).getBeanClass();
- // make sure the same handler is used for both the aliased and non-aliased names, in order to avoid "no CompiledObject has been registered" error
- // the line below doesn't bother to handle the case where the aliased class name doesn't have a package, since it's a pretty safe assumption that
- // that will never happen
- assert alias.getPackageName() != null && alias.getPackageName().length() > 0 : "aliasing with no package name has not been implemented";
- registeredTags.put(new QName(alias.getPackageName() + ".*", alias.getName().substring(alias.getPackageName().length() + 1)), handler);
- result = alias.getName();
- break;
- } else { // no alias
- result = packageName.substring(0, packageName.length() - 1) + name;
- break;
- }
- }
- // else we found a class by the same name, but in the wrong package
- }
-
- if (dotPos <= 0)
- break;
- dotPos = originalName.lastIndexOf('.', dotPos - 1);
- }
- }*/
-
- //if (result != null && !result.equals(originalName))
- //result = resolveClassName(result); // check for aliases against the new name as well
-
- Class clazz;
- try {
- clazz = Class.forName(name);
- result = clazz.getCanonicalName();
- } catch (ClassNotFoundException ex) {
- result = null;
- }
-
- return result;
+ return null;
}
1
0