Buix-commits
Threads by month
- ----- 2026 -----
- August
- July
- 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
Author: tchemit
Date: 2008-10-21 02:06:04 +0000 (Tue, 21 Oct 2008)
New Revision: 985
Modified:
lutinjaxx/trunk/pom.xml
Log:
plugin release can not deal with current.version substitution
Modified: lutinjaxx/trunk/pom.xml
===================================================================
--- lutinjaxx/trunk/pom.xml 2008-10-21 02:03:17 UTC (rev 984)
+++ lutinjaxx/trunk/pom.xml 2008-10-21 02:06:04 UTC (rev 985)
@@ -122,23 +122,23 @@
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>jaxx-util</artifactId>
- <version>${current.version}</version>
+ <version>0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>jaxx-core</artifactId>
- <version>${current.version}</version>
+ <version>0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>jaxx-swing-action</artifactId>
- <version>${current.version}</version>
+ <version>0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>jaxx-example</artifactId>
- <version>${current.version}</version>
+ <version>0.5-SNAPSHOT</version>
</dependency>
<dependency>
1
0
Author: tchemit
Date: 2008-10-21 02:03:17 +0000 (Tue, 21 Oct 2008)
New Revision: 984
Modified:
lutinjaxx/trunk/pom.xml
Log:
not used license-switcher on snapshot
Modified: lutinjaxx/trunk/pom.xml
===================================================================
--- lutinjaxx/trunk/pom.xml 2008-10-20 15:48:21 UTC (rev 983)
+++ lutinjaxx/trunk/pom.xml 2008-10-21 02:03:17 UTC (rev 984)
@@ -48,7 +48,7 @@
<properties>
- <license-switcher.version>0.5-SNAPSHOT</license-switcher.version>
+ <!--license-switcher.version>0.5-SNAPSHOT</license-switcher.version-->
<!-- current version -->
<current.version>0.5-SNAPSHOT</current.version>
1
0
r983 - in lutinjaxx/trunk: jaxx-core/src/main/java/jaxx/runtime/validator jaxx-example/Validation/src/main/resources/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
Oct. 20, 2008
Author: tchemit
Date: 2008-10-20 15:48:21 +0000 (Mon, 20 Oct 2008)
New Revision: 983
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java
lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
Log:
add requiredFilFieldValidator in example + fix a little error on this validator for directory
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java 2008-10-20 15:46:13 UTC (rev 982)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java 2008-10-20 15:48:21 UTC (rev 983)
@@ -59,7 +59,7 @@
return;
}
- if (f.getName().trim().isEmpty() && !f.isDirectory()) {
+ if (f.getPath().trim().isEmpty()) {
// f is not a directory nor exists
addFieldError(fieldName, object);
}
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-20 15:46:13 UTC (rev 982)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-20 15:48:21 UTC (rev 983)
@@ -24,7 +24,7 @@
<field name="config">
<field-validator type="requiredFile" short-circuit="true">
- <message>You must enter a valuer for config.</message>
+ <message>You must enter a value for config.</message>
</field-validator>
<field-validator type="existingFile" short-circuit="true">
<message>The configuration file ${config} does not exist.</message>
@@ -33,7 +33,7 @@
<field name="dir">
<field-validator type="requiredFile" short-circuit="true">
- <message>You must enter a valuer for dir.</message>
+ <message>You must enter a value for dir.</message>
</field-validator>
<field-validator type="existingDirectory" short-circuit="true">
<message>The directory ${dir} does not exist.</message>
1
0
r982 - in lutinjaxx/trunk: jaxx-core/src/main/java/jaxx/runtime/validator jaxx-example/Validation/src/main/resources/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
Oct. 20, 2008
Author: tchemit
Date: 2008-10-20 15:46:13 +0000 (Mon, 20 Oct 2008)
New Revision: 982
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java
lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
Log:
add requiredFilFieldValidator in example + fix a little error on this validator for directory
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java 2008-10-20 15:38:01 UTC (rev 981)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java 2008-10-20 15:46:13 UTC (rev 982)
@@ -59,7 +59,7 @@
return;
}
- if (f.getName().trim().isEmpty()) {
+ if (f.getName().trim().isEmpty() && !f.isDirectory()) {
// f is not a directory nor exists
addFieldError(fieldName, object);
}
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-20 15:38:01 UTC (rev 981)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-20 15:46:13 UTC (rev 982)
@@ -23,8 +23,8 @@
</field>
<field name="config">
- <field-validator type="file" short-circuit="true">
- <message>${config} is not a file.</message>
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>You must enter a valuer for config.</message>
</field-validator>
<field-validator type="existingFile" short-circuit="true">
<message>The configuration file ${config} does not exist.</message>
@@ -32,8 +32,8 @@
</field>
<field name="dir">
- <field-validator type="directory" short-circuit="true">
- <message>${dir} is not a directory.</message>
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>You must enter a valuer for dir.</message>
</field-validator>
<field-validator type="existingDirectory" short-circuit="true">
<message>The directory ${dir} does not exist.</message>
1
0
r981 - in lutinjaxx/trunk/jaxx-core/src: main/java/jaxx/runtime/validator main/resources test/java/jaxx/junit test/resources test/resources/jaxx test/resources/jaxx/junit
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
Oct. 20, 2008
Author: tchemit
Date: 2008-10-20 15:38:01 +0000 (Mon, 20 Oct 2008)
New Revision: 981
Added:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingDirectoryFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingFileFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorBean.java
lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorTest.java
lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/
lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/junit/
lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/junit/ValidatorBean-validation.xml
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml
lutinjaxx/trunk/jaxx-core/src/test/resources/log4j.properties
Log:
test new validators
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java 2008-10-20 13:49:00 UTC (rev 980)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -1,6 +1,7 @@
package jaxx.runtime.validator;
import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -21,14 +22,14 @@
* <!-- START SNIPPET: examples -->
* <validators>
* <!-- Plain-Validator Syntax -->
- * <validator type="directoryExisting">
+ * <validator type="existingDirectory">
* <param name="fieldName">tmp</param>
* <message>tmp is not an existing directory</message>
* </validator>
* <p/>
* <!-- Field-Validator Syntax -->
* <field name="tmp">
- * <field-validator type="directoryExisting">
+ * <field-validator type="existingDirectory">
* <message>tmp is not an existing directory</message>
* </field-validator>
* </field>
@@ -38,18 +39,16 @@
*
* @author chemit
*/
-public class ExistingDirectoryFieldValidator extends DirectoryFieldValidator {
+public class ExistingDirectoryFieldValidator extends FieldValidatorSupport {
- @Override
public void validate(Object object) throws ValidationException {
- super.validate(object);
- if (getValidatorContext().getFieldErrors().containsKey(getFieldName())) {
- // error already detected
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value==null) {
+ // no value defined
+ addFieldError(fieldName, object);
return;
}
- String fieldName = getFieldName();
- Object value = this.getFieldValue(fieldName, object);
-
File f;
if (value instanceof File) {
f = (File) value;
@@ -60,7 +59,8 @@
return;
}
- if (!f.exists()) {
+ if (!(f.isDirectory() && f.exists())) {
+ // f is not a directory, nor exists
addFieldError(fieldName, object);
}
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java 2008-10-20 13:49:00 UTC (rev 980)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -1,6 +1,7 @@
package jaxx.runtime.validator;
import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
import java.io.File;
@@ -38,18 +39,16 @@
*
* @author chemit
*/
-public class ExistingFileFieldValidator extends FileFieldValidator {
+public class ExistingFileFieldValidator extends FieldValidatorSupport {
- @Override
public void validate(Object object) throws ValidationException {
- super.validate(object);
- if (getValidatorContext().getFieldErrors().containsKey(getFieldName())) {
- // error already detected
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
return;
}
- String fieldName = getFieldName();
- Object value = this.getFieldValue(fieldName, object);
-
File f;
if (value instanceof File) {
f = (File) value;
@@ -60,7 +59,8 @@
return;
}
- if (!f.exists()) {
+ if (!(f.isFile() && f.exists())) {
+ // f is not a file nor exists
addFieldError(fieldName, object);
}
}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingDirectoryFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingDirectoryFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingDirectoryFieldValidator.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -0,0 +1,72 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * NotExistingDirectoryFieldValidator checks that a File field as a directory does not exist. *
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="notExistingDirectory">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is an existing directory</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="notExistingDirectory">
+ * <message>tmp is an existing directory</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class NotExistingDirectoryFieldValidator extends FieldValidatorSupport {
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (f.exists() || f.isFile()) {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "notExistingDirectory";
+ }
+}
\ No newline at end of file
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingFileFieldValidator.java (from rev 979, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingFileFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingFileFieldValidator.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -0,0 +1,73 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * NotExistingFileFieldValidator checks that a File field as a file does not exist. *
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="notExistingFile">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is an existing file</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="notExistingFile">
+ * <message>tmp is an existing file</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class NotExistingFileFieldValidator extends FieldValidatorSupport {
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value==null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (f.exists() || f.isDirectory()) {
+ // f is not a file and exist
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "notExistingFile";
+ }
+}
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/NotExistingFileFieldValidator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java (from rev 979, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -0,0 +1,72 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * RequiredFileFieldValidator checks that a File field is not null nor have an empty filename.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="requiredFile">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is required</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="requiredFile">
+ * <message>tmp is required</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class RequiredFileFieldValidator extends FieldValidatorSupport {
+
+ public void validate(Object object) throws ValidationException {
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (f.getName().trim().isEmpty()) {
+ // f is not a directory nor exists
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "requiredFile";
+ }
+}
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/RequiredFileFieldValidator.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml 2008-10-20 13:49:00 UTC (rev 980)
+++ lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml 2008-10-20 15:38:01 UTC (rev 981)
@@ -5,9 +5,10 @@
<!-- START SNIPPET: validators -->
<validators>
- <validator name="file" class="jaxx.runtime.validator.FileFieldValidator"/>
- <validator name="directory" class="jaxx.runtime.validator.DirectoryFieldValidator"/>
+ <validator name="requiredFile" class="jaxx.runtime.validator.RequiredFileFieldValidator"/>
<validator name="existingFile" class="jaxx.runtime.validator.ExistingFileFieldValidator"/>
+ <validator name="notExistingFile" class="jaxx.runtime.validator.NotExistingFileFieldValidator"/>
<validator name="existingDirectory" class="jaxx.runtime.validator.ExistingDirectoryFieldValidator"/>
+ <validator name="notExistingDirectory" class="jaxx.runtime.validator.NotExistingDirectoryFieldValidator"/>
</validators>
<!-- END SNIPPET: validators -->
Copied: lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorBean.java (from rev 979, lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorBean.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorBean.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -0,0 +1,79 @@
+package jaxx.junit;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.File;
+
+public class ValidatorBean {
+
+ protected File existingFile;
+ protected File notExistingFile;
+
+ protected File existingDirectory;
+ protected File notExistingDirectory;
+
+
+ PropertyChangeSupport p;
+
+ public ValidatorBean() {
+ p = new PropertyChangeSupport(this);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ p.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ p.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.removePropertyChangeListener(propertyName, listener);
+ }
+
+
+ public File getExistingFile() {
+ return existingFile;
+ }
+
+ public File getNotExistingFile() {
+ return notExistingFile;
+ }
+
+ public File getExistingDirectory() {
+ return existingDirectory;
+ }
+
+ public File getNotExistingDirectory() {
+ return notExistingDirectory;
+ }
+
+ public void setExistingFile(File existingFile) {
+ File old = this.existingFile;
+ this.existingFile = existingFile;
+ p.firePropertyChange("existingFile", old, existingFile);
+ }
+
+ public void setNotExistingFile(File notExistingFile) {
+ File old = this.notExistingFile;
+ this.notExistingFile = notExistingFile;
+ p.firePropertyChange("notExistingFile", old, notExistingFile);
+ }
+
+ public void setExistingDirectory(File existingDirectory) {
+ File old = this.existingDirectory;
+ this.existingDirectory = existingDirectory;
+ p.firePropertyChange("existingDirectory", old, existingDirectory);
+ }
+
+ public void setNotExistingDirectory(File notExistingDirectory) {
+ File old = this.notExistingDirectory;
+ this.notExistingDirectory = notExistingDirectory;
+ p.firePropertyChange("notExistingDirectory", old, notExistingDirectory);
+ }
+
+}
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorBean.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorTest.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorTest.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/test/java/jaxx/junit/ValidatorTest.java 2008-10-20 15:38:01 UTC (rev 981)
@@ -0,0 +1,167 @@
+package jaxx.junit;
+
+import jaxx.runtime.validator.BeanValidator;
+import jaxx.runtime.validator.BeanValidatorError;
+import jaxx.runtime.validator.BeanValidatorErrorListModel;
+import junit.framework.TestCase;
+
+import javax.swing.JLabel;
+import java.io.File;
+import java.util.Enumeration;
+
+/** @author chemit */
+public class ValidatorTest extends TestCase {
+
+ ValidatorBean bean;
+
+ static protected Boolean init = null;
+
+
+ static protected BeanValidator<ValidatorBean> validator;
+
+ static protected BeanValidatorErrorListModel errors;
+
+ static protected File basedir;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (init == null) {
+ String b = System.getenv("basedir");
+ if (b == null) {
+ b = new File("").getAbsolutePath();
+ }
+ basedir = new File(b);
+ validator = new BeanValidator<ValidatorBean>();
+ validator.setErrorListModel(errors = new BeanValidatorErrorListModel());
+ JLabel label = new JLabel();
+ validator.setFieldRepresentation("existingFile", label);
+ validator.setFieldRepresentation("existingDirectory", label);
+ validator.setFieldRepresentation("notExistingFile", label);
+ validator.setFieldRepresentation("notExistingDirectory", label);
+ init = true;
+ }
+ validator.setBean(bean = new ValidatorBean());
+ }
+
+ public void testRequiredFileFieldValidator() throws Exception {
+
+ assertNull(bean.getExistingFile());
+ assertFieldInError("existingFile", "existingFile.required", true);
+
+ bean.setExistingFile(new File(""));
+ assertFieldInError("existingFile", "existingFile.required", true);
+
+ bean.setExistingFile(basedir);
+ assertFieldInError("existingFile", "existingFile.required", false);
+
+ assertFieldInError("existingFile", "existingFile.not.exist", true);
+
+ bean.setExistingFile(new File(basedir, "pom.xml"));
+ assertFieldInError("existingFile", "existingFile.required", false);
+ assertFieldInError("existingFile", "existingFile.not.exist", false);
+
+ }
+
+ public void testExistingFileFieldValidator() throws Exception {
+
+ assertNull(bean.getExistingFile());
+ assertFieldInError("existingFile", "existingFile.required", true);
+
+ bean.setExistingFile(new File(""));
+ assertFieldInError("existingFile", "existingFile.required", true);
+
+ // existing directory
+ bean.setExistingFile(basedir);
+ assertFieldInError("existingFile", "existingFile.required", false);
+ assertFieldInError("existingFile", "existingFile.not.exist", true);
+
+ // existing file
+ bean.setExistingFile(new File(basedir, "pom.xml"));
+ assertFieldInError("existingFile", "existingFile.required", false);
+ assertFieldInError("existingFile", "existingFile.not.exist", false);
+
+ }
+
+ public void testNotExistingFileFieldValidator() throws Exception {
+
+ assertNull(bean.getNotExistingFile());
+ assertFieldInError("notExistingFile", "notExistingFile.required", true);
+
+ bean.setNotExistingFile(new File(""));
+ assertFieldInError("notExistingFile", "notExistingFile.required", true);
+
+ // existing directory
+ bean.setNotExistingFile(basedir);
+ assertFieldInError("notExistingFile", "notExistingFile.required", false);
+ assertFieldInError("notExistingFile", "notExistingFile.exist", true);
+
+ // existing file
+ bean.setNotExistingFile(new File(basedir, "pom.xml"));
+ assertFieldInError("notExistingFile", "notExistingFile.required", false);
+ assertFieldInError("notExistingFile", "notExistingFile.exist", true);
+
+ // none existing file
+ bean.setNotExistingFile(new File(basedir, "pom.xml-" + System.currentTimeMillis()));
+ assertFieldInError("notExistingFile", "notEexistingFile.required", false);
+ assertFieldInError("notExistingFile", "notExistingFile.exist", false);
+
+
+ }
+
+ public void testExistingDirectoryFieldValidator() throws Exception {
+
+ assertNull(bean.getExistingDirectory());
+ assertFieldInError("existingDirectory", "existingDirectory.required", true);
+
+ bean.setExistingDirectory(new File(""));
+ assertFieldInError("existingDirectory", "existingDirectory.required", true);
+
+ // existing file
+ bean.setExistingDirectory(new File(basedir, "pom.xml"));
+ assertFieldInError("existingDirectory", "existingDirectory.required", false);
+ assertFieldInError("existingDirectory", "existingDirectory.not.exist", true);
+
+ // existing directory
+ bean.setExistingDirectory(basedir);
+ assertFieldInError("existingDirectory", "existingDirectory.required", false);
+ assertFieldInError("existingDirectory", "existingDirectory.not.exist", false);
+
+ }
+
+ public void testNotExistingDirectoryFieldValidator() throws Exception {
+ assertNull(bean.getNotExistingDirectory());
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.required", true);
+
+ bean.setNotExistingDirectory(new File(""));
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.required", true);
+
+ // existing directory
+ bean.setNotExistingDirectory(basedir);
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.required", false);
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.exist", true);
+
+ // existing file
+ bean.setNotExistingDirectory(new File(basedir, "pom.xml"));
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.required", false);
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.exist", true);
+
+ // none existing directory
+ bean.setNotExistingDirectory(new File(basedir, "pom.xml-" + System.currentTimeMillis()));
+ assertFieldInError("notExistingDirectory", "notEexistingFile.required", false);
+ assertFieldInError("notExistingDirectory", "notExistingDirectory.exist", false);
+ }
+
+ protected void assertFieldInError(String s, String error, boolean required) {
+ Enumeration<?> myErrors = errors.elements();
+ while (myErrors.hasMoreElements()) {
+ BeanValidatorError o = (BeanValidatorError) myErrors.nextElement();
+ if (o.getFieldName().equals(s) && o.getError().equals(error)) {
+ assertTrue(required);
+ return;
+ }
+ }
+ // error was not found
+ assertFalse(required);
+ }
+}
Copied: lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/junit/ValidatorBean-validation.xml (from rev 979, lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/junit/ValidatorBean-validation.xml (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/junit/ValidatorBean-validation.xml 2008-10-20 15:38:01 UTC (rev 981)
@@ -0,0 +1,44 @@
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="existingFile">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>existingFile.required</message>
+ </field-validator>
+ <field-validator type="existingFile" short-circuit="true">
+ <message>existingFile.not.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="notExistingFile">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>notExistingFile.required</message>
+ </field-validator>
+ <field-validator type="notExistingFile" short-circuit="true">
+ <message>notExistingFile.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="existingDirectory">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>existingDirectory.required</message>
+ </field-validator>
+
+ <field-validator type="existingDirectory" short-circuit="true">
+ <message>existingDirectory.not.exist</message>
+ </field-validator>
+ </field>
+
+ <field name="notExistingDirectory">
+ <field-validator type="requiredFile" short-circuit="true">
+ <message>notExistingDirectory.required</message>
+ </field-validator>
+
+ <field-validator type="notExistingDirectory" short-circuit="true">
+ <message>notExistingDirectory.exist</message>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-core/src/test/resources/jaxx/junit/ValidatorBean-validation.xml
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: lutinjaxx/trunk/jaxx-core/src/test/resources/log4j.properties
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/test/resources/log4j.properties 2008-10-20 13:49:00 UTC (rev 980)
+++ lutinjaxx/trunk/jaxx-core/src/test/resources/log4j.properties 2008-10-20 15:38:01 UTC (rev 981)
@@ -1,5 +1,5 @@
# Global logging configuration
-log4j.rootLogger=INFO, stdout
+log4j.rootLogger=ERROR, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
1
0
r980 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 20, 2008
Oct. 20, 2008
Author: tchemit
Date: 2008-10-20 13:49:00 +0000 (Mon, 20 Oct 2008)
New Revision: 980
Removed:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java
Log:
test if parent is not null from a component to use it with no ui...
clean code, remove unsued FileFieldValidator
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-19 21:56:45 UTC (rev 979)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-20 13:49:00 UTC (rev 980)
@@ -25,7 +25,6 @@
import com.opensymphony.xwork2.ValidationAwareSupport;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
-import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.validator.ActionValidatorManager;
@@ -330,7 +329,9 @@
for (String fieldname : fieldRepresentation.keySet()) {
JComponent c = fieldRepresentation.get(fieldname);
//todo: a supprimer mais actuellemnt le layer ne se repaint pas bien, cela n'est pas normal
- c.getParent().repaint();
+ if (c.getParent() != null) {
+ c.getParent().repaint();
+ }
}
} catch (ValidationException eee) {
log.warn("Error during validation", eee);
@@ -340,8 +341,6 @@
protected ActionValidatorManager getValidator() {
if (validator == null) {
ConfigurationManager confManager = new ConfigurationManager();
- //confManager.addContainerProvider(new XmlConfigurationProvider("my-xworks.xml"));
- //confManager.addContainerProvider(new XmlConfigurationProvider("my-validators.xml"));
Configuration conf = confManager.getConfiguration();
ValueStackFactory vsf = conf.getContainer().getInstance(
@@ -372,8 +371,6 @@
if (container instanceof JXLayer) {
Constructor<? extends AbstractBeanValidatorUI> cons = uiClass.getConstructor(String.class, String.class, ValidationAware.class);
AbstractBeanValidatorUI ui = cons.newInstance(fieldname, c.getName(), validationSupport);
- //IconValidationUI ui = new IconValidationUI(fieldname, c.getName(), validationSupport);
- //TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, c.getName(), validationSupport);
ui.setEnabled(true);
JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
jx.setUI(ui);
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java 2008-10-19 21:56:45 UTC (rev 979)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java 2008-10-20 13:49:00 UTC (rev 980)
@@ -1,70 +0,0 @@
-package jaxx.runtime.validator;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-
-import java.io.File;
-
-/**
- * <!-- START SNIPPET: javadoc -->
- * ExistingDirectoryFieldValidator checks that a File field exists and is a directory.
- * <!-- END SNIPPET: javadoc -->
- * <p/>
- * <p/>
- * <!-- START SNIPPET: parameters -->
- * <ul>
- * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
- * </ul>
- * <!-- END SNIPPET: parameters -->
- * <p/>
- * <p/>
- * <pre>
- * <!-- START SNIPPET: examples -->
- * <validators>
- * <!-- Plain-Validator Syntax -->
- * <validator type="directoryExisting">
- * <param name="fieldName">tmp</param>
- * <message>tmp is not an existing directory</message>
- * </validator>
- * <p/>
- * <!-- Field-Validator Syntax -->
- * <field name="tmp">
- * <field-validator type="directoryExisting">
- * <message>tmp is not an existing directory</message>
- * </field-validator>
- * </field>
- * </validators>
- * <!-- END SNIPPET: examples -->
- * </pre>
- *
- * @author chemit
- */
-public class DirectoryFieldValidator extends FieldValidatorSupport {
-
- public void validate(Object object) throws ValidationException {
- String fieldName = getFieldName();
- Object value = this.getFieldValue(fieldName, object);
- if (value==null) {
- addFieldError(fieldName, object);
- return;
- }
- File f;
- if (value instanceof File) {
- f = (File) value;
- } else if (value instanceof String) {
- f = new File((String) value);
- } else {
- addFieldError(fieldName, object);
- return;
- }
-
- if (!f.isDirectory()) {
- addFieldError(fieldName, object);
- }
- }
-
- @Override
- public String getValidatorType() {
- return "directory";
- }
-}
\ No newline at end of file
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java 2008-10-19 21:56:45 UTC (rev 979)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java 2008-10-20 13:49:00 UTC (rev 980)
@@ -1,70 +0,0 @@
-package jaxx.runtime.validator;
-
-import com.opensymphony.xwork2.validator.ValidationException;
-import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
-
-import java.io.File;
-
-/**
- * <!-- START SNIPPET: javadoc -->
- * ExistingFileFieldValidator checks that a File field exists. *
- * <!-- END SNIPPET: javadoc -->
- * <p/>
- * <p/>
- * <!-- START SNIPPET: parameters -->
- * <ul>
- * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
- * </ul>
- * <!-- END SNIPPET: parameters -->
- * <p/>
- * <p/>
- * <pre>
- * <!-- START SNIPPET: examples -->
- * <validators>
- * <!-- Plain-Validator Syntax -->
- * <validator type="fileExisting">
- * <param name="fieldName">tmp</param>
- * <message>tmp is not an existing file</message>
- * </validator>
- * <p/>
- * <!-- Field-Validator Syntax -->
- * <field name="tmp">
- * <field-validator type="fileExisting">
- * <message>tmp is not an existing file</message>
- * </field-validator>
- * </field>
- * </validators>
- * <!-- END SNIPPET: examples -->
- * </pre>
- *
- * @author chemit
- */
-public class FileFieldValidator extends FieldValidatorSupport {
-
- public void validate(Object object) throws ValidationException {
- String fieldName = getFieldName();
- Object value = this.getFieldValue(fieldName, object);
- if (value == null) {
- addFieldError(fieldName, object);
- return;
- }
- File f;
- if (value instanceof File) {
- f = (File) value;
- } else if (value instanceof String) {
- f = new File((String) value);
- } else {
- addFieldError(fieldName, object);
- return;
- }
-
- if (!f.isFile()) {
- addFieldError(fieldName, object);
- }
- }
-
- @Override
- public String getValidatorType() {
- return "file";
- }
-}
\ No newline at end of file
1
0
r979 - in lutinjaxx/trunk: jaxx-core/src/main/java/jaxx/runtime/validator jaxx-core/src/main/resources jaxx-example/Validation/src/main/java/examples/Validation jaxx-example/Validation/src/main/resources/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 19, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 19, 2008
Oct. 19, 2008
Author: tchemit
Date: 2008-10-19 21:56:45 +0000 (Sun, 19 Oct 2008)
New Revision: 979
Added:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java
lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
Log:
adding validator on files and directories
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-19 20:15:06 UTC (rev 978)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-19 21:56:45 UTC (rev 979)
@@ -25,6 +25,7 @@
import com.opensymphony.xwork2.ValidationAwareSupport;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.validator.ActionValidatorManager;
@@ -339,6 +340,8 @@
protected ActionValidatorManager getValidator() {
if (validator == null) {
ConfigurationManager confManager = new ConfigurationManager();
+ //confManager.addContainerProvider(new XmlConfigurationProvider("my-xworks.xml"));
+ //confManager.addContainerProvider(new XmlConfigurationProvider("my-validators.xml"));
Configuration conf = confManager.getConfiguration();
ValueStackFactory vsf = conf.getContainer().getInstance(
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/DirectoryFieldValidator.java 2008-10-19 21:56:45 UTC (rev 979)
@@ -0,0 +1,70 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * ExistingDirectoryFieldValidator checks that a File field exists and is a directory.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="directoryExisting">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is not an existing directory</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="directoryExisting">
+ * <message>tmp is not an existing directory</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class DirectoryFieldValidator extends FieldValidatorSupport {
+
+ public void validate(Object object) throws ValidationException {
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value==null) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (!f.isDirectory()) {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "directory";
+ }
+}
\ No newline at end of file
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingDirectoryFieldValidator.java 2008-10-19 21:56:45 UTC (rev 979)
@@ -0,0 +1,72 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * ExistingDirectoryFieldValidator checks that a File field exists and is a directory.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="directoryExisting">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is not an existing directory</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="directoryExisting">
+ * <message>tmp is not an existing directory</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class ExistingDirectoryFieldValidator extends DirectoryFieldValidator {
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+ super.validate(object);
+ if (getValidatorContext().getFieldErrors().containsKey(getFieldName())) {
+ // error already detected
+ return;
+ }
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (!f.exists()) {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "existingDirectory";
+ }
+}
\ No newline at end of file
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ExistingFileFieldValidator.java 2008-10-19 21:56:45 UTC (rev 979)
@@ -0,0 +1,72 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * ExistingFileFieldValidator checks that a File field exists. *
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="fileExisting">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is not an existing file</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="fileExisting">
+ * <message>tmp is not an existing file</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class ExistingFileFieldValidator extends FileFieldValidator {
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+ super.validate(object);
+ if (getValidatorContext().getFieldErrors().containsKey(getFieldName())) {
+ // error already detected
+ return;
+ }
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (!f.exists()) {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "existingFile";
+ }
+}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/FileFieldValidator.java 2008-10-19 21:56:45 UTC (rev 979)
@@ -0,0 +1,70 @@
+package jaxx.runtime.validator;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+
+import java.io.File;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * ExistingFileFieldValidator checks that a File field exists. *
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * <p/>
+ * <p/>
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * <validators>
+ * <!-- Plain-Validator Syntax -->
+ * <validator type="fileExisting">
+ * <param name="fieldName">tmp</param>
+ * <message>tmp is not an existing file</message>
+ * </validator>
+ * <p/>
+ * <!-- Field-Validator Syntax -->
+ * <field name="tmp">
+ * <field-validator type="fileExisting">
+ * <message>tmp is not an existing file</message>
+ * </field-validator>
+ * </field>
+ * </validators>
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author chemit
+ */
+public class FileFieldValidator extends FieldValidatorSupport {
+
+ public void validate(Object object) throws ValidationException {
+ String fieldName = getFieldName();
+ Object value = this.getFieldValue(fieldName, object);
+ if (value == null) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ File f;
+ if (value instanceof File) {
+ f = (File) value;
+ } else if (value instanceof String) {
+ f = new File((String) value);
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+
+ if (!f.isFile()) {
+ addFieldError(fieldName, object);
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "file";
+ }
+}
\ No newline at end of file
Added: lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/resources/validators.xml 2008-10-19 21:56:45 UTC (rev 979)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator Config 1.0//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd">
+
+<!-- START SNIPPET: validators -->
+<validators>
+ <validator name="file" class="jaxx.runtime.validator.FileFieldValidator"/>
+ <validator name="directory" class="jaxx.runtime.validator.DirectoryFieldValidator"/>
+ <validator name="existingFile" class="jaxx.runtime.validator.ExistingFileFieldValidator"/>
+ <validator name="existingDirectory" class="jaxx.runtime.validator.ExistingDirectoryFieldValidator"/>
+</validators>
+<!-- END SNIPPET: validators -->
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java 2008-10-19 20:15:06 UTC (rev 978)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java 2008-10-19 21:56:45 UTC (rev 979)
@@ -2,6 +2,7 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
+import java.io.File;
public class Identity {
@@ -13,7 +14,10 @@
protected int age = 51;
+ protected File config = new File("/tmp");
+ protected File dir = new File("/tmp");
+
PropertyChangeSupport p;
public Identity() {
@@ -53,6 +57,14 @@
return age;
}
+ public File getConfig() {
+ return config;
+ }
+
+ public File getDir() {
+ return dir;
+ }
+
public void setFirstName(String firstName) {
String oldFirstName = this.firstName;
this.firstName = firstName;
@@ -66,7 +78,7 @@
}
public void setEmail(String email) {
- String oldEmail =this.email;
+ String oldEmail = this.email;
this.email = email;
p.firePropertyChange("email", oldEmail, email);
}
@@ -76,4 +88,16 @@
this.age = age;
p.firePropertyChange("age", oldAge, age);
}
+
+ public void setConfig(File config) {
+ File oldConfig = this.config;
+ this.config = config;
+ p.firePropertyChange("config", oldConfig, config);
+ }
+
+ public void setDir(File dir) {
+ File oldDir = this.dir;
+ this.dir = dir;
+ p.firePropertyChange("dir", oldDir, dir);
+ }
}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-19 20:15:06 UTC (rev 978)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-19 21:56:45 UTC (rev 979)
@@ -166,7 +166,7 @@
<row>
<cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
<JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
- layout='{new GridLayout()}' width='250' height='140'>
+ layout='{new GridLayout()}' width='250' height='180'>
<Table anchor='west' fill='both'>
<row>
<cell>
@@ -205,6 +205,24 @@
onStateChanged='identity.setAge(age.getValue())'/>
</cell>
</row>
+ <row>
+ <cell>
+ <JLabel text='Config file :'/>
+ </cell>
+ <cell>
+ <JTextField id='config' text='{identity.getConfig()}'
+ onKeyReleased='identity.setConfig(new java.io.File(config.getText()))'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Working directory:'/>
+ </cell>
+ <cell>
+ <JTextField id='dir' text='{identity.getDir()}'
+ onKeyReleased='identity.setDir(new java.io.File(dir.getText()))'/>
+ </cell>
+ </row>
</Table>
</JPanel>
</cell>
@@ -236,7 +254,6 @@
<JLabel text='{identity.getEmail()}'/>
</cell>
</row>
-
<row>
<cell>
<JLabel text='Age:'/>
@@ -245,6 +262,22 @@
<JLabel text='{identity.getAge()}'/>
</cell>
</row>
+ <row>
+ <cell>
+ <JLabel text='Config file:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getConfig()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Directory file:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getDir()}'/>
+ </cell>
+ </row>
</Table>
</JPanel>
</cell>
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-19 20:15:06 UTC (rev 978)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-19 21:56:45 UTC (rev 979)
@@ -22,6 +22,24 @@
</field-validator>
</field>
+ <field name="config">
+ <field-validator type="file" short-circuit="true">
+ <message>${config} is not a file.</message>
+ </field-validator>
+ <field-validator type="existingFile" short-circuit="true">
+ <message>The configuration file ${config} does not exist.</message>
+ </field-validator>
+ </field>
+
+ <field name="dir">
+ <field-validator type="directory" short-circuit="true">
+ <message>${dir} is not a directory.</message>
+ </field-validator>
+ <field-validator type="existingDirectory" short-circuit="true">
+ <message>The directory ${dir} does not exist.</message>
+ </field-validator>
+ </field>
+
<field name="age">
<field-validator type="int">
<param name="min">18</param>
1
0
r978 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 19, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 19, 2008
Oct. 19, 2008
Author: tchemit
Date: 2008-10-19 20:15:06 +0000 (Sun, 19 Oct 2008)
New Revision: 978
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java
Log:
begin of refactor of this tools to make it works with rst... to be finished
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java 2008-10-19 19:44:06 UTC (rev 977)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/PrintTagInfo.java 2008-10-19 20:15:06 UTC (rev 978)
@@ -8,6 +8,11 @@
import jaxx.tags.DefaultObjectHandler;
import jaxx.tags.TagManager;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
/** Generates information about a tag for use on the jaxxframework.org web site. */
public class PrintTagInfo {
/**
@@ -17,20 +22,48 @@
* @throws Exception if an error occurs
*/
public static void main(String[] arg) throws Exception {
- JAXXCompiler.init();
+ if (arg.length < 1) {
+ throw new IllegalArgumentException("programm needs at least two parameters : the file where to put the result, and at least one fqn class to treate");
+ }
+ String firstarg = arg[0];
+ boolean toFile = false;
+ BufferedWriter w;
+ if (firstarg.startsWith("file:")) {
+ w = new BufferedWriter(new FileWriter(firstarg.substring(5)));
+ toFile = true;
+ } else {
+ w = new BufferedWriter(new OutputStreamWriter(System.out));
+ }
- ClassDescriptor beanClass = ClassDescriptorLoader.getClassDescriptor(arg[0]);
+ try {
+ JAXXCompiler.loadLibraries(false);
+ for (int i = toFile ? 1 : 0; i < arg.length; i++) {
+ String className = arg[i];
+ treateClass(w, className);
+ }
+ } finally {
+ w.flush();
+ w.close();
+ }
+
+ }
+
+ protected static void treateClass(BufferedWriter w, String className) throws ClassNotFoundException, IOException {
+
+ ClassDescriptor beanClass = ClassDescriptorLoader.getClassDescriptor(className);
DefaultObjectHandler handler = TagManager.getTagHandler(beanClass);
DefaultObjectHandler superHandler = TagManager.getTagHandler(beanClass.getSuperclass());
// dump all bean properties
- System.out.println("Properties in " + beanClass);
+ w.append("Properties in ").append(String.valueOf(beanClass));
+ w.newLine();
JAXXPropertyDescriptor[] properties = handler.getJAXXBeanInfo().getJAXXPropertyDescriptors();
JAXXPropertyDescriptor[] superProperties = superHandler.getJAXXBeanInfo().getJAXXPropertyDescriptors();
for (JAXXPropertyDescriptor property : properties) {
- if (property.getWriteMethodDescriptor() == null)
+ if (property.getWriteMethodDescriptor() == null) {
continue;
+ }
boolean found = false;
String name = property.getName();
@@ -41,29 +74,42 @@
}
}
if (!found) {
- if (property.getPropertyType() == null)
+ if (property.getPropertyType() == null) {
System.err.println(name + " has null type");
- else {
- System.out.println("{{EquivalentAttribute|" + name + "|" + arg[0].replace('.', '/') +
- "|set" + JAXXCompiler.capitalize(name) + "|" +
- JAXXCompiler.getCanonicalName(property.getPropertyType()) + "}}");
- System.out.println("|-");
+ } else {
+ w.append("{{EquivalentAttribute|");
+ w.append(name);
+ w.append("|");
+ w.append(className.replace('.', '/'));
+ w.append("|set");
+ w.append(JAXXCompiler.capitalize(name));
+ w.append("|");
+ w.append(JAXXCompiler.getCanonicalName(property.getPropertyType()));
+ w.append("}}");
+ w.append("|-");
+ w.newLine();
}
}
}
- System.out.println();
- System.out.println();
+ w.newLine();
+ w.newLine();
// dump all bound methods
+ dumpMethods(w, beanClass, handler);
+ }
+
+ protected static void dumpMethods(BufferedWriter w, ClassDescriptor beanClass, DefaultObjectHandler handler) throws IOException {
MethodDescriptor[] methods = beanClass.getMethodDescriptors();
- System.out.println("Bound methods in " + beanClass);
+ w.append("Bound methods in ").append(String.valueOf(beanClass));
+ w.newLine();
for (MethodDescriptor method : methods) {
try {
- if (handler.isMemberBound(method.getName()))
- System.out.println("* <tt>" + method.getName() + "()</tt>");
- }
- catch (Throwable e) {
+ if (handler.isMemberBound(method.getName())) {
+ w.append("* <tt>").append(method.getName()).append("()</tt>");
+ w.newLine();
+ }
+ } catch (Throwable e) {
// ignore ?
}
}
1
0
r977 - in lutinjaxx/trunk: jaxx-core/src/main/java/jaxx/compiler jaxx-core/src/main/java/jaxx/css jaxx-core/src/main/java/jaxx/tags jaxx-core/src/main/java/jaxx/tags/swing maven-jaxx-plugin/src/test/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 19, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 19, 2008
Oct. 19, 2008
Author: tchemit
Date: 2008-10-19 19:44:06 +0000 (Sun, 19 Oct 2008)
New Revision: 977
Added:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompilerHelper.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/ScriptManager.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/css/Stylesheet.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/ApplicationHandler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JInternalFrameHandler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JWindowHandler.java
lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
Log:
refactor JAXXCompiler :
now use two others class :
- JAXXCompilerHelper which contains all static methods
- JAXXObjectGenerator which manage the generation of the java file
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -420,7 +420,7 @@
eventHandlers.add(handler);
if (getJavaCode().indexOf(".") != -1) { // object lives in another JAXX file and consequently its initialization code won't be output
- compiler.initializer.append(getInitializationCode(handler, compiler));
+ compiler.appendInitializerCode(getInitializationCode(handler, compiler));
}
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataBinding.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -66,13 +66,13 @@
if (!result && quickNoDependencies) {
if (!dest.endsWith(".layout")) // layout is specially handled early in the chain
- compiler.initDataBindings.append(assignment).append(JAXXCompiler.getLineSeparator());
+ compiler.appendInitDataBindings(assignment+ JAXXCompiler.getLineSeparator());
return false; // no dependencies, just a static expression
- } else {
- if (compiler.processDataBinding.length() > 0)
- compiler.processDataBinding.append("else ");
- compiler.processDataBinding.append("if ($dest.equals(").append(TypeManager.getJavaCode(id)).append(")) { ").append(assignment).append("}\n").append(JAXXCompiler.getLineSeparator());
- return true;
}
+ if (compiler.haveProcessDataBinding()) {
+ compiler.appendProcessDataBinding("else ");
+ }
+ compiler.appendProcessDataBinding("if ($dest.equals(" + TypeManager.getJavaCode(id) + ")) { " + assignment + "}\n" + JAXXCompiler.getLineSeparator());
+ return true;
}
}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/DataSource.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -82,8 +82,9 @@
* @throws CompilerException if a compilation error occurs
*/
public boolean compile(String propertyChangeListenerCode) throws CompilerException {
- if (compiled)
+ if (compiled) {
throw new IllegalStateException(this + " has already been compiled");
+ }
String id = compiler.getAutoId(ClassDescriptorLoader.getClassDescriptor(getClass()));
JavaParser p = new JavaParser(new StringReader(source + ";"));
while (!p.Line()) {
@@ -91,8 +92,9 @@
scanNode(node, id);
}
- if (dependencySymbols.size() > 0)
- compiler.bodyCode.append("private PropertyChangeListener ").append(id).append(" = ").append(propertyChangeListenerCode).append(";\n");
+ if (dependencySymbols.size() > 0) {
+ compiler.appendBodyCode("private PropertyChangeListener " + id + " = " + propertyChangeListenerCode + ";\n");
+ }
compileListeners();
compiled = true;
@@ -121,8 +123,9 @@
default:
int count = node.jjtGetNumChildren();
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++) {
scanNode(node.getChild(i), listenerId);
+ }
determineNodeType(node, listenerId);
}
}
@@ -131,33 +134,33 @@
assert node.getId() == JavaParserTreeConstants.JJTLITERAL;
if (node.jjtGetNumChildren() == 1) {
int id = node.getChild(0).getId();
- if (id == JavaParserTreeConstants.JJTBOOLEANLITERAL)
+ if (id == JavaParserTreeConstants.JJTBOOLEANLITERAL) {
return ClassDescriptorLoader.getClassDescriptor(boolean.class);
- else if (id == JavaParserTreeConstants.JJTNULLLITERAL)
+ }
+ if (id == JavaParserTreeConstants.JJTNULLLITERAL) {
return ClassDescriptorLoader.getClassDescriptor(NULL.class);
- else
- throw new RuntimeException("Expected BooleanLiteral or NullLiteral, found " + JavaParserTreeConstants.jjtNodeName[id]);
- } else {
- int id = node.firstToken.kind;
- switch (id) {
- case JavaParserConstants.INTEGER_LITERAL:
- if (node.firstToken.image.toLowerCase().endsWith("l"))
- return ClassDescriptorLoader.getClassDescriptor(long.class);
- else
- return ClassDescriptorLoader.getClassDescriptor(int.class);
- case JavaParserConstants.CHARACTER_LITERAL:
- return ClassDescriptorLoader.getClassDescriptor(char.class);
- case JavaParserConstants.FLOATING_POINT_LITERAL:
- if (node.firstToken.image.toLowerCase().endsWith("f"))
- return ClassDescriptorLoader.getClassDescriptor(float.class);
- else
- return ClassDescriptorLoader.getClassDescriptor(double.class);
- case JavaParserConstants.STRING_LITERAL:
- return ClassDescriptorLoader.getClassDescriptor(String.class);
- default:
- throw new RuntimeException("Expected literal token, found " + JavaParserConstants.tokenImage[id]);
}
+ throw new RuntimeException("Expected BooleanLiteral or NullLiteral, found " + JavaParserTreeConstants.jjtNodeName[id]);
}
+ int id = node.firstToken.kind;
+ switch (id) {
+ case JavaParserConstants.INTEGER_LITERAL:
+ if (node.firstToken.image.toLowerCase().endsWith("l")) {
+ return ClassDescriptorLoader.getClassDescriptor(long.class);
+ }
+ return ClassDescriptorLoader.getClassDescriptor(int.class);
+ case JavaParserConstants.CHARACTER_LITERAL:
+ return ClassDescriptorLoader.getClassDescriptor(char.class);
+ case JavaParserConstants.FLOATING_POINT_LITERAL:
+ if (node.firstToken.image.toLowerCase().endsWith("f")) {
+ return ClassDescriptorLoader.getClassDescriptor(float.class);
+ }
+ return ClassDescriptorLoader.getClassDescriptor(double.class);
+ case JavaParserConstants.STRING_LITERAL:
+ return ClassDescriptorLoader.getClassDescriptor(String.class);
+ default:
+ throw new RuntimeException("Expected literal token, found " + JavaParserConstants.tokenImage[id]);
+ }
}
/**
@@ -179,11 +182,13 @@
for (int j = 0; j < tokens.length - (isMethod ? 1 : 0); j++) {
accepted = false;
- if (tokensSeenSoFar.length() > 0)
+ if (tokensSeenSoFar.length() > 0) {
tokensSeenSoFar.append('.');
+ }
tokensSeenSoFar.append(tokens[j]);
- if (currentSymbol.length() > 0)
+ if (currentSymbol.length() > 0) {
currentSymbol.append('.');
+ }
currentSymbol.append(tokens[j]);
if (currentSymbol.indexOf(".") == -1) {
@@ -234,8 +239,9 @@
return null;
}
}
- if (!accepted)
+ if (!accepted) {
return null;
+ }
}
return contextClass;
@@ -254,11 +260,13 @@
SimpleNode prefix = expression.getChild(0);
if (prefix.jjtGetNumChildren() == 1) {
int type = prefix.getChild(0).getId();
- if (type == JavaParserTreeConstants.JJTLITERAL || type == JavaParserTreeConstants.JJTEXPRESSION)
+ if (type == JavaParserTreeConstants.JJTLITERAL || type == JavaParserTreeConstants.JJTEXPRESSION) {
prefix.setJavaType(prefix.getChild(0).getJavaType());
- else
+ } else
if (type == JavaParserTreeConstants.JJTNAME && expression.jjtGetNumChildren() == 1) // name with no arguments after it
+ {
prefix.setJavaType(scanCompoundSymbol(prefix.getText().trim(), compiler.getRootObject().getObjectClass(), false, listenerId));
+ }
}
if (expression.jjtGetNumChildren() == 1) {
@@ -266,8 +274,9 @@
}
ClassDescriptor contextClass = prefix.getJavaType();
- if (contextClass == null)
+ if (contextClass == null) {
contextClass = compiler.getRootObject().getObjectClass();
+ }
String lastNode = prefix.getText().trim();
for (int i = 1; i < expression.jjtGetNumChildren(); i++) {
@@ -275,14 +284,17 @@
if (suffix.jjtGetNumChildren() == 1 && suffix.getChild(0).getId() == JavaParserTreeConstants.JJTARGUMENTS) {
if (suffix.getChild(0).jjtGetNumChildren() == 0) { // at the moment only no-argument methods are trackable
contextClass = scanCompoundSymbol(lastNode, contextClass, true, listenerId);
- if (contextClass == null)
+ if (contextClass == null) {
return null;
+ }
int dotPos = lastNode.lastIndexOf(".");
String objectCode = dotPos == -1 ? "" : lastNode.substring(0, dotPos);
- for (int j = i - 2; j >= 0; j--)
+ for (int j = i - 2; j >= 0; j--) {
objectCode = expression.getChild(j).getText() + objectCode;
- if (objectCode.length() == 0)
+ }
+ if (objectCode.length() == 0) {
objectCode = compiler.getRootObject().getJavaCode();
+ }
String methodName = lastNode.substring(dotPos + 1).trim();
try {
MethodDescriptor method = contextClass.getMethodDescriptor(methodName, new ClassDescriptor[0]);
@@ -292,10 +304,11 @@
catch (NoSuchMethodException e) {
// happens for methods defined in the current JAXX file via scripts
String propertyName = null;
- if (methodName.startsWith("is"))
+ if (methodName.startsWith("is")) {
propertyName = Introspector.decapitalize(methodName.substring("is".length()));
- else if (methodName.startsWith("get"))
+ } else if (methodName.startsWith("get")) {
propertyName = Introspector.decapitalize(methodName.substring("get".length()));
+ }
if (propertyName != null) {
MethodDescriptor[] newMethods = compiler.getScriptMethods();
for (MethodDescriptor newMethod : newMethods) {
@@ -313,8 +326,9 @@
}
}
lastNode = suffix.getText().trim();
- if (lastNode.startsWith("."))
+ if (lastNode.startsWith(".")) {
lastNode = lastNode.substring(1);
+ }
}
return null;
@@ -322,7 +336,9 @@
private void trackMemberIfPossible(String objectCode, ClassDescriptor objectClass, String memberName, boolean method, String listenerId) {
if (objectClass.isInterface()) // might be technically possible to track in some cases, but for now
+ {
return; // we can't create a DefaultObjectHandler for interfaces
+ }
DefaultObjectHandler handler = TagManager.getTagHandler(objectClass);
try {
@@ -344,12 +360,13 @@
* can be tracked.
*
* @param node node to scan
- * @param listenerId
+ * @param listenerId the listener id
*/
private void determineNodeType(SimpleNode node, String listenerId) {
ClassDescriptor type = null;
- if (node.jjtGetNumChildren() == 1)
+ if (node.jjtGetNumChildren() == 1) {
type = node.getChild(0).getJavaType();
+ }
switch (node.getId()) {
case JavaParserTreeConstants.JJTCLASSORINTERFACETYPE:
type = ClassDescriptorLoader.getClassDescriptor(Class.class);
@@ -375,34 +392,48 @@
addListenerCode.append(" ");
}
addListenerCode.append(addCode);
- if (objectCode != null)
+ if (objectCode != null) {
addListenerCode.append("}");
+ }
if (objectCode != null) {
removeListenerCode.append("if (").append(objectCode).append(" != null) {").append(JAXXCompiler.getLineSeparator());
removeListenerCode.append(" ");
}
removeListenerCode.append(removeCode);
- if (objectCode != null)
+ if (objectCode != null) {
removeListenerCode.append("}");
+ }
}
}
private void compileListeners() {
if (addListenerCode.length() > 0) {
- if (compiler.applyDataBinding.length() > 0)
- compiler.applyDataBinding.append("else ");
- compiler.applyDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator());
- compiler.applyDataBinding.append(" ").append(addListenerCode).append(JAXXCompiler.getLineSeparator());
- compiler.applyDataBinding.append("}").append(JAXXCompiler.getLineSeparator());
+ if (compiler.haveApplyDataBinding()) {
+ compiler.appendApplyDataBinding("else ");
+ }
+ compiler.appendApplyDataBinding("if ($binding.equals(" + TypeManager.getJavaCode(id) + ")) {" + JAXXCompiler.getLineSeparator());
+ compiler.appendApplyDataBinding(" " + addListenerCode + JAXXCompiler.getLineSeparator());
+ compiler.appendApplyDataBinding("}" + JAXXCompiler.getLineSeparator());
+ //if (compiler.applyDataBinding.length() > 0)
+ // compiler.applyDataBinding.append("else ");
+ //compiler.applyDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator());
+ //compiler.applyDataBinding.append(" ").append(addListenerCode).append(JAXXCompiler.getLineSeparator());
+ //compiler.applyDataBinding.append("}").append(JAXXCompiler.getLineSeparator());
}
if (removeListenerCode.length() > 0) {
- if (compiler.removeDataBinding.length() > 0)
- compiler.removeDataBinding.append("else ");
- compiler.removeDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator());
- compiler.removeDataBinding.append(" ").append(removeListenerCode).append(JAXXCompiler.getLineSeparator());
- compiler.removeDataBinding.append("}").append(JAXXCompiler.getLineSeparator());
+ if (compiler.haveRemoveDataBinding()) {
+ compiler.appendRemoveDataBinding("else ");
+ }
+ compiler.appendRemoveDataBinding("if ($binding.equals(" + TypeManager.getJavaCode(id) + ")) {" + JAXXCompiler.getLineSeparator());
+ compiler.appendRemoveDataBinding(" " + removeListenerCode + JAXXCompiler.getLineSeparator());
+ compiler.appendRemoveDataBinding("}" + JAXXCompiler.getLineSeparator());
+ //if (compiler.removeDataBinding.length() > 0)
+ // compiler.removeDataBinding.append("else ");
+ //compiler.removeDataBinding.append("if ($binding.equals(").append(TypeManager.getJavaCode(id)).append(")) {").append(JAXXCompiler.getLineSeparator());
+ //compiler.removeDataBinding.append(" ").append(removeListenerCode).append(JAXXCompiler.getLineSeparator());
+ //compiler.removeDataBinding.append("}").append(JAXXCompiler.getLineSeparator());
}
}
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -15,265 +15,141 @@
import jaxx.reflect.FieldDescriptor;
import jaxx.reflect.MethodDescriptor;
import jaxx.runtime.ComponentDescriptor;
-import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXObjectDescriptor;
-import jaxx.runtime.swing.Application;
-import jaxx.spi.Initializer;
import jaxx.tags.DefaultObjectHandler;
import jaxx.tags.TagHandler;
import jaxx.tags.TagManager;
import jaxx.tags.validator.BeanValidatorHandler.CompiledBeanValidator;
-import jaxx.types.TypeManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
-import org.xml.sax.helpers.AttributesImpl;
-import org.xml.sax.helpers.XMLFilterImpl;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.ErrorListener;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.sax.SAXSource;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectOutputStream;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.ServiceLoader;
import java.util.Set;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.zip.GZIPOutputStream;
-/** Compiles JAXX files into Java classes. */
-public class JAXXCompiler {
- /** log */
- protected static final Log log = LogFactory.getLog(JAXXCompiler.class);
+/**
+ * Compiles JAXX files into Java classes.
+ * <p/>
+ * extends the {@link JAXXCompilerHelper} class wich contains all static usefull method.
+ * <p/>
+ * In that way, this class should not contains any static code, but use by inheritance the ones defined in the {@link JAXXCompilerHelper}
+ * <p/>
+ * use also a {@link #generator} ({@link JAXXObjectGenerator} to generate the java file,
+ * after the compilation.
+ */
+public class JAXXCompiler extends JAXXCompilerHelper {
- /**
- * True to throw exceptions when we encounter unresolvable classes, false to ignore.
- * This is currently set to false until JAXX has full support for inner classes
- * (including enumerations), because currently they don't always resolve (but will
- * generally compile without error anyway).
- */
- public static final boolean STRICT_CHECKS = false;
+ /*---------------------------------------------------------------------------------*/
+ /*-- compiler fields --------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
- public static final String JAXX_NAMESPACE = "http://www.jaxxframework.org/";
- public static final String JAXX_INTERNAL_NAMESPACE = "http://www.jaxxframework.org/internal";
+ /** flag to detec if an error occurs while compiling jaxx file */
+ protected boolean failed;
- /** Maximum length of an inlinable creation method. */
- private static final int INLINE_THRESHOLD = 300;
-
- /** Contains import declarations (of the form "javax.swing.") which are always imported in all compiler instances. */
- private static List<String> staticImports = new ArrayList<String>();
-
- static {
- //TODO humm, we should be able to import only what is needed
- staticImports.add("java.awt.*");
- staticImports.add("java.awt.event.*");
- staticImports.add("java.beans.*");
- staticImports.add("java.io.*");
- staticImports.add("java.lang.*");
- staticImports.add("java.util.*");
- staticImports.add("javax.swing.*");
- staticImports.add("javax.swing.border.*");
- staticImports.add("javax.swing.event.*");
- staticImports.add("jaxx.runtime.swing.JAXXButtonGroup");
- staticImports.add("jaxx.runtime.swing.HBox");
- staticImports.add("jaxx.runtime.swing.VBox");
- staticImports.add("jaxx.runtime.swing.Table");
- staticImports.add("static org.codelutin.i18n.I18n._");
- staticImports.add("static org.codelutin.jaxx.util.UIHelper.createImageIcon");
- }
-
- private static DefaultObjectHandler firstPassClassTagHandler = new DefaultObjectHandler(ClassDescriptorLoader.getClassDescriptor(Object.class));
-
- /**
- * A list of Runnables which will be run after the first compilation pass. This is primarily used
- * to trigger the creation of CompiledObjects, which cannot be created during the first pass and must be
- * created in document order.
- */
- private List<Runnable> initializers = new ArrayList<Runnable>();
-
- /** Files being compiled during the compilation session, may be modified as compilation progresses and additional dependencies are found. */
- private static List<File> jaxxFiles = new ArrayList<File>();
-
- /** Class names corresponding to the files in the jaxxFiles list. */
- private static List<String> jaxxFileClassNames = new ArrayList<String>();
-
- /** Maps the names of classes being compiled to the compiler instance handling the compilation. */
- private static Map<String, JAXXCompiler> compilers = new HashMap<String, JAXXCompiler>();
-
- /** Maps the names of classes being compiled to their symbol tables (created after the first compiler pass). */
- private static Map<File, SymbolTable> symbolTables = new HashMap<File, SymbolTable>();
-
- private CompilerOptions options;
-
- /** Used for error reporting purposes, so we can report the right line number. */
- private Stack<Element> tagsBeingCompiled = new Stack<Element>();
-
- /** Used for error reporting purposes, so we can report the right source file. */
- private Stack<File> sourceFiles = new Stack<File>();
-
- /** Maps object ID strings to the objects themselves. These are created during the second compilation pass. */
- private Map<String, CompiledObject> objects = new LinkedHashMap<String, CompiledObject>();
-
- /** Maps objects to their ID strings. These are created during the second compilation pass. */
- private Map<CompiledObject, String> ids = new LinkedHashMap<CompiledObject, String>();
-
- private static int errorCount;
- private static int warningCount;
-
- private boolean failed;
-
/** Object corresponding to the root tag in the document. */
- private CompiledObject root;
+ protected CompiledObject root;
/** Contains strings of the form "javax.swing." */
- private Set<String> importedPackages = new HashSet<String>();
+ protected Set<String> importedPackages = new HashSet<String>();
/** Contains strings of the form "javax.swing.Timer" */
- private Set<String> importedClasses = new HashSet<String>();
+ protected Set<String> importedClasses = new HashSet<String>();
/** Keeps track of open components (components still having children added). */
- private Stack<CompiledObject> openComponents = new Stack<CompiledObject>();
+ protected Stack<CompiledObject> openComponents = new Stack<CompiledObject>();
/** Sequence number used to create automatic variable names. */
- private int autogenID = 0;
+ protected int autogenID = 0;
- private List<DataBinding> dataBindings = new ArrayList<DataBinding>();
+ protected List<DataBinding> dataBindings = new ArrayList<DataBinding>();
- private JavaFile javaFile = new JavaFile();
-
- // true if a main() method has been declared in a script
- boolean mainDeclared;
-
/** list of validators */
protected List<CompiledBeanValidator> validators = new ArrayList<CompiledBeanValidator>();
/** list of objectId attached to a validator * */
protected List<String> validatedComponents = new ArrayList<String>();
- private SymbolTable symbolTable = new SymbolTable();
+ protected SymbolTable symbolTable = new SymbolTable();
- // TODO: replace these public StringBuffers with something a little less stupid
-
- /** Extra code to be added to the instance initializer. */
- public StringBuffer initializer = new StringBuffer();
-
- /** Extra code to be added at the end of the instance initializer. */
- public StringBuffer lateInitializer = new StringBuffer();
-
- /** Extra code to be added to the class body. */
- public StringBuffer bodyCode = new StringBuffer();
-
- /** Code to initialize data bindings. */
- public StringBuffer initDataBindings = new StringBuffer();
-
- /** Body of the applyDataBinding method. */
- public StringBuffer applyDataBinding = new StringBuffer();
-
- /** Body of the removeDataBinding method. */
- public StringBuffer removeDataBinding = new StringBuffer();
-
- /** Body of the processDataBinding method. */
- public StringBuffer processDataBinding = new StringBuffer();
-
/** Base directory used for path resolution (normally the directory in which the .jaxx file resides). */
- private File baseDir;
+ protected File baseDir;
/** .jaxx file being compiled. */
- private File src;
+ protected File src;
- /** Generated .java file. */
- private File dest;
-
/** Parsed XML of src file. */
- private Document document;
+ protected Document document;
/** Name of class being compiled. */
- private String outputClassName;
+ protected String outputClassName;
- private ScriptManager scriptManager = new ScriptManager(this);
+ protected ScriptManager scriptManager = new ScriptManager(this);
/** Combination of all stylesheets registered using {@link #registerStylesheet}. */
- private Stylesheet stylesheet;
+ protected Stylesheet stylesheet;
/** Contains all attributes defined inline on class tags. */
- private List<Rule> inlineStyles = new ArrayList<Rule>();
+ protected List<Rule> inlineStyles = new ArrayList<Rule>();
/**
* Maps objects (expressed in Java code) to event listener classes (e.g. MouseListener) to Lists of EventHandlers. The final list
* contains all event handlers of a particular type attached to a particular object (again, as represented by a Java expression).
*/
- private Map<String, Map<ClassDescriptor, List<EventHandler>>> eventHandlers = new HashMap<String, Map<ClassDescriptor, List<EventHandler>>>();
+ protected Map<String, Map<ClassDescriptor, List<EventHandler>>> eventHandlers = new HashMap<String, Map<ClassDescriptor, List<EventHandler>>>();
- private Map<Object, String> uniqueIds = new HashMap<Object, String>();
+ /** Maps of uniqued id for objects used in compiler */
+ protected Map<Object, String> uniqueIds = new HashMap<Object, String>();
- private Map<EventHandler, String> eventHandlerMethodNames = new HashMap<EventHandler, String>();
+ /** Map of event handler method names used in compiler */
+ protected Map<EventHandler, String> eventHandlerMethodNames = new HashMap<EventHandler, String>();
/** ClassLoader which searches the user-specified class path in addition to the normal class path */
- private ClassLoader classLoader;
+ protected ClassLoader classLoader;
- private static final int PASS_1 = 0;
- private static final int PASS_2 = 1;
- private static int currentPass;
+ /** the generator of the java file */
+ protected final JAXXObjectGenerator generator;
- public static void init() {
- // forces static initializer to run if it hasn't yet
- }
+ /**
+ * A list of Runnables which will be run after the first compilation pass. This is primarily used
+ * to trigger the creation of CompiledObjects, which cannot be created during the first pass and must be
+ * created in document order.
+ */
+ protected List<Runnable> initializers = new ArrayList<Runnable>();
- public static void loadLibraries(boolean verbose) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- ClassLoader classloader = Thread.currentThread().getContextClassLoader();
- if (verbose) {
- log.info("with cl " + classloader);
- }
- ServiceLoader<Initializer> loader = ServiceLoader.load(Initializer.class, classloader);
- for (Initializer initializer : loader) {
- if (verbose) {
- log.info("load initializer " + initializer);
- }
- initializer.initialize();
- }
- }
+ /** left brace matcher */
+ protected Matcher leftBraceMatcher = Pattern.compile("^(\\{)|[^\\\\](\\{)").matcher("");
- private JAXXCompiler(ClassLoader classLoader) {
+ /** right brace matcher */
+ protected Matcher rightBraceMatcher = Pattern.compile("^(\\})|[^\\\\](\\})").matcher("");
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Constructor methods ----------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ protected JAXXCompiler(ClassLoader classLoader) {
this.options = new CompilerOptions();
this.classLoader = classLoader;
+ this.generator = new JAXXObjectGenerator(this);
addImport("java.lang.*");
}
-
/**
* Creates a new JAXXCompiler.
*
@@ -288,61 +164,18 @@
sourceFiles.push(src);
this.outputClassName = outputClassName;
this.options = options;
+ this.generator = new JAXXObjectGenerator(this);
addImport(outputClassName.substring(0, outputClassName.lastIndexOf(".") + 1) + "*");
for (Object staticImport : staticImports) {
addImport((String) staticImport);
}
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- Initializer methods -----------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
- /**
- * Creates a dummy JAXXCompiler for use in unit testing.
- *
- * @return the compiler
- */
- public static JAXXCompiler createDummyCompiler() {
- return createDummyCompiler(JAXXCompiler.class.getClassLoader());
- }
-
-
- /**
- * Creates a dummy JAXXCompiler for use in unit testing.
- *
- * @param classLoader class loader to use
- * @return the compiler
- */
- public static JAXXCompiler createDummyCompiler(ClassLoader classLoader) {
- return new JAXXCompiler(classLoader);
- }
-
-
- public CompilerOptions getOptions() {
- return options;
- }
-
-
- public JavaFile getJavaFile() {
- return javaFile;
- }
-
-
- private void compileFirstPass() throws IOException {
- try {
- InputStream in = new FileInputStream(src);
- document = parseDocument(in);
- in.close();
- compileFirstPass(document.getDocumentElement());
- }
- catch (SAXParseException e) {
- reportError(e.getLineNumber(), "Invalid XML: " + e.getMessage());
- }
- catch (SAXException e) {
- reportError(null, "Error parsing XML document: " + e);
- }
- }
-
-
- private void runInitializers() {
+ protected void runInitializers() {
for (Runnable runnable : initializers) {
if (log.isDebugEnabled()) {
log.debug(runnable);
@@ -369,735 +202,10 @@
initializers.add(r);
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- Compile methods --------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
- private void compileSecondPass() throws IOException {
- if (!tagsBeingCompiled.isEmpty()) {
- throw new RuntimeException("Internal error: starting pass two, but tagsBeingCompiled is not empty: " + tagsBeingCompiled);
- }
- compileSecondPass(document.getDocumentElement());
- }
-
-
- private void applyStylesheets() {
- for (Object o : new ArrayList<CompiledObject>(objects.values())) {
- CompiledObject object = (CompiledObject) o;
- TagManager.getTagHandler(object.getObjectClass()).applyStylesheets(object, this);
- }
- }
-
-
- private void generateCode() throws IOException {
- if (options.getTargetDirectory() != null) {
- dest = new File(options.getTargetDirectory(), outputClassName.replace('.', File.separatorChar) + ".java");
- } else {
- dest = new File(baseDir, outputClassName.substring(outputClassName.lastIndexOf(".") + 1) + ".java");
- }
- if (dest.exists() && !dest.setLastModified(System.currentTimeMillis())) {
- log.warn("could not touch file " + dest);
- }
- PrintWriter out = new PrintWriter(new FileWriter(dest));
- createJavaSource(out);
- out.close();
- }
-
- private void createJavaSource(PrintWriter out) throws IOException {
- int dotPos = outputClassName.lastIndexOf(".");
- String packageName = dotPos != -1 ? outputClassName.substring(0, dotPos) : null;
- String simpleClassName = outputClassName.substring(dotPos + 1);
- outputClass(packageName, simpleClassName, out);
- }
-
-
- public String getOutputClassName() {
- return outputClassName;
- }
-
- public static SAXParser getSAXParser() {
- try {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- SAXParser parser;
- parser = factory.newSAXParser();
- return parser;
- }
- catch (SAXException e) {
- throw new RuntimeException(e);
- }
- catch (ParserConfigurationException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static Document parseDocument(InputStream in) throws IOException, SAXException {
- try {
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer();
- transformer.setErrorListener(new ErrorListener() {
- public void warning(TransformerException ex) throws TransformerException {
- throw ex;
- }
-
- public void error(TransformerException ex) throws TransformerException {
- throw ex;
- }
-
- public void fatalError(TransformerException ex) throws TransformerException {
- throw ex;
- }
- });
-
- DOMResult result = new DOMResult();
- transformer.transform(new SAXSource(new XMLFilterImpl(getSAXParser().getXMLReader()) {
- Locator locator;
-
- @Override
- public void setDocumentLocator(Locator locator) {
- this.locator = locator;
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
- AttributesImpl resultAtts = new AttributesImpl(atts);
- resultAtts.addAttribute(JAXX_INTERNAL_NAMESPACE, "line", "internal:line", "CDATA", String.valueOf(locator.getLineNumber()));
- getContentHandler().startElement(uri, localName, qName, resultAtts);
- }
- }, new InputSource(in)), result);
- return (Document) result.getNode();
- }
- catch (TransformerConfigurationException e) {
- throw new RuntimeException(e);
- }
- catch (TransformerException e) {
- Throwable ex = e;
- while (ex.getCause() != null) {
- ex = ex.getCause();
- }
- if (ex instanceof IOException) {
- throw (IOException) ex;
- }
- if (ex instanceof SAXException) {
- throw (SAXException) ex;
- }
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- }
- throw new RuntimeException(ex);
- }
- }
-
-
- public File getBaseDir() {
- return baseDir;
- }
-
-
- public Set<String> getImportedClasses() {
- return importedClasses;
- }
-
-
- public Set<String> getImportedPackages() {
- return importedPackages;
- }
-
-
- private boolean inlineCreation(CompiledObject object) {
- return object.getId().startsWith("$") && object.getInitializationCode(this).length() < INLINE_THRESHOLD;
- }
-
-
- public void checkOverride(CompiledObject object) throws CompilerException {
- if (object.getId().startsWith("$")) {
- return;
- }
- ClassDescriptor ancestor = root.getObjectClass();
- if (ancestor == object.getObjectClass()) {
- return;
- }
- while (ancestor != null) {
- try {
- FieldDescriptor f = ancestor.getDeclaredFieldDescriptor(object.getId());
- if (!f.getType().isAssignableFrom(object.getObjectClass())) {
- reportError("attempting to redefine superclass member '" + object.getId() + "' as incompatible type (was " + f.getType() + ", redefined as " + object.getObjectClass() + ")");
- }
- object.setOverride(true);
- break;
- }
- catch (NoSuchFieldException e) {
- ancestor = ancestor.getSuperclass();
- }
- }
- }
-
-
- private Iterator<CompiledObject> getObjectCreationOrder() {
- return objects.values().iterator();
- }
-
-
- protected JavaMethod createConstructor(String className) throws CompilerException {
- StringBuffer code = new StringBuffer();
- String constructorParams = root.getConstructorParams();
- if (constructorParams != null) {
- code.append(" super(").append(constructorParams).append(");");
- code.append(getLineSeparator());
- }
- code.append("$initialize();");
- code.append(getLineSeparator());
- return new JavaMethod(Modifier.PUBLIC, null, className, null, null, code.toString());
- }
-
-
- protected JavaMethod createInitializer(String className) throws CompilerException {
- StringBuffer code = new StringBuffer();
- code.append("$objectMap.put(").append(TypeManager.getJavaCode(root.getId())).append(", this);");
- code.append(getLineSeparator());
-
- Iterator<CompiledObject> i = getObjectCreationOrder();
- boolean lastWasMethodCall = false;
- while (i.hasNext()) {
- CompiledObject object = i.next();
- if (object != root && !object.isOverride()) {
- if (inlineCreation(object)) {
- if (lastWasMethodCall) {
- lastWasMethodCall = false;
- code.append(getLineSeparator());
- }
- code.append(getCreationCode(object));
- code.append(getLineSeparator());
- } else {
- code.append(object.getCreationMethodName()).append("();");
- code.append(getLineSeparator());
- lastWasMethodCall = true;
- }
- }
- }
- String rootCode = root.getInitializationCode(this);
- if (rootCode != null && rootCode.length() > 0) {
- code.append(rootCode);
- code.append(getLineSeparator());
- }
- code.append(getLineSeparator());
- if (initializer.length() > 0) {
- code.append(initializer);
- code.append(getLineSeparator());
- }
- code.append("$completeSetup();");
- code.append(getLineSeparator());
- return new JavaMethod(Modifier.PRIVATE, "void", "$initialize", null, null, code.toString());
- }
-
-
- protected JavaMethod createCompleteSetupMethod() {
- StringBuffer code = new StringBuffer();
- code.append("allComponentsCreated = true;");
- code.append(getLineSeparator());
- for (CompiledObject object : objects.values()) {
- //TC - 20081017 only generate the method if not empty ?
- if (object.getId().startsWith("$")) {
- code.append(object.getAdditionCode()).append(getLineSeparator());
- } else {
- String additionCode = object.getAdditionCode();
- if (additionCode.length() > 0) {
- code.append(object.getAdditionMethodName()).append("();").append(getLineSeparator());
- additionCode = "if (allComponentsCreated) {" + getLineSeparator() + additionCode + "}";
- javaFile.addMethod(new JavaMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), null, null, additionCode));
- }
- }
- //code.append(getLineSeparator());
- }
-
- code.append(initDataBindings);
-
- if (lateInitializer.length() > 0) {
- code.append(lateInitializer);
- code.append(getLineSeparator());
- }
-
- if (hasValidator()) {
- // register validator
- for (CompiledBeanValidator validator : validators) {
- String id = TypeManager.getJavaCode(validator.getId());
- code.append("validatorIds.add(").append(id).append(");");
- code.append(getLineSeparator());
- code.append("getValidator(").append(id).append(").installUIs();");
- code.append("getValidator(").append(id).append(").validate();");
- code.append(getLineSeparator());
- }
- }
- return new JavaMethod(Modifier.PRIVATE, "void", "$completeSetup", null, null, code.toString());
- }
-
-
- protected JavaMethod createProcessDataBindingMethod() {
- StringBuffer code = new StringBuffer();
- boolean superclassIsJAXXObject = ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(root.getObjectClass());
- // the force parameter forces the update to happen even if it is already in activeBindings. This
- // is used on superclass invocations b/c by the time the call gets to the superclass, it is already
- // marked active and would otherwise be skipped
- if (processDataBinding.length() > 0) {
- code.append(" if (!$force && $activeBindings.contains($dest)) return;");
- code.append(getLineSeparator());
- code.append(" $activeBindings.add($dest);");
- code.append(getLineSeparator());
- code.append(" try {");
- code.append(getLineSeparator());
- if (processDataBinding.length() > 0) {
- code.append(processDataBinding);
- code.append(getLineSeparator());
- }
- if (superclassIsJAXXObject) {
- code.append(" else");
- code.append(getLineSeparator());
- code.append(" super.processDataBinding($dest, true);");
- code.append(getLineSeparator());
- }
- code.append(" }");
- code.append(getLineSeparator());
- code.append(" finally {");
- code.append(getLineSeparator());
- code.append(" $activeBindings.remove($dest);");
- code.append(getLineSeparator());
- code.append(" }");
- code.append(getLineSeparator());
- } else if (superclassIsJAXXObject) {
- code.append(" super.processDataBinding($dest, true);");
- code.append(getLineSeparator());
- }
- return new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding",
- new JavaArgument[]{new JavaArgument("String", "$dest"), new JavaArgument("boolean", "$force")},
- null, code.toString());
- }
-
-
- protected void createJavaFile(String packageName, String className) throws CompilerException {
- String fullClassName = packageName != null ? packageName + "." + className : className;
- if (root == null) {
- throw new CompilerException("root tag must be a class tag");
- }
- ClassDescriptor superclass = root.getObjectClass();
- boolean superclassIsJAXXObject = ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(superclass);
- javaFile.setModifiers(Modifier.PUBLIC);
- javaFile.setClassName(fullClassName);
- javaFile.setSuperClass(getCanonicalName(superclass));
- javaFile.setInterfaces(new String[]{getCanonicalName(JAXXObject.class)});
-
- for (CompiledObject object : objects.values()) {
- if (!object.isOverride() && !(object instanceof ScriptInitializer)) {
- int access = object.getId().startsWith("$") ? Modifier.PRIVATE : Modifier.PROTECTED;
- if (object == root) {
- javaFile.addField(new JavaField(access, fullClassName, object.getId(), "this"));
- } else {
- //TC -20081017 can have generic on compiled Object
- javaFile.addField(new JavaField(access, getCanonicalName(object), object.getId()));
- //javaFile.addField(new JavaField(access, getCanonicalName(object.getObjectClass()), object.getId()));
- }
- }
- }
-
- if (!superclassIsJAXXObject) {
- // add logger
- if (getOptions().isAddLogger()) {
- javaFile.addImport("org.apache.commons.logging.Log");
- javaFile.addImport("org.apache.commons.logging.LogFactory");
- javaFile.addField(createLoggerField(fullClassName));
- }
-
- javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<Object>", "$activeBindings", "new ArrayList<Object>()"));
- javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.Map<String,Object>", "$bindingSources", "new HashMap<String,Object>()"));
- }
-
- javaFile.addImport("jaxx.runtime.validator.BeanValidator");
- javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<String>", "validatorIds", "new ArrayList<String>()"));
-
- if (stylesheet != null) {
- javaFile.addField(new JavaField(0, "java.util.Map", "$previousValues", "new java.util.HashMap()"));
- }
-
- javaFile.addMethod(createConstructor(className));
- javaFile.addMethod(createInitializer(className));
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "BeanValidator<?>", "getValidator", new JavaArgument[]{new JavaArgument("String", "validatorId")},
- null, "return (BeanValidator)(validatorIds.contains(validatorId)?getObjectById(validatorId):null);"));
-
- for (DataBinding dataBinding : dataBindings) {
- if (dataBinding.compile(true)) {
- initDataBindings.append("applyDataBinding(").append(TypeManager.getJavaCode(dataBinding.getId())).append(");").append(JAXXCompiler.getLineSeparator());
- }
- }
-
- javaFile.addBodyCode(bodyCode.toString());
-
- for (CompiledObject object : objects.values()) {
- if (!inlineCreation(object) && object != root) {
- javaFile.addMethod(new JavaMethod(Modifier.PROTECTED, "void", object.getCreationMethodName(), null, null, getCreationCode(object)));
- }
- }
-
- javaFile.addField(new JavaField(Modifier.PRIVATE, "boolean", "allComponentsCreated"));
-
- javaFile.addMethod(createCompleteSetupMethod());
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "$binding")},
- null, applyDataBinding.toString() + getLineSeparator() + " processDataBinding($binding);"));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "$binding")},
- null, removeDataBinding.toString()));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "dest")},
- null, "processDataBinding(dest, false);"));
-
- javaFile.addMethod(createProcessDataBindingMethod());
-
- if (!superclassIsJAXXObject) {
- javaFile.addField(createObjectMap());
- javaFile.addMethod(createGetObjectByIdMethod());
- }
-
- javaFile.addField(createJAXXObjectDescriptorField());
- javaFile.addMethod(createGetJAXXObjectDescriptorMethod());
-
- /*
- * Gestion du context
- */
- javaFile.addField(createContextField());
- javaFile.addMethod(createSetContextValueMethod());
- javaFile.addMethod(createSetContextValueNameMethod());
- javaFile.addMethod(createGetContextValueMethod());
- javaFile.addMethod(createGetContextValueNameMethod());
- javaFile.addMethod(createGetParentContainer());
- javaFile.addMethod(createGetParentContainerMore());
- ClassDescriptor currentClass = root.getObjectClass();
- MethodDescriptor firePropertyChange = null;
- while (firePropertyChange == null && currentClass != null) {
- try {
- firePropertyChange = currentClass.getDeclaredMethodDescriptor("firePropertyChange", new ClassDescriptor[]{
- ClassDescriptorLoader.getClassDescriptor(String.class),
- ClassDescriptorLoader.getClassDescriptor(Object.class),
- ClassDescriptorLoader.getClassDescriptor(Object.class)
- });
-
- }
- catch (NoSuchMethodException e) {
- currentClass = currentClass.getSuperclass();
- }
- }
-
- int modifiers = firePropertyChange != null ? firePropertyChange.getModifiers() : 0;
- if (Modifier.isPublic(modifiers)) {
- // we have all the support we need
- }
- if (Modifier.isProtected(modifiers)) {
- // there is property change support but the firePropertyChange method is protected
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "firePropertyChange", new JavaArgument[]{
- new JavaArgument("java.lang.String", "propertyName"), new JavaArgument("java.lang.Object", "oldValue"), new JavaArgument("java.lang.Object", "newValue")},
- null, "super.firePropertyChange(propertyName, oldValue, newValue);"));
- } else {
- // either no support at all or firePropertyChange isn't accessible
- addPropertyChangeSupport(javaFile);
- }
-
- addEventHandlers(javaFile);
-
- if (ClassDescriptorLoader.getClassDescriptor(Application.class).isAssignableFrom(root.getObjectClass()) && !mainDeclared) {
- // TODO: check for existing main method first
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC | Modifier.STATIC, "void", "main",
- new JavaArgument[]{new JavaArgument("String[]", "arg")}, null,
- "SwingUtilities.invokeLater(new Runnable() { public void run() { new " + className + "().setVisible(true); } });"));
- }
- }
-
-
- protected void outputClass(String packageName, String className, PrintWriter out) throws CompilerException {
- createJavaFile(packageName, className);
- out.println(javaFile.toString());
- }
-
-
- public void addImport(String text) {
- if (text.endsWith("*")) {
- importedPackages.add(text.substring(0, text.length() - 1));
- } else {
- importedClasses.add(text);
- }
-
- if (!text.equals("*")) {
- getJavaFile().addImport(text);
- }
- }
-
- private JavaField createLoggerField(String className) {
- return new JavaField(Modifier.PUBLIC + Modifier.STATIC + Modifier.FINAL, "Log", "log", "LogFactory.getLog(" + className + ".class)");
- }
-
- /*
- * Gestion du context
- */
- private JavaField createContextField() {
- return new JavaField(Modifier.PROTECTED, "Map<Object,String>", "$contextMap", "new HashMap<Object,String>()");
- }
-
- private JavaMethod createSetContextValueMethod() {
-
- return new JavaMethod(Modifier.PUBLIC, "void", "setContextValue",
- new JavaArgument[]{new JavaArgument("Object", "clazz")}, null, getSetContextValueMethodCode());
- }
-
- private JavaMethod createSetContextValueNameMethod() {
- return new JavaMethod(Modifier.PUBLIC, "void", "setContextValue",
- new JavaArgument[]{new JavaArgument("Object", "clazz"), new JavaArgument("String", "name")}, null, getSetContextValueNameMethodCode());
- }
-
- private JavaMethod createGetContextValueMethod() {
- return new JavaMethod(Modifier.PUBLIC, "<T> T", "getContextValue",
- new JavaArgument[]{new JavaArgument("Class<T>", "clazz")}, null, getGetContextValueMethodCode());
- }
-
- private JavaMethod createGetContextValueNameMethod() {
- return new JavaMethod(Modifier.PUBLIC, "<T> T", "getContextValue",
- new JavaArgument[]{new JavaArgument("Class<T>", "clazz"), new JavaArgument("String", "name")}, null, getGetContextValueNameMethodCode());
- }
-
- private JavaMethod createGetParentContainer() {
- return new JavaMethod(Modifier.PUBLIC, "<O extends Container> O", "getParentContainer",
- new JavaArgument[]{new JavaArgument("Class<O>", "clazz")}, null, getGetParentContenerMethodCode());
- }
-
- private JavaMethod createGetParentContainerMore() {
- return new JavaMethod(Modifier.PUBLIC, "<O extends Container> O", "getParentContainer",
- new JavaArgument[]{new JavaArgument("Object", "source"), new JavaArgument("Class<O>", "clazz")}, null, getGetParentContenerMethodMoreCode());
- }
-
- private String getSetContextValueMethodCode() {
- return "this.setContextValue(clazz, null);";
- }
-
- private String getSetContextValueNameMethodCode() {
- StringBuffer result = new StringBuffer();
- result.append("$contextMap.put(clazz, name);");
- return result.toString();
- }
-
- private String getGetContextValueMethodCode() {
- return "return this.getContextValue(clazz, null);";
- }
-
- private String getGetContextValueNameMethodCode() {
- StringBuffer result = new StringBuffer();
- result.append("for (Map.Entry<Object,String> entry : $contextMap.entrySet()) {");
- result.append("if (clazz.isAssignableFrom(entry.getKey().getClass()) && (name == null || name == entry.getValue())) {");
- result.append("return (T) entry.getKey();}}");
- result.append("return null;");
- return result.toString();
- }
-
- private String getGetParentContenerMethodCode() {
- StringBuffer result = new StringBuffer();
- result.append("return this.getParentContainer(this, clazz);");
- return result.toString();
- }
-
- private String getGetParentContenerMethodMoreCode() {
- StringBuffer result = new StringBuffer();
- result.append("if (!Container.class.isAssignableFrom(source.getClass())) {return null;}");
- result.append(getLineSeparator());
- result.append("Container parent = ((Container)source).getParent();");
- result.append(getLineSeparator());
- result.append("if (parent != null && !clazz.isAssignableFrom(parent.getClass())){parent = getParentContainer(parent, clazz);}");
- result.append(getLineSeparator());
- result.append("return (O)parent;");
- return result.toString();
- }
-
- private JavaField createObjectMap() {
- return new JavaField(Modifier.PROTECTED, "Map<String,Object>", "$objectMap", "new HashMap<String,Object>()");
- }
-
-
- protected JavaMethod createGetObjectByIdMethod() {
- return new JavaMethod(Modifier.PUBLIC, "java.lang.Object", "getObjectById",
- new JavaArgument[]{new JavaArgument("String", "id")}, null,
- "return $objectMap.get(id);");
- }
-
-
- public JAXXObjectDescriptor getJAXXObjectDescriptor() {
- runInitializers();
- CompiledObject[] components = new ArrayList<CompiledObject>(objects.values()).toArray(new CompiledObject[objects.size()]);
- assert initializers.isEmpty() : "there are pending initializers remaining";
- assert root != null : "root object has not been defined";
- assert Arrays.asList(components).contains(root) : "root object is not registered";
- ComponentDescriptor[] descriptors = new ComponentDescriptor[components.length];
- // as we print, sort the array so that component's parents are always before the components themselves
- for (int i = 0; i < components.length; i++) {
- CompiledObject parent = components[i].getParent();
- while (parent != null) {
- boolean found = false;
- for (int j = i + 1; j < components.length; j++) { // found parent after component, swap them
- if (components[j] == parent) {
- components[j] = components[i];
- components[i] = parent;
- found = true;
- break;
- }
- }
- if (!found) {
- break;
- }
- parent = components[i].getParent();
- }
- int parentIndex = -1;
- if (parent != null) {
- for (int j = 0; j < i; j++) {
- if (components[j] == parent) {
- parentIndex = j;
- break;
- }
- }
- }
- descriptors[i] = new ComponentDescriptor(components[i].getId(), components[i] == root ? outputClassName : components[i].getObjectClass().getName(),
- components[i].getStyleClass(), parentIndex != -1 ? descriptors[parentIndex] : null);
- }
-
- Stylesheet stylesheet = getStylesheet();
- if (stylesheet == null) {
- stylesheet = new Stylesheet();
- }
-
- return new JAXXObjectDescriptor(descriptors, stylesheet);
- }
-
-
- protected JavaField createJAXXObjectDescriptorField() {
- try {
- JAXXObjectDescriptor descriptor = getJAXXObjectDescriptor();
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(buffer));
- out.writeObject(descriptor);
- out.close();
- // the use of the weird deprecated constructor is deliberate -- we need to store the data as a String
- // in the compiled class file, since byte array initialization is horribly inefficient compared to
- // String initialization. So we store the bytes in the String, and we quite explicitly want a 1:1
- // mapping between bytes and chars, with the high byte of the char set to zero. We can then safely
- // reconstitute the original byte[] at a later date. This is unquestionably an abuse of the String
- // type, but if we could efficiently store a byte[] we wouldn't have to do this.
- String data = new String(buffer.toByteArray(), 0);
-
- int sizeLimit = 65000; // constant strings are limited to 64K, and I'm not brave enough to push right up to the limit
- if (data.length() < sizeLimit) {
- return new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", "$jaxxObjectDescriptor", TypeManager.getJavaCode(data));
- } else {
- StringBuffer initializer = new StringBuffer();
- for (int i = 0; i < data.length(); i += sizeLimit) {
- String name = "$jaxxObjectDescriptor" + i;
- javaFile.addField(new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", name,
- TypeManager.getJavaCode(data.substring(i, Math.min(i + sizeLimit, data.length())))));
- if (initializer.length() > 0) {
- initializer.append(" + ");
- }
- initializer.append("String.valueOf(").append(name).append(")");
- }
- return new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", "$jaxxObjectDescriptor", initializer.toString());
- }
- }
- catch (IOException e) {
- throw new RuntimeException("Internal error: can't-happen error", e);
- }
- }
-
-
- protected JavaMethod createGetJAXXObjectDescriptorMethod() {
- return new JavaMethod(Modifier.PUBLIC | Modifier.STATIC, "jaxx.runtime.JAXXObjectDescriptor", "$getJAXXObjectDescriptor",
- null, null, "return jaxx.runtime.Util.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);");
- }
-
-
- public String getEventHandlerMethodName(EventHandler handler) {
- String result = eventHandlerMethodNames.get(handler);
- if (result == null) {
- result = "$ev" + eventHandlerMethodNames.size();
- eventHandlerMethodNames.put(handler, result);
- }
- return result;
- }
-
- protected void addEventHandlers(JavaFile javaFile) {
- for (Map.Entry<String, Map<ClassDescriptor, List<EventHandler>>> e1 : eventHandlers.entrySet()) {
- // outer loop is iterating over different objects (well, technically, different Java expressions)
- for (Map.Entry<ClassDescriptor, List<EventHandler>> e2 : e1.getValue().entrySet()) {
- // iterate over different types of listeners for this particular object (MouseListener, ComponentListener, etc.)
- for (EventHandler handler : e2.getValue()) {
- // iterate over individual event handlers of a single type
- String methodName = getEventHandlerMethodName(handler);
- MethodDescriptor listenerMethod = handler.getListenerMethod();
- if (listenerMethod.getParameterTypes().length != 1) {
- throw new CompilerException("Expected event handler " + listenerMethod.getName() + " of class " + handler.getListenerClass() + " to have exactly one argument");
- }
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", methodName,
- new JavaArgument[]{new JavaArgument(getCanonicalName(listenerMethod.getParameterTypes()[0]), "event")}, null,
- handler.getJavaCode()));
-
- }
- }
- }
- }
-
- protected String getCreationCode(CompiledObject object) throws CompilerException {
- if (object instanceof ScriptInitializer) {
- return object.getInitializationCode(this);
- }
- StringBuffer result = new StringBuffer();
- result.append(object.getId());
- result.append(" = ");
- String constructorParams = object.getConstructorParams();
- if (constructorParams != null) {
- //TC - 20081017 compiledObject can have generics
- result.append(" new ").append(getCanonicalName(object)).append("(").append(constructorParams).append(");");
- //result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
- } else {
- //TC - 20081017 compiledObject can have generics
- result.append("new ").append(getCanonicalName(object)).append("();");
- }
- result.append(getLineSeparator());
- String initCode = object.getInitializationCode(this);
- if (initCode != null && initCode.length() > 0) {
- result.append(initCode);
- }
- result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
-
- return result.toString();
- }
-
-
- protected void addPropertyChangeSupport(JavaFile javaFile) throws CompilerException {
- javaFile.addField(new JavaField(0, "java.beans.PropertyChangeSupport", "$propertyChangeSupport"));
-
- javaFile.addMethod(new JavaMethod(0, "java.beans.PropertyChangeSupport", "$getPropertyChangeSupport", null, null,
- "if ($propertyChangeSupport == null)\n" +
- " $propertyChangeSupport = new PropertyChangeSupport(this);\n" +
- "return $propertyChangeSupport;"));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "addPropertyChangeListener", new JavaArgument[]{
- new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
- "$getPropertyChangeSupport().addPropertyChangeListener(listener);"));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "addPropertyChangeListener", new JavaArgument[]{
- new JavaArgument("java.lang.String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
- "$getPropertyChangeSupport().addPropertyChangeListener(property, listener);"));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removePropertyChangeListener", new JavaArgument[]{
- new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
- "$getPropertyChangeSupport().removePropertyChangeListener(listener);"));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removePropertyChangeListener", new JavaArgument[]{
- new JavaArgument("java.lang.String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
- "$getPropertyChangeSupport().removePropertyChangeListener(property, listener);"));
-
- javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "firePropertyChange", new JavaArgument[]{
- new JavaArgument("java.lang.String", "propertyName"), new JavaArgument("java.lang.Object", "oldValue"), new JavaArgument("java.lang.Object", "newValue")},
- null, "$getPropertyChangeSupport().firePropertyChange(propertyName, oldValue, newValue);"));
- }
-
-
public void compileFirstPass(final Element tag) throws IOException {
tagsBeingCompiled.push(tag);
@@ -1194,144 +302,36 @@
}
-
- // 1.5 adds getCanonicalName; unfortunately we can't depend on 1.5 features yet
- public static String getCanonicalName(Class clazz) {
- if (clazz.isArray()) {
- String canonicalName = getCanonicalName(clazz.getComponentType());
- if (canonicalName != null) {
- return canonicalName + "[]";
- }
- return null;
+ protected void compileFirstPass() throws IOException {
+ try {
+ InputStream in = new FileInputStream(src);
+ document = parseDocument(in);
+ in.close();
+ compileFirstPass(document.getDocumentElement());
}
- return clazz.getName().replace('$', '.');
- }
-
-
- public static String getCanonicalName(ClassDescriptor clazz) {
- if (clazz.isArray()) {
- String canonicalName = getCanonicalName(clazz.getComponentType());
- if (canonicalName != null) {
- return canonicalName + "[]";
- }
- return null;
+ catch (SAXParseException e) {
+ reportError(e.getLineNumber(), "Invalid XML: " + e.getMessage());
}
- return clazz.getName().replace('$', '.');
- }
-
-
- public static String getCanonicalName(CompiledObject compiled) {
- ClassDescriptor clazz = compiled.getObjectClass();
- if (clazz.isArray()) {
- String canonicalName = getCanonicalName(clazz.getComponentType());
- if (canonicalName != null) {
- if (compiled.getGenericTypes().length > 0) {
- canonicalName += "<";
- for (int i = 0; i < compiled.getGenericTypes().length; i++) {
- ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
- if (i > 0) {
- canonicalName += " ,";
- }
- canonicalName += classDescriptor.getName();
- }
- canonicalName += ">";
-
- }
- return canonicalName + "[]";
- }
- return null;
+ catch (SAXException e) {
+ reportError(null, "Error parsing XML document: " + e);
}
-
- String canonicalName = clazz.getName().replace('$', '.');
- if (compiled.getGenericTypes().length > 0) {
- canonicalName += "<";
- for (int i = 0; i < compiled.getGenericTypes().length; i++) {
- ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
- if (i > 0) {
- canonicalName += " ,";
- }
- canonicalName += classDescriptor.getName();
- }
- canonicalName += ">";
-
- }
- return canonicalName;
}
-
- public static String capitalize(String s) {
- if (s.length() == 0) {
- return s;
+ protected void compileSecondPass() throws IOException {
+ if (!tagsBeingCompiled.isEmpty()) {
+ throw new RuntimeException("Internal error: starting pass two, but tagsBeingCompiled is not empty: " + tagsBeingCompiled);
}
- return Character.toUpperCase(s.charAt(0)) + s.substring(1);
+ compileSecondPass(document.getDocumentElement());
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- CompiledObject methods -------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
- public String[] parseParameterList(String parameters) throws CompilerException {
- List<String> result = new ArrayList<String>();
- StringBuffer current = new StringBuffer();
- int state = 0; // normal
- for (int i = 0; i < parameters.length(); i++) {
- char c = parameters.charAt(i);
- switch (state) {
- case 0: // normal
- switch (c) {
- case '"':
- current.append(c);
- state = 1;
- break; // in quoted string
- case '\\':
- current.append(c);
- state = 2;
- break; // immediately after backslash
- case ',':
- if (current.length() > 0) {
- result.add(current.toString());
- current.setLength(0);
- break;
- } else {
- reportError("error parsing parameter list: " + parameters);
- }
- default:
- current.append(c);
- }
- break;
- case 1: // in quoted string
- switch (c) {
- case '"':
- current.append(c);
- state = 0;
- break; // normal
- case '\\':
- current.append(c);
- state = 3;
- break; // immediate after backslash in quoted string
- default:
- current.append(c);
- }
- break;
- case 2: // immediately after backslash
- current.append(c);
- state = 0; // normal
- break;
- case 3: // immediately after backslash in quoted string
- current.append(c);
- state = 1; // in quoted string
- break;
- }
- }
- if (current.length() > 0) {
- result.add(current.toString());
- }
- return result.toArray(new String[result.size()]);
- }
-
-
public void openComponent(CompiledObject component) throws CompilerException {
openComponent(component, null);
}
-
public void openComponent(CompiledObject component, String constraints) throws CompilerException {
CompiledObject parent = getOpenComponent();
openInvisibleComponent(component);
@@ -1340,7 +340,6 @@
}
}
-
public void openInvisibleComponent(CompiledObject component) {
if (!ids.containsKey(component)) {
registerCompiledObject(component);
@@ -1348,7 +347,6 @@
openComponents.push(component);
}
-
public CompiledObject getOpenComponent() {
if (openComponents.isEmpty()) {
return null;
@@ -1356,19 +354,12 @@
return openComponents.peek();
}
-
public void closeComponent(CompiledObject component) {
if (openComponents.pop() != component) {
throw new IllegalArgumentException("can only close the topmost open object");
}
}
-
- public CompiledObject getRootObject() {
- return root;
- }
-
-
public void registerCompiledObject(CompiledObject object) {
assert symbolTables.values().contains(symbolTable) : "attempting to register CompiledObject before pass 1 is complete";
if (root == null) {
@@ -1386,33 +377,6 @@
ids.put(object, id);
}
-
- public String getAutoId(ClassDescriptor objectClass) {
- if (options.getOptimize()) {
- return "$" + Integer.toString(autogenID++, 36);
- } else {
- String name = objectClass.getName();
- name = name.substring(name.lastIndexOf(".") + 1);
- return "$" + name + autogenID++;
- }
- }
-
-
- public String getUniqueId(Object object) {
- String result = uniqueIds.get(object);
- if (result == null) {
- result = "$u" + uniqueIds.size();
- uniqueIds.put(object, result);
- }
- return result;
- }
-
-
- public SymbolTable getSymbolTable() {
- return symbolTable;
- }
-
-
public CompiledObject getCompiledObject(String id) {
runInitializers();
assert symbolTables.values().contains(symbolTable) : "attempting to retrieve CompiledObject before pass 1 is complete";
@@ -1420,40 +384,36 @@
}
- private Matcher leftBraceMatcher = Pattern.compile("^(\\{)|[^\\\\](\\{)").matcher("");
-
- private int getNextLeftBrace(String string, int pos) {
- leftBraceMatcher.reset(string);
- return leftBraceMatcher.find(pos) ? Math.max(leftBraceMatcher.start(1), leftBraceMatcher.start(2)) : -1;
+ protected boolean inlineCreation(CompiledObject object) {
+ return object.getId().startsWith("$") && object.getInitializationCode(this).length() < INLINE_THRESHOLD;
}
-
- private Matcher rightBraceMatcher = Pattern.compile("^(\\})|[^\\\\](\\})").matcher("");
-
- private int getNextRightBrace(String string, int pos) {
- leftBraceMatcher.reset(string);
- rightBraceMatcher.reset(string);
- int openCount = 1;
- int rightPos;
- while (openCount > 0) {
- pos++;
- int leftPos = leftBraceMatcher.find(pos) ? Math.max(leftBraceMatcher.start(1), leftBraceMatcher.start(2)) : -1;
- rightPos = rightBraceMatcher.find(pos) ? Math.max(rightBraceMatcher.start(1), rightBraceMatcher.start(2)) : -1;
- assert leftPos == -1 || leftPos >= pos;
- assert rightPos == -1 || rightPos >= pos;
- if (leftPos != -1 && leftPos < rightPos) {
- pos = leftPos;
- openCount++;
- } else if (rightPos != -1) {
- pos = rightPos;
- openCount--;
- } else {
- openCount = 0;
+ public void checkOverride(CompiledObject object) throws CompilerException {
+ if (object.getId().startsWith("$")) {
+ return;
+ }
+ ClassDescriptor ancestor = root.getObjectClass();
+ if (ancestor == object.getObjectClass()) {
+ return;
+ }
+ while (ancestor != null) {
+ try {
+ FieldDescriptor f = ancestor.getDeclaredFieldDescriptor(object.getId());
+ if (!f.getType().isAssignableFrom(object.getObjectClass())) {
+ reportError("attempting to redefine superclass member '" + object.getId() + "' as incompatible type (was " + f.getType() + ", redefined as " + object.getObjectClass() + ")");
+ }
+ object.setOverride(true);
+ break;
}
+ catch (NoSuchFieldException e) {
+ ancestor = ancestor.getSuperclass();
+ }
}
- return pos;
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- DataBinding methods ----------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
/**
* Examine an attribute value for data binding expressions. Returns a 'cooked' expression which
@@ -1525,27 +485,6 @@
}
}
-
- public ScriptManager getScriptManager() {
- return scriptManager;
- }
-
-
- /**
- * Verifies that a snippet of Java code parses correctly. A warning is generated if the string has enclosing
- * curly braces.
- *
- * @param javaCode the Java code snippet to test
- * @return a "cooked" version of the string which has enclosing curly braces removed.
- * @throws CompilerException if the code cannot be parsed
- */
- public String checkJavaCode(String javaCode) {
- javaCode = scriptManager.trimScript(javaCode);
- scriptManager.checkParse(javaCode);
- return javaCode;
- }
-
-
public void registerEventHandler(EventHandler handler) {
String objectCode = handler.getObjectCode();
Map<ClassDescriptor, List<EventHandler>> listeners = eventHandlers.get(objectCode);
@@ -1562,37 +501,34 @@
handlerList.add(handler);
}
-
- public FieldDescriptor[] getScriptFields() {
- List<FieldDescriptor> scriptFields = symbolTable.getScriptFields();
- return scriptFields.toArray(new FieldDescriptor[scriptFields.size()]);
+ public String getEventHandlerMethodName(EventHandler handler) {
+ String result = eventHandlerMethodNames.get(handler);
+ if (result == null) {
+ result = "$ev" + eventHandlerMethodNames.size();
+ eventHandlerMethodNames.put(handler, result);
+ }
+ return result;
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- Script methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
public void addScriptField(FieldDescriptor field) {
symbolTable.getScriptFields().add(field);
}
-
- public MethodDescriptor[] getScriptMethods() {
- List<MethodDescriptor> scriptMethods = symbolTable.getScriptMethods();
- return scriptMethods.toArray(new MethodDescriptor[scriptMethods.size()]);
- }
-
-
public void addScriptMethod(MethodDescriptor method) {
if (method.getName().equals("main") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0].getName().equals("[Ljava.lang.String;")) {
- mainDeclared = true;
+ generator.setMainDeclared(true);
}
symbolTable.getScriptMethods().add(method);
}
-
public void registerScript(String script) throws CompilerException {
registerScript(script, null);
}
-
public void registerScript(String script, File sourceFile) throws CompilerException {
if (sourceFile != null) {
sourceFiles.push(sourceFile);
@@ -1611,12 +547,21 @@
}
}
-
public String preprocessScript(String script) throws CompilerException {
return scriptManager.preprocessScript(script);
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- StyleSheet methods -----------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+ protected void applyStylesheets() {
+ for (Object o : new ArrayList<CompiledObject>(objects.values())) {
+ CompiledObject object = (CompiledObject) o;
+ TagManager.getTagHandler(object.getObjectClass()).applyStylesheets(object, this);
+ }
+ }
+
public void registerStylesheet(Stylesheet stylesheet) {
if (this.stylesheet == null) {
this.stylesheet = stylesheet;
@@ -1625,26 +570,13 @@
}
}
-
- public Stylesheet getStylesheet() {
- Stylesheet merged = new Stylesheet();
- if (stylesheet != null) {
- merged.add(stylesheet.getRules());
- }
- merged.add(inlineStyles.toArray(new Rule[inlineStyles.size()]));
- return merged;
- }
-
-
- public Stack<File> getSourceFiles() {
- return sourceFiles;
- }
-
-
public void addInlineStyle(CompiledObject object, String propertyName, boolean dataBinding) {
inlineStyles.add(Rule.inlineAttribute(object, propertyName, dataBinding));
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- Report methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
public void reportWarning(String warning) {
Element currentTag = null;
@@ -1688,12 +620,10 @@
reportError(currentTag, error);
}
-
public void reportError(CompilerException ex) {
reportError(null, ex);
}
-
public void reportError(String extraMessage, CompilerException ex) {
String message = ex.getMessage();
if (ex.getClass() == UnsupportedAttributeException.class || ex.getClass() == UnsupportedTagException.class) {
@@ -1712,12 +642,10 @@
reportError(currentTag, extraMessage != null ? extraMessage + message : message, lineOffset);
}
-
public void reportError(Element tag, String error) {
reportError(tag, error, 0);
}
-
public void reportError(Element tag, String error, int lineOffset) {
int lineNumber = 0;
if (tag != null) {
@@ -1730,7 +658,6 @@
reportError(lineNumber, error);
}
-
public void reportError(int lineNumber, String error) {
File src = sourceFiles.isEmpty() ? null : sourceFiles.peek();
try {
@@ -1751,50 +678,129 @@
failed = true;
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- Validator methods ------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
/**
- * Escapes a string using standard Java escape sequences, generally in preparation to including it in a string literal
- * in a compiled Java file.
+ * Register in this compiler a new compiled validator.
*
- * @param raw the raw string to be escape
- * @return a string in which all 'dangerous' characters have been replaced by equivalent Java escape sequences
+ * @param validator the compiled validator to register
*/
- public static String escapeJavaString(String raw) {
- StringBuffer out = new StringBuffer(raw);
- for (int i = 0; i < out.length(); i++) {
- char c = out.charAt(i);
- if (c == '\\' || c == '"') {
- out.insert(i, '\\');
- i++;
- } else if (c == '\n') {
- out.replace(i, i + 1, "\\n");
- i++;
- } else if (c == '\r') {
- out.replace(i, i + 1, "\\r");
- i++;
- } else if (c < 32 || c > 127) {
- String value = Integer.toString((int) c, 16);
- while (value.length() < 4) {
- value = "0" + value;
- }
- out.replace(i, i + 1, "\\u" + value);
- i += 5;
- }
- }
- return out.toString();
+ public void registerValidator(CompiledBeanValidator validator) {
+ validators.add(validator);
+ validatedComponents.addAll(validator.getFields().values());
}
+ /** @return <code>true</code> if some validators were detected, <code>false</code> otherwise */
+ public boolean hasValidator() {
+ return !validators.isEmpty();
+ }
/**
- * Returns the system line separator string.
+ * Test if a given CompiledObject is attached to a validator.
*
- * @return the string used to separate lines
+ * @param componentId the compiled object to test
+ * @return <code>true</code> if the given compiled object is attached to a validator, <code>false</code> otherwise
*/
- public static String getLineSeparator() {
- return System.getProperty("line.separator", "\n");
+ public boolean isComponentUsedByValidator(String componentId) {
+ return validatedComponents.contains(componentId);
}
+ /**
+ * Test if a given bean is attached to a validator.
+ *
+ * @param beanId the bean to test
+ * @return <code>true</code> if the given bean is attached to a validator, <code>false</code> otherwise
+ */
+ public boolean isBeanUsedByValidator(String beanId) {
+ for (CompiledBeanValidator validator : validators) {
+ if (beanId.equals(validator.getBean())) {
+ return true;
+ }
+ }
+ return false;
+ }
+ /*---------------------------------------------------------------------------------*/
+ /*-- Getter methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ public Map<String, CompiledObject> getObjects() {
+ return objects;
+ }
+
+ public List<DataBinding> getDataBindings() {
+ return dataBindings;
+ }
+
+ public List<CompiledBeanValidator> getValidators() {
+ return validators;
+ }
+
+ public Map<String, Map<ClassDescriptor, List<EventHandler>>> getEventHandlers() {
+ return eventHandlers;
+ }
+
+ public CompilerOptions getOptions() {
+ return options;
+ }
+
+ public String getOutputClassName() {
+ return outputClassName;
+ }
+
+ public File getBaseDir() {
+ return baseDir;
+ }
+
+ public Set<String> getImportedClasses() {
+ return importedClasses;
+ }
+
+ public Set<String> getImportedPackages() {
+ return importedPackages;
+ }
+
+ protected Iterator<CompiledObject> getObjectCreationOrder() {
+ return objects.values().iterator();
+ }
+
+ public CompiledObject getRootObject() {
+ return root;
+ }
+
+ public Stack<File> getSourceFiles() {
+ return sourceFiles;
+ }
+
+ public ScriptManager getScriptManager() {
+ return scriptManager;
+ }
+
+ public SymbolTable getSymbolTable() {
+ return symbolTable;
+ }
+
+ public Stylesheet getStylesheet() {
+ Stylesheet merged = new Stylesheet();
+ if (stylesheet != null) {
+ merged.add(stylesheet.getRules());
+ }
+ merged.add(inlineStyles.toArray(new Rule[inlineStyles.size()]));
+ return merged;
+ }
+
+ public FieldDescriptor[] getScriptFields() {
+ List<FieldDescriptor> scriptFields = symbolTable.getScriptFields();
+ return scriptFields.toArray(new FieldDescriptor[scriptFields.size()]);
+ }
+
+ public MethodDescriptor[] getScriptMethods() {
+ List<MethodDescriptor> scriptMethods = symbolTable.getScriptMethods();
+ return scriptMethods.toArray(new MethodDescriptor[scriptMethods.size()]);
+ }
+
/**
* Returns a <code>ClassLoader</code> which searches the user-specified class path in addition
* to the normal system class path.
@@ -1823,48 +829,132 @@
return classLoader;
}
+ public JAXXObjectDescriptor getJAXXObjectDescriptor() {
+ runInitializers();
+ CompiledObject[] components = new ArrayList<CompiledObject>(objects.values()).toArray(new CompiledObject[objects.size()]);
+ assert initializers.isEmpty() : "there are pending initializers remaining";
+ assert root != null : "root object has not been defined";
+ assert Arrays.asList(components).contains(root) : "root object is not registered";
+ ComponentDescriptor[] descriptors = new ComponentDescriptor[components.length];
+ // as we print, sort the array so that component's parents are always before the components themselves
+ for (int i = 0; i < components.length; i++) {
+ CompiledObject parent = components[i].getParent();
+ while (parent != null) {
+ boolean found = false;
+ for (int j = i + 1; j < components.length; j++) { // found parent after component, swap them
+ if (components[j] == parent) {
+ components[j] = components[i];
+ components[i] = parent;
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ break;
+ }
+ parent = components[i].getParent();
+ }
+ int parentIndex = -1;
+ if (parent != null) {
+ for (int j = 0; j < i; j++) {
+ if (components[j] == parent) {
+ parentIndex = j;
+ break;
+ }
+ }
+ }
+ descriptors[i] = new ComponentDescriptor(components[i].getId(), components[i] == root ? outputClassName : components[i].getObjectClass().getName(),
+ components[i].getStyleClass(), parentIndex != -1 ? descriptors[parentIndex] : null);
+ }
- /**
- * @param className the name of the class to use
- * @return the compiler instance which is processing the specified JAXX class. Each class is compiled by a
- * different compiler instance.
- */
- public static JAXXCompiler getJAXXCompiler(String className) {
- return compilers != null ? compilers.get(className) : null;
+ Stylesheet stylesheet = getStylesheet();
+ if (stylesheet == null) {
+ stylesheet = new Stylesheet();
+ }
+
+ return new JAXXObjectDescriptor(descriptors, stylesheet);
}
+ /*---------------------------------------------------------------------------------*/
+ /*-- Setter methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
- /**
- * @param className the name of the class to use
- * @return the symbol table for the specified JAXX class. Must be called during the second compiler pass.
- * Returns <code>null</code> if no such symbol table could be found.
- */
- public static SymbolTable getSymbolTable(String className) {
- JAXXCompiler compiler = getJAXXCompiler(className);
- if (compiler == null) {
- return null;
- }
- return compiler.getSymbolTable();
+ public void setFailed(boolean failed) {
+ this.failed = failed;
}
- public static File URLtoFile(URL url) {
- return URLtoFile(url.toString());
+ /*---------------------------------------------------------------------------------*/
+ /*-- Delegate methods from JAXXObjectGenerator ------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ public void appendInitializerCode(String code) {
+ generator.getInitializer().append(code);
}
- public static File URLtoFile(String urlString) {
- if (!urlString.startsWith("file:")) {
- throw new IllegalArgumentException("url must start with 'file:'");
+ public void appendBodyCode(String code) {
+ generator.getBodyCode().append(code);
+ }
+
+ public void appendInitDataBindings(String code) {
+ generator.getInitDataBindings().append(code);
+ }
+
+ public void appendProcessDataBinding(String code) {
+ generator.getProcessDataBinding().append(code);
+ }
+
+ public void appendApplyDataBinding(String code) {
+ generator.getApplyDataBinding().append(code);
+ }
+
+ public void appendRemoveDataBinding(String code) {
+ generator.getRemoveDataBinding().append(code);
+ }
+
+ public void appendLateInitializer(String code) {
+ generator.getLateInitializer().append(code);
+ }
+
+ public boolean haveProcessDataBinding() {
+ return generator.getProcessDataBinding().length() > 0;
+ }
+
+ public boolean haveApplyDataBinding() {
+ return generator.getApplyDataBinding().length() > 0;
+ }
+
+ public boolean haveRemoveDataBinding() {
+ return generator.getRemoveDataBinding().length() > 0;
+ }
+
+ public void addMethodToJavaFile(JavaMethod method) {
+ generator.getJavaFile().addMethod(method);
+ }
+
+ public boolean hasMethod(String methodName) {
+ JavaMethod[] methods = generator.getJavaFile().getMethods();
+ for (JavaMethod method : methods) {
+ if (methodName.equals(method.getName())) {
+ return true;
+ }
}
- urlString = urlString.substring("file:".length());
- if (urlString.startsWith("/") && System.getProperty("os.name").startsWith("Windows")) {
- urlString = urlString.substring(1);
+ return false;
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Other methods ----------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ public void addImport(String text) {
+ if (text.endsWith("*")) {
+ importedPackages.add(text.substring(0, text.length() - 1));
+ } else {
+ importedClasses.add(text);
}
- try {
- return new File(URLDecoder.decode(urlString.replace('/', File.separatorChar), "utf-8"));
+
+ if (!text.equals("*")) {
+ generator.getJavaFile().addImport(text);
}
- catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
}
public void addDependencyClass(String className) {
@@ -1905,335 +995,21 @@
}
}
-
/**
- * Compiled a set of files, expressed as paths relative to a base directory. The class names of the compiled files are derived
- * from the relative path strings (e.g. "example/Foo.jaxx" compiles into a class named "example.Foo"). Returns <code>true</code>
- * if compilation succeeds, <code>false</code> if it fails. Warning and error messages are sent to <code>System.err</code>.
+ * Verifies that a snippet of Java code parses correctly. A warning is generated if the string has enclosing
+ * curly braces.
*
- * @param base the directory against which to resolve relative paths
- * @param relativePaths a list of relative paths to .jaxx files being compiled
- * @param options the compiler options to use
- * @return <code>true</code> if compilation succeeds, <code>false</code> otherwise
+ * @param javaCode the Java code snippet to test
+ * @return a "cooked" version of the string which has enclosing curly braces removed.
+ * @throws CompilerException if the code cannot be parsed
*/
- public static synchronized boolean compile(File base, String[] relativePaths, CompilerOptions options) {
- File[] files = new File[relativePaths.length];
- String[] classNames = new String[relativePaths.length];
- for (int i = 0; i < files.length; i++) {
- files[i] = new File(base, relativePaths[i]);
- classNames[i] = relativePaths[i].substring(0, relativePaths[i].lastIndexOf("."));
- classNames[i] = classNames[i].replace(File.separatorChar, '.');
- classNames[i] = classNames[i].replace('/', '.');
- classNames[i] = classNames[i].replace('\\', '.');
- classNames[i] = classNames[i].replace(':', '.');
- }
- return compile(files, classNames, options);
+ public String checkJavaCode(String javaCode) {
+ javaCode = scriptManager.trimScript(javaCode);
+ scriptManager.checkParse(javaCode);
+ return javaCode;
}
-
- /** Resets all state in preparation for a new compilation session. */
- private static void reset() {
- errorCount = 0;
- warningCount = 0;
- jaxxFiles.clear();
- jaxxFileClassNames.clear();
- symbolTables.clear();
- compilers.clear();
- }
-
-
/**
- * Compiled a set of files, with the class names specified explicitly. The class compiled from files[i] will be named classNames[i].
- * Returns <code>true</code> if compilation succeeds, <code>false</code> if it fails. Warning and error messages are sent to
- * <code>System.err</code>.
- *
- * @param files the .jaxx files to compile
- * @param classNames the names of the classes being compiled
- * @param options the compiler options to use
- * @return <code>true</code> if compilation succeeds, <code>false</code> otherwise
- */
- public static synchronized boolean compile(File[] files, String[] classNames, CompilerOptions options) {
- reset(); // just to be safe...
- jaxxFiles.addAll(Arrays.asList(files));
- jaxxFileClassNames.addAll(Arrays.asList(classNames));
- try {
- boolean success = true;
-
- // pass 1
- currentPass = PASS_1;
- boolean compiled;
- do {
- compiled = false;
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- java.util.Iterator<File> filesIterator = new ArrayList<File>(jaxxFiles).iterator(); // clone it so it can safely be modified while we're iterating
- java.util.Iterator<String> classNamesIterator = new ArrayList<String>(jaxxFileClassNames).iterator();
- while (filesIterator.hasNext()) {
- File file = filesIterator.next();
- String className = classNamesIterator.next();
- if (options.isVerbose()) {
- log.info("compile first pass for " + className);
- }
- if (symbolTables.get(file) == null) {
- compiled = true;
- if (compilers.containsKey(className)) {
- throw new CompilerException("Internal error: " + className + " is already being compiled, attempting to compile it again");
- }
-
- File destDir = options.getTargetDirectory();
- if (destDir != null) {
- int dotPos = className.lastIndexOf(".");
- if (dotPos != -1) {
- destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
- }
- destDir.mkdirs();
- } else {
- //destDir = file.getParentFile();
- }
- JAXXCompiler compiler = new JAXXCompiler(file.getParentFile(), file, className, options);
- compilers.put(className, compiler);
- compiler.compileFirstPass();
- assert !symbolTables.values().contains(compiler.getSymbolTable()) : "symbolTable is already registered";
- symbolTables.put(file, compiler.getSymbolTable());
- if (compiler.failed) {
- success = false;
- }
- }
- }
-
- } while (compiled);
-
- // pass 2
- currentPass = PASS_2;
- if (success) {
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- List<File> jaxxFilesClone = new ArrayList<File>(jaxxFiles);
- for (String className : jaxxFileClassNames) {
- JAXXCompiler compiler = compilers.get(className);
- if (compiler == null) {
- throw new CompilerException("Internal error: could not find compiler for " + className + " during second pass");
- }
- if (options.isVerbose()) {
-
- log.info("runInitializers for " + className);
- }
- if (!compiler.failed) {
- compiler.runInitializers();
- }
- if (options.isVerbose()) {
-
- log.info("compile second pass for " + className);
- }
- compiler.compileSecondPass();
- if (options.isVerbose()) {
-
- log.info("done with result [" + !compiler.failed + "] for " + className);
- }
- if (!compiler.failed) {
-
- } else {
- success = false;
- }
- }
- if (!jaxxFilesClone.equals(jaxxFiles)) {
- throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + jaxxFiles + ")");
- }
- }
-
- // stylesheet application
- if (success) {
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- for (String className : jaxxFileClassNames) {
- JAXXCompiler compiler = compilers.get(className);
- if (compiler == null) {
- throw new CompilerException("Internal error: could not find compiler for " + className + " during stylesheet application");
- }
- compiler.applyStylesheets();
- if (compiler.failed) {
- success = false;
- }
- }
- }
-
- // code generation
- if (success) {
- assert jaxxFiles.size() == jaxxFileClassNames.size();
- for (String className : jaxxFileClassNames) {
- JAXXCompiler compiler = compilers.get(className);
- if (compiler == null) {
- throw new CompilerException("Internal error: could not find compiler for " + className + " during code generation");
- }
- compiler.generateCode();
- if (compiler.failed) {
- success = false;
- }
- }
- }
-
- if (warningCount == 1) {
- System.err.println("1 warning");
- } else if (warningCount > 0) {
- System.err.println(warningCount + " warnings");
- }
- if (errorCount == 1) {
- System.err.println("1 error");
- } else if (errorCount > 0) {
- System.err.println(errorCount + " errors");
- }
- return success;
- }
- catch (CompilerException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- return false;
- }
- catch (Throwable e) {
- e.printStackTrace();
- return false;
- }
- finally {
- //TC - 20081018 only reset when no error was detected
- if (errorCount==0) {
- reset();
- }
- }
- }
-
-
- private static void showUsage() {
- System.out.println("Usage: jaxxc <options> <source files>");
- System.out.println();
- System.out.println("Source files must end in extension .jaxx");
- System.out.println("Use JAXX_OPTS environment variable to pass arguments to Java runtime");
- System.out.println();
- System.out.println("Supported options include:");
- System.out.println(" -classpath <paths> paths to search for user classes");
- System.out.println(" -cp <paths> same as -classpath");
- System.out.println(" -d <directory> target directory for generated class files");
- System.out.println(" -java or -j produce .java files, but do not compile them");
- System.out.println(" -keep or -k preserve generated .java files after compilation");
- System.out.println(" -optimize or -o optimize during compilation");
- System.out.println(" -version display version information");
- System.out.println();
- System.out.println("See http://www.jaxxframework.org/ for full documentation.");
- }
-
-
- public static String getVersion() {
- return "1.0.4";
- }
-
-
- public static void main(String[] arg) throws Exception {
- boolean success = true;
-
- CompilerOptions options = new CompilerOptions();
- List<String> files = new ArrayList<String>();
- for (int i = 0; i < arg.length; i++) {
- if (arg[i].endsWith(".jaxx")) {
- files.add(arg[i]);
- } else if (arg[i].equals("-d")) {
- if (++i < arg.length) {
- File targetDirectory = new File(arg[i]);
- if (!targetDirectory.exists()) {
- System.err.println("Error: could not find target directory: " + targetDirectory);
- errorCount++;
- success = false;
- }
- options.setTargetDirectory(targetDirectory);
- } else {
- success = false;
- }
- } else if (arg[i].equals("-cp") || arg[i].equals("-classpath")) {
- if (++i < arg.length) {
- options.setClassPath(arg[i]);
- } else {
- success = false;
- }
- } else if (arg[i].equals("-javac_opts")) {
- if (++i < arg.length) {
- options.setJavacOpts(arg[i]);
- } else {
- success = false;
- }
- } else if (arg[i].equals("-k") || arg[i].equals("-keep")) {
- options.setKeepJavaFiles(true);
- } else if (arg[i].equals("-j") || arg[i].equals("-java")) {
- options.setKeepJavaFiles(true);
- } else if (arg[i].equals("-o") || arg[i].equals("-optimize")) {
- options.setOptimize(true);
- } else if (arg[i].equals("-version")) {
- System.err.println("jaxxc version " + getVersion() + " by Ethan Nicholas");
- System.err.println("http://www.jaxxframework.org/");
- System.exit(0);
- } else if (arg[i].equals("-internalDumpVersion")) { // used by ant to extract the version info
- System.out.println("jaxx.version=" + getVersion());
- return;
- } else {
- success = false;
- }
- }
-
- success &= (errorCount == 0 && files.size() > 0);
-
- if (success) {
- success = compile(new File("."), files.toArray(new String[files.size()]), options);
- } else {
- showUsage();
- System.exit(1);
- }
-
- System.exit(success ? 0 : 1);
- }
-
- public File getDest() {
- return dest;
- }
-
- public void setFailed(boolean failed) {
- this.failed = failed;
- }
-
- /**
- * Register in this compiler a new compiled validator.
- *
- * @param validator the compiled validator to register
- */
- public void registerValidator(CompiledBeanValidator validator) {
- validators.add(validator);
- validatedComponents.addAll(validator.getFields().values());
- }
-
- /** @return <code>true</code> if some validators were detected, <code>false</code> otherwise */
- public boolean hasValidator() {
- return !validators.isEmpty();
- }
-
- /**
- * Test if a given CompiledObject is attached to a validator.
- *
- * @param componentId the compiled object to test
- * @return <code>true</code> if the given compiled object is attached to a validator, <code>false</code> otherwise
- */
- public boolean isComponentUsedByValidator(String componentId) {
- return validatedComponents.contains(componentId);
- }
-
- /**
- * Test if a given bean is attached to a validator.
- *
- * @param beanId the bean to test
- * @return <code>true</code> if the given bean is attached to a validator, <code>false</code> otherwise
- */
- public boolean isBeanUsedByValidator(String beanId) {
- for (CompiledBeanValidator validator : validators) {
- if(beanId.equals(validator.getBean())) {
- return true;
- }
- }
- return false;
- }
-
- /**
* Check that a reference exists in symbol table on second compil pass
*
* @param tag the current tag
@@ -2258,4 +1034,112 @@
}
return true;
}
+
+ protected int getNextLeftBrace(String string, int pos) {
+ leftBraceMatcher.reset(string);
+ return leftBraceMatcher.find(pos) ? Math.max(leftBraceMatcher.start(1), leftBraceMatcher.start(2)) : -1;
+ }
+
+ protected int getNextRightBrace(String string, int pos) {
+ leftBraceMatcher.reset(string);
+ rightBraceMatcher.reset(string);
+ int openCount = 1;
+ int rightPos;
+ while (openCount > 0) {
+ pos++;
+ int leftPos = leftBraceMatcher.find(pos) ? Math.max(leftBraceMatcher.start(1), leftBraceMatcher.start(2)) : -1;
+ rightPos = rightBraceMatcher.find(pos) ? Math.max(rightBraceMatcher.start(1), rightBraceMatcher.start(2)) : -1;
+ assert leftPos == -1 || leftPos >= pos;
+ assert rightPos == -1 || rightPos >= pos;
+ if (leftPos != -1 && leftPos < rightPos) {
+ pos = leftPos;
+ openCount++;
+ } else if (rightPos != -1) {
+ pos = rightPos;
+ openCount--;
+ } else {
+ openCount = 0;
+ }
+ }
+ return pos;
+ }
+
+ public String[] parseParameterList(String parameters) throws CompilerException {
+ List<String> result = new ArrayList<String>();
+ StringBuffer current = new StringBuffer();
+ int state = 0; // normal
+ for (int i = 0; i < parameters.length(); i++) {
+ char c = parameters.charAt(i);
+ switch (state) {
+ case 0: // normal
+ switch (c) {
+ case '"':
+ current.append(c);
+ state = 1;
+ break; // in quoted string
+ case '\\':
+ current.append(c);
+ state = 2;
+ break; // immediately after backslash
+ case ',':
+ if (current.length() > 0) {
+ result.add(current.toString());
+ current.setLength(0);
+ break;
+ } else {
+ reportError("error parsing parameter list: " + parameters);
+ }
+ default:
+ current.append(c);
+ }
+ break;
+ case 1: // in quoted string
+ switch (c) {
+ case '"':
+ current.append(c);
+ state = 0;
+ break; // normal
+ case '\\':
+ current.append(c);
+ state = 3;
+ break; // immediate after backslash in quoted string
+ default:
+ current.append(c);
+ }
+ break;
+ case 2: // immediately after backslash
+ current.append(c);
+ state = 0; // normal
+ break;
+ case 3: // immediately after backslash in quoted string
+ current.append(c);
+ state = 1; // in quoted string
+ break;
+ }
+ }
+ if (current.length() > 0) {
+ result.add(current.toString());
+ }
+ return result.toArray(new String[result.size()]);
+ }
+
+ public String getAutoId(ClassDescriptor objectClass) {
+ if (options.getOptimize()) {
+ return "$" + Integer.toString(autogenID++, 36);
+ } else {
+ String name = objectClass.getName();
+ name = name.substring(name.lastIndexOf(".") + 1);
+ return "$" + name + autogenID++;
+ }
+ }
+
+ public String getUniqueId(Object object) {
+ String result = uniqueIds.get(object);
+ if (result == null) {
+ result = "$u" + uniqueIds.size();
+ uniqueIds.put(object, result);
+ }
+ return result;
+ }
+
}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompilerHelper.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompilerHelper.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompilerHelper.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -0,0 +1,657 @@
+package jaxx.compiler;
+
+import jaxx.CompilerException;
+import jaxx.reflect.ClassDescriptor;
+import jaxx.reflect.ClassDescriptorLoader;
+import jaxx.spi.Initializer;
+import jaxx.tags.DefaultObjectHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.sax.SAXSource;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.Stack;
+
+/** @author chemit */
+public class JAXXCompilerHelper {
+
+ /** log */
+ protected static final Log log = LogFactory.getLog(JAXXCompiler.class);
+
+ /**
+ * True to throw exceptions when we encounter unresolvable classes, false to ignore.
+ * This is currently set to false until JAXX has full support for inner classes
+ * (including enumerations), because currently they don't always resolve (but will
+ * generally compile without error anyway).
+ */
+ public static final boolean STRICT_CHECKS = false;
+
+ public static final String JAXX_NAMESPACE = "http://www.jaxxframework.org/";
+
+ public static final String JAXX_INTERNAL_NAMESPACE = "http://www.jaxxframework.org/internal";
+
+ /** Maximum length of an inlinable creation method. */
+ protected static final int INLINE_THRESHOLD = 300;
+
+ protected static final int PASS_1 = 0;
+
+ protected static final int PASS_2 = 1;
+
+ /** Contains import declarations (of the form "javax.swing.") which are always imported in all compiler instances. */
+ protected static List<String> staticImports = new ArrayList<String>();
+
+ static {
+ //TODO humm, we should be able to import only what is needed
+ staticImports.add("java.awt.*");
+ staticImports.add("java.awt.event.*");
+ staticImports.add("java.beans.*");
+ staticImports.add("java.io.*");
+ staticImports.add("java.lang.*");
+ staticImports.add("java.util.*");
+ staticImports.add("javax.swing.*");
+ staticImports.add("javax.swing.border.*");
+ staticImports.add("javax.swing.event.*");
+ staticImports.add("jaxx.runtime.swing.JAXXButtonGroup");
+ staticImports.add("jaxx.runtime.swing.HBox");
+ staticImports.add("jaxx.runtime.swing.VBox");
+ staticImports.add("jaxx.runtime.swing.Table");
+ staticImports.add("static org.codelutin.i18n.I18n._");
+ staticImports.add("static org.codelutin.jaxx.util.UIHelper.createImageIcon");
+ }
+
+ protected static DefaultObjectHandler firstPassClassTagHandler = new DefaultObjectHandler(ClassDescriptorLoader.getClassDescriptor(Object.class));
+
+ /** Files being compiled during the compilation session, may be modified as compilation progresses and additional dependencies are found. */
+ protected static List<File> jaxxFiles = new ArrayList<File>();
+
+ /** Class names corresponding to the files in the jaxxFiles list. */
+ protected static List<String> jaxxFileClassNames = new ArrayList<String>();
+
+ /** Maps the names of classes being compiled to the compiler instance handling the compilation. */
+ protected static Map<String, JAXXCompiler> compilers = new HashMap<String, JAXXCompiler>();
+
+ /** Maps the names of classes being compiled to their symbol tables (created after the first compiler pass). */
+ protected static Map<File, SymbolTable> symbolTables = new HashMap<File, SymbolTable>();
+
+ protected static int currentPass;
+
+ protected CompilerOptions options;
+
+ /** Used for error reporting purposes, so we can report the right line number. */
+ protected Stack<Element> tagsBeingCompiled = new Stack<Element>();
+
+ /** Used for error reporting purposes, so we can report the right source file. */
+ protected Stack<File> sourceFiles = new Stack<File>();
+
+ /** Maps object ID strings to the objects themselves. These are created during the second compilation pass. */
+ protected Map<String, CompiledObject> objects = new LinkedHashMap<String, CompiledObject>();
+
+ /** Maps objects to their ID strings. These are created during the second compilation pass. */
+ protected Map<CompiledObject, String> ids = new LinkedHashMap<CompiledObject, String>();
+
+ protected static int errorCount;
+ protected static int warningCount;
+
+ public static void loadLibraries(boolean verbose) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if (verbose) {
+ log.info("with cl " + classloader);
+ }
+ ServiceLoader<Initializer> loader = ServiceLoader.load(Initializer.class, classloader);
+ for (Initializer initializer : loader) {
+ if (verbose) {
+ log.info("load initializer " + initializer);
+ }
+ initializer.initialize();
+ }
+ }
+
+ public static void init() {
+ // forces static initializer to run if it hasn't yet
+ }
+
+ /** Resets all state in preparation for a new compilation session. */
+ protected static void reset() {
+ errorCount = warningCount = 0;
+ jaxxFiles.clear();
+ jaxxFileClassNames.clear();
+ symbolTables.clear();
+ compilers.clear();
+ }
+
+ public static String getVersion() {
+ return "1.0.4";
+ }
+
+ /**
+ * Creates a dummy JAXXCompiler for use in unit testing.
+ *
+ * @return the compiler
+ */
+ public static JAXXCompiler createDummyCompiler() {
+ return createDummyCompiler(JAXXCompiler.class.getClassLoader());
+ }
+
+ /**
+ * Creates a dummy JAXXCompiler for use in unit testing.
+ *
+ * @param classLoader class loader to use
+ * @return the compiler
+ */
+ public static JAXXCompiler createDummyCompiler(ClassLoader classLoader) {
+ return new JAXXCompiler(classLoader);
+ }
+
+ /**
+ * @param className the name of the class to use
+ * @return the compiler instance which is processing the specified JAXX class. Each class is compiled by a
+ * different compiler instance.
+ */
+ public static JAXXCompiler getJAXXCompiler(String className) {
+ return compilers != null ? compilers.get(className) : null;
+ }
+
+ /**
+ * @param className the name of the class to use
+ * @return the symbol table for the specified JAXX class. Must be called during the second compiler pass.
+ * Returns <code>null</code> if no such symbol table could be found.
+ */
+ public static SymbolTable getSymbolTable(String className) {
+ JAXXCompiler compiler = getJAXXCompiler(className);
+ if (compiler == null) {
+ return null;
+ }
+ return compiler.getSymbolTable();
+ }
+
+ /**
+ * Returns the system line separator string.
+ *
+ * @return the string used to separate lines
+ */
+ public static String getLineSeparator() {
+ return System.getProperty("line.separator", "\n");
+ }
+
+ /**
+ * Compiled a set of files, expressed as paths relative to a base directory. The class names of the compiled files are derived
+ * from the relative path strings (e.g. "example/Foo.jaxx" compiles into a class named "example.Foo"). Returns <code>true</code>
+ * if compilation succeeds, <code>false</code> if it fails. Warning and error messages are sent to <code>System.err</code>.
+ *
+ * @param base the directory against which to resolve relative paths
+ * @param relativePaths a list of relative paths to .jaxx files being compiled
+ * @param options the compiler options to use
+ * @return <code>true</code> if compilation succeeds, <code>false</code> otherwise
+ */
+ public static synchronized boolean compile(File base, String[] relativePaths, CompilerOptions options) {
+ File[] files = new File[relativePaths.length];
+ String[] classNames = new String[relativePaths.length];
+ for (int i = 0; i < files.length; i++) {
+ files[i] = new File(base, relativePaths[i]);
+ classNames[i] = relativePaths[i].substring(0, relativePaths[i].lastIndexOf("."));
+ classNames[i] = classNames[i].replace(File.separatorChar, '.');
+ classNames[i] = classNames[i].replace('/', '.');
+ classNames[i] = classNames[i].replace('\\', '.');
+ classNames[i] = classNames[i].replace(':', '.');
+ }
+ return compile(files, classNames, options);
+ }
+
+ /**
+ * Compiled a set of files, with the class names specified explicitly. The class compiled from files[i] will be named classNames[i].
+ * Returns <code>true</code> if compilation succeeds, <code>false</code> if it fails. Warning and error messages are sent to
+ * <code>System.err</code>.
+ *
+ * @param files the .jaxx files to compile
+ * @param classNames the names of the classes being compiled
+ * @param options the compiler options to use
+ * @return <code>true</code> if compilation succeeds, <code>false</code> otherwise
+ */
+ public static synchronized boolean compile(File[] files, String[] classNames, CompilerOptions options) {
+ reset(); // just to be safe...
+ jaxxFiles.addAll(Arrays.asList(files));
+ jaxxFileClassNames.addAll(Arrays.asList(classNames));
+ try {
+ boolean success = true;
+
+ // pass 1
+ currentPass = PASS_1;
+ boolean compiled;
+ do {
+ compiled = false;
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ java.util.Iterator<File> filesIterator = new ArrayList<File>(jaxxFiles).iterator(); // clone it so it can safely be modified while we're iterating
+ java.util.Iterator<String> classNamesIterator = new ArrayList<String>(jaxxFileClassNames).iterator();
+ while (filesIterator.hasNext()) {
+ File file = filesIterator.next();
+ String className = classNamesIterator.next();
+ if (options.isVerbose()) {
+ log.info("compile first pass for " + className);
+ }
+ if (symbolTables.get(file) == null) {
+ compiled = true;
+ if (compilers.containsKey(className)) {
+ throw new CompilerException("Internal error: " + className + " is already being compiled, attempting to compile it again");
+ }
+
+ File destDir = options.getTargetDirectory();
+ if (destDir != null) {
+ int dotPos = className.lastIndexOf(".");
+ if (dotPos != -1) {
+ destDir = new File(destDir, className.substring(0, dotPos).replace('.', File.separatorChar));
+ }
+ destDir.mkdirs();
+ } else {
+ //destDir = file.getParentFile();
+ }
+ JAXXCompiler compiler = new JAXXCompiler(file.getParentFile(), file, className, options);
+ compilers.put(className, compiler);
+ compiler.compileFirstPass();
+ assert !symbolTables.values().contains(compiler.getSymbolTable()) : "symbolTable is already registered";
+ symbolTables.put(file, compiler.getSymbolTable());
+ if (compiler.failed) {
+ success = false;
+ }
+ }
+ }
+
+ } while (compiled);
+
+ // pass 2
+ currentPass = PASS_2;
+ if (success) {
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ List<File> jaxxFilesClone = new ArrayList<File>(jaxxFiles);
+ for (String className : jaxxFileClassNames) {
+ JAXXCompiler compiler = compilers.get(className);
+ if (compiler == null) {
+ throw new CompilerException("Internal error: could not find compiler for " + className + " during second pass");
+ }
+ if (options.isVerbose()) {
+
+ log.info("runInitializers for " + className);
+ }
+ if (!compiler.failed) {
+ compiler.runInitializers();
+ }
+ if (options.isVerbose()) {
+
+ log.info("compile second pass for " + className);
+ }
+ compiler.compileSecondPass();
+ if (options.isVerbose()) {
+
+ log.info("done with result [" + !compiler.failed + "] for " + className);
+ }
+ if (!compiler.failed) {
+
+ } else {
+ success = false;
+ }
+ }
+ if (!jaxxFilesClone.equals(jaxxFiles)) {
+ throw new AssertionError("Internal error: compilation set altered during pass 2 (was " + jaxxFilesClone + ", modified to " + jaxxFiles + ")");
+ }
+ }
+
+ // stylesheet application
+ if (success) {
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ for (String className : jaxxFileClassNames) {
+ JAXXCompiler compiler = compilers.get(className);
+ if (compiler == null) {
+ throw new CompilerException("Internal error: could not find compiler for " + className + " during stylesheet application");
+ }
+ compiler.applyStylesheets();
+ if (compiler.failed) {
+ success = false;
+ }
+ }
+ }
+
+ // code generation
+ if (success) {
+ assert jaxxFiles.size() == jaxxFileClassNames.size();
+ for (String className : jaxxFileClassNames) {
+ JAXXCompiler compiler = compilers.get(className);
+ if (compiler == null) {
+ throw new CompilerException("Internal error: could not find compiler for " + className + " during code generation");
+ }
+ compiler.generator.generateCode();
+ //compiler.generateCode();
+ if (compiler.failed) {
+ success = false;
+ }
+ }
+ }
+
+ if (warningCount == 1) {
+ System.err.println("1 warning");
+ } else if (warningCount > 0) {
+ System.err.println(warningCount + " warnings");
+ }
+ if (errorCount == 1) {
+ System.err.println("1 error");
+ } else if (errorCount > 0) {
+ System.err.println(errorCount + " errors");
+ }
+ return success;
+ }
+ catch (CompilerException e) {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ return false;
+ }
+ catch (Throwable e) {
+ e.printStackTrace();
+ return false;
+ }
+ finally {
+ //TC - 20081018 only reset when no error was detected
+ if (errorCount == 0) {
+ reset();
+ }
+ }
+ }
+
+ // 1.5 adds getCanonicalName; unfortunately we can't depend on 1.5 features yet
+ public static String getCanonicalName(Class clazz) {
+ if (clazz.isArray()) {
+ String canonicalName = getCanonicalName(clazz.getComponentType());
+ if (canonicalName != null) {
+ return canonicalName + "[]";
+ }
+ return null;
+ }
+ return clazz.getName().replace('$', '.');
+ }
+
+ public static String getCanonicalName(ClassDescriptor clazz) {
+ if (clazz.isArray()) {
+ String canonicalName = getCanonicalName(clazz.getComponentType());
+ if (canonicalName != null) {
+ return canonicalName + "[]";
+ }
+ return null;
+ }
+ return clazz.getName().replace('$', '.');
+ }
+
+ public static String getCanonicalName(CompiledObject compiled) {
+ ClassDescriptor clazz = compiled.getObjectClass();
+ if (clazz.isArray()) {
+ String canonicalName = getCanonicalName(clazz.getComponentType());
+ if (canonicalName != null) {
+ if (compiled.getGenericTypes().length > 0) {
+ canonicalName += "<";
+ for (int i = 0; i < compiled.getGenericTypes().length; i++) {
+ ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
+ if (i > 0) {
+ canonicalName += " ,";
+ }
+ canonicalName += classDescriptor.getName();
+ }
+ canonicalName += ">";
+ }
+ return canonicalName + "[]";
+ }
+ return null;
+ }
+
+ String canonicalName = clazz.getName().replace('$', '.');
+ if (compiled.getGenericTypes().length > 0) {
+ canonicalName += "<";
+ for (int i = 0; i < compiled.getGenericTypes().length; i++) {
+ ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
+ if (i > 0) {
+ canonicalName += " ,";
+ }
+ canonicalName += classDescriptor.getName();
+ }
+ canonicalName += ">";
+ }
+ return canonicalName;
+ }
+
+ public static String capitalize(String s) {
+ if (s.length() == 0) {
+ return s;
+ }
+ return Character.toUpperCase(s.charAt(0)) + s.substring(1);
+ }
+
+ /**
+ * Escapes a string using standard Java escape sequences, generally in preparation to including it in a string literal
+ * in a compiled Java file.
+ *
+ * @param raw the raw string to be escape
+ * @return a string in which all 'dangerous' characters have been replaced by equivalent Java escape sequences
+ */
+ public static String escapeJavaString(String raw) {
+ StringBuffer out = new StringBuffer(raw);
+ for (int i = 0; i < out.length(); i++) {
+ char c = out.charAt(i);
+ if (c == '\\' || c == '"') {
+ out.insert(i, '\\');
+ i++;
+ } else if (c == '\n') {
+ out.replace(i, i + 1, "\\n");
+ i++;
+ } else if (c == '\r') {
+ out.replace(i, i + 1, "\\r");
+ i++;
+ } else if (c < 32 || c > 127) {
+ String value = Integer.toString((int) c, 16);
+ while (value.length() < 4) {
+ value = "0" + value;
+ }
+ out.replace(i, i + 1, "\\u" + value);
+ i += 5;
+ }
+ }
+ return out.toString();
+ }
+
+ public static File URLtoFile(URL url) {
+ return URLtoFile(url.toString());
+ }
+
+ public static File URLtoFile(String urlString) {
+ if (!urlString.startsWith("file:")) {
+ throw new IllegalArgumentException("url must start with 'file:'");
+ }
+ urlString = urlString.substring("file:".length());
+ if (urlString.startsWith("/") && System.getProperty("os.name").startsWith("Windows")) {
+ urlString = urlString.substring(1);
+ }
+ try {
+ return new File(URLDecoder.decode(urlString.replace('/', File.separatorChar), "utf-8"));
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static SAXParser getSAXParser() {
+ try {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ SAXParser parser;
+ parser = factory.newSAXParser();
+ return parser;
+ }
+ catch (SAXException e) {
+ throw new RuntimeException(e);
+ }
+ catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Document parseDocument(InputStream in) throws IOException, SAXException {
+ try {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ transformer.setErrorListener(new ErrorListener() {
+ public void warning(TransformerException ex) throws TransformerException {
+ throw ex;
+ }
+
+ public void error(TransformerException ex) throws TransformerException {
+ throw ex;
+ }
+
+ public void fatalError(TransformerException ex) throws TransformerException {
+ throw ex;
+ }
+ });
+
+ DOMResult result = new DOMResult();
+ transformer.transform(new SAXSource(new XMLFilterImpl(getSAXParser().getXMLReader()) {
+ Locator locator;
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ this.locator = locator;
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+ AttributesImpl resultAtts = new AttributesImpl(atts);
+ resultAtts.addAttribute(JAXX_INTERNAL_NAMESPACE, "line", "internal:line", "CDATA", String.valueOf(locator.getLineNumber()));
+ getContentHandler().startElement(uri, localName, qName, resultAtts);
+ }
+ }, new InputSource(in)), result);
+ return (Document) result.getNode();
+ }
+ catch (TransformerConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ catch (TransformerException e) {
+ Throwable ex = e;
+ while (ex.getCause() != null) {
+ ex = ex.getCause();
+ }
+ if (ex instanceof IOException) {
+ throw (IOException) ex;
+ }
+ if (ex instanceof SAXException) {
+ throw (SAXException) ex;
+ }
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException) ex;
+ }
+ throw new RuntimeException(ex);
+ }
+ }
+
+ protected static void showUsage() {
+ System.out.println("Usage: jaxxc <options> <source files>");
+ System.out.println();
+ System.out.println("Source files must end in extension .jaxx");
+ System.out.println("Use JAXX_OPTS environment variable to pass arguments to Java runtime");
+ System.out.println();
+ System.out.println("Supported options include:");
+ System.out.println(" -classpath <paths> paths to search for user classes");
+ System.out.println(" -cp <paths> same as -classpath");
+ System.out.println(" -d <directory> target directory for generated class files");
+ System.out.println(" -java or -j produce .java files, but do not compile them");
+ System.out.println(" -keep or -k preserve generated .java files after compilation");
+ System.out.println(" -optimize or -o optimize during compilation");
+ System.out.println(" -version display version information");
+ System.out.println();
+ System.out.println("See http://www.jaxxframework.org/ for full documentation.");
+ }
+
+ public static void main(String[] arg) throws Exception {
+ boolean success = true;
+
+ CompilerOptions options = new CompilerOptions();
+ List<String> files = new ArrayList<String>();
+ for (int i = 0; i < arg.length; i++) {
+ if (arg[i].endsWith(".jaxx")) {
+ files.add(arg[i]);
+ } else if (arg[i].equals("-d")) {
+ if (++i < arg.length) {
+ File targetDirectory = new File(arg[i]);
+ if (!targetDirectory.exists()) {
+ System.err.println("Error: could not find target directory: " + targetDirectory);
+ JAXXCompiler.errorCount++;
+ success = false;
+ }
+ options.setTargetDirectory(targetDirectory);
+ } else {
+ success = false;
+ }
+ } else if (arg[i].equals("-cp") || arg[i].equals("-classpath")) {
+ if (++i < arg.length) {
+ options.setClassPath(arg[i]);
+ } else {
+ success = false;
+ }
+ } else if (arg[i].equals("-javac_opts")) {
+ if (++i < arg.length) {
+ options.setJavacOpts(arg[i]);
+ } else {
+ success = false;
+ }
+ } else if (arg[i].equals("-k") || arg[i].equals("-keep")) {
+ options.setKeepJavaFiles(true);
+ } else if (arg[i].equals("-j") || arg[i].equals("-java")) {
+ options.setKeepJavaFiles(true);
+ } else if (arg[i].equals("-o") || arg[i].equals("-optimize")) {
+ options.setOptimize(true);
+ } else if (arg[i].equals("-version")) {
+ System.err.println("jaxxc version " + getVersion() + " by Ethan Nicholas");
+ System.err.println("http://www.jaxxframework.org/");
+ System.exit(0);
+ } else if (arg[i].equals("-internalDumpVersion")) { // used by ant to extract the version info
+ System.out.println("jaxx.version=" + getVersion());
+ return;
+ } else {
+ success = false;
+ }
+ }
+
+ success &= (JAXXCompiler.errorCount == 0 && files.size() > 0);
+
+ if (success) {
+ success = JAXXCompiler.compile(new File("."), files.toArray(new String[files.size()]), options);
+ } else {
+ showUsage();
+ System.exit(1);
+ }
+
+ System.exit(success ? 0 : 1);
+ }
+
+}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -0,0 +1,657 @@
+package jaxx.compiler;
+
+import jaxx.CompilerException;
+import jaxx.reflect.ClassDescriptor;
+import jaxx.reflect.ClassDescriptorLoader;
+import jaxx.reflect.MethodDescriptor;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.JAXXObjectDescriptor;
+import jaxx.runtime.swing.Application;
+import jaxx.tags.validator.BeanValidatorHandler.CompiledBeanValidator;
+import jaxx.types.TypeManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Modifier;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * This class is a refactoring of the {@link jaxx.compiler.JAXXCompiler}.
+ * <p/>
+ * We delegate now the generation of a {@link jaxx.runtime.JAXXObject} to this class, the
+ * {@link jaxx.compiler.JAXXCompiler} now only deals with the compilation of files.
+ *
+ * @author chemit
+ */
+public class JAXXObjectGenerator {
+
+ /** log */
+ protected static final Log log = LogFactory.getLog(JAXXObjectGenerator.class);
+
+ /** the compile used to parse the file to be generated here. */
+ protected JAXXCompiler compiler;
+
+ /** the file to be generated */
+ protected JavaFile javaFile = new JavaFile();
+
+ /** Generated .java file. */
+ protected File dest;
+
+ /** Extra code to be added to the instance initializer. */
+ protected StringBuffer initializer = new StringBuffer();
+
+ /** Extra code to be added at the end of the instance initializer. */
+ protected StringBuffer lateInitializer = new StringBuffer();
+
+ /** Extra code to be added to the class body. */
+ protected StringBuffer bodyCode = new StringBuffer();
+
+ /** Code to initialize data bindings. */
+ protected StringBuffer initDataBindings = new StringBuffer();
+
+ /** Body of the applyDataBinding method. */
+ protected StringBuffer applyDataBinding = new StringBuffer();
+
+ /** Body of the removeDataBinding method. */
+ protected StringBuffer removeDataBinding = new StringBuffer();
+
+ /** Body of the processDataBinding method. */
+ protected StringBuffer processDataBinding = new StringBuffer();
+
+ /** true if a main() method has been declared in a script */
+ protected boolean mainDeclared;
+
+ public JAXXObjectGenerator(JAXXCompiler compiler) {
+ this.compiler = compiler;
+ }
+
+ protected void generateCode() throws IOException {
+ if (getOptions().getTargetDirectory() != null) {
+ dest = new File(getOptions().getTargetDirectory(), getOutputClassName().replace('.', File.separatorChar) + ".java");
+ } else {
+ dest = new File(getBaseDir(), getOutputClassName().substring(getOutputClassName().lastIndexOf(".") + 1) + ".java");
+ }
+ if (dest.exists() && !dest.setLastModified(System.currentTimeMillis())) {
+ log.warn("could not touch file " + dest);
+ }
+ PrintWriter out = new PrintWriter(new FileWriter(dest));
+ createJavaSource(out);
+ out.close();
+ }
+
+ protected void createJavaSource(PrintWriter out) throws IOException {
+ int dotPos = getOutputClassName().lastIndexOf(".");
+ String packageName = dotPos != -1 ? getOutputClassName().substring(0, dotPos) : null;
+ String simpleClassName = getOutputClassName().substring(dotPos + 1);
+ outputClass(packageName, simpleClassName, out);
+ }
+
+ protected void outputClass(String packageName, String className, PrintWriter out) throws CompilerException {
+ createJavaFile(packageName, className);
+ out.println(javaFile.toString());
+ }
+
+ protected void createJavaFile(String packageName, String className) throws CompilerException {
+ String fullClassName = packageName != null ? packageName + "." + className : className;
+ CompiledObject root = compiler.getRootObject();
+ if (root == null) {
+ throw new CompilerException("root tag must be a class tag");
+ }
+ Map<String, CompiledObject> objects = compiler.getObjects();
+ ClassDescriptor superclass = root.getObjectClass();
+ boolean superclassIsJAXXObject = ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(superclass);
+ javaFile.setModifiers(Modifier.PUBLIC);
+ javaFile.setClassName(fullClassName);
+ javaFile.setSuperClass(JAXXCompiler.getCanonicalName(superclass));
+ javaFile.setInterfaces(new String[]{JAXXCompiler.getCanonicalName(JAXXObject.class)});
+
+ for (CompiledObject object : compiler.getObjects().values()) {
+ if (!object.isOverride() && !(object instanceof ScriptInitializer)) {
+ int access = object.getId().startsWith("$") ? Modifier.PRIVATE : Modifier.PROTECTED;
+ if (object == root) {
+ javaFile.addField(new JavaField(access, fullClassName, object.getId(), "this"));
+ } else {
+ //TC -20081017 can have generic on compiled Object
+ javaFile.addField(new JavaField(access, JAXXCompiler.getCanonicalName(object), object.getId()));
+ //javaFile.addField(new JavaField(access, getCanonicalName(object.getObjectClass()), object.getId()));
+ }
+ }
+ }
+
+ if (!superclassIsJAXXObject) {
+ // add logger
+ if (getOptions().isAddLogger()) {
+ javaFile.addImport("org.apache.commons.logging.Log");
+ javaFile.addImport("org.apache.commons.logging.LogFactory");
+ javaFile.addField(createLoggerField(fullClassName));
+ }
+
+ javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<Object>", "$activeBindings", "new ArrayList<Object>()"));
+ javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.Map<String,Object>", "$bindingSources", "new HashMap<String,Object>()"));
+ javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<String>", "validatorIds", "new ArrayList<String>()"));
+ }
+
+ javaFile.addImport("jaxx.runtime.validator.BeanValidator");
+
+ if (compiler.getStylesheet() != null) {
+ javaFile.addField(new JavaField(0, "java.util.Map", "$previousValues", "new java.util.HashMap()"));
+ }
+
+ javaFile.addMethod(createConstructor(className));
+ javaFile.addMethod(createInitializer(className));
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "BeanValidator<?>", "getValidator", new JavaArgument[]{new JavaArgument("String", "validatorId")},
+ null, "return (BeanValidator)(validatorIds.contains(validatorId)?getObjectById(validatorId):null);"));
+
+ for (DataBinding dataBinding : compiler.getDataBindings()) {
+ if (dataBinding.compile(true)) {
+ initDataBindings.append("applyDataBinding(").append(TypeManager.getJavaCode(dataBinding.getId())).append(");").append(JAXXCompiler.getLineSeparator());
+ }
+ }
+
+ javaFile.addBodyCode(bodyCode.toString());
+
+ for (CompiledObject object : objects.values()) {
+ if (!compiler.inlineCreation(object) && object != root) {
+ javaFile.addMethod(new JavaMethod(Modifier.PROTECTED, "void", object.getCreationMethodName(), null, null, getCreationCode(object)));
+ }
+ }
+
+ javaFile.addField(new JavaField(Modifier.PRIVATE, "boolean", "allComponentsCreated"));
+
+ javaFile.addMethod(createCompleteSetupMethod());
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "applyDataBinding", new JavaArgument[]{new JavaArgument("String", "$binding")},
+ null, applyDataBinding.toString() + JAXXCompiler.getLineSeparator() + " processDataBinding($binding);"));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removeDataBinding", new JavaArgument[]{new JavaArgument("String", "$binding")},
+ null, removeDataBinding.toString()));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding", new JavaArgument[]{new JavaArgument("String", "dest")},
+ null, "processDataBinding(dest, false);"));
+
+ javaFile.addMethod(createProcessDataBindingMethod());
+
+ if (!superclassIsJAXXObject) {
+ javaFile.addField(createObjectMap());
+ javaFile.addMethod(createGetObjectByIdMethod());
+ }
+
+ javaFile.addField(createJAXXObjectDescriptorField());
+ javaFile.addMethod(createGetJAXXObjectDescriptorMethod());
+
+ /*
+ * Gestion du context
+ */
+ javaFile.addField(createContextField());
+ javaFile.addMethod(createSetContextValueMethod());
+ javaFile.addMethod(createSetContextValueNameMethod());
+ javaFile.addMethod(createGetContextValueMethod());
+ javaFile.addMethod(createGetContextValueNameMethod());
+ javaFile.addMethod(createGetParentContainer());
+ javaFile.addMethod(createGetParentContainerMore());
+ ClassDescriptor currentClass = root.getObjectClass();
+ MethodDescriptor firePropertyChange = null;
+ while (firePropertyChange == null && currentClass != null) {
+ try {
+ firePropertyChange = currentClass.getDeclaredMethodDescriptor("firePropertyChange", new ClassDescriptor[]{
+ ClassDescriptorLoader.getClassDescriptor(String.class),
+ ClassDescriptorLoader.getClassDescriptor(Object.class),
+ ClassDescriptorLoader.getClassDescriptor(Object.class)
+ });
+
+ }
+ catch (NoSuchMethodException e) {
+ currentClass = currentClass.getSuperclass();
+ }
+ }
+
+ int modifiers = firePropertyChange != null ? firePropertyChange.getModifiers() : 0;
+ if (Modifier.isPublic(modifiers)) {
+ // we have all the support we need
+ }
+ if (Modifier.isProtected(modifiers)) {
+ // there is property change support but the firePropertyChange method is protected
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "firePropertyChange", new JavaArgument[]{
+ new JavaArgument("java.lang.String", "propertyName"), new JavaArgument("java.lang.Object", "oldValue"), new JavaArgument("java.lang.Object", "newValue")},
+ null, "super.firePropertyChange(propertyName, oldValue, newValue);"));
+ } else {
+ // either no support at all or firePropertyChange isn't accessible
+ addPropertyChangeSupport(javaFile);
+ }
+
+ addEventHandlers(javaFile);
+
+ if (ClassDescriptorLoader.getClassDescriptor(Application.class).isAssignableFrom(root.getObjectClass()) && !isMainDeclared()) {
+ // TODO: check for existing main method first
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC | Modifier.STATIC, "void", "main",
+ new JavaArgument[]{new JavaArgument("String[]", "arg")}, null,
+ "SwingUtilities.invokeLater(new Runnable() { public void run() { new " + className + "().setVisible(true); } });"));
+ }
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Create fields ----------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ private JavaField createObjectMap() {
+ return new JavaField(Modifier.PROTECTED, "Map<String,Object>", "$objectMap", "new HashMap<String,Object>()");
+ }
+
+ private JavaField createContextField() {
+ return new JavaField(Modifier.PROTECTED, "Map<Object,String>", "$contextMap", "new HashMap<Object,String>()");
+ }
+
+ private JavaField createLoggerField(String className) {
+ return new JavaField(Modifier.PUBLIC + Modifier.STATIC + Modifier.FINAL, "Log", "log", "LogFactory.getLog(" + className + ".class)");
+ }
+
+ protected JavaField createJAXXObjectDescriptorField() {
+ try {
+ JAXXObjectDescriptor descriptor = compiler.getJAXXObjectDescriptor();
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(buffer));
+ out.writeObject(descriptor);
+ out.close();
+ // the use of the weird deprecated constructor is deliberate -- we need to store the data as a String
+ // in the compiled class file, since byte array initialization is horribly inefficient compared to
+ // String initialization. So we store the bytes in the String, and we quite explicitly want a 1:1
+ // mapping between bytes and chars, with the high byte of the char set to zero. We can then safely
+ // reconstitute the original byte[] at a later date. This is unquestionably an abuse of the String
+ // type, but if we could efficiently store a byte[] we wouldn't have to do this.
+ String data = new String(buffer.toByteArray(), 0);
+
+ int sizeLimit = 65000; // constant strings are limited to 64K, and I'm not brave enough to push right up to the limit
+ if (data.length() < sizeLimit) {
+ return new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", "$jaxxObjectDescriptor", TypeManager.getJavaCode(data));
+ } else {
+ StringBuffer initializer = new StringBuffer();
+ for (int i = 0; i < data.length(); i += sizeLimit) {
+ String name = "$jaxxObjectDescriptor" + i;
+ javaFile.addField(new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", name,
+ TypeManager.getJavaCode(data.substring(i, Math.min(i + sizeLimit, data.length())))));
+ if (initializer.length() > 0) {
+ initializer.append(" + ");
+ }
+ initializer.append("String.valueOf(").append(name).append(")");
+ }
+ return new JavaField(Modifier.PRIVATE | Modifier.STATIC, "java.lang.String", "$jaxxObjectDescriptor", initializer.toString());
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Internal error: can't-happen error", e);
+ }
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Create methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ protected JavaMethod createGetJAXXObjectDescriptorMethod() {
+ return new JavaMethod(Modifier.PUBLIC | Modifier.STATIC, "jaxx.runtime.JAXXObjectDescriptor", "$getJAXXObjectDescriptor",
+ null, null, "return jaxx.runtime.Util.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);");
+ }
+
+ protected JavaMethod createGetObjectByIdMethod() {
+ return new JavaMethod(Modifier.PUBLIC, "java.lang.Object", "getObjectById",
+ new JavaArgument[]{new JavaArgument("String", "id")}, null,
+ "return $objectMap.get(id);");
+ }
+
+ private JavaMethod createSetContextValueMethod() {
+
+ return new JavaMethod(Modifier.PUBLIC, "void", "setContextValue",
+ new JavaArgument[]{new JavaArgument("Object", "clazz")}, null, getSetContextValueMethodCode());
+ }
+
+ private JavaMethod createSetContextValueNameMethod() {
+ return new JavaMethod(Modifier.PUBLIC, "void", "setContextValue",
+ new JavaArgument[]{new JavaArgument("Object", "clazz"), new JavaArgument("String", "name")}, null, getSetContextValueNameMethodCode());
+ }
+
+ private JavaMethod createGetContextValueMethod() {
+ return new JavaMethod(Modifier.PUBLIC, "<T> T", "getContextValue",
+ new JavaArgument[]{new JavaArgument("Class<T>", "clazz")}, null, getGetContextValueMethodCode());
+ }
+
+ private JavaMethod createGetContextValueNameMethod() {
+ return new JavaMethod(Modifier.PUBLIC, "<T> T", "getContextValue",
+ new JavaArgument[]{new JavaArgument("Class<T>", "clazz"), new JavaArgument("String", "name")}, null, getGetContextValueNameMethodCode());
+ }
+
+ private JavaMethod createGetParentContainer() {
+ return new JavaMethod(Modifier.PUBLIC, "<O extends Container> O", "getParentContainer",
+ new JavaArgument[]{new JavaArgument("Class<O>", "clazz")}, null, getGetParentContenerMethodCode());
+ }
+
+ private JavaMethod createGetParentContainerMore() {
+ return new JavaMethod(Modifier.PUBLIC, "<O extends Container> O", "getParentContainer",
+ new JavaArgument[]{new JavaArgument("Object", "source"), new JavaArgument("Class<O>", "clazz")}, null, getGetParentContenerMethodMoreCode());
+ }
+
+
+ protected void addPropertyChangeSupport(JavaFile javaFile) throws CompilerException {
+ javaFile.addField(new JavaField(0, "java.beans.PropertyChangeSupport", "$propertyChangeSupport"));
+
+ javaFile.addMethod(new JavaMethod(0, "java.beans.PropertyChangeSupport", "$getPropertyChangeSupport", null, null,
+ "if ($propertyChangeSupport == null)\n" +
+ " $propertyChangeSupport = new PropertyChangeSupport(this);\n" +
+ "return $propertyChangeSupport;"));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "addPropertyChangeListener", new JavaArgument[]{
+ new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
+ "$getPropertyChangeSupport().addPropertyChangeListener(listener);"));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "addPropertyChangeListener", new JavaArgument[]{
+ new JavaArgument("java.lang.String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
+ "$getPropertyChangeSupport().addPropertyChangeListener(property, listener);"));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removePropertyChangeListener", new JavaArgument[]{
+ new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
+ "$getPropertyChangeSupport().removePropertyChangeListener(listener);"));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "removePropertyChangeListener", new JavaArgument[]{
+ new JavaArgument("java.lang.String", "property"), new JavaArgument("java.beans.PropertyChangeListener", "listener")}, null,
+ "$getPropertyChangeSupport().removePropertyChangeListener(property, listener);"));
+
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", "firePropertyChange", new JavaArgument[]{
+ new JavaArgument("java.lang.String", "propertyName"), new JavaArgument("java.lang.Object", "oldValue"), new JavaArgument("java.lang.Object", "newValue")},
+ null, "$getPropertyChangeSupport().firePropertyChange(propertyName, oldValue, newValue);"));
+ }
+
+
+ protected void addEventHandlers(JavaFile javaFile) {
+ for (Map.Entry<String, Map<ClassDescriptor, List<EventHandler>>> e1 : compiler.getEventHandlers().entrySet()) {
+ // outer loop is iterating over different objects (well, technically, different Java expressions)
+ for (Map.Entry<ClassDescriptor, List<EventHandler>> e2 : e1.getValue().entrySet()) {
+ // iterate over different types of listeners for this particular object (MouseListener, ComponentListener, etc.)
+ for (EventHandler handler : e2.getValue()) {
+ // iterate over individual event handlers of a single type
+ String methodName = compiler.getEventHandlerMethodName(handler);
+ MethodDescriptor listenerMethod = handler.getListenerMethod();
+ if (listenerMethod.getParameterTypes().length != 1) {
+ throw new CompilerException("Expected event handler " + listenerMethod.getName() + " of class " + handler.getListenerClass() + " to have exactly one argument");
+ }
+ javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "void", methodName,
+ new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(listenerMethod.getParameterTypes()[0]), "event")}, null,
+ handler.getJavaCode()));
+ }
+ }
+ }
+ }
+
+ protected JavaMethod createConstructor(String className) throws CompilerException {
+ StringBuffer code = new StringBuffer();
+ String constructorParams = compiler.getRootObject().getConstructorParams();
+ if (constructorParams != null) {
+ code.append(" super(").append(constructorParams).append(");");
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ code.append("$initialize();");
+ code.append(JAXXCompiler.getLineSeparator());
+ return new JavaMethod(Modifier.PUBLIC, null, className, null, null, code.toString());
+ }
+
+
+ protected JavaMethod createInitializer(String className) throws CompilerException {
+ StringBuffer code = new StringBuffer();
+ CompiledObject root = compiler.getRootObject();
+ code.append("$objectMap.put(").append(TypeManager.getJavaCode(root.getId())).append(", this);");
+ code.append(JAXXCompiler.getLineSeparator());
+
+ Iterator<CompiledObject> i = compiler.getObjectCreationOrder();
+ boolean lastWasMethodCall = false;
+ while (i.hasNext()) {
+ CompiledObject object = i.next();
+ if (object != root && !object.isOverride()) {
+ if (compiler.inlineCreation(object)) {
+ if (lastWasMethodCall) {
+ lastWasMethodCall = false;
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ code.append(getCreationCode(object));
+ code.append(JAXXCompiler.getLineSeparator());
+ } else {
+ code.append(object.getCreationMethodName()).append("();");
+ code.append(JAXXCompiler.getLineSeparator());
+ lastWasMethodCall = true;
+ }
+ }
+ }
+ String rootCode = root.getInitializationCode(compiler);
+ if (rootCode != null && rootCode.length() > 0) {
+ code.append(rootCode);
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ code.append(JAXXCompiler.getLineSeparator());
+ if (initializer.length() > 0) {
+ code.append(initializer);
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ code.append("$completeSetup();");
+ code.append(JAXXCompiler.getLineSeparator());
+ return new JavaMethod(Modifier.PRIVATE, "void", "$initialize", null, null, code.toString());
+ }
+
+
+ protected JavaMethod createCompleteSetupMethod() {
+ StringBuffer code = new StringBuffer();
+ code.append("allComponentsCreated = true;");
+ code.append(JAXXCompiler.getLineSeparator());
+ for (CompiledObject object : compiler.getObjects().values()) {
+ //TC - 20081017 only generate the method if not empty ?
+ if (object.getId().startsWith("$")) {
+ code.append(object.getAdditionCode()).append(JAXXCompiler.getLineSeparator());
+ } else {
+ String additionCode = object.getAdditionCode();
+ if (additionCode.length() > 0) {
+ code.append(object.getAdditionMethodName()).append("();").append(JAXXCompiler.getLineSeparator());
+ additionCode = "if (allComponentsCreated) {" + JAXXCompiler.getLineSeparator() + additionCode + "}";
+ javaFile.addMethod(new JavaMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), null, null, additionCode));
+ }
+ }
+ //code.append(getLineSeparator());
+ }
+
+ code.append(initDataBindings);
+
+ if (lateInitializer.length() > 0) {
+ code.append(lateInitializer);
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+
+ if (compiler.hasValidator()) {
+ // register validator
+ for (CompiledBeanValidator validator : compiler.getValidators()) {
+ String id = TypeManager.getJavaCode(validator.getId());
+ code.append("validatorIds.add(").append(id).append(");");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append("getValidator(").append(id).append(").installUIs();");
+ code.append("getValidator(").append(id).append(").validate();");
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ }
+ return new JavaMethod(Modifier.PRIVATE, "void", "$completeSetup", null, null, code.toString());
+ }
+
+ protected JavaMethod createProcessDataBindingMethod() {
+ StringBuffer code = new StringBuffer();
+ boolean superclassIsJAXXObject = ClassDescriptorLoader.getClassDescriptor(JAXXObject.class).isAssignableFrom(compiler.getRootObject().getObjectClass());
+ // the force parameter forces the update to happen even if it is already in activeBindings. This
+ // is used on superclass invocations b/c by the time the call gets to the superclass, it is already
+ // marked active and would otherwise be skipped
+ if (processDataBinding.length() > 0) {
+ code.append(" if (!$force && $activeBindings.contains($dest)) return;");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append(" $activeBindings.add($dest);");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append(" try {");
+ code.append(JAXXCompiler.getLineSeparator());
+ if (processDataBinding.length() > 0) {
+ code.append(processDataBinding);
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ if (superclassIsJAXXObject) {
+ code.append(" else");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append(" super.processDataBinding($dest, true);");
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ code.append(" }");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append(" finally {");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append(" $activeBindings.remove($dest);");
+ code.append(JAXXCompiler.getLineSeparator());
+ code.append(" }");
+ code.append(JAXXCompiler.getLineSeparator());
+ } else if (superclassIsJAXXObject) {
+ code.append(" super.processDataBinding($dest, true);");
+ code.append(JAXXCompiler.getLineSeparator());
+ }
+ return new JavaMethod(Modifier.PUBLIC, "void", "processDataBinding",
+ new JavaArgument[]{new JavaArgument("String", "$dest"), new JavaArgument("boolean", "$force")},
+ null, code.toString());
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Create methods code ----------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+ private String getSetContextValueMethodCode() {
+ return "this.setContextValue(clazz, null);";
+ }
+
+ private String getSetContextValueNameMethodCode() {
+ StringBuffer result = new StringBuffer();
+ result.append("$contextMap.put(clazz, name);");
+ return result.toString();
+ }
+
+ private String getGetContextValueMethodCode() {
+ return "return this.getContextValue(clazz, null);";
+ }
+
+ private String getGetContextValueNameMethodCode() {
+ StringBuffer result = new StringBuffer();
+ result.append("for (Map.Entry<Object,String> entry : $contextMap.entrySet()) {");
+ result.append("if (clazz.isAssignableFrom(entry.getKey().getClass()) && (name == null || name == entry.getValue())) {");
+ result.append("return (T) entry.getKey();}}");
+ result.append("return null;");
+ return result.toString();
+ }
+
+ private String getGetParentContenerMethodCode() {
+ StringBuffer result = new StringBuffer();
+ result.append("return this.getParentContainer(this, clazz);");
+ return result.toString();
+ }
+
+ private String getGetParentContenerMethodMoreCode() {
+ StringBuffer result = new StringBuffer();
+ result.append("if (!Container.class.isAssignableFrom(source.getClass())) {return null;}");
+ result.append(JAXXCompiler.getLineSeparator());
+ result.append("Container parent = ((Container)source).getParent();");
+ result.append(JAXXCompiler.getLineSeparator());
+ result.append("if (parent != null && !clazz.isAssignableFrom(parent.getClass())){parent = getParentContainer(parent, clazz);}");
+ result.append(JAXXCompiler.getLineSeparator());
+ result.append("return (O)parent;");
+ return result.toString();
+ }
+
+ protected String getCreationCode(CompiledObject object) throws CompilerException {
+ if (object instanceof ScriptInitializer) {
+ return object.getInitializationCode(compiler);
+ }
+ StringBuffer result = new StringBuffer();
+ result.append(object.getId());
+ result.append(" = ");
+ String constructorParams = object.getConstructorParams();
+ if (constructorParams != null) {
+ //TC - 20081017 compiledObject can have generics
+ result.append(" new ").append(JAXXCompiler.getCanonicalName(object)).append("(").append(constructorParams).append(");");
+ //result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
+ } else {
+ //TC - 20081017 compiledObject can have generics
+ result.append("new ").append(JAXXCompiler.getCanonicalName(object)).append("();");
+ }
+ result.append(JAXXCompiler.getLineSeparator());
+ String initCode = object.getInitializationCode(compiler);
+ if (initCode != null && initCode.length() > 0) {
+ result.append(initCode);
+ }
+ result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
+
+ return result.toString();
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Delegate methods from JAXXCompiler -------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ public String getOutputClassName() {
+ return compiler.getOutputClassName();
+ }
+
+ public File getBaseDir() {
+ return compiler.getBaseDir();
+ }
+
+ public CompilerOptions getOptions() {
+ return compiler.getOptions();
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Getter methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ public JavaFile getJavaFile() {
+ return javaFile;
+ }
+
+ public StringBuffer getInitializer() {
+ return initializer;
+ }
+
+ public StringBuffer getLateInitializer() {
+ return lateInitializer;
+ }
+
+ public StringBuffer getBodyCode() {
+ return bodyCode;
+ }
+
+ public StringBuffer getInitDataBindings() {
+ return initDataBindings;
+ }
+
+ public StringBuffer getApplyDataBinding() {
+ return applyDataBinding;
+ }
+
+ public StringBuffer getRemoveDataBinding() {
+ return removeDataBinding;
+ }
+
+ public StringBuffer getProcessDataBinding() {
+ return processDataBinding;
+ }
+
+ public boolean isMainDeclared() {
+ return mainDeclared;
+ }
+
+ /*---------------------------------------------------------------------------------*/
+ /*-- Setter methods ---------------------------------------------------------------*/
+ /*---------------------------------------------------------------------------------*/
+
+ public void setMainDeclared(boolean mainDeclared) {
+ this.mainDeclared = mainDeclared;
+ }
+}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/ScriptManager.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/ScriptManager.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/ScriptManager.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -1,181 +1,181 @@
-package jaxx.compiler;
-
-import jaxx.CompilerException;
-import jaxx.parser.JavaParser;
-import jaxx.parser.JavaParserTreeConstants;
-import jaxx.parser.SimpleNode;
-import jaxx.reflect.FieldDescriptor;
-import jaxx.reflect.MethodDescriptor;
-import jaxx.tags.TagManager;
-
-import java.io.StringReader;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class ScriptManager {
- private JAXXCompiler compiler;
-
-
- ScriptManager(JAXXCompiler compiler) {
- this.compiler = compiler;
- }
-
-
- /**
- * Strips unnecessary curly braces from around the script, generating a warning if they are found.
- *
- * @param script script to trim
- * @return the trimed script
- */
- public String trimScript(String script) {
- script = script.trim();
- if (script.startsWith("{") && script.endsWith("}")) {
- compiler.reportWarning("curly braces are unnecessary for script '" + script + "'");
- script = script.substring(1, script.length() - 1);
- }
- return script;
- }
-
-
- public void checkParse(String script) throws CompilerException {
- script = trimScript(script);
- JavaParser p = new JavaParser(new StringReader(script));
- while (!p.Line()) {
- // ???
- }
- }
-
-
- public String preprocessScript(String script) throws CompilerException {
- script = trimScript(script);
- StringBuffer result = new StringBuffer();
- JavaParser p = new JavaParser(new StringReader(script));
- //JavaParser p = new JavaParser(new StringReader(script + ";"));
- while (!p.Line()) {
- SimpleNode node = p.popNode();
- if (node != null) {
- preprocessScriptNode(node, false);
- result.append(node.getText());
- }
- }
- return result.toString();
- }
-
-
- /**
- * Scans through a compound symbol (foo.bar.baz) to identify and compile the JAXX class it refers to, if any.
- *
- * @param symbol symbol to scan
- */
- private void scanCompoundSymbol(String symbol) {
- String[] tokens = symbol.split("\\.");
- StringBuffer currentSymbol = new StringBuffer();
- for (String token : tokens) {
- if (currentSymbol.length() > 0)
- currentSymbol.append('.');
- currentSymbol.append(token.trim());
-
- String contextClass = TagManager.resolveClassName(currentSymbol.toString(), compiler);
- if (contextClass != null) {
- compiler.addDependencyClass(contextClass);
- }
- }
- }
-
-
- private void preprocessScriptNode(SimpleNode node, boolean staticContext) throws CompilerException {
- // identify static methods and initializers -- we can't fire events statically
- if (node.getId() == JavaParserTreeConstants.JJTMETHODDECLARATION) {
- if (node.getParent().getChild(0).getText().indexOf("static") != -1) {
- staticContext = true;
- }
- } else if (node.getId() == JavaParserTreeConstants.JJTINITIALIZER)
- if (node.getText().trim().startsWith("static")) {
- staticContext = true;
- }
-
- int count = node.jjtGetNumChildren();
- for (int i = 0; i < count; i++) {
- preprocessScriptNode(node.getChild(i), staticContext);
- }
-
- int id = node.getId();
- if (id == JavaParserTreeConstants.JJTNAME || id == JavaParserTreeConstants.JJTCLASSORINTERFACETYPE) {
- scanCompoundSymbol(node.getText());
- }
- if (!staticContext) {
- String lhs = null;
- if (id == JavaParserTreeConstants.JJTASSIGNMENTEXPRESSION || (id == JavaParserTreeConstants.JJTPOSTFIXEXPRESSION && node.jjtGetNumChildren() == 2)) {
- lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim();
- }
- else
- if (id == JavaParserTreeConstants.JJTPREINCREMENTEXPRESSION || id == JavaParserTreeConstants.JJTPREDECREMENTEXPRESSION) {
- lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim();
- }
- if (lhs != null) {
- FieldDescriptor[] fields = compiler.getScriptFields();
- for (FieldDescriptor field : fields) {
- if (field.getName().equals(lhs)) {
- //lhs.substring(lhs.lastIndexOf(".") + 1);
- node.firstToken.image = "jaxx.runtime.Util.assignment(" + node.firstToken.image;
- String outputClassName = compiler.getOutputClassName();
- node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)";
- }
- }
- }
- }
- }
-
-
- /**
- * Examines a Line to determine its real type. As all tokens returned by the parser are Lines, and
- * they are just a tiny wrapper around the real node, this method strips off the wrapper layers to identify
- * the real type of a node.
- *
- * @param line line to scan
- * @return the line type
- */
- private int getLineType(SimpleNode line) {
- if (line.jjtGetNumChildren() == 1) {
- SimpleNode node = line.getChild(0);
- if (node.getId() == JavaParserTreeConstants.JJTBLOCKSTATEMENT) {
- if (node.jjtGetNumChildren() == 1) {
- return node.getChild(0).getId();
- }
- } else
- if (node.getId() == JavaParserTreeConstants.JJTCLASSORINTERFACEBODYDECLARATION) {
- int id = node.getChild(0).getId();
- if (id == JavaParserTreeConstants.JJTMODIFIERS) {
- return node.getChild(1).getId();
- }
- if (id == JavaParserTreeConstants.JJTINITIALIZER) {
- return id;
- }
- }
- return node.getId();
- }
- return JavaParserTreeConstants.JJTLINE; // generic value implying that it's okay to put into the initializer block
- }
-
-
- private SimpleNode findExplicitConstructorInvocation(SimpleNode parent) {
- if (parent.getId() == JavaParserTreeConstants.JJTEXPLICITCONSTRUCTORINVOCATION) {
- return parent;
- }
-
- int count = parent.jjtGetNumChildren();
- for (int i = 0; i < count; i++) {
- SimpleNode result = findExplicitConstructorInvocation(parent.getChild(i));
- if (result != null) {
- return result;
- }
- }
- return null;
- }
-
-
+package jaxx.compiler;
+
+import jaxx.CompilerException;
+import jaxx.parser.JavaParser;
+import jaxx.parser.JavaParserTreeConstants;
+import jaxx.parser.SimpleNode;
+import jaxx.reflect.FieldDescriptor;
+import jaxx.reflect.MethodDescriptor;
+import jaxx.tags.TagManager;
+
+import java.io.StringReader;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class ScriptManager {
+ private JAXXCompiler compiler;
+
+
+ ScriptManager(JAXXCompiler compiler) {
+ this.compiler = compiler;
+ }
+
+
+ /**
+ * Strips unnecessary curly braces from around the script, generating a warning if they are found.
+ *
+ * @param script script to trim
+ * @return the trimed script
+ */
+ public String trimScript(String script) {
+ script = script.trim();
+ if (script.startsWith("{") && script.endsWith("}")) {
+ compiler.reportWarning("curly braces are unnecessary for script '" + script + "'");
+ script = script.substring(1, script.length() - 1);
+ }
+ return script;
+ }
+
+
+ public void checkParse(String script) throws CompilerException {
+ script = trimScript(script);
+ JavaParser p = new JavaParser(new StringReader(script));
+ while (!p.Line()) {
+ // ???
+ }
+ }
+
+
+ public String preprocessScript(String script) throws CompilerException {
+ script = trimScript(script);
+ StringBuffer result = new StringBuffer();
+ JavaParser p = new JavaParser(new StringReader(script));
+ //JavaParser p = new JavaParser(new StringReader(script + ";"));
+ while (!p.Line()) {
+ SimpleNode node = p.popNode();
+ if (node != null) {
+ preprocessScriptNode(node, false);
+ result.append(node.getText());
+ }
+ }
+ return result.toString();
+ }
+
+
+ /**
+ * Scans through a compound symbol (foo.bar.baz) to identify and compile the JAXX class it refers to, if any.
+ *
+ * @param symbol symbol to scan
+ */
+ private void scanCompoundSymbol(String symbol) {
+ String[] tokens = symbol.split("\\.");
+ StringBuffer currentSymbol = new StringBuffer();
+ for (String token : tokens) {
+ if (currentSymbol.length() > 0)
+ currentSymbol.append('.');
+ currentSymbol.append(token.trim());
+
+ String contextClass = TagManager.resolveClassName(currentSymbol.toString(), compiler);
+ if (contextClass != null) {
+ compiler.addDependencyClass(contextClass);
+ }
+ }
+ }
+
+
+ private void preprocessScriptNode(SimpleNode node, boolean staticContext) throws CompilerException {
+ // identify static methods and initializers -- we can't fire events statically
+ if (node.getId() == JavaParserTreeConstants.JJTMETHODDECLARATION) {
+ if (node.getParent().getChild(0).getText().indexOf("static") != -1) {
+ staticContext = true;
+ }
+ } else if (node.getId() == JavaParserTreeConstants.JJTINITIALIZER)
+ if (node.getText().trim().startsWith("static")) {
+ staticContext = true;
+ }
+
+ int count = node.jjtGetNumChildren();
+ for (int i = 0; i < count; i++) {
+ preprocessScriptNode(node.getChild(i), staticContext);
+ }
+
+ int id = node.getId();
+ if (id == JavaParserTreeConstants.JJTNAME || id == JavaParserTreeConstants.JJTCLASSORINTERFACETYPE) {
+ scanCompoundSymbol(node.getText());
+ }
+ if (!staticContext) {
+ String lhs = null;
+ if (id == JavaParserTreeConstants.JJTASSIGNMENTEXPRESSION || (id == JavaParserTreeConstants.JJTPOSTFIXEXPRESSION && node.jjtGetNumChildren() == 2)) {
+ lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim();
+ }
+ else
+ if (id == JavaParserTreeConstants.JJTPREINCREMENTEXPRESSION || id == JavaParserTreeConstants.JJTPREDECREMENTEXPRESSION) {
+ lhs = ((SimpleNode) node.jjtGetChild(0)).getText().trim();
+ }
+ if (lhs != null) {
+ FieldDescriptor[] fields = compiler.getScriptFields();
+ for (FieldDescriptor field : fields) {
+ if (field.getName().equals(lhs)) {
+ //lhs.substring(lhs.lastIndexOf(".") + 1);
+ node.firstToken.image = "jaxx.runtime.Util.assignment(" + node.firstToken.image;
+ String outputClassName = compiler.getOutputClassName();
+ node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)";
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Examines a Line to determine its real type. As all tokens returned by the parser are Lines, and
+ * they are just a tiny wrapper around the real node, this method strips off the wrapper layers to identify
+ * the real type of a node.
+ *
+ * @param line line to scan
+ * @return the line type
+ */
+ private int getLineType(SimpleNode line) {
+ if (line.jjtGetNumChildren() == 1) {
+ SimpleNode node = line.getChild(0);
+ if (node.getId() == JavaParserTreeConstants.JJTBLOCKSTATEMENT) {
+ if (node.jjtGetNumChildren() == 1) {
+ return node.getChild(0).getId();
+ }
+ } else
+ if (node.getId() == JavaParserTreeConstants.JJTCLASSORINTERFACEBODYDECLARATION) {
+ int id = node.getChild(0).getId();
+ if (id == JavaParserTreeConstants.JJTMODIFIERS) {
+ return node.getChild(1).getId();
+ }
+ if (id == JavaParserTreeConstants.JJTINITIALIZER) {
+ return id;
+ }
+ }
+ return node.getId();
+ }
+ return JavaParserTreeConstants.JJTLINE; // generic value implying that it's okay to put into the initializer block
+ }
+
+
+ private SimpleNode findExplicitConstructorInvocation(SimpleNode parent) {
+ if (parent.getId() == JavaParserTreeConstants.JJTEXPLICITCONSTRUCTORINVOCATION) {
+ return parent;
+ }
+
+ int count = parent.jjtGetNumChildren();
+ for (int i = 0; i < count; i++) {
+ SimpleNode result = findExplicitConstructorInvocation(parent.getChild(i));
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+
private void processConstructor(String modifiers, SimpleNode node) {
assert node.getId() == JavaParserTreeConstants.JJTCONSTRUCTORDECLARATION : "expected node to be ConstructorDeclaration, found " + JavaParserTreeConstants.jjtNodeName[node.getId()] + " instead";
assert node.getChild(0).getId() == JavaParserTreeConstants.JJTFORMALPARAMETERS : "expected node 0 to be FormalParameters, found " + JavaParserTreeConstants.jjtNodeName[node.getChild(1).getId()] + " instead";
@@ -196,141 +196,141 @@
}
}
- compiler.bodyCode.append(modifiers).append(" ").append(node.getText().substring(0,node.getText().length()-1) + code + "}");
+ compiler.appendBodyCode(modifiers + " "+ node.getText().substring(0,node.getText().length()-1) + code + "}");
//compiler.bodyCode.append(";\n");
- }
-
-
- private void scanScriptNode(SimpleNode node) throws CompilerException {
- int nodeType = getLineType(node);
- if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) { // have to handle imports early so the preprocessing takes them into account
- String text = node.getChild(0).getText().trim();
- if (text.startsWith("import")) {
- text = text.substring("import".length()).trim();
- }
- if (text.endsWith(";")) {
- text = text.substring(0, text.length() - 1);
- }
- compiler.addImport(text);
- }
-
- preprocessScriptNode(node, false);
-
- if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) {
- // do nothing, already handled above
- } else if (nodeType == JavaParserTreeConstants.JJTMETHODDECLARATION) {
- String returnType = null;
- String name = null;
- List<String> parameterTypes = new ArrayList<String>();
- //List<String> parameterNames = new ArrayList<String>();
- SimpleNode methodDeclaration = node.getChild(0).getChild(1);
- assert methodDeclaration.getId() == JavaParserTreeConstants.JJTMETHODDECLARATION;
- for (int i = 0; i < methodDeclaration.jjtGetNumChildren(); i++) {
- SimpleNode child = methodDeclaration.getChild(i);
- int type = child.getId();
- if (type == JavaParserTreeConstants.JJTRESULTTYPE) {
- String rawReturnType = child.getText().trim();
- returnType = TagManager.resolveClassName(rawReturnType, compiler);
- // FIXME: this check fails for inner classes defined in this file
- //if (returnType == null)
- // throw new CompilerException("could not find class '" + rawReturnType + "'");
- } else
- if (type == JavaParserTreeConstants.JJTMETHODDECLARATOR) {
- name = child.firstToken.image.trim();
- SimpleNode formalParameters = child.getChild(0);
- assert formalParameters.getId() == JavaParserTreeConstants.JJTFORMALPARAMETERS;
- for (int j = 0; j < formalParameters.jjtGetNumChildren(); j++)
- {
- SimpleNode parameter = formalParameters.getChild(j);
- String rawParameterType = parameter.getChild(1).getText().trim().replaceAll("\\.\\.\\.", "[]");
- String parameterType = TagManager.resolveClassName(rawParameterType, compiler);
- // FIXME: this check fails for inner classes defined in this file
- //if (parameterType == null)
- // throw new CompilerException("could not find class '" + rawParameterType + "'");
- parameterTypes.add(parameterType);
- //parameterNames.add(parameter.getChild(2).getText().trim());
- }
- }
- }
- compiler.bodyCode.append(node.getText());
- //compiler.bodyCode.append(";\n");
- compiler.addScriptMethod(new MethodDescriptor(name, Modifier.PUBLIC, returnType, parameterTypes.toArray(new String[parameterTypes.size()]), compiler.getClassLoader()));
- } else
- if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEDECLARATION ||
- nodeType == JavaParserTreeConstants.JJTINITIALIZER) {
- String str = node.getText().trim();
- if (str.endsWith(";")) {
- str+=";";
- }
- compiler.bodyCode.append(str);
- //compiler.bodyCode.append(";\n");
- } else
- if (nodeType == JavaParserTreeConstants.JJTCONSTRUCTORDECLARATION) {
- processConstructor(node.getChild(0).getChild(0).getText(), node.getChild(0).getChild(1));
- } else
- if (nodeType == JavaParserTreeConstants.JJTLOCALVARIABLEDECLARATION || nodeType == JavaParserTreeConstants.JJTFIELDDECLARATION) {
- // the "local" variable declarations in this expression aren't actually local -- they are flagged local
- // just because there isn't an enclosing class scope visible to the parser. "Real" local variable
- // declarations won't show up here, because they will be buried inside of methods.
- String text = node.getText().trim();
- if (!text.endsWith(";")) {
- text+=";";
- }
- String declaration = text;
- int equals = text.indexOf("=");
- if (equals != -1) {
- declaration = declaration.substring(0, equals);
- }
- declaration = declaration.trim();
- String[] declarationTokens = declaration.split("\\s");
- boolean isFinal = Arrays.asList(declarationTokens).contains("final");
- boolean isStatic = Arrays.asList(declarationTokens).contains("static");
- String name = declarationTokens[declarationTokens.length - 1];
- if (name.endsWith(";")) {
- name = name.substring(0, name.length() - 1).trim();
- }
- String className = declarationTokens[declarationTokens.length - 2];
- String type = TagManager.resolveClassName(className, compiler);
- compiler.addScriptField(new FieldDescriptor(name, Modifier.PUBLIC, type, compiler.getClassLoader())); // TODO: determine the actual modifiers
- if (equals != -1 && !isFinal && !isStatic) { // declare the field in the class body, but wait to actually initialize it
- //compiler.bodyCode.append(text.substring(0, equals).trim());
- compiler.bodyCode.append(text.substring(0, equals).trim()).append(";");
- String initializer = text.substring(equals + 1).trim();
- if (type.endsWith("[]")) {
- initializer = "new " + type + " " + initializer;
- }
- final String finalInitializer = name + " = " + initializer;
- compiler.registerInitializer(new Runnable() {
- public void run() {
- compiler.registerCompiledObject(new ScriptInitializer(finalInitializer, compiler));
- }
- });
- } else {
- compiler.bodyCode.append(text);
- }
- compiler.bodyCode.append("\n");
- //compiler.bodyCode.append(";\n");
- } else {
- String text = node.getText().trim();
- if (text.length() > 0) {
- if (!text.endsWith(";")) {
- text += ";";
- }
- compiler.initializer.append(text);
- //compiler.initializer.append(";\n");
- }
- }
- }
-
-
- public void registerScript(String script) throws CompilerException {
- JavaParser p = new JavaParser(new StringReader(script));
- //JavaParser p = new JavaParser(new StringReader(script + ";"));
- while (!p.Line()) {
- SimpleNode node = p.popNode();
- if (node != null) {
- scanScriptNode(node);
- }
- }
- }
+ }
+
+
+ private void scanScriptNode(SimpleNode node) throws CompilerException {
+ int nodeType = getLineType(node);
+ if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) { // have to handle imports early so the preprocessing takes them into account
+ String text = node.getChild(0).getText().trim();
+ if (text.startsWith("import")) {
+ text = text.substring("import".length()).trim();
+ }
+ if (text.endsWith(";")) {
+ text = text.substring(0, text.length() - 1);
+ }
+ compiler.addImport(text);
+ }
+
+ preprocessScriptNode(node, false);
+
+ if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) {
+ // do nothing, already handled above
+ } else if (nodeType == JavaParserTreeConstants.JJTMETHODDECLARATION) {
+ String returnType = null;
+ String name = null;
+ List<String> parameterTypes = new ArrayList<String>();
+ //List<String> parameterNames = new ArrayList<String>();
+ SimpleNode methodDeclaration = node.getChild(0).getChild(1);
+ assert methodDeclaration.getId() == JavaParserTreeConstants.JJTMETHODDECLARATION;
+ for (int i = 0; i < methodDeclaration.jjtGetNumChildren(); i++) {
+ SimpleNode child = methodDeclaration.getChild(i);
+ int type = child.getId();
+ if (type == JavaParserTreeConstants.JJTRESULTTYPE) {
+ String rawReturnType = child.getText().trim();
+ returnType = TagManager.resolveClassName(rawReturnType, compiler);
+ // FIXME: this check fails for inner classes defined in this file
+ //if (returnType == null)
+ // throw new CompilerException("could not find class '" + rawReturnType + "'");
+ } else
+ if (type == JavaParserTreeConstants.JJTMETHODDECLARATOR) {
+ name = child.firstToken.image.trim();
+ SimpleNode formalParameters = child.getChild(0);
+ assert formalParameters.getId() == JavaParserTreeConstants.JJTFORMALPARAMETERS;
+ for (int j = 0; j < formalParameters.jjtGetNumChildren(); j++)
+ {
+ SimpleNode parameter = formalParameters.getChild(j);
+ String rawParameterType = parameter.getChild(1).getText().trim().replaceAll("\\.\\.\\.", "[]");
+ String parameterType = TagManager.resolveClassName(rawParameterType, compiler);
+ // FIXME: this check fails for inner classes defined in this file
+ //if (parameterType == null)
+ // throw new CompilerException("could not find class '" + rawParameterType + "'");
+ parameterTypes.add(parameterType);
+ //parameterNames.add(parameter.getChild(2).getText().trim());
+ }
+ }
+ }
+ compiler.appendBodyCode(node.getText());
+ //compiler.bodyCode.append(";\n");
+ compiler.addScriptMethod(new MethodDescriptor(name, Modifier.PUBLIC, returnType, parameterTypes.toArray(new String[parameterTypes.size()]), compiler.getClassLoader()));
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTCLASSORINTERFACEDECLARATION ||
+ nodeType == JavaParserTreeConstants.JJTINITIALIZER) {
+ String str = node.getText().trim();
+ if (str.endsWith(";")) {
+ str+=";";
+ }
+ compiler.appendBodyCode(str);
+ //compiler.bodyCode.append(";\n");
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTCONSTRUCTORDECLARATION) {
+ processConstructor(node.getChild(0).getChild(0).getText(), node.getChild(0).getChild(1));
+ } else
+ if (nodeType == JavaParserTreeConstants.JJTLOCALVARIABLEDECLARATION || nodeType == JavaParserTreeConstants.JJTFIELDDECLARATION) {
+ // the "local" variable declarations in this expression aren't actually local -- they are flagged local
+ // just because there isn't an enclosing class scope visible to the parser. "Real" local variable
+ // declarations won't show up here, because they will be buried inside of methods.
+ String text = node.getText().trim();
+ if (!text.endsWith(";")) {
+ text+=";";
+ }
+ String declaration = text;
+ int equals = text.indexOf("=");
+ if (equals != -1) {
+ declaration = declaration.substring(0, equals);
+ }
+ declaration = declaration.trim();
+ String[] declarationTokens = declaration.split("\\s");
+ boolean isFinal = Arrays.asList(declarationTokens).contains("final");
+ boolean isStatic = Arrays.asList(declarationTokens).contains("static");
+ String name = declarationTokens[declarationTokens.length - 1];
+ if (name.endsWith(";")) {
+ name = name.substring(0, name.length() - 1).trim();
+ }
+ String className = declarationTokens[declarationTokens.length - 2];
+ String type = TagManager.resolveClassName(className, compiler);
+ compiler.addScriptField(new FieldDescriptor(name, Modifier.PUBLIC, type, compiler.getClassLoader())); // TODO: determine the actual modifiers
+ if (equals != -1 && !isFinal && !isStatic) { // declare the field in the class body, but wait to actually initialize it
+ //compiler.bodyCode.append(text.substring(0, equals).trim());
+ compiler.appendBodyCode(text.substring(0, equals).trim() + ";");
+ String initializer = text.substring(equals + 1).trim();
+ if (type.endsWith("[]")) {
+ initializer = "new " + type + " " + initializer;
+ }
+ final String finalInitializer = name + " = " + initializer;
+ compiler.registerInitializer(new Runnable() {
+ public void run() {
+ compiler.registerCompiledObject(new ScriptInitializer(finalInitializer, compiler));
+ }
+ });
+ } else {
+ compiler.appendBodyCode(text);
+ }
+ compiler.appendBodyCode("\n");
+ //compiler.bodyCode.append(";\n");
+ } else {
+ String text = node.getText().trim();
+ if (text.length() > 0) {
+ if (!text.endsWith(";")) {
+ text += ";";
+ }
+ compiler.appendInitializerCode(text);
+ //compiler.initializer.append(";\n");
+ }
+ }
+ }
+
+
+ public void registerScript(String script) throws CompilerException {
+ JavaParser p = new JavaParser(new StringReader(script));
+ //JavaParser p = new JavaParser(new StringReader(script + ";"));
+ while (!p.Line()) {
+ SimpleNode node = p.popNode();
+ if (node != null) {
+ scanScriptNode(node);
+ }
+ }
+ }
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/css/Stylesheet.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/css/Stylesheet.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/css/Stylesheet.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -168,7 +168,7 @@
ClassDescriptorLoader.getClassDescriptor(MouseListener.class).getMethodDescriptor("mouseExited",
new ClassDescriptor[]{ClassDescriptorLoader.getClassDescriptor(MouseEvent.class)}),
propertyCode, compiler);
- compiler.initDataBindings.append("{").append(propertyCode).append("}");
+ compiler.appendInitDataBindings("{" + propertyCode + "}");
}
catch (NoSuchMethodException e) {
compiler.reportError("mouseout pseudoclass cannot be applied to object " + object.getObjectClass().getName() + " (no addMouseListener method)");
@@ -193,7 +193,7 @@
ClassDescriptorLoader.getClassDescriptor(MouseListener.class).getMethodDescriptor("mouseReleased",
new ClassDescriptor[]{ClassDescriptorLoader.getClassDescriptor(MouseEvent.class)}),
propertyCode, compiler);
- compiler.initDataBindings.append("{").append(propertyCode).append("}");
+ compiler.appendInitDataBindings("{" + propertyCode + "}");
}
catch (NoSuchMethodException e) {
compiler.reportError("mouseup pseudoclass cannot be applied to object " + object.getObjectClass().getName() + " (no addMouseListener method)");
@@ -203,11 +203,12 @@
pseudoClass = replaceObjectReferences(pseudoClass, object.getJavaCode());
String dest = object.getId() + ".style." + pseudoClass + ".add";
String destCode = TypeManager.getJavaCode(dest);
- if (compiler.processDataBinding.length() > 0)
- compiler.processDataBinding.append("else ");
- compiler.processDataBinding.append("if ($dest.equals(").append(destCode).append(")) { if (").append(pseudoClass).append(") { ").append(propertyCode).append("} }");
+ if (compiler.haveProcessDataBinding()) {
+ compiler.appendProcessDataBinding("else ");
+ }
+ compiler.appendProcessDataBinding("if ($dest.equals(" + destCode + ")) { if (" + pseudoClass + ") { "+ propertyCode + "} }");
new DataSource(dest, pseudoClass, compiler).compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + destCode + ")");
- compiler.initDataBindings.append("applyDataBinding(").append(destCode).append(");");
+ compiler.appendInitDataBindings("applyDataBinding("+ destCode + ");");
} else
throw new IllegalArgumentException("unrecognized pseudoclass: " + pseudoClass);
}
@@ -267,11 +268,12 @@
pseudoClass = replaceObjectReferences(pseudoClass, object.getJavaCode());
String dest = object.getId() + ".style." + pseudoClass + ".remove";
String destCode = TypeManager.getJavaCode(dest);
- if (compiler.processDataBinding.length() > 0)
- compiler.processDataBinding.append("else ");
- compiler.processDataBinding.append("if ($dest.equals(").append(destCode).append(")) { if (").append(invert(pseudoClass)).append(") { ").append(propertyCode).append("} }");
+ if (compiler.haveProcessDataBinding()) {
+ compiler.appendProcessDataBinding("else ");
+ }
+ compiler.appendProcessDataBinding("if ($dest.equals(" + destCode + ")) { if (" + invert(pseudoClass) + ") { " + propertyCode + "} }");
new DataSource(dest, pseudoClass, compiler).compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + destCode + ")");
- compiler.initDataBindings.append("applyDataBinding(").append(destCode).append(");");
+ compiler.appendInitDataBindings("applyDataBinding(" + destCode + ");");
} else
throw new IllegalArgumentException("unrecognized pseudoclass: " + pseudoClass);
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -295,17 +295,10 @@
if (eventInfo != null) { // a "proxied" event is one that doesn't fire PropertyChangeEvent, so we need to convert its native event type into PropertyChangeEvents
StringBuffer result = new StringBuffer();
String methodName = "$pr" + compiler.getUniqueId(propertyChangeListenerCode);
- boolean methodExists = false;
- JavaMethod[] methods = compiler.getJavaFile().getMethods();
- for (JavaMethod method : methods) {
- if (method.getName().equals(methodName)) {
- methodExists = true;
- break;
- }
- }
+ boolean methodExists = compiler.hasMethod(methodName);
ClassDescriptor eventClass = getEventClass(eventInfo.listenerClass);
if (!methodExists) {
- compiler.getJavaFile().addMethod(new JavaMethod(Modifier.PUBLIC, "void", methodName,
+ compiler.addMethodToJavaFile(new JavaMethod(Modifier.PUBLIC, "void", methodName,
new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null,
propertyChangeListenerCode + ".propertyChange(null);"));
}
@@ -358,19 +351,12 @@
if (eventInfo != null) { // a "proxied" event is one that doesn't fire PropertyChangeEvent, so we need to convert its native event type into PropertyChangeEvents
StringBuffer result = new StringBuffer();
String methodName = "$pr" + compiler.getUniqueId(propertyChangeListenerCode);
- boolean methodExists = false;
- JavaMethod[] methods = compiler.getJavaFile().getMethods();
- for (JavaMethod method : methods) {
- if (method.getName().equals(methodName)) {
- methodExists = true;
- break;
- }
- }
- ClassDescriptor eventClass = getEventClass(eventInfo.listenerClass);
+ boolean methodExists = compiler.hasMethod(methodName);
if (!methodExists) {
- compiler.getJavaFile().addMethod(new JavaMethod(Modifier.PUBLIC, "void", methodName,
+ ClassDescriptor eventClass = getEventClass(eventInfo.listenerClass);
+ compiler.addMethodToJavaFile(new JavaMethod(Modifier.PUBLIC, "void", methodName,
new JavaArgument[]{new JavaArgument(JAXXCompiler.getCanonicalName(eventClass), "event")}, null,
- propertyChangeListenerCode + ".propertyChange(null);"));
+ propertyChangeListenerCode + ".propertyChange(null);"));
}
try {
String modelMemberName = eventInfo.modelName != null ? "get" + JAXXCompiler.capitalize(eventInfo.modelName) : null;
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/ApplicationHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/ApplicationHandler.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/ApplicationHandler.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -26,7 +26,7 @@
@Override
public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) throws CompilerException {
if (propertyName.equals("lookAndFeel") && stringValue != null && !stringValue.trim().startsWith("{")) {
- compiler.bodyCode.append("{ ").append(object.getJavaCode()).append(".setLookAndFeel(").append(TypeManager.getJavaCode(stringValue)).append("); }").append(JAXXCompiler.getLineSeparator());
+ compiler.appendBodyCode("{ " + object.getJavaCode() + ".setLookAndFeel(" + TypeManager.getJavaCode(stringValue) + "); }" + JAXXCompiler.getLineSeparator());
} else {
super.setAttribute(object, propertyName, stringValue, inline, compiler);
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JInternalFrameHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JInternalFrameHandler.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JInternalFrameHandler.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -48,6 +48,6 @@
@Override
public void setAttributes(CompiledObject object, Element tag, JAXXCompiler compiler) throws CompilerException {
super.setAttributes(object, tag, compiler);
- compiler.initializer.append(object.getId()).append(".pack();\n");
+ compiler.appendInitializerCode(object.getId() + ".pack();\n");
}
}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JWindowHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JWindowHandler.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/JWindowHandler.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -50,9 +50,10 @@
@Override
public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
super.compileSecondPass(tag, compiler);
- CompiledObject object = (CompiledObject) objectMap.get(tag);
+ CompiledObject object = objectMap.get(tag);
Map properties = object.getProperties();
- if (!properties.containsKey("width") && !properties.containsKey("height"))
- compiler.lateInitializer.append(object.getId()).append(".pack();\n");
+ if (!properties.containsKey("width") && !properties.containsKey("height")) {
+ compiler.appendLateInitializer(object.getId() + ".pack();\n");
+ }
}
}
\ No newline at end of file
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-19 18:05:04 UTC (rev 976)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-19 19:44:06 UTC (rev 977)
@@ -1,6 +1,7 @@
package org.codelutin.jaxx;
import jaxx.compiler.JAXXCompiler;
+import jaxx.compiler.JAXXCompilerHelper;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.SystemStreamLog;
@@ -89,8 +90,8 @@
//do nothing
}
});
- Field fieldCompilers = JAXXCompiler.class.getDeclaredField("compilers");
- Field fieldErrorCount = JAXXCompiler.class.getDeclaredField("errorCount");
+ Field fieldCompilers = JAXXCompilerHelper.class.getDeclaredField("compilers");
+ Field fieldErrorCount = JAXXCompilerHelper.class.getDeclaredField("errorCount");
fieldCompilers.setAccessible(true);
fieldErrorCount.setAccessible(true);
@@ -207,8 +208,8 @@
//do nothing
}
});
- Field fieldCompilers = JAXXCompiler.class.getDeclaredField("compilers");
- Field fieldErrorCount = JAXXCompiler.class.getDeclaredField("errorCount");
+ Field fieldCompilers = JAXXCompilerHelper.class.getDeclaredField("compilers");
+ Field fieldErrorCount = JAXXCompilerHelper.class.getDeclaredField("errorCount");
fieldCompilers.setAccessible(true);
fieldErrorCount.setAccessible(true);
1
0
Author: tchemit
Date: 2008-10-19 18:05:04 +0000 (Sun, 19 Oct 2008)
New Revision: 976
Added:
lutinjaxx/tags/20081019_0.5-SNAPSHOT-before-JAXXCompiler-refactor/
Log:
make a tag before commit of JAXXCompiler refactor in two class : JAXXCompiler and JAXXObjectGenerator wich is now responsible of the java file generator
Copied: lutinjaxx/tags/20081019_0.5-SNAPSHOT-before-JAXXCompiler-refactor (from rev 975, lutinjaxx/trunk)
1
0
r975 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:29:08 +0000 (Sat, 18 Oct 2008)
New Revision: 975
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
Log:
improve coherence
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 11:28:25 UTC (rev 974)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 11:29:08 UTC (rev 975)
@@ -98,6 +98,7 @@
}
String bean = info.getBean();
+ boolean error = false;
if (bean != null) {
if (compiler.checkReference(tag, bean, true, BEAN_ATTRIBUTE)) {
String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler);
@@ -105,23 +106,37 @@
// add generic type to validator
JAXXBeanInfo beanInfo = info.getBeanDescriptor(compiler);
info.setGenericTypes(new String[]{beanInfo.getJAXXBeanDescriptor().getClassDescriptor().getName()});
+ } else {
+ error=true;
}
- }
- if (info.getAutoField()) {
- if (bean == null) {
- compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode");
- } else {
+ //TODO: checkthe bean is not already used in another validator
+ if (!error && compiler.isBeanUsedByValidator(bean)) {
+ compiler.reportError("the bean '" + bean + "' is already used in another the validator, can not used it in '" + tag + "'");
+ error = true;
+ }
+
+ if (!error && info.getAutoField()) {
+ //if (bean == null) {
+ // compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode");
+ //} else {
registerAutoFieldBean(tag, compiler, info);
+ // }
}
- }
- // add fieldrepresentation invocations
- addFieldRepresentations(tag, compiler, info);
+ if (!error && info.getBeanDescriptor(compiler) != null) {
- // register the validator in compiler
- compiler.registerValidator(info);
+ // add fieldrepresentation invocations
+ addFieldRepresentations(tag, compiler, info);
+ // register the validator in compiler
+ compiler.registerValidator(info);
+ }
+
+ } else {
+ compiler.reportError("tag '" + tag + "' requires a bean attribute");
+ }
+
// close the compiled object
compiler.closeComponent(info);
}
@@ -178,7 +193,7 @@
}
if (compiler.isComponentUsedByValidator(component)) {
// component is already used by another validator
- compiler.reportError("component '"+component+"' is already used by another validator.");
+ compiler.reportError("component '" + component + "' is already used by another validator.");
continue;
}
String keyCode = TypeManager.getJavaCode(propertyName);
@@ -300,7 +315,12 @@
public JAXXBeanInfo getBeanDescriptor(JAXXCompiler compiler) {
if (beanDescriptor == null && bean != null) {
try {
- ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(compiler.getSymbolTable().getClassTagIds().get(bean));
+ String beanClassName = compiler.getSymbolTable().getClassTagIds().get(bean);
+ if (beanClassName == null) {
+ compiler.reportError("could not find class of the bean '" + bean + "'");
+ return null;
+ }
+ ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(beanClassName);
beanDescriptor = getJAXXBeanInfo(beanClassDescriptor);
} catch (ClassNotFoundException e) {
compiler.reportError("could not load class " + bean);
1
0
r974 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:28:25 +0000 (Sat, 18 Oct 2008)
New Revision: 974
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java
Log:
test if component is not already attached to another validator
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java 2008-10-18 11:27:58 UTC (rev 973)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java 2008-10-18 11:28:25 UTC (rev 974)
@@ -61,8 +61,13 @@
}
component = component.trim();
+ // check component is not already used by this validator
+ if (validator.getFields().containsValue(component)) {
+ compiler.reportError(FIELD_VALIDATOR_TAG + " tag found a attribute " + COMPONENT_ATTRIBUTE + " ["+component+"] already used in this validator");
+ return;
+ }
// check component exist (again perharps, but if error will known exactly which tag failed...)
- if (compiler.checkReference(tag, component, true, component)) {
+ if (compiler.checkReference(tag, component, true, COMPONENT_ATTRIBUTE)) {
// add a field
validator.addField(name, component, compiler);
}
1
0
r973 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:27:58 +0000 (Sat, 18 Oct 2008)
New Revision: 973
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
Log:
catch runtime execption to add error to report
add method to test if a bean was not previously attached to a validator
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-18 11:26:34 UTC (rev 972)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-18 11:27:58 UTC (rev 973)
@@ -347,7 +347,13 @@
if (log.isDebugEnabled()) {
log.debug(runnable);
}
- runnable.run();
+ try {
+ runnable.run();
+ } catch (Exception e) {
+ //TC - 20081018 report error and quit
+ reportError(e.getMessage());
+ return;
+ }
}
initializers.clear();
}
@@ -2085,7 +2091,10 @@
return false;
}
finally {
- reset();
+ //TC - 20081018 only reset when no error was detected
+ if (errorCount==0) {
+ reset();
+ }
}
}
@@ -2210,6 +2219,21 @@
}
/**
+ * Test if a given bean is attached to a validator.
+ *
+ * @param beanId the bean to test
+ * @return <code>true</code> if the given bean is attached to a validator, <code>false</code> otherwise
+ */
+ public boolean isBeanUsedByValidator(String beanId) {
+ for (CompiledBeanValidator validator : validators) {
+ if(beanId.equals(validator.getBean())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Check that a reference exists in symbol table on second compil pass
*
* @param tag the current tag
1
0
r972 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:26:34 +0000 (Sat, 18 Oct 2008)
New Revision: 972
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java
Log:
catch runtime execption to add error to report
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java 2008-10-18 11:25:58 UTC (rev 971)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/DefaultObjectHandler.java 2008-10-18 11:26:34 UTC (rev 972)
@@ -859,6 +859,8 @@
}
catch (ClassNotFoundException e) {
throw new CompilerException(e);
+ } catch (IllegalArgumentException e) {
+ compiler.reportError(e.getMessage());
}
}
1
0
r971 - lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:25:58 +0000 (Sat, 18 Oct 2008)
New Revision: 971
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
Log:
add excludes property on goal
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-10-18 11:25:38 UTC (rev 970)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-10-18 11:25:58 UTC (rev 971)
@@ -116,6 +116,13 @@
protected String[] includes;
/**
+ * pour filter les fichiers a ne pas traiter
+ *
+ * @parameter expression="${jaxx.excludes}"
+ */
+ protected String[] excludes;
+
+ /**
* to force generation of java source for any jaxx files with no timestamp checking.
* <p/>
* By default, never force generation.
@@ -179,6 +186,11 @@
ds.setBasedir(src);
boolean noIncludes = includes == null || includes.length == 0;
ds.setIncludes(noIncludes ? INCLUDES : includes);
+
+ if (excludes!=null && excludes.length>0) {
+ ds.setExcludes(excludes);
+ }
+
ds.scan();
String[] files = ds.getIncludedFiles();
if (verbose) {
1
0
r970 - lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:25:38 +0000 (Sat, 18 Oct 2008)
New Revision: 970
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
Log:
add test cases for validator + improve test of errors
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-18 11:25:15 UTC (rev 969)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-18 11:25:38 UTC (rev 970)
@@ -1,16 +1,18 @@
package org.codelutin.jaxx;
+import jaxx.compiler.JAXXCompiler;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.SystemStreamLog;
import java.io.File;
+import java.lang.reflect.Field;
+import java.util.Map;
public class CompilerTest extends JaxxBaseTest {
- protected String prefix = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testcases" + File.separator;
+ protected String prefix = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "testcases" + File.separator;
- public String getPrefix() {
+ public String getPrefix() {
return prefix;
}
@@ -65,34 +67,51 @@
// init mojo to get alls files to treate
mojo.init();
String[] files = mojo.getFiles();
+ assertEquals(34, mojo.getFiles().length);
+ mojo.setLog(new SystemStreamLog() {
+ @Override
+ public boolean isErrorEnabled() {
+ return false;
+ }
+
+ @Override
+ public void error(Throwable error) {
+ //do nothing
+ }
+
+ @Override
+ public void error(CharSequence content) {
+ //do nothing
+ }
+
+ @Override
+ public void error(CharSequence content, Throwable error) {
+ //do nothing
+ }
+ });
+ Field fieldCompilers = JAXXCompiler.class.getDeclaredField("compilers");
+ Field fieldErrorCount = JAXXCompiler.class.getDeclaredField("errorCount");
+
+ fieldCompilers.setAccessible(true);
+ fieldErrorCount.setAccessible(true);
+
// execute mjo on each jaxx file to produce the error
for (String file : files) {
- getLog().info("test bad file "+file);
+ getLog().info("test bad file " + file);
mojo.setFiles(new String[]{file});
try {
- mojo.setLog(new SystemStreamLog() {
- public boolean isErrorEnabled() {
- return false;
- }
-
- public void error(Throwable error) {
- //do nothing
- }
-
- public void error(CharSequence content) {
- //do nothing
- }
-
- public void error(CharSequence content, Throwable error) {
- //do nothing
- }
- });
mojo.doAction();
// should never pass
fail();
} catch (MojoExecutionException e) {
// ok jaxx compiler failed
assertTrue(true);
+
+ Map<String, JAXXCompiler> compilers = (Map<String, JAXXCompiler>) fieldCompilers.get(null);
+ assertEquals(1, compilers.size());
+ JAXXCompiler compiler = compilers.values().iterator().next();
+ Integer nberrors = (Integer) fieldErrorCount.get(compiler);
+ assertTrue(nberrors > 0);
}
}
}
@@ -155,4 +174,64 @@
assertEquals(1, files.length);
assertTrue(mojo.getUpdater().getMirrorFile(srcFile).lastModified() > oldTime);
}
+
+ public void testValidatorOk() throws Exception {
+ mojo.execute();
+ assertEquals(1, mojo.getFiles().length);
+
+ }
+
+ public void testValidatorErrors() throws Exception {
+ // init mojo to get alls files to treate
+ mojo.init();
+ String[] files = mojo.getFiles();
+ assertEquals(16, mojo.getFiles().length);
+ mojo.setLog(new SystemStreamLog() {
+ @Override
+ public boolean isErrorEnabled() {
+ return false;
+ }
+
+ @Override
+ public void error(Throwable error) {
+ //do nothing
+ }
+
+ @Override
+ public void error(CharSequence content) {
+ //do nothing
+ }
+
+ @Override
+ public void error(CharSequence content, Throwable error) {
+ //do nothing
+ }
+ });
+ Field fieldCompilers = JAXXCompiler.class.getDeclaredField("compilers");
+ Field fieldErrorCount = JAXXCompiler.class.getDeclaredField("errorCount");
+
+ fieldCompilers.setAccessible(true);
+ fieldErrorCount.setAccessible(true);
+
+ // execute mjo on each jaxx file to produce the error
+ for (String file : files) {
+ getLog().info("test bad file " + file);
+ mojo.setFiles(new String[]{file});
+ try {
+ mojo.doAction();
+ // should never pass
+ fail();
+ } catch (MojoExecutionException e) {
+ // ok jaxx compiler failed
+ assertTrue(true);
+
+ Map<String, JAXXCompiler> compilers = (Map<String, JAXXCompiler>) fieldCompilers.get(null);
+ assertEquals(1, compilers.size());
+ JAXXCompiler compiler = compilers.values().iterator().next();
+ Integer nberrors = (Integer) fieldErrorCount.get(compiler);
+ assertEquals(1, nberrors.intValue());
+ }
+ }
+ }
+
}
\ No newline at end of file
1
0
r969 - lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:25:15 +0000 (Sat, 18 Oct 2008)
New Revision: 969
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/BuildExamples.java
Log:
deprecated test
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/BuildExamples.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/BuildExamples.java 2008-10-18 11:25:03 UTC (rev 968)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/BuildExamples.java 2008-10-18 11:25:15 UTC (rev 969)
@@ -3,8 +3,8 @@
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
-import org.apache.maven.it.VerificationException;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
@@ -13,8 +13,11 @@
import java.util.Arrays;
import java.util.List;
-/** @author chemit */
-public class BuildExamples extends TestCase {
+/**
+ * @author chemit
+ * @deprecated This goal is not ny longer used : we have specific maven modules to build examples...
+ */
+public abstract class BuildExamples extends TestCase {
protected static final Log log = LogFactory.getLog(BuildExamples.class);
@@ -95,8 +98,8 @@
protected void buildExample() throws VerificationException, IOException {
verifier.executeGoals(Arrays.asList("jaxx:generate", "package"));
verifier.verifyErrorFreeLog();
- FileUtils.copyDirectory(new File(siteDir, "lib"), new File(siteDestDir,"lib"));
- FileUtils.copyDirectory(siteDir, siteDestDir,"*.jnlp","");
+ FileUtils.copyDirectory(new File(siteDir, "lib"), new File(siteDestDir, "lib"));
+ FileUtils.copyDirectory(siteDir, siteDestDir, "*.jnlp", "");
}
1
0
r968 - in lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases: . validator validator/errors validator/ok
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 11:25:03 +0000 (Sat, 18 Oct 2008)
New Revision: 968
Added:
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorErrors.xml
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorOk.xml
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/AutoFieldComponentNotFound.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean2.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInOtherValidator.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInSameValidator.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldBeanPropertyNotFound.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated2.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound2.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName2.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/Model.java
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/NoBean.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundBean.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundErrorListModel.jaxx
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Identity.java
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Model.java
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/Errors.xml
Log:
add test cases for validator
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/Errors.xml
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/Errors.xml 2008-10-18 02:09:55 UTC (rev 967)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/Errors.xml 2008-10-18 11:25:03 UTC (rev 968)
@@ -15,6 +15,9 @@
<includes>
<value>**/errors/*.jaxx</value>
</includes>
+ <excludes>
+ <value>**/validator/errors/*.jaxx</value>
+ </excludes>
</configuration>
</plugin>
</plugins>
Copied: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorErrors.xml (from rev 948, lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/Errors.xml)
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorErrors.xml (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorErrors.xml 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-jaxx-plugin</artifactId>
+ <configuration>
+ <src>${basedir}/src/test/resources</src>
+ <outJava>${basedir}/target/it-generated-source/java</outJava>
+ <outResource>${basedir}/target/it-generated-source/resources</outResource>
+ <force>true</force>
+ <includes>
+ <value>**/validator/errors/*.jaxx</value>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Property changes on: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorErrors.xml
___________________________________________________________________
Name: svn:mergeinfo
+
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorOk.xml
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorOk.xml (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/ValidatorOk.xml 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-jaxx-plugin</artifactId>
+ <configuration>
+ <src>${basedir}/src/test/resources</src>
+ <outJava>${basedir}/target/it-generated-source/java</outJava>
+ <outResource>${basedir}/target/it-generated-source/resources</outResource>
+ <force>true</force>
+ <includes>
+ <value>**/validator/ok/*.jaxx</value>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/AutoFieldComponentNotFound.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/AutoFieldComponentNotFound.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/AutoFieldComponentNotFound.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,263 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' autoField='true' strictMode='true' errorListModel='errors'/>
+
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='textFake' text='{model.getText()}'
+ onKeyReleased='model.setText(textFake.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors' bean='yo'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean2.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean2.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedBean2.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedErrorListModel.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors' errorListModel='yo'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInOtherValidator.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInOtherValidator.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInOtherValidator.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInSameValidator.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInSameValidator.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/DuplicatedFieldInSameValidator.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,267 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldBeanPropertyNotFound.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldBeanPropertyNotFound.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldBeanPropertyNotFound.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field name="fake" component="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field name="text2" component="text"/>
+ <field name="text" component="text"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated2.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated2.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentDuplicated2.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field name="text" component="text"/>
+ <field name="text2" />
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field name="text2" component="fake"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound2.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound2.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldComponentNotFound2.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field name="fake"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field />
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName2.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName2.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/FieldNoName2.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors' bean="model">
+ <field component="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/Model.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/Model.java (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/Model.java 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,66 @@
+package testcases.validator.errors;
+
+import java.beans.*;
+
+public class Model {
+
+ protected String text = "text";
+
+ protected String text2 = "text2";
+
+ protected int ratio = 51;
+
+
+ PropertyChangeSupport p;
+
+ public Model() {
+ p = new PropertyChangeSupport(this);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ p.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ p.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.removePropertyChangeListener(propertyName, listener);
+ }
+
+
+ public String getText() {
+ return text;
+ }
+
+ public String getText2() {
+ return text2;
+ }
+
+ public int getRatio() {
+ return ratio;
+ }
+
+ public void setText(String text) {
+ String oldText = this.text;
+ this.text = text;
+ p.firePropertyChange("text", oldText, text);
+ }
+
+ public void setText2(String text2) {
+ String oldText2 = this.text2;
+ this.text2 = text2;
+ p.firePropertyChange("text2", oldText2, text2);
+ }
+
+ public void setRatio(int ratio) {
+ int oldRatio = this.ratio;
+ this.ratio = ratio;
+ p.firePropertyChange("ratio",oldRatio, ratio);
+ }
+}
\ No newline at end of file
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/NoBean.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/NoBean.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/NoBean.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundBean.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundBean.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundBean.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='fake' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundErrorListModel.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundErrorListModel.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/errors/UnfoundErrorListModel.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,266 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='fake'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Identity.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Identity.java (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Identity.java 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,79 @@
+package testcases.validator.ok;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+public class Identity {
+
+ protected String firstName = "";
+
+ protected String lastName = "";
+
+ protected String email = "dummy(a)codelutin.com";
+
+ protected int age = 51;
+
+
+ PropertyChangeSupport p;
+
+ public Identity() {
+ p = new PropertyChangeSupport(this);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ p.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ p.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.removePropertyChangeListener(propertyName, listener);
+ }
+
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setFirstName(String firstName) {
+ String oldFirstName = this.firstName;
+ this.firstName = firstName;
+ p.firePropertyChange("firstName", oldFirstName, firstName);
+ }
+
+ public void setLastName(String lastName) {
+ String oldLastName = this.lastName;
+ this.lastName = lastName;
+ p.firePropertyChange("lastName", oldLastName, lastName);
+ }
+
+ public void setEmail(String email) {
+ String oldEmail =this.email;
+ this.email = email;
+ p.firePropertyChange("email", oldEmail, email);
+ }
+
+ public void setAge(int age) {
+ int oldAge = this.age;
+ this.age = age;
+ p.firePropertyChange("age", oldAge, age);
+ }
+}
\ No newline at end of file
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Model.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Model.java (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Model.java 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,66 @@
+package testcases.validator.ok;
+
+import java.beans.*;
+
+public class Model {
+
+ protected String text = "text";
+
+ protected String text2 = "text2";
+
+ protected int ratio = 51;
+
+
+ PropertyChangeSupport p;
+
+ public Model() {
+ p = new PropertyChangeSupport(this);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ p.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ p.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.removePropertyChangeListener(propertyName, listener);
+ }
+
+
+ public String getText() {
+ return text;
+ }
+
+ public String getText2() {
+ return text2;
+ }
+
+ public int getRatio() {
+ return ratio;
+ }
+
+ public void setText(String text) {
+ String oldText = this.text;
+ this.text = text;
+ p.firePropertyChange("text", oldText, text);
+ }
+
+ public void setText2(String text2) {
+ String oldText2 = this.text2;
+ this.text2 = text2;
+ p.firePropertyChange("text2", oldText2, text2);
+ }
+
+ public void setRatio(int ratio) {
+ int oldRatio = this.ratio;
+ this.ratio = ratio;
+ p.firePropertyChange("ratio",oldRatio, ratio);
+ }
+}
\ No newline at end of file
Added: lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx (rev 0)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/resources/testcases/validator/ok/Validation.jaxx 2008-10-18 11:25:03 UTC (rev 968)
@@ -0,0 +1,270 @@
+<Application title="Validation.jaxx">
+
+ <!-- models -->
+ <Model id='model'/>
+ <Model id='model2'/>
+ <Identity id='identity'/>
+
+ <!-- errors model -->
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
+ <field name="text" component="_text"/>
+ <field name="text2" component="_text2"/>
+ <field name="ratio" component="_ratio"/>
+ </BeanValidator>
+ <BeanValidator id='validator3' autoField='true' bean='identity' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.TranslucentValidationUI">
+ <field name="email" component="email2"/>
+ </BeanValidator>
+
+ <Table fill='both'>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text' text='{model.getText()}'
+ onKeyReleased='model.setText(text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='text2' text='{model.getText2()}'
+ onKeyReleased='model.setText2(text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
+ onStateChanged='model.setRatio(ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Form2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text' text='{model2.getText()}'
+ onKeyReleased='model2.setText(_text.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='_text2' text='{model2.getText2()}'
+ onKeyReleased='model2.setText2(_text2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
+ onStateChanged='model2.setRatio(_ratio.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Model2")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='Text:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Text2:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{model2.getText2()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Ratio:'/>
+ </cell>
+ <cell>
+ <JLabel text='{model2.getRatio()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
+ <JScrollPane>
+ <JList model='{errors}'/>
+ </JScrollPane>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
+ <cell columns='2' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton text='cancel' onActionPerformed='dispose()'/>
+ <JButton id='ok' text='valid' onActionPerformed='dispose()'/>
+ </JPanel>
+ </cell>
+ </row>
+
+ </Table>
+</Application>
1
0
r967 - in lutinjaxx/trunk/maven-jaxx-plugin/src: main/java/org/codelutin/jaxx test/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 02:09:55 +0000 (Sat, 18 Oct 2008)
New Revision: 967
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
Log:
minimize logging when testing errors and do not test n times the same files :)
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-10-18 02:02:29 UTC (rev 966)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-10-18 02:09:55 UTC (rev 967)
@@ -250,6 +250,11 @@
return;
}
+ doAction();
+
+ }
+
+ public void doAction() throws MojoExecutionException {
getLog().info("jaxx - will generate " + this.files.length + " jaxx file(s). ");
try {
@@ -271,7 +276,6 @@
throw new MojoExecutionException(e.getMessage(), e);
}
-
}
protected void fixCompileSourceRoots() {
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-18 02:02:29 UTC (rev 966)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-18 02:09:55 UTC (rev 967)
@@ -67,6 +67,7 @@
String[] files = mojo.getFiles();
// execute mjo on each jaxx file to produce the error
for (String file : files) {
+ getLog().info("test bad file "+file);
mojo.setFiles(new String[]{file});
try {
mojo.setLog(new SystemStreamLog() {
@@ -86,15 +87,12 @@
//do nothing
}
});
- mojo.execute();
+ mojo.doAction();
// should never pass
fail();
} catch (MojoExecutionException e) {
// ok jaxx compiler failed
assertTrue(true);
- } catch (MojoFailureException e) {
- // this exception should not appear
- fail();
}
}
}
1
0
r966 - lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 02:02:29 +0000 (Sat, 18 Oct 2008)
New Revision: 966
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
Log:
minimize logging when testing errors
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-18 02:02:02 UTC (rev 965)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/test/java/org/codelutin/jaxx/CompilerTest.java 2008-10-18 02:02:29 UTC (rev 966)
@@ -2,6 +2,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.SystemStreamLog;
import java.io.File;
@@ -68,6 +69,23 @@
for (String file : files) {
mojo.setFiles(new String[]{file});
try {
+ mojo.setLog(new SystemStreamLog() {
+ public boolean isErrorEnabled() {
+ return false;
+ }
+
+ public void error(Throwable error) {
+ //do nothing
+ }
+
+ public void error(CharSequence content) {
+ //do nothing
+ }
+
+ public void error(CharSequence content, Throwable error) {
+ //do nothing
+ }
+ });
mojo.execute();
// should never pass
fail();
1
0
r965 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 02:02:02 +0000 (Sat, 18 Oct 2008)
New Revision: 965
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/StyleHandler.java
Log:
do not throw an error when css parsing has failed... just an exception
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/StyleHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/StyleHandler.java 2008-10-18 01:35:48 UTC (rev 964)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/StyleHandler.java 2008-10-18 02:02:02 UTC (rev 965)
@@ -14,6 +14,7 @@
import jaxx.css.Selector;
import jaxx.css.SimpleNode;
import jaxx.css.Stylesheet;
+import jaxx.css.ParseException;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -161,7 +162,12 @@
protected Stylesheet processStylesheet(String stylesheetText) throws CompilerException {
CSSParser p = new CSSParser(new StringReader(stylesheetText));
- SimpleNode node = p.Stylesheet();
+ SimpleNode node;
+ try {
+ node = p.Stylesheet();
+ } catch (Error e) {
+ throw new CompilerException(e);
+ }
List<Rule> rules = new ArrayList<Rule>();
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
SimpleNode ruleNode = node.getChild(i);
1
0
r964 - in lutinjaxx/trunk/jaxx-example: . Calculator Components Counter LabelStyle Validation
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 01:35:48 +0000 (Sat, 18 Oct 2008)
New Revision: 964
Modified:
lutinjaxx/trunk/jaxx-example/Calculator/pom.xml
lutinjaxx/trunk/jaxx-example/Components/pom.xml
lutinjaxx/trunk/jaxx-example/Counter/pom.xml
lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml
lutinjaxx/trunk/jaxx-example/Validation/pom.xml
lutinjaxx/trunk/jaxx-example/pom.xml
Log:
using webstart plugin 1.0-alpha-2-cl_20081018 :
will not execute this goal form a pom module, so no more need to add in build cycle the webstart plugin on each example (directly in jaxx-example pom)
Modified: lutinjaxx/trunk/jaxx-example/Calculator/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Calculator/pom.xml 2008-10-18 01:34:21 UTC (rev 963)
+++ lutinjaxx/trunk/jaxx-example/Calculator/pom.xml 2008-10-18 01:35:48 UTC (rev 964)
@@ -30,15 +30,6 @@
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo.webstart</groupId>
- <artifactId>webstart-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/Components/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Components/pom.xml 2008-10-18 01:34:21 UTC (rev 963)
+++ lutinjaxx/trunk/jaxx-example/Components/pom.xml 2008-10-18 01:35:48 UTC (rev 964)
@@ -22,8 +22,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>Components example</name>
- <version>0.5-SNAPSHOT</version>
- <inceptionYear>2008</inceptionYear>
<description>Jaxx Components example</description>
<!-- ************************************************************* -->
@@ -32,12 +30,12 @@
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo.webstart</groupId>
- <artifactId>webstart-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>${scm.connection.example}</connection>
+ <developerConnection>${scm.developerConnection.example}</developerConnection>
+ <url>${scm.url.example}</url>
+ </scm>
</project>
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/Counter/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Counter/pom.xml 2008-10-18 01:34:21 UTC (rev 963)
+++ lutinjaxx/trunk/jaxx-example/Counter/pom.xml 2008-10-18 01:35:48 UTC (rev 964)
@@ -30,15 +30,6 @@
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo.webstart</groupId>
- <artifactId>webstart-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml 2008-10-18 01:34:21 UTC (rev 963)
+++ lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml 2008-10-18 01:35:48 UTC (rev 964)
@@ -30,15 +30,6 @@
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo.webstart</groupId>
- <artifactId>webstart-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/Validation/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/pom.xml 2008-10-18 01:34:21 UTC (rev 963)
+++ lutinjaxx/trunk/jaxx-example/Validation/pom.xml 2008-10-18 01:35:48 UTC (rev 964)
@@ -30,15 +30,6 @@
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo.webstart</groupId>
- <artifactId>webstart-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/pom.xml 2008-10-18 01:34:21 UTC (rev 963)
+++ lutinjaxx/trunk/jaxx-example/pom.xml 2008-10-18 01:35:48 UTC (rev 964)
@@ -152,7 +152,7 @@
<plugin>
<groupId>org.codelutin</groupId>
<artifactId>maven-jaxx-plugin</artifactId>
- <version>0.5-SNAPSHOT</version>
+ <version>${current.version}</version>
<configuration>
<src>${basedir}/src/main/java</src>
<force>true</force>
@@ -192,7 +192,7 @@
<plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
- <version>1.0-alpha-2-cl_20081016</version>
+ <version>1.0-alpha-2-cl_20081018</version>
<executions>
<execution>
<phase>package</phase>
@@ -202,6 +202,7 @@
</execution>
</executions>
<configuration>
+ <force>false</force>
<dependencies>
<excludes>
<exclude>javax.help:javahelp</exclude>
@@ -262,6 +263,11 @@
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo.webstart</groupId>
+ <artifactId>webstart-maven-plugin</artifactId>
+ </plugin>
+
</plugins>
</build>
1
0
r963 - lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 01:34:21 +0000 (Sat, 18 Oct 2008)
New Revision: 963
Modified:
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
Log:
validation example with all new stuff (auto JXLayer boxing, uiClass)
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-18 01:33:05 UTC (rev 962)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-18 01:34:21 UTC (rev 963)
@@ -7,7 +7,7 @@
<Identity id='identity'/>
<!-- errors model -->
- <DefaultListModel id='errors' onIntervalAdded='ok.setEnabled(errors.size()==0)' onIntervalRemoved='ok.setEnabled(errors.size()==0)'/>
+ <jaxx.runtime.validator.BeanValidatorErrorListModel id='errors' onContentsChanged='ok.setEnabled(errors.size()==0)'/>
<!-- validators -->
<BeanValidator id='validator' bean='model' errorListModel='errors'>
@@ -15,12 +15,12 @@
<field name="text2"/>
<field name="ratio"/>
</BeanValidator>
- <BeanValidator id='validator2' bean='model2' errorListModel='errors'>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.IconValidationUI">
<field name="text" component="_text"/>
<field name="text2" component="_text2"/>
<field name="ratio" component="_ratio"/>
</BeanValidator>
- <BeanValidator id='validator3' autoField='true' bean='identity' errorListModel='errors'>
+ <BeanValidator id='validator3' autoField='true' bean='identity' errorListModel='errors' uiClass="jaxx.runtime.validator.ui.TranslucentValidationUI">
<field name="email" component="email2"/>
</BeanValidator>
@@ -35,10 +35,8 @@
<JLabel text='Text:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='text' text='{model.getText()}'
onKeyReleased='model.setText(text.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
<row>
@@ -46,10 +44,8 @@
<JLabel text='Text2:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='text2' text='{model.getText2()}'
onKeyReleased='model.setText2(text2.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
@@ -58,10 +54,8 @@
<JLabel text='Ratio:'/>
</cell>
<cell>
- <org.jdesktop.jxlayer.JXLayer>
<JSlider id='ratio' minimum='0' maximum='100' value='{model.getRatio()}'
onStateChanged='model.setRatio(ratio.getValue())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
</Table>
@@ -110,10 +104,8 @@
<JLabel text='Text:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='_text' text='{model2.getText()}'
onKeyReleased='model2.setText(_text.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
<row>
@@ -121,10 +113,8 @@
<JLabel text='Text2:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='_text2' text='{model2.getText2()}'
onKeyReleased='model2.setText2(_text2.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
@@ -133,10 +123,8 @@
<JLabel text='Ratio:'/>
</cell>
<cell>
- <org.jdesktop.jxlayer.JXLayer>
<JSlider id='_ratio' minimum='0' maximum='100' value='{model2.getRatio()}'
onStateChanged='model2.setRatio(_ratio.getValue())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
</Table>
@@ -185,10 +173,8 @@
<JLabel text='FirstName:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='firstName' text='{identity.getFirstName()}'
onKeyReleased='identity.setFirstName(firstName.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
<row>
@@ -196,10 +182,8 @@
<JLabel text='LastName:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='lastName' text='{identity.getLastName()}'
onKeyReleased='identity.setLastName(lastName.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
<row>
@@ -207,10 +191,8 @@
<JLabel text='Email:'/>
</cell>
<cell weightx='1'>
- <org.jdesktop.jxlayer.JXLayer>
<JTextField id='email2' text='{identity.getEmail()}'
onKeyReleased='identity.setEmail(email2.getText())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
@@ -219,10 +201,8 @@
<JLabel text='Age:'/>
</cell>
<cell>
- <org.jdesktop.jxlayer.JXLayer>
<JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
onStateChanged='identity.setAge(age.getValue())'/>
- </org.jdesktop.jxlayer.JXLayer>
</cell>
</row>
</Table>
1
0
r962 - lutinjaxx/trunk/jaxx-core/src/main/resources
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 01:33:05 +0000 (Sat, 18 Oct 2008)
New Revision: 962
Removed:
lutinjaxx/trunk/jaxx-core/src/main/resources/example.jnlp
lutinjaxx/trunk/jaxx-core/src/main/resources/manifest.mf
Log:
not used (see jaxx-examples for jnlp building of examples)
Deleted: lutinjaxx/trunk/jaxx-core/src/main/resources/example.jnlp
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/resources/example.jnlp 2008-10-18 00:56:40 UTC (rev 961)
+++ lutinjaxx/trunk/jaxx-core/src/main/resources/example.jnlp 2008-10-18 01:33:05 UTC (rev 962)
@@ -1,16 +0,0 @@
-<jnlp spec="1.0+" codebase="http://www.jaxxframework.org/examples/@name@" href="@name@.jnlp">
- <information>
- <title>@name@.jaxx</title>
- <vendor>jaxxframework.org</vendor>
- <offline-allowed/>
- </information>
-
- <resources>
- <j2se version="1.4.0+" href="http://java.sun.com/products/autodl/j2se"/>
- <jar href="@name@.jar"/>
- <jar href="../jaxx-runtime.jar"/>
- </resources>
-
- <application-desc main-class="examples.@name@.@name@"/>
-</jnlp>
-
Deleted: lutinjaxx/trunk/jaxx-core/src/main/resources/manifest.mf
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/resources/manifest.mf 2008-10-18 00:56:40 UTC (rev 961)
+++ lutinjaxx/trunk/jaxx-core/src/main/resources/manifest.mf 2008-10-18 01:33:05 UTC (rev 962)
@@ -1,4 +0,0 @@
-Manifest-Version: 1.0
-Class-Path: ../jaxx-runtime.jar
-Main-Class: @class@
-
1
0
r961 - in lutinjaxx/trunk/jaxx-core/src/main/java/jaxx: compiler runtime tags/validator
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 00:56:40 +0000 (Sat, 18 Oct 2008)
New Revision: 961
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
Log:
automatic boxing by a JXLayer for any component attached toa validator
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-18 00:53:46 UTC (rev 960)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-18 00:56:40 UTC (rev 961)
@@ -133,8 +133,9 @@
public static boolean isValidID(String id) {
boolean valid = true;
- if (id.length() == 0)
+ if (id.length() == 0) {
valid = false;
+ }
if (valid) {
if (!Character.isJavaIdentifierStart(id.charAt(0))) {
valid = false;
@@ -467,13 +468,21 @@
String delegateCode = containerDelegate != null ? "." + containerDelegate + "()" : "";
child.setParent(this);
+ String javaCode = child.getJavaCode();
+ if (compiler.hasValidator()) {
+ // some validators are defined on this object
+ boolean found = compiler.isComponentUsedByValidator(child.getId());
+ if (found) {
+ // box the child component in a JxLayer
+ javaCode = "jaxx.runtime.Util.boxComponentWithJxLayer(" + javaCode + ")";
+ }
+ }
if (constraints != null) {
- appendAdditionCode(getJavaCode() + delegateCode + ".add(" + child.getJavaCode() + ", " + constraints + ");");
+ appendAdditionCode(getJavaCode() + delegateCode + ".add(" + javaCode + ", " + constraints + ");");
+ } else {
+ appendAdditionCode(getJavaCode() + delegateCode + ".add(" + javaCode + ");");
}
- else {
- appendAdditionCode(getJavaCode() + delegateCode + ".add(" + child.getJavaCode() + ");");
- }
}
}
@@ -487,8 +496,9 @@
compiler.registerDataBinding(src, getId() + "." + property, assignment);
}
+ /** @return the array of generic types of the compiled object, or a empty array if none defined */
public ClassDescriptor[] getGenericTypes() {
- if (genericTypes==null) {
+ if (genericTypes == null) {
return new ClassDescriptor[0];
}
try {
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-18 00:53:46 UTC (rev 960)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-18 00:56:40 UTC (rev 961)
@@ -181,6 +181,9 @@
/** list of validators */
protected List<CompiledBeanValidator> validators = new ArrayList<CompiledBeanValidator>();
+ /** list of objectId attached to a validator * */
+ protected List<String> validatedComponents = new ArrayList<String>();
+
private SymbolTable symbolTable = new SymbolTable();
// TODO: replace these public StringBuffers with something a little less stupid
@@ -2181,15 +2184,32 @@
this.failed = failed;
}
+ /**
+ * Register in this compiler a new compiled validator.
+ *
+ * @param validator the compiled validator to register
+ */
public void registerValidator(CompiledBeanValidator validator) {
validators.add(validator);
+ validatedComponents.addAll(validator.getFields().values());
}
+ /** @return <code>true</code> if some validators were detected, <code>false</code> otherwise */
public boolean hasValidator() {
return !validators.isEmpty();
}
/**
+ * Test if a given CompiledObject is attached to a validator.
+ *
+ * @param componentId the compiled object to test
+ * @return <code>true</code> if the given compiled object is attached to a validator, <code>false</code> otherwise
+ */
+ public boolean isComponentUsedByValidator(String componentId) {
+ return validatedComponents.contains(componentId);
+ }
+
+ /**
* Check that a reference exists in symbol table on second compil pass
*
* @param tag the current tag
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-10-18 00:53:46 UTC (rev 960)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-10-18 00:56:40 UTC (rev 961)
@@ -2,6 +2,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jdesktop.jxlayer.JXLayer;
import javax.swing.JComponent;
import java.awt.Component;
@@ -282,7 +283,7 @@
*
* @param clazz la classe ou recherche les champs
* @param container le container ou rechercher les composants d'edition
- * @return
+ * @return le dictionnaire des composants recherches.
*/
public static Map<String, JComponent> lookingForEditor(Class clazz, Container container) {
Map<String, JComponent> result = new HashMap<String, JComponent>();
@@ -331,4 +332,15 @@
return result;
}
+ /**
+ * Box a component in a {@link org.jdesktop.jxlayer.JXLayer}.
+ *
+ * @param component the component to box
+ * @return the {@link org.jdesktop.jxlayer.JXLayer} boxing the component
+ */
+ public static JXLayer boxComponentWithJxLayer(JComponent component) {
+ JXLayer layer = new org.jdesktop.jxlayer.JXLayer();
+ layer.add(component);
+ return layer;
+ }
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 00:53:46 UTC (rev 960)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-18 00:56:40 UTC (rev 961)
@@ -176,6 +176,11 @@
// editor component not find on ui
continue;
}
+ if (compiler.isComponentUsedByValidator(component)) {
+ // component is already used by another validator
+ compiler.reportError("component '"+component+"' is already used by another validator.");
+ continue;
+ }
String keyCode = TypeManager.getJavaCode(propertyName);
info.appendAdditionCode(info.getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
1
0
r960 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 18, 2008
Oct. 18, 2008
Author: tchemit
Date: 2008-10-18 00:53:46 +0000 (Sat, 18 Oct 2008)
New Revision: 960
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java
Log:
inverse parameters
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java 2008-10-17 22:05:40 UTC (rev 959)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java 2008-10-18 00:53:46 UTC (rev 960)
@@ -24,7 +24,7 @@
/** validation context */
protected ValidationAware validationContext;
- public AbstractBeanValidatorUI(String field,String componentId, ValidationAware validationContext) {
+ public AbstractBeanValidatorUI(String field, String componentId, ValidationAware validationContext) {
this.componentId = componentId;
this.field = field;
this.validationContext = validationContext;
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java 2008-10-17 22:05:40 UTC (rev 959)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java 2008-10-18 00:53:46 UTC (rev 960)
@@ -14,8 +14,7 @@
public class TranslucentValidationUI extends AbstractBeanValidatorUI {
public TranslucentValidationUI(String field, String componentId, ValidationAware validationContext) {
- super(componentId, field, validationContext);
-
+ super(field, componentId, validationContext);
}
@Override
1
0
r959 - in lutinjaxx/trunk/jaxx-core/src/main/java/jaxx: compiler tags/validator
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 22:05:40 +0000 (Fri, 17 Oct 2008)
New Revision: 959
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
Log:
add generic types on compiled object :)
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-17 20:55:15 UTC (rev 958)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/CompiledObject.java 2008-10-17 22:05:40 UTC (rev 959)
@@ -71,6 +71,8 @@
/** All properties that have been applied to this CompiledObject. */
private Map<String, String> properties = new HashMap<String, String>();
+ /** generic types of the compiled object */
+ private String[] genericTypes;
/**
* Creates a new <code>CompiledObject</code>. To be useful, the object should be registered with a
@@ -475,7 +477,7 @@
}
}
-
+ @Override
public String toString() {
return getObjectClass().getName() + "[id='" + id + "']";
}
@@ -484,4 +486,24 @@
public void registerDataBinding(String src, String property, String assignment, JAXXCompiler compiler) throws CompilerException {
compiler.registerDataBinding(src, getId() + "." + property, assignment);
}
+
+ public ClassDescriptor[] getGenericTypes() {
+ if (genericTypes==null) {
+ return new ClassDescriptor[0];
+ }
+ try {
+ ClassDescriptor[] result = new ClassDescriptor[genericTypes.length];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = ClassDescriptorLoader.getClassDescriptor(genericTypes[i], getObjectClass().getClassLoader());
+ }
+ return result;
+ }
+ catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setGenericTypes(String[] genericTypes) {
+ this.genericTypes = genericTypes;
+ }
}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 20:55:15 UTC (rev 958)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 22:05:40 UTC (rev 959)
@@ -584,17 +584,18 @@
code.append("allComponentsCreated = true;");
code.append(getLineSeparator());
for (CompiledObject object : objects.values()) {
+ //TC - 20081017 only generate the method if not empty ?
if (object.getId().startsWith("$")) {
- code.append(object.getAdditionCode());
+ code.append(object.getAdditionCode()).append(getLineSeparator());
} else {
- code.append(object.getAdditionMethodName()).append("();").append(getLineSeparator());
String additionCode = object.getAdditionCode();
if (additionCode.length() > 0) {
+ code.append(object.getAdditionMethodName()).append("();").append(getLineSeparator());
additionCode = "if (allComponentsCreated) {" + getLineSeparator() + additionCode + "}";
+ javaFile.addMethod(new JavaMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), null, null, additionCode));
}
- javaFile.addMethod(new JavaMethod(Modifier.PROTECTED, "void", object.getAdditionMethodName(), null, null, additionCode));
}
- code.append(getLineSeparator());
+ //code.append(getLineSeparator());
}
code.append(initDataBindings);
@@ -678,7 +679,9 @@
if (object == root) {
javaFile.addField(new JavaField(access, fullClassName, object.getId(), "this"));
} else {
- javaFile.addField(new JavaField(access, getCanonicalName(object.getObjectClass()), object.getId()));
+ //TC -20081017 can have generic on compiled Object
+ javaFile.addField(new JavaField(access, getCanonicalName(object), object.getId()));
+ //javaFile.addField(new JavaField(access, getCanonicalName(object.getObjectClass()), object.getId()));
}
}
}
@@ -1038,10 +1041,12 @@
result.append(" = ");
String constructorParams = object.getConstructorParams();
if (constructorParams != null) {
- result.append(" new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
+ //TC - 20081017 compiledObject can have generics
+ result.append(" new ").append(getCanonicalName(object)).append("(").append(constructorParams).append(");");
//result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
} else {
- result.append("new ").append(getCanonicalName(object.getObjectClass())).append("();");
+ //TC - 20081017 compiledObject can have generics
+ result.append("new ").append(getCanonicalName(object)).append("();");
}
result.append(getLineSeparator());
String initCode = object.getInitializationCode(this);
@@ -1206,6 +1211,45 @@
}
+ public static String getCanonicalName(CompiledObject compiled) {
+ ClassDescriptor clazz = compiled.getObjectClass();
+ if (clazz.isArray()) {
+ String canonicalName = getCanonicalName(clazz.getComponentType());
+ if (canonicalName != null) {
+ if (compiled.getGenericTypes().length > 0) {
+ canonicalName += "<";
+ for (int i = 0; i < compiled.getGenericTypes().length; i++) {
+ ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
+ if (i > 0) {
+ canonicalName += " ,";
+ }
+ canonicalName += classDescriptor.getName();
+ }
+ canonicalName += ">";
+
+ }
+ return canonicalName + "[]";
+ }
+ return null;
+ }
+
+ String canonicalName = clazz.getName().replace('$', '.');
+ if (compiled.getGenericTypes().length > 0) {
+ canonicalName += "<";
+ for (int i = 0; i < compiled.getGenericTypes().length; i++) {
+ ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
+ if (i > 0) {
+ canonicalName += " ,";
+ }
+ canonicalName += classDescriptor.getName();
+ }
+ canonicalName += ">";
+
+ }
+ return canonicalName;
+ }
+
+
public static String capitalize(String s) {
if (s.length() == 0) {
return s;
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-17 20:55:15 UTC (rev 958)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-17 22:05:40 UTC (rev 959)
@@ -102,6 +102,9 @@
if (compiler.checkReference(tag, bean, true, BEAN_ATTRIBUTE)) {
String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler);
info.appendAdditionCode(code);
+ // add generic type to validator
+ JAXXBeanInfo beanInfo = info.getBeanDescriptor(compiler);
+ info.setGenericTypes(new String[]{beanInfo.getJAXXBeanDescriptor().getClassDescriptor().getName()});
}
}
1
0
r958 - in lutinjaxx/trunk/jaxx-core/src/main/java/jaxx: compiler runtime runtime/validator runtime/validator/ui tags tags/swing tags/validator
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 20:55:15 +0000 (Fri, 17 Oct 2008)
New Revision: 958
Added:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorError.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorListModel.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/IconValidationUI.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java
Removed:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java
Log:
add package validator
introduce ui package (to put error rendering)
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -22,7 +22,7 @@
import jaxx.tags.DefaultObjectHandler;
import jaxx.tags.TagHandler;
import jaxx.tags.TagManager;
-import jaxx.tags.swing.BeanValidatorHandler.CompiledBeanValidator;
+import jaxx.tags.validator.BeanValidatorHandler.CompiledBeanValidator;
import jaxx.types.TypeManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -610,7 +610,7 @@
String id = TypeManager.getJavaCode(validator.getId());
code.append("validatorIds.add(").append(id).append(");");
code.append(getLineSeparator());
- code.append("getValidator(").append(id).append(").installLayers();");
+ code.append("getValidator(").append(id).append(").installUIs();");
code.append("getValidator(").append(id).append(").validate();");
code.append(getLineSeparator());
}
@@ -695,7 +695,7 @@
javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.Map<String,Object>", "$bindingSources", "new HashMap<String,Object>()"));
}
- javaFile.addImport("jaxx.runtime.BeanValidator");
+ javaFile.addImport("jaxx.runtime.validator.BeanValidator");
javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<String>", "validatorIds", "new ArrayList<String>()"));
if (stylesheet != null) {
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -1,484 +0,0 @@
-/* *##%
- * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
- *##%*/
-
-package jaxx.runtime;
-
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ValidationAware;
-import com.opensymphony.xwork2.ValidationAwareSupport;
-import com.opensymphony.xwork2.config.Configuration;
-import com.opensymphony.xwork2.config.ConfigurationManager;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
-import com.opensymphony.xwork2.validator.ActionValidatorManager;
-import com.opensymphony.xwork2.validator.DelegatingValidatorContext;
-import com.opensymphony.xwork2.validator.ValidationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.jxlayer.JXLayer;
-import org.jdesktop.jxlayer.plaf.AbstractLayerUI;
-
-import javax.swing.BorderFactory;
-import javax.swing.JComponent;
-import javax.swing.SwingUtilities;
-import java.awt.AlphaComposite;
-import java.awt.Color;
-import java.awt.Container;
-import java.awt.Graphics2D;
-import java.awt.Insets;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * <p/>
- * Permet d'ajouter facilement le support de la validation des champs d'un
- * bean et de le relier a une interface graphique.
- * Utilise xwork pour la validation et JXLayer pour la visualisation.
- * <p/>
- * <p/>
- * Le mieux pour son integration dans Jaxx est de faire de la generation pour
- * force la compilation du code suivant:
- * <p/>
- * <pre>
- * myValidor.getBean().get<field>();
- * </pre>
- * <p/>
- * et ceci pour chaque field ajoute a la map fieldRepresentation. De cette
- * facon meme si le champs field est en texte on a une verification de son
- * existance a la compilation.
- * <p/>
- * <p/>
- * La representation en tag pourrait etre
- * <pre>
- * <validator id="myValidator" beanClass="{Personne.class}" errorList="$list">
- * <field name="name" component="$name"/>
- * <field name="firstName" component="$firstName"/>
- * <field name="birthDate" component="$birthDate"/>
- * </validator>
- * <validator beanClass="{Personne.class}" autoField="true" errorList="$list">
- * <fieldRepresentation name="name" component="$lastName"/>
- * </validator>
- * </pre>
- * <p/>
- * dans le premier exemple on fait un mapping explicite des champs, mais on voit
- * que le nom du composant graphique est le meme que celui du champs. Pour eviter
- * de longue saisie, il est possible d'utiliser le flag <b>autoField</b>
- * qui pour chaque champs du ayant une methode get du bean recherche un composant
- * avec cet Id. Il est aussi possible de surcharge un champs explicitement
- * comme ici name, dans le cas ou le composant qui porterait ce nom serait
- * utilise pour autre chose.
- * <p/>
- * <p/>
- * Il faut un handler particulier pour ce composant car les attributs
- * <b>beanClass</b> et <b>autoField</b> ne sont present que dans le XML jaxx et
- * servent a la generation. Il faut aussi prendre en compte les elements
- * fieldRepresentation fils du tag validator.
- * <p/>
- * <p/>
- * Voici ce que pourrait etre le code genere par jaxx
- * <pre>
- * // declaration du bean
- * BeanValidator<beanClass> $myValidator;
- * // init du bean
- * protected void createMyValidator() {
- * $myValidator = new BeanValidator<beanClass>();
- * // genere seulement si autoField = true
- * for (Method m : beanClass.getMethod()) {
- * if (m.getName().startsWith("get")) {
- * String fieldName = m.getName().substring(3).toLowerCase();
- * $myValidator.setFieldRepresentation(fieldName, $objectMap.get(fieldName));
- * }
- * }
- * // pour chaque tag fieldRepresentation
- * myValidator.setFieldRepresentation("name", $lastName);
- * // si beanClass est specifie et n'est pas Object, on force l'acces au champs
- * // pour validation a la compilation
- * $myValidator.getBean().getName();
- * $objectMap.put("myValidator", $myValidator);
- * }
- * </pre>
- *
- * @author poussin
- * @version $Revision$
- * <p/>
- * Last update: $Date$
- * by : $Author$
- */
-public class BeanValidator<T> {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(BeanValidator.class);
-
- protected PropertyChangeSupport pcs;
-
- protected ValidationAwareSupport validationSupport;
- protected DelegatingValidatorContext validationContext;
-
- protected transient ActionValidatorManager validator;
-
- /** indique si le bean a ete modifie depuis son arrivee */
- protected boolean changed = false;
-
- /** le bean a surveiller */
- protected T bean = null;
-
- /** l'objet qui recoit les notifications de modification du bean */
- protected Listener l = new Listener();
-
- /** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */
- protected Map<String, JComponent> fieldRepresentation;
-
- /** Object servant a contenir la liste des erreurs */
- protected BeanValidatorErrorListModel errorListModel;
-
- public BeanValidator() {
- pcs = new PropertyChangeSupport(this);
- validationSupport = new ValidationAwareSupport();
- validationContext = new DelegatingValidatorContext(validationSupport);
- fieldRepresentation = new HashMap<String, JComponent>();
- }
-
- public BeanValidatorErrorListModel getErrorListModel() {
- return errorListModel;
- }
-
- public void setErrorListModel(BeanValidatorErrorListModel errorListModel) {
- this.errorListModel = errorListModel;
- if (errorListModel != null) {
- errorListModel.registerValidator(this);
- }
- }
-
- /**
- * Permet d'indiquer le composant graphique responsable de l'affichage
- * d'un attribut du bean
- *
- * @param fieldname the field name in the bean
- * @param c the editor component for the field
- */
- public void setFieldRepresentation(String fieldname, JComponent c) {
- JComponent old = fieldRepresentation.put(fieldname, c);
- setErrorRepresentation(fieldname, old, c);
- }
-
- public void setFieldRepresentation(Map<String, JComponent> fieldRepresentation) {
- for (Map.Entry<String, JComponent> e : fieldRepresentation.entrySet()) {
- setFieldRepresentation(e.getKey(), e.getValue());
- }
- }
-
- public JComponent getFieldRepresentation(String fieldname) {
- return fieldRepresentation.get(fieldname);
- }
-
- /**
- * Retourne vrai si l'objet bean a ete modifie depuis le dernier
- * {@link #setBean}
- *
- * @return <code>true</code> if bean was modify since last {@link #setBean(Object)} invocation
- */
- public boolean isChanged() {
- return changed;
- }
-
- /**
- * Permet de force la remise a false de l'etat de changement du bean
- *
- * @param changed flag to force reset of property {@link #changed}
- */
- public void setChanged(boolean changed) {
- boolean oldChanged = this.changed;
- this.changed = changed;
- pcs.firePropertyChange("changed", oldChanged, changed);
- }
-
- public T getBean() {
- return bean;
- }
-
- public void setBean(T bean) {
- T oldBean = this.bean;
- if (this.bean != null) {
- try {
- Method method = this.bean.getClass().getMethod("removePropertyChangeListener", PropertyChangeListener.class);
- method.invoke(this.bean, l);
- } catch (Exception eee) {
- log.info("Can't register as listener", eee);
- }
- }
- this.bean = bean;
- if (this.bean != null) {
- try {
- Method method = this.bean.getClass().getMethod("addPropertyChangeListener", PropertyChangeListener.class);
- method.invoke(this.bean, l);
- } catch (Exception eee) {
- log.info("Can't register as listener", eee);
- }
- }
- validate();
- pcs.firePropertyChange("bean", oldBean, bean);
- }
-
- public Map getFieldErrors() {
- return validationContext.getFieldErrors();
- }
-
- public Collection getActionErrors() {
- return validationContext.getActionErrors();
- }
-
- public Collection getActionMessages() {
- return validationContext.getActionMessages();
- }
-
- /** install layers on required components */
- public void installLayers() {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- for (String fieldname : fieldRepresentation.keySet()) {
- JComponent c = fieldRepresentation.get(fieldname);
- setErrorRepresentation(fieldname, null, c);
- }
- }
- });
-
- }
-
- protected ActionValidatorManager getValidator() {
- if (validator == null) {
- ConfigurationManager confManager = new ConfigurationManager();
- Configuration conf = confManager.getConfiguration();
-
- ValueStackFactory vsf = conf.getContainer().getInstance(
- ValueStackFactory.class);
- ValueStack vs = vsf.createValueStack();
- ActionContext context = new ActionContext(vs.getContext());
- ActionContext.setContext(context);
-
- validator = conf.getContainer().getInstance(
- ActionValidatorManager.class, "no-annotations");
- }
- return validator;
- }
-
- /**
- * il faut eviter le code re-intrant (durant une validation, une autre est
- * demandee). Pour cela on fait la validation dans un thread, et tant
- * que la premiere validation n'est pas fini, on ne repond pas aux
- * solicitations.
- * Cette method est public pour permettre de force une validation par
- * programmation, ce qui est utile par exemple si le bean ne supporte
- * pas les {@link PropertyChangeListener}
- */
- public void validate() {
- // on ne valide que si il y a un bean et que le resultat de la validation
- // pourra etre affiche quelque part
- if (bean == null || getErrorListModel() == null || fieldRepresentation.size() == 0) {
- return;
- }
-
- try {
-
- validationSupport.clearErrorsAndMessages();
-
- getValidator().validate(bean, null, validationContext);
-
- if (log.isDebugEnabled()) {
- log.debug("Action errors: " + validationContext.getActionErrors());
- log.debug("Action messages: " + validationContext.getActionMessages());
- log.debug("Field errors: " + validationContext.getFieldErrors());
- }
-
- log.info(this + " : " + validationContext.getFieldErrors());
-
- // add errors
- errorListModel.addErrors(this);
-
- for (String fieldname : fieldRepresentation.keySet()) {
- JComponent c = fieldRepresentation.get(fieldname);
- //todo: a supprimer mais actuellemnt le layer ne se repaint pas bien, cela n'est pas normal
- c.getParent().repaint();
- }
- } catch (ValidationException eee) {
- log.warn("Error during validation", eee);
- }
- }
-
- protected void setErrorRepresentation(String fieldname, JComponent old, JComponent c) {
- if (old != c) {
- if (old != null) {
- // suppression du jxlayer sous l'ancien composant
- Container container = old.getParent();
- if (container instanceof JXLayer) {
- JXLayer<?> jx = (JXLayer<?>) container;
- jx.setUI(null);
- }
- }
- if (c != null) {
- // ajout du jxlayer sous ce composant
- Container container = c.getParent();
- if (container instanceof JXLayer) {
- IconValidationUI ui = new IconValidationUI(fieldname, c.getName(), validationSupport);
- //TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, c.getName(), validationSupport);
- ui.setEnabled(true);
- JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
- jx.setUI(ui);
- }
- }
- }
- }
-
- protected class Listener implements PropertyChangeListener {
-
- public void propertyChange(PropertyChangeEvent evt) {
- // only validate if the property has really changed...
- Object oldValue = evt.getOldValue();
- Object newValue = evt.getNewValue();
- if (oldValue == null && newValue == null) {
- return;
- }
- if ((oldValue != null && oldValue.equals(newValue)) || (newValue != null && newValue.equals(oldValue))) {
- return;
- }
- if (log.isDebugEnabled()) {
- log.debug("launch validation from event [name:" + evt.getPropertyName() + " <old:" + oldValue + ", new:" + newValue + ">]");
- }
- validate();
- setChanged(true);
- }
- }
-
- /** @return <code>true</code> if errors are detected, <code>false</code> otherwise */
- public boolean hasErrors() {
- //todo should also detecte actionErrors ?
- return validationContext.hasFieldErrors();
- //return validationContext.hasFieldErrors() || validationContext.hasActionErrors();
- }
-
- public static class TranslucentValidationUI extends AbstractLayerUI<JComponent> {
-
- /** bean field */
- protected String field;
-
- /** component id */
- protected String componentId;
-
- /** validation context */
- protected ValidationAware validationContext;
-
- public TranslucentValidationUI(String field, String componentId, ValidationAware validationContext) {
- this.field = field;
- this.componentId = componentId;
- this.validationContext = validationContext;
- log.info("install " + this + "<field:" + field + ", componentId:" + componentId + ">");
- }
-
- @Override
- protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
- // paints the layer as is
- super.paintLayer(g2, l);
-
- // to be in sync with the view if the layer has a border
- Insets layerInsets = l.getInsets();
- g2.translate(layerInsets.left, layerInsets.top);
-
- JComponent view = l.getView();
- // To prevent painting on view's border
- Insets insets = view.getInsets();
- g2.clip(new Rectangle(insets.left, insets.top,
- view.getWidth() - insets.left - insets.right,
- view.getHeight() - insets.top - insets.bottom));
-
- g2.setColor(!validationContext.getFieldErrors().containsKey(field) ?
- Color.GREEN : Color.RED);
- g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
- g2.fillRect(0, 0, l.getWidth(), l.getHeight());
- }
- }
-
- public static class IconValidationUI extends AbstractLayerUI<JComponent> {
-
- // The red icon to be shown at the layer's corner
- private final static BufferedImage INVALID_ICON;
-
- static {
- int width = 7;
- int height = 8;
- INVALID_ICON = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D g2 = (Graphics2D) INVALID_ICON.getGraphics();
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
- g2.setColor(Color.RED);
- g2.fillRect(0, 0, width, height);
- g2.setColor(Color.WHITE);
- g2.drawLine(0, 0, width, height);
- g2.drawLine(0, height, width, 0);
- g2.dispose();
- }
-
- /** bean validation field */
- protected String field;
-
- /** component id */
- protected String componentId;
-
- /** validation context */
- protected ValidationAware validationContext;
-
- public IconValidationUI(String field, String componentId, ValidationAware validationContext) {
- this.field = field;
- this.componentId = componentId;
- this.validationContext = validationContext;
- log.info("install " + this + "<field:" + field + ", componentId:" + componentId + ">");
- }
-
- @Override
- public void installUI(JComponent c) {
- super.installUI(c);
- c.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 3));
- }
-
- @Override
- public void uninstallUI(JComponent c) {
- super.uninstallUI(c);
- c.setBorder(null);
- }
-
- @Override
- protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
- super.paintLayer(g2, l);
- // There is no need to take insets into account for this painter
- if (validationContext.getFieldErrors().containsKey(field)) {
- g2.drawImage(INVALID_ICON, l.getWidth() - INVALID_ICON.getWidth() - 1, 0, null);
- // g2.drawImage(INVALID_ICON, 0, 0, null);
- }
- }
- }
-
-
-}
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -1,83 +0,0 @@
-package jaxx.runtime;
-
-import org.codelutin.i18n.I18n;
-
-import javax.swing.JComponent;
-
-/**
- * The model of an error.
- *
- * @author chemit
- */
-public class BeanValidatorError<T> {
-
- protected BeanValidator<T> validator;
-
- protected String fieldName;
-
- protected String error;
-
- protected JComponent component;
-
- public BeanValidator<T> getValidator() {
- return validator;
- }
-
- public String getFieldName() {
- return fieldName;
- }
-
- public String getError() {
- return error;
- }
-
- public JComponent getComponent() {
- return component;
- }
-
- public void setValidator(BeanValidator<T> validator) {
- this.validator = validator;
- }
-
- public void setFieldName(String fieldName) {
- this.fieldName = fieldName;
- }
-
- public void setError(String error) {
- this.error = error;
- }
-
- public void setComponent(JComponent component) {
- this.component = component;
- }
-
- @Override
- public String toString() {
- return component.getName() + " : " + I18n._(error);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof BeanValidatorError)) {
- return false;
- }
-
- BeanValidatorError that = (BeanValidatorError) o;
-
- return component.equals(that.component) && error.equals(that.error) && fieldName.equals(that.fieldName) && validator.equals(that.validator);
-
- }
-
- @Override
- public int hashCode() {
- int result;
- result = validator.hashCode();
- result = 31 * result + fieldName.hashCode();
- result = 31 * result + error.hashCode();
- result = 31 * result + component.hashCode();
- return result;
- }
-}
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -1,138 +0,0 @@
-package jaxx.runtime;
-
-import javax.swing.DefaultListModel;
-import javax.swing.JComponent;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The model of the list of errors
- *
- * @author chemit
- */
-public class BeanValidatorErrorListModel extends DefaultListModel {
- private static final long serialVersionUID = 1L;
-
- /** list of registred validators */
- protected transient List<BeanValidator<?>> validators;
-
- /** comporatorof errors */
- protected transient Comparator<BeanValidatorError> comparator;
-
- public BeanValidatorErrorListModel() {
- validators = new ArrayList<BeanValidator<?>>();
- }
-
- public void registerValidator(BeanValidator<?> validator) {
- if (validators.contains(validator)) {
- throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
- }
- validators.add(validator);
- }
-
- public <T> void addErrors(BeanValidator<T> validator) {
- if (!validators.contains(validator)) {
- throw new IllegalArgumentException("the validator " + validator + " is not registred in " + this);
- }
-
- // new errors for the given validator
- List<BeanValidatorError> newErrors = new ArrayList<BeanValidatorError>();
- // old errors for the given validator
- List<BeanValidatorError> oldErrors = new ArrayList<BeanValidatorError>();
- // old errors for other validators
- List<BeanValidatorError> oldOtherErrors = new ArrayList<BeanValidatorError>();
-
- // split old errors from other validators
- splitOldErrors(validator, oldErrors, oldOtherErrors);
-
- // fill new errors
- fillNewErrors(validator, newErrors);
-
- // check if something has changed for the given validator
- if (hasChanged(oldErrors, newErrors)) {
-
- // reinject other errors
- newErrors.addAll(oldOtherErrors);
-
- // sort errors
- Collections.sort(newErrors, getComparator());
-
- // clean errors in model
- clear();
-
- // reinject in list model, all the errors
- for (BeanValidatorError error : newErrors) {
- addElement(error);
- }
-
- // notify thaht the model has changed
- fireContentsChanged(this, 0, getSize() - 1);
- }
- }
-
- protected boolean hasChanged(List<BeanValidatorError> oldErrors, List<BeanValidatorError> newErrors) {
- if (oldErrors.size() != newErrors.size()) {
- return true;
- }
- for (BeanValidatorError oldError : oldErrors) {
- if (!newErrors.contains(oldError)) {
- return true;
- }
- }
- return false;
- }
-
- protected <T> void fillNewErrors(BeanValidator<T> validator, List<BeanValidatorError> newErrors) {
- if (validator.hasErrors()) {
- // inject this validator errors
- for (Object o : validator.getFieldErrors().entrySet()) {
- Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
- BeanValidatorError<T> error;
- String field = (String) r.getKey();
-
- JComponent component = validator.getFieldRepresentation(field);
- for (Object errorString : (List<?>) r.getValue()) {
- String error1 = (String) errorString;
- error = new BeanValidatorError<T>();
- error.setComponent(component);
- error.setValidator(validator);
- error.setError(error1);
- error.setFieldName(field);
- newErrors.add(error);
- }
- }
- //todo should also do actionErrors
- }
- }
-
- protected <T> void splitOldErrors(BeanValidator<T> validator, List<BeanValidatorError> oldErrors, List<BeanValidatorError> oldOtherErrors) {
- Enumeration enumeration = elements();
-
- while (enumeration.hasMoreElements()) {
- Object o = enumeration.nextElement();
- BeanValidatorError<?> error = (BeanValidatorError) o;
- if (!error.getValidator().equals(validator)) {
- // error from another validator, keep it
- oldOtherErrors.add(error);
- } else {
- oldErrors.add(error);
- }
- }
- }
-
- protected Comparator<BeanValidatorError> getComparator() {
- if (comparator == null) {
- comparator = new Comparator<BeanValidatorError>() {
- public int compare(BeanValidatorError o1, BeanValidatorError o2) {
- return o1.toString().compareTo(o2.toString());
- }
- };
- }
- return comparator;
- }
-
-}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -1,5 +1,7 @@
package jaxx.runtime;
+import jaxx.runtime.validator.BeanValidator;
+
import java.util.List;
/**
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java (from rev 957, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidator.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,402 @@
+/* *##%
+ * Copyright (C) 2002-2008 Code Lutin, Benjamin Poussin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ *##%*/
+
+package jaxx.runtime.validator;
+
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ValidationAware;
+import com.opensymphony.xwork2.ValidationAwareSupport;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import com.opensymphony.xwork2.validator.ActionValidatorManager;
+import com.opensymphony.xwork2.validator.DelegatingValidatorContext;
+import com.opensymphony.xwork2.validator.ValidationException;
+import jaxx.runtime.validator.ui.AbstractBeanValidatorUI;
+import jaxx.runtime.validator.ui.IconValidationUI;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.jxlayer.JXLayer;
+
+import javax.swing.JComponent;
+import javax.swing.SwingUtilities;
+import java.awt.Container;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p/>
+ * Permet d'ajouter facilement le support de la validation des champs d'un
+ * bean et de le relier a une interface graphique.
+ * Utilise xwork pour la validation et JXLayer pour la visualisation.
+ * <p/>
+ * <p/>
+ * Le mieux pour son integration dans Jaxx est de faire de la generation pour
+ * force la compilation du code suivant:
+ * <p/>
+ * <pre>
+ * myValidor.getBean().get<field>();
+ * </pre>
+ * <p/>
+ * et ceci pour chaque field ajoute a la map fieldRepresentation. De cette
+ * facon meme si le champs field est en texte on a une verification de son
+ * existance a la compilation.
+ * <p/>
+ * <p/>
+ * La representation en tag pourrait etre
+ * <pre>
+ * <validator id="myValidator" beanClass="{Personne.class}" errorList="$list">
+ * <field name="name" component="$name"/>
+ * <field name="firstName" component="$firstName"/>
+ * <field name="birthDate" component="$birthDate"/>
+ * </validator>
+ * <validator beanClass="{Personne.class}" autoField="true" errorList="$list">
+ * <fieldRepresentation name="name" component="$lastName"/>
+ * </validator>
+ * </pre>
+ * <p/>
+ * dans le premier exemple on fait un mapping explicite des champs, mais on voit
+ * que le nom du composant graphique est le meme que celui du champs. Pour eviter
+ * de longue saisie, il est possible d'utiliser le flag <b>autoField</b>
+ * qui pour chaque champs du ayant une methode get du bean recherche un composant
+ * avec cet Id. Il est aussi possible de surcharge un champs explicitement
+ * comme ici name, dans le cas ou le composant qui porterait ce nom serait
+ * utilise pour autre chose.
+ * <p/>
+ * <p/>
+ * Il faut un handler particulier pour ce composant car les attributs
+ * <b>beanClass</b> et <b>autoField</b> ne sont present que dans le XML jaxx et
+ * servent a la generation. Il faut aussi prendre en compte les elements
+ * fieldRepresentation fils du tag validator.
+ * <p/>
+ * <p/>
+ * Voici ce que pourrait etre le code genere par jaxx
+ * <pre>
+ * // declaration du bean
+ * BeanValidator<beanClass> $myValidator;
+ * // init du bean
+ * protected void createMyValidator() {
+ * $myValidator = new BeanValidator<beanClass>();
+ * // genere seulement si autoField = true
+ * for (Method m : beanClass.getMethod()) {
+ * if (m.getName().startsWith("get")) {
+ * String fieldName = m.getName().substring(3).toLowerCase();
+ * $myValidator.setFieldRepresentation(fieldName, $objectMap.get(fieldName));
+ * }
+ * }
+ * // pour chaque tag fieldRepresentation
+ * myValidator.setFieldRepresentation("name", $lastName);
+ * // si beanClass est specifie et n'est pas Object, on force l'acces au champs
+ * // pour validation a la compilation
+ * $myValidator.getBean().getName();
+ * $objectMap.put("myValidator", $myValidator);
+ * }
+ * </pre>
+ *
+ * @author poussin
+ * @version $Revision$
+ * <p/>
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class BeanValidator<T> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private final Log log = LogFactory.getLog(BeanValidator.class);
+
+ static private final Class<? extends AbstractBeanValidatorUI> DEFAULT_UI_CLASS = IconValidationUI.class;
+
+ protected PropertyChangeSupport pcs;
+
+ protected ValidationAwareSupport validationSupport;
+ protected DelegatingValidatorContext validationContext;
+
+ protected transient ActionValidatorManager validator;
+
+ /** indique si le bean a ete modifie depuis son arrivee */
+ protected boolean changed = false;
+
+ /** le bean a surveiller */
+ protected T bean = null;
+
+ /** l'objet qui recoit les notifications de modification du bean */
+ protected Listener l = new Listener();
+
+ /** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */
+ protected Map<String, JComponent> fieldRepresentation;
+
+ /** Object servant a contenir la liste des erreurs */
+ protected BeanValidatorErrorListModel errorListModel;
+
+ protected Class<? extends AbstractBeanValidatorUI> uiClass;
+
+ public BeanValidator() {
+ pcs = new PropertyChangeSupport(this);
+ validationSupport = new ValidationAwareSupport();
+ validationContext = new DelegatingValidatorContext(validationSupport);
+ fieldRepresentation = new HashMap<String, JComponent>();
+ }
+
+ public BeanValidatorErrorListModel getErrorListModel() {
+ return errorListModel;
+ }
+
+ public void setErrorListModel(BeanValidatorErrorListModel errorListModel) {
+ this.errorListModel = errorListModel;
+ if (errorListModel != null) {
+ errorListModel.registerValidator(this);
+ }
+ }
+
+ /**
+ * Permet d'indiquer le composant graphique responsable de l'affichage
+ * d'un attribut du bean
+ *
+ * @param fieldname the field name in the bean
+ * @param c the editor component for the field
+ */
+ public void setFieldRepresentation(String fieldname, JComponent c) {
+ fieldRepresentation.put(fieldname, c);
+ //todo we do not want at this moment to add something in ui, since ui is perharps not useable
+ //todo prefer to use the method installUIs
+ //JComponent old = fieldRepresentation.put(fieldname, c);
+ //setErrorRepresentation(fieldname, old, c, uiClass);
+ }
+
+ public void setFieldRepresentation(Map<String, JComponent> fieldRepresentation) {
+ for (Map.Entry<String, JComponent> e : fieldRepresentation.entrySet()) {
+ setFieldRepresentation(e.getKey(), e.getValue());
+ }
+ }
+
+ public JComponent getFieldRepresentation(String fieldname) {
+ return fieldRepresentation.get(fieldname);
+ }
+
+ /**
+ * Retourne vrai si l'objet bean a ete modifie depuis le dernier
+ * {@link #setBean}
+ *
+ * @return <code>true</code> if bean was modify since last {@link #setBean(Object)} invocation
+ */
+ public boolean isChanged() {
+ return changed;
+ }
+
+ /**
+ * Permet de force la remise a false de l'etat de changement du bean
+ *
+ * @param changed flag to force reset of property {@link #changed}
+ */
+ public void setChanged(boolean changed) {
+ boolean oldChanged = this.changed;
+ this.changed = changed;
+ pcs.firePropertyChange("changed", oldChanged, changed);
+ }
+
+ public T getBean() {
+ return bean;
+ }
+
+ public void setBean(T bean) {
+ T oldBean = this.bean;
+ if (this.bean != null) {
+ try {
+ Method method = this.bean.getClass().getMethod("removePropertyChangeListener", PropertyChangeListener.class);
+ method.invoke(this.bean, l);
+ } catch (Exception eee) {
+ log.info("Can't register as listener", eee);
+ }
+ }
+ this.bean = bean;
+ if (this.bean != null) {
+ try {
+ Method method = this.bean.getClass().getMethod("addPropertyChangeListener", PropertyChangeListener.class);
+ method.invoke(this.bean, l);
+ } catch (Exception eee) {
+ log.info("Can't register as listener", eee);
+ }
+ }
+ validate();
+ pcs.firePropertyChange("bean", oldBean, bean);
+ }
+
+ public Class<? extends AbstractBeanValidatorUI> getUiClass() {
+ return uiClass;
+ }
+
+ public void setUiClass(Class<? extends AbstractBeanValidatorUI> uiClass) {
+ this.uiClass = uiClass;
+ }
+
+ /** @return <code>true</code> if errors are detected, <code>false</code> otherwise */
+ public boolean hasErrors() {
+ //todo should also detecte actionErrors ?
+ return validationContext.hasFieldErrors();
+ //return validationContext.hasFieldErrors() || validationContext.hasActionErrors();
+ }
+
+ public Map getFieldErrors() {
+ return validationContext.getFieldErrors();
+ }
+
+ public Collection getActionErrors() {
+ return validationContext.getActionErrors();
+ }
+
+ public Collection getActionMessages() {
+ return validationContext.getActionMessages();
+ }
+
+ /** install ui on required components */
+ public void installUIs() {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ if (uiClass == null) {
+ // use the default one
+ uiClass = DEFAULT_UI_CLASS;
+ }
+ for (String fieldname : fieldRepresentation.keySet()) {
+ try {
+ setErrorRepresentation(fieldname, null, fieldRepresentation.get(fieldname), uiClass);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ });
+
+ }
+
+ /**
+ * il faut eviter le code re-intrant (durant une validation, une autre est
+ * demandee). Pour cela on fait la validation dans un thread, et tant
+ * que la premiere validation n'est pas fini, on ne repond pas aux
+ * solicitations.
+ * Cette method est public pour permettre de force une validation par
+ * programmation, ce qui est utile par exemple si le bean ne supporte
+ * pas les {@link PropertyChangeListener}
+ */
+ public void validate() {
+ // on ne valide que si il y a un bean et que le resultat de la validation
+ // pourra etre affiche quelque part
+ if (bean == null || getErrorListModel() == null || fieldRepresentation.size() == 0) {
+ return;
+ }
+
+ try {
+
+ validationSupport.clearErrorsAndMessages();
+
+ getValidator().validate(bean, null, validationContext);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Action errors: " + validationContext.getActionErrors());
+ log.debug("Action messages: " + validationContext.getActionMessages());
+ log.debug("Field errors: " + validationContext.getFieldErrors());
+ }
+
+ log.info(this + " : " + validationContext.getFieldErrors());
+
+ // add errors
+ errorListModel.addErrors(this);
+
+ for (String fieldname : fieldRepresentation.keySet()) {
+ JComponent c = fieldRepresentation.get(fieldname);
+ //todo: a supprimer mais actuellemnt le layer ne se repaint pas bien, cela n'est pas normal
+ c.getParent().repaint();
+ }
+ } catch (ValidationException eee) {
+ log.warn("Error during validation", eee);
+ }
+ }
+
+ protected ActionValidatorManager getValidator() {
+ if (validator == null) {
+ ConfigurationManager confManager = new ConfigurationManager();
+ Configuration conf = confManager.getConfiguration();
+
+ ValueStackFactory vsf = conf.getContainer().getInstance(
+ ValueStackFactory.class);
+ ValueStack vs = vsf.createValueStack();
+ ActionContext context = new ActionContext(vs.getContext());
+ ActionContext.setContext(context);
+
+ validator = conf.getContainer().getInstance(
+ ActionValidatorManager.class, "no-annotations");
+ }
+ return validator;
+ }
+
+ protected void setErrorRepresentation(String fieldname, JComponent old, JComponent c, Class<? extends AbstractBeanValidatorUI> uiClass) throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException {
+ if (old != c) {
+ if (old != null) {
+ // suppression du jxlayer sous l'ancien composant
+ Container container = old.getParent();
+ if (container instanceof JXLayer) {
+ JXLayer<?> jx = (JXLayer<?>) container;
+ jx.setUI(null);
+ }
+ }
+ if (c != null) {
+ // ajout du jxlayer sous ce composant
+ Container container = c.getParent();
+ if (container instanceof JXLayer) {
+ Constructor<? extends AbstractBeanValidatorUI> cons = uiClass.getConstructor(String.class, String.class, ValidationAware.class);
+ AbstractBeanValidatorUI ui = cons.newInstance(fieldname, c.getName(), validationSupport);
+ //IconValidationUI ui = new IconValidationUI(fieldname, c.getName(), validationSupport);
+ //TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, c.getName(), validationSupport);
+ ui.setEnabled(true);
+ JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
+ jx.setUI(ui);
+ }
+ }
+ }
+ }
+
+ protected class Listener implements PropertyChangeListener {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ // only validate if the property has really changed...
+ Object oldValue = evt.getOldValue();
+ Object newValue = evt.getNewValue();
+ if (oldValue == null && newValue == null) {
+ return;
+ }
+ if ((oldValue != null && oldValue.equals(newValue)) || (newValue != null && newValue.equals(oldValue))) {
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("launch validation from event [name:" + evt.getPropertyName() + " <old:" + oldValue + ", new:" + newValue + ">]");
+ }
+ validate();
+ setChanged(true);
+ }
+ }
+
+}
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorError.java (from rev 957, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorError.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorError.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,83 @@
+package jaxx.runtime.validator;
+
+import org.codelutin.i18n.I18n;
+
+import javax.swing.JComponent;
+
+/**
+ * The model of an error.
+ *
+ * @author chemit
+ */
+public class BeanValidatorError<T> {
+
+ protected BeanValidator<T> validator;
+
+ protected String fieldName;
+
+ protected String error;
+
+ protected JComponent component;
+
+ public BeanValidator<T> getValidator() {
+ return validator;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public JComponent getComponent() {
+ return component;
+ }
+
+ public void setValidator(BeanValidator<T> validator) {
+ this.validator = validator;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public void setComponent(JComponent component) {
+ this.component = component;
+ }
+
+ @Override
+ public String toString() {
+ return component.getName() + " : " + I18n._(error);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof BeanValidatorError)) {
+ return false;
+ }
+
+ BeanValidatorError that = (BeanValidatorError) o;
+
+ return component.equals(that.component) && error.equals(that.error) && fieldName.equals(that.fieldName) && validator.equals(that.validator);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ result = validator.hashCode();
+ result = 31 * result + fieldName.hashCode();
+ result = 31 * result + error.hashCode();
+ result = 31 * result + component.hashCode();
+ return result;
+ }
+}
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorListModel.java (from rev 957, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorListModel.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/BeanValidatorErrorListModel.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,140 @@
+package jaxx.runtime.validator;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JComponent;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The model of the list of errors
+ *
+ * @author chemit
+ */
+public class BeanValidatorErrorListModel extends DefaultListModel {
+ private static final long serialVersionUID = 1L;
+
+ /** list of registred validators */
+ protected transient List<BeanValidator<?>> validators;
+
+ /** comporatorof errors */
+ protected transient Comparator<BeanValidatorError> comparator;
+
+ public BeanValidatorErrorListModel() {
+ validators = new ArrayList<BeanValidator<?>>();
+ }
+
+ public void registerValidator(BeanValidator<?> validator) {
+ if (validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
+ }
+ validators.add(validator);
+ }
+
+ public <T> void addErrors(BeanValidator<T> validator) {
+ if (!validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is not registred in " + this);
+ }
+
+ // new errors for the given validator
+ List<BeanValidatorError> newErrors = new ArrayList<BeanValidatorError>();
+ // old errors for the given validator
+ List<BeanValidatorError> oldErrors = new ArrayList<BeanValidatorError>();
+ // old errors for other validators
+ List<BeanValidatorError> oldOtherErrors = new ArrayList<BeanValidatorError>();
+
+ // split old errors from other validators
+ splitOldErrors(validator, oldErrors, oldOtherErrors);
+
+ // fill new errors
+ fillNewErrors(validator, newErrors);
+
+ // check if something has changed for the given validator
+ if (hasChanged(oldErrors, newErrors)) {
+
+ // reinject other errors
+ newErrors.addAll(oldOtherErrors);
+
+ // sort errors
+ Collections.sort(newErrors, getComparator());
+
+ // clean errors in model
+ clear();
+
+ // reinject in list model, all the errors
+ for (BeanValidatorError error : newErrors) {
+ addElement(error);
+ }
+
+ // notify thaht the model has changed
+ fireContentsChanged(this, 0, getSize() - 1);
+ }
+ }
+
+ protected boolean hasChanged(List<BeanValidatorError> oldErrors, List<BeanValidatorError> newErrors) {
+ if (oldErrors.size() != newErrors.size()) {
+ return true;
+ }
+ for (BeanValidatorError oldError : oldErrors) {
+ if (!newErrors.contains(oldError)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected <T> void fillNewErrors(BeanValidator<T> validator, List<BeanValidatorError> newErrors) {
+ if (validator.hasErrors()) {
+ // inject this validator errors
+ for (Object o : validator.getFieldErrors().entrySet()) {
+ Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
+ BeanValidatorError<T> error;
+ String field = (String) r.getKey();
+
+ JComponent component = validator.getFieldRepresentation(field);
+ if (component!=null) {
+ for (Object errorString : (List<?>) r.getValue()) {
+ String error1 = (String) errorString;
+ error = new BeanValidatorError<T>();
+ error.setComponent(component);
+ error.setValidator(validator);
+ error.setError(error1);
+ error.setFieldName(field);
+ newErrors.add(error);
+ }
+ }
+ }
+ //todo should also do actionErrors
+ }
+ }
+
+ protected <T> void splitOldErrors(BeanValidator<T> validator, List<BeanValidatorError> oldErrors, List<BeanValidatorError> oldOtherErrors) {
+ Enumeration enumeration = elements();
+
+ while (enumeration.hasMoreElements()) {
+ Object o = enumeration.nextElement();
+ BeanValidatorError<?> error = (BeanValidatorError) o;
+ if (!error.getValidator().equals(validator)) {
+ // error from another validator, keep it
+ oldOtherErrors.add(error);
+ } else {
+ oldErrors.add(error);
+ }
+ }
+ }
+
+ protected Comparator<BeanValidatorError> getComparator() {
+ if (comparator == null) {
+ comparator = new Comparator<BeanValidatorError>() {
+ public int compare(BeanValidatorError o1, BeanValidatorError o2) {
+ return o1.toString().compareTo(o2.toString());
+ }
+ };
+ }
+ return comparator;
+ }
+
+}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/AbstractBeanValidatorUI.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,33 @@
+package jaxx.runtime.validator.ui;
+
+import com.opensymphony.xwork2.ValidationAware;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.jxlayer.plaf.AbstractLayerUI;
+
+/**
+ * Abstract renderer
+ *
+ * @author chemit
+ */
+public abstract class AbstractBeanValidatorUI extends AbstractLayerUI<javax.swing.JComponent> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ protected static Log log = LogFactory.getLog(AbstractBeanValidatorUI.class);
+
+ /** bean field */
+ protected String field;
+
+ /** component id */
+ protected String componentId;
+
+ /** validation context */
+ protected ValidationAware validationContext;
+
+ public AbstractBeanValidatorUI(String field,String componentId, ValidationAware validationContext) {
+ this.componentId = componentId;
+ this.field = field;
+ this.validationContext = validationContext;
+ log.info("install " + this + "<field:" + field + ", componentId:" + componentId + ">");
+ }
+}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/IconValidationUI.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/IconValidationUI.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/IconValidationUI.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,61 @@
+package jaxx.runtime.validator.ui;
+
+import org.jdesktop.jxlayer.JXLayer;
+
+import javax.swing.JComponent;
+import javax.swing.BorderFactory;
+import java.awt.image.BufferedImage;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Color;
+
+import com.opensymphony.xwork2.ValidationAware;
+
+/** @author chemit */
+public class IconValidationUI extends AbstractBeanValidatorUI {
+
+ // The red icon to be shown at the layer's corner
+ private final static BufferedImage INVALID_ICON;
+
+ static {
+ int width = 7;
+ int height = 8;
+ INVALID_ICON = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g2 = (Graphics2D) INVALID_ICON.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
+ g2.setColor(Color.RED);
+ g2.fillRect(0, 0, width, height);
+ g2.setColor(Color.WHITE);
+ g2.drawLine(0, 0, width, height);
+ g2.drawLine(0, height, width, 0);
+ g2.dispose();
+ }
+
+ public IconValidationUI(String field, String componentId, ValidationAware validationContext) {
+ super(field,componentId,validationContext);
+ }
+
+ @Override
+ public void installUI(JComponent c) {
+ super.installUI(c);
+ c.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 3));
+ }
+
+ @Override
+ public void uninstallUI(JComponent c) {
+ super.uninstallUI(c);
+ c.setBorder(null);
+ }
+
+ @Override
+ protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
+ super.paintLayer(g2, l);
+ //log.info("paintLayer "+field);
+ // There is no need to take insets into account for this painter
+ if (validationContext.getFieldErrors().containsKey(field)) {
+ g2.drawImage(INVALID_ICON, l.getWidth() - INVALID_ICON.getWidth() - 1, 0, null);
+ // g2.drawImage(INVALID_ICON, 0, 0, null);
+ }
+ }
+}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/ui/TranslucentValidationUI.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,42 @@
+package jaxx.runtime.validator.ui;
+
+import com.opensymphony.xwork2.ValidationAware;
+import org.jdesktop.jxlayer.JXLayer;
+
+import javax.swing.JComponent;
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Insets;
+import java.awt.Rectangle;
+
+/** @author chemit */
+public class TranslucentValidationUI extends AbstractBeanValidatorUI {
+
+ public TranslucentValidationUI(String field, String componentId, ValidationAware validationContext) {
+ super(componentId, field, validationContext);
+
+ }
+
+ @Override
+ protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
+ // paints the layer as is
+ super.paintLayer(g2, l);
+
+ // to be in sync with the view if the layer has a border
+ Insets layerInsets = l.getInsets();
+ g2.translate(layerInsets.left, layerInsets.top);
+
+ JComponent view = l.getView();
+ // To prevent painting on view's border
+ Insets insets = view.getInsets();
+ g2.clip(new Rectangle(insets.left, insets.top,
+ view.getWidth() - insets.left - insets.right,
+ view.getHeight() - insets.top - insets.bottom));
+
+ g2.setColor(!validationContext.getFieldErrors().containsKey(field) ?
+ Color.GREEN : Color.RED);
+ g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
+ g2.fillRect(0, 0, l.getWidth(), l.getHeight());
+ }
+}
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -1,282 +0,0 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
-package jaxx.tags.swing;
-
-import jaxx.CompilerException;
-import jaxx.compiler.CompiledObject;
-import jaxx.compiler.JAXXCompiler;
-import jaxx.introspection.JAXXBeanInfo;
-import jaxx.introspection.JAXXPropertyDescriptor;
-import jaxx.reflect.ClassDescriptor;
-import jaxx.reflect.ClassDescriptorLoader;
-import jaxx.runtime.BeanValidator;
-import jaxx.tags.DefaultObjectHandler;
-import jaxx.types.TypeManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Element;
-
-import java.beans.IntrospectionException;
-import java.io.IOException;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-
-public class BeanValidatorHandler extends DefaultObjectHandler {
-
- public static final String BEAN_VALIDATOR_TAG = BeanValidator.class.getSimpleName();
- public static final String BEAN_ATTRIBUTE = "bean";
- public static final String ERROR_LIST_MODEL_ATTRIBUTE = "errorListModel";
- public static final String AUTOFIELD_ATTRIBUTE = "autoField";
- public static final String STRICT_MODE_ATTRIBUTE = "strictMode";
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static Log log = LogFactory.getLog(BeanValidatorHandler.class);
-
- /**
- * Creates a new <code>DefaultObjectHandler</code> which provides support for the specified class. The
- * class is not actually introspected until the {@link #compileFirstPass} method is invoked.
- *
- * @param beanClass the class which this handler supports
- */
- public BeanValidatorHandler(ClassDescriptor beanClass) {
- super(beanClass);
- ClassDescriptorLoader.checkSupportClass(getClass(), beanClass, BeanValidator.class);
- }
-
- @Override
- protected CompiledObject createCompiledObject(String id, JAXXCompiler compiler) {
- return new CompiledBeanValidator(id, getBeanClass(), compiler);
- }
-
- @Override
- protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
- if (compiler.getOptions().isVerbose()) {
- log.info(tag);
- }
- if (!tag.getLocalName().equals(FieldValidatorHandler.FIELD_VALIDATOR_TAG)) {
- compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.FIELD_VALIDATOR_TAG + " as children, but found : " + tag.getLocalName());
- } else {
- compiler.compileFirstPass(tag);
- }
- }
-
- @Override
- public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
-
- super.compileSecondPass(tag, compiler);
-
- CompiledBeanValidator info = (CompiledBeanValidator) objectMap.get(tag);
-
- String tmp = info.getErrorListModel();
-
- if (tmp != null) {
- if (compiler.checkReference(tag, tmp, true, ERROR_LIST_MODEL_ATTRIBUTE)) {
- String code = getSetPropertyCode(info.getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, tmp, compiler);
- info.appendAdditionCode(code);
- }
- }
- String bean = info.getBean();
- if (bean != null) {
- if (compiler.checkReference(tag, bean, true, BEAN_ATTRIBUTE)) {
- String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler);
- info.appendAdditionCode(code);
- }
- }
-
- if (info.getAutoField()) {
- if (bean == null) {
- compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode");
- } else {
- registerAutoFieldBean(tag, compiler, info);
- }
- }
-
- // add fieldrepresentation invocations
- addFieldRepresentations(tag, compiler, info);
-
- // register the validator in compiler
- compiler.registerValidator(info);
-
- // close the compiled object
- compiler.closeComponent(info);
- }
-
- @Override
- protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) {
- // open the compiled object
- compiler.openInvisibleComponent(object);
- }
-
- @Override
- public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) {
- if (compiler.getOptions().isVerbose()) {
- log.info(propertyName + " : " + stringValue + " for " + object);
- }
- object.addProperty(propertyName, stringValue);
- }
-
- protected void registerAutoFieldBean(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
- JAXXBeanInfo beanInfo = info.getBeanDescriptor(compiler);
- for (JAXXPropertyDescriptor beanProperty : beanInfo.getJAXXPropertyDescriptors()) {
- String descriptionName = beanProperty.getName();
- if (compiler.getOptions().isVerbose()) {
- log.info("try to bind on bean " + beanInfo.getJAXXBeanDescriptor().getName() + " property " + descriptionName);
- }
- if (beanProperty.getWriteMethodDescriptor() == null) {
- // read-only property
- continue;
- }
- if (info.getFields().containsKey(descriptionName)) {
- // already defined in field
- continue;
- }
- if (!compiler.checkReference(tag, descriptionName, info.getStrictMode(), null)) {
- // no editor component found
- continue;
- }
- // ok add the field mapping
- info.addField(descriptionName, descriptionName, compiler);
- }
- }
-
- protected void addFieldRepresentations(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
- for (Entry<String, String> entry : info.getFields().entrySet()) {
- String propertyName = entry.getKey();
- String component = entry.getValue();
- if (!checkBeanProperty(compiler, info, propertyName)) {
- // property not find on bean
- continue;
- }
- if (!compiler.checkReference(tag, component, true, null)) {
- // editor component not find on ui
- continue;
- }
- String keyCode = TypeManager.getJavaCode(propertyName);
- info.appendAdditionCode(info.getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
-
- }
- }
-
- protected boolean checkBeanProperty(JAXXCompiler compiler, CompiledBeanValidator info, String propertyName) {
-
- for (JAXXPropertyDescriptor beanProperty : info.getBeanDescriptor(compiler).getJAXXPropertyDescriptors()) {
- if (beanProperty.getName().equals(propertyName)) {
- if (beanProperty.getWriteMethodDescriptor() == null) {
- // read-onlyproperty
- compiler.reportError("could not bind the readonly property '" + propertyName + "' on bean [" + info.getBean() + "] ");
- return false;
- }
- return true;
- }
- }
- compiler.reportError("could not find the property '" + propertyName + "' on bean [" + info.getBean() + "] ");
- return false;
- }
-
- /** @author chemit */
- public static class CompiledBeanValidator extends CompiledObject {
-
- protected Map<String, String> fields;
- protected String bean;
- protected String errorListModel;
- protected Boolean autoField;
- protected Boolean strictMode;
- protected JAXXBeanInfo beanDescriptor;
-
- public CompiledBeanValidator(String id, ClassDescriptor objectClass, JAXXCompiler compiler) {
- super(id, objectClass, compiler);
- fields = new TreeMap<String, String>();
- }
-
- public Map<String, String> getFields() {
- return fields;
- }
-
- public void setFields(Map<String, String> fields) {
- this.fields = fields;
- }
-
- @Override
- public void addProperty(String property, String value) {
-
- if (BEAN_ATTRIBUTE.equals(property)) {
- if (value != null && !value.trim().isEmpty()) {
- bean = value;
- }
- return;
- }
- if (ERROR_LIST_MODEL_ATTRIBUTE.equals(property)) {
- if (value != null && !value.trim().isEmpty()) {
- errorListModel = value;
- }
- return;
- }
- if (AUTOFIELD_ATTRIBUTE.equals(property)) {
- if (value != null && !value.trim().isEmpty()) {
-
- autoField = (Boolean) TypeManager.convertFromString(value, Boolean.class);
- }
- return;
- }
- if (STRICT_MODE_ATTRIBUTE.equals(property)) {
- if (value != null && !value.trim().isEmpty()) {
-
- strictMode = (Boolean) TypeManager.convertFromString(value, Boolean.class);
- }
- return;
- }
- //todo should not allowed to find other attributes
- super.addProperty(property, value);
- }
-
- public void addField(String id, String component, JAXXCompiler compiler) {
- if (fields.containsKey(id)) {
- compiler.reportError("duplicate field '" + id + "' for validator " + this);
- } else {
- if (compiler.getOptions().isVerbose()) {
- log.info("add field <" + id + ":" + component + ">");
- }
- fields.put(id, component);
- }
- }
-
- public String getBean() {
- return bean;
- }
-
- public String getErrorListModel() {
- return errorListModel;
- }
-
- public boolean getAutoField() {
- return autoField != null && autoField;
- }
-
- public boolean getStrictMode() {
- return strictMode != null && strictMode;
- }
-
- public JAXXBeanInfo getBeanDescriptor(JAXXCompiler compiler) {
- if (beanDescriptor == null && bean != null) {
- try {
- ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(compiler.getSymbolTable().getClassTagIds().get(bean));
- beanDescriptor = getJAXXBeanInfo(beanClassDescriptor);
- } catch (ClassNotFoundException e) {
- compiler.reportError("could not load class " + bean);
- } catch (IntrospectionException e) {
- compiler.reportError("could not load class " + bean);
- }
- }
- return beanDescriptor;
- }
-
- @Override
- public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler) throws CompilerException {
- // do nothing
- compiler.reportError("can not add CompiledObject in the tag '" + BEAN_VALIDATOR_TAG + " (only field tags)");
- }
- }
-}
\ No newline at end of file
Deleted: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -1,73 +0,0 @@
-/*
- * Copyright 2006 Ethan Nicholas. All rights reserved.
- * Use is subject to license terms.
- */
-package jaxx.tags.swing;
-
-import jaxx.CompilerException;
-import jaxx.compiler.JAXXCompiler;
-import jaxx.reflect.ClassDescriptorLoader;
-import jaxx.runtime.BeanValidator;
-import jaxx.tags.TagHandler;
-import jaxx.tags.swing.BeanValidatorHandler.CompiledBeanValidator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Element;
-
-import java.io.IOException;
-
-public class FieldValidatorHandler implements TagHandler {
-
- public static final String FIELD_VALIDATOR_TAG = "field";
- public static final String NAME_ATTRIBUTE = "name";
- public static final String COMPONENT_ATTRIBUTE = "component";
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(FieldValidatorHandler.class);
-
- public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
- if (compiler.getOptions().isVerbose()) {
- log.info(tag);
- }
- //todo check there is no child
- }
-
- public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
- if (compiler.getOptions().isVerbose()) {
- log.info(tag);
- }
-
- if (!ClassDescriptorLoader.getClassDescriptor(BeanValidator.class).isAssignableFrom(compiler.getOpenComponent().getObjectClass())) {
- compiler.reportError(FIELD_VALIDATOR_TAG + " tag may only appear within " + BeanValidatorHandler.BEAN_VALIDATOR_TAG + " tag but was " + tag);
- return;
- }
-
- CompiledBeanValidator validator = (CompiledBeanValidator) compiler.getOpenComponent();
-
- String name = tag.getAttribute(NAME_ATTRIBUTE);
- String component = tag.getAttribute(COMPONENT_ATTRIBUTE);
- if (name == null || name.trim().isEmpty()) {
- compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute");
- return;
- }
- name = name.trim();
- if (component == null || component.trim().isEmpty()) {
- // try to use the name as component
- if (!compiler.checkReference(tag, name, false, name)) {
- compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute ["+name+"] for the component, but no such component found");
- return;
- }
- component = name;
- }
- component = component.trim();
-
- // check component exist (again perharps, but if error will known exactly which tag failed...)
- if (compiler.checkReference(tag, component, true, component)) {
- // add a field
- validator.addField(name, component, compiler);
- }
-
-
- }
-
-}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java 2008-10-17 19:44:04 UTC (rev 957)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/SwingInitializer.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -13,13 +13,13 @@
import jaxx.runtime.swing.JAXXTab;
import jaxx.runtime.swing.JAXXTree;
import jaxx.runtime.swing.Table;
-import jaxx.runtime.BeanValidator;
+import jaxx.runtime.validator.BeanValidator;
import jaxx.spi.Initializer;
import jaxx.tags.DefaultComponentHandler;
import jaxx.tags.DefaultObjectHandler;
import jaxx.tags.TagManager;
-import jaxx.tags.swing.BeanValidatorHandler;
-import jaxx.tags.swing.FieldValidatorHandler;
+import jaxx.tags.validator.BeanValidatorHandler;
+import jaxx.tags.validator.FieldValidatorHandler;
import jaxx.types.KeyStrokeConverter;
import jaxx.types.TypeManager;
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java (from rev 953, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,312 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package jaxx.tags.validator;
+
+import jaxx.CompilerException;
+import jaxx.compiler.CompiledObject;
+import jaxx.compiler.JAXXCompiler;
+import jaxx.introspection.JAXXBeanInfo;
+import jaxx.introspection.JAXXPropertyDescriptor;
+import jaxx.reflect.ClassDescriptor;
+import jaxx.reflect.ClassDescriptorLoader;
+import jaxx.runtime.validator.BeanValidator;
+import jaxx.runtime.validator.ui.AbstractBeanValidatorUI;
+import jaxx.tags.DefaultObjectHandler;
+import jaxx.types.TypeManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Element;
+
+import java.beans.IntrospectionException;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+public class BeanValidatorHandler extends DefaultObjectHandler {
+
+ public static final String BEAN_VALIDATOR_TAG = BeanValidator.class.getSimpleName();
+ public static final String BEAN_ATTRIBUTE = "bean";
+ public static final String ERROR_LIST_MODEL_ATTRIBUTE = "errorListModel";
+ public static final String AUTOFIELD_ATTRIBUTE = "autoField";
+ public static final String UI_CLASS_ATTRIBUTE = "uiClass";
+ public static final String STRICT_MODE_ATTRIBUTE = "strictMode";
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static Log log = LogFactory.getLog(BeanValidatorHandler.class);
+
+ /**
+ * Creates a new <code>DefaultObjectHandler</code> which provides support for the specified class. The
+ * class is not actually introspected until the {@link #compileFirstPass} method is invoked.
+ *
+ * @param beanClass the class which this handler supports
+ */
+ public BeanValidatorHandler(ClassDescriptor beanClass) {
+ super(beanClass);
+ ClassDescriptorLoader.checkSupportClass(getClass(), beanClass, BeanValidator.class);
+ }
+
+ @Override
+ protected CompiledObject createCompiledObject(String id, JAXXCompiler compiler) {
+ return new CompiledBeanValidator(id, getBeanClass(), compiler);
+ }
+
+ @Override
+ protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ if (compiler.getOptions().isVerbose()) {
+ log.info(tag);
+ }
+ if (!tag.getLocalName().equals(FieldValidatorHandler.FIELD_VALIDATOR_TAG)) {
+ compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.FIELD_VALIDATOR_TAG + " as children, but found : " + tag.getLocalName());
+ } else {
+ compiler.compileFirstPass(tag);
+ }
+ }
+
+ @Override
+ public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+
+ super.compileSecondPass(tag, compiler);
+
+ CompiledBeanValidator info = (CompiledBeanValidator) objectMap.get(tag);
+
+ String tmp;
+
+ tmp = info.getErrorListModel();
+ if (tmp != null) {
+ if (compiler.checkReference(tag, tmp, true, ERROR_LIST_MODEL_ATTRIBUTE)) {
+ String code = getSetPropertyCode(info.getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, tmp, compiler);
+ info.appendAdditionCode(code);
+ }
+ }
+
+ tmp = info.getUiClass();
+ if (tmp != null) {
+ try {
+ ClassDescriptor uiClass = ClassDescriptorLoader.getClassDescriptor(tmp);
+ if (!ClassDescriptorLoader.getClassDescriptor(AbstractBeanValidatorUI.class).isAssignableFrom(uiClass)) {
+ compiler.reportError("attribute 'ui' :'" + tmp + "' is not assignable from class " + AbstractBeanValidatorUI.class);
+ } else {
+ String code = getSetPropertyCode(info.getJavaCode(), UI_CLASS_ATTRIBUTE, uiClass.getName() + ".class", compiler);
+ info.appendAdditionCode(code);
+ }
+ } catch (ClassNotFoundException e) {
+ compiler.reportError("class not found '" + tmp + "'");
+ }
+ }
+
+ String bean = info.getBean();
+ if (bean != null) {
+ if (compiler.checkReference(tag, bean, true, BEAN_ATTRIBUTE)) {
+ String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler);
+ info.appendAdditionCode(code);
+ }
+ }
+
+ if (info.getAutoField()) {
+ if (bean == null) {
+ compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode");
+ } else {
+ registerAutoFieldBean(tag, compiler, info);
+ }
+ }
+
+ // add fieldrepresentation invocations
+ addFieldRepresentations(tag, compiler, info);
+
+ // register the validator in compiler
+ compiler.registerValidator(info);
+
+ // close the compiled object
+ compiler.closeComponent(info);
+ }
+
+ @Override
+ protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) {
+ // open the compiled object
+ compiler.openInvisibleComponent(object);
+ }
+
+ @Override
+ public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) {
+ if (compiler.getOptions().isVerbose()) {
+ log.info(propertyName + " : " + stringValue + " for " + object);
+ }
+ object.addProperty(propertyName, stringValue);
+ }
+
+ protected void registerAutoFieldBean(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
+ JAXXBeanInfo beanInfo = info.getBeanDescriptor(compiler);
+ for (JAXXPropertyDescriptor beanProperty : beanInfo.getJAXXPropertyDescriptors()) {
+ String descriptionName = beanProperty.getName();
+ if (compiler.getOptions().isVerbose()) {
+ log.info("try to bind on bean " + beanInfo.getJAXXBeanDescriptor().getName() + " property " + descriptionName);
+ }
+ if (beanProperty.getWriteMethodDescriptor() == null) {
+ // read-only property
+ continue;
+ }
+ if (info.getFields().containsKey(descriptionName)) {
+ // already defined in field
+ continue;
+ }
+ if (!compiler.checkReference(tag, descriptionName, info.getStrictMode(), null)) {
+ // no editor component found
+ continue;
+ }
+ // ok add the field mapping
+ info.addField(descriptionName, descriptionName, compiler);
+ }
+ }
+
+ protected void addFieldRepresentations(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
+ for (Entry<String, String> entry : info.getFields().entrySet()) {
+ String propertyName = entry.getKey();
+ String component = entry.getValue();
+ if (!checkBeanProperty(compiler, info, propertyName)) {
+ // property not find on bean
+ continue;
+ }
+ if (!compiler.checkReference(tag, component, true, null)) {
+ // editor component not find on ui
+ continue;
+ }
+ String keyCode = TypeManager.getJavaCode(propertyName);
+ info.appendAdditionCode(info.getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
+
+ }
+ }
+
+ protected boolean checkBeanProperty(JAXXCompiler compiler, CompiledBeanValidator info, String propertyName) {
+
+ for (JAXXPropertyDescriptor beanProperty : info.getBeanDescriptor(compiler).getJAXXPropertyDescriptors()) {
+ if (beanProperty.getName().equals(propertyName)) {
+ if (beanProperty.getWriteMethodDescriptor() == null) {
+ // read-onlyproperty
+ compiler.reportError("could not bind the readonly property '" + propertyName + "' on bean [" + info.getBean() + "] ");
+ return false;
+ }
+ return true;
+ }
+ }
+ compiler.reportError("could not find the property '" + propertyName + "' on bean [" + info.getBean() + "] ");
+ return false;
+ }
+
+ /** @author chemit */
+ public static class CompiledBeanValidator extends CompiledObject {
+
+ protected Map<String, String> fields;
+ protected String bean;
+ protected String uiClass;
+ protected String errorListModel;
+ protected Boolean autoField;
+ protected Boolean strictMode;
+ protected JAXXBeanInfo beanDescriptor;
+
+ public CompiledBeanValidator(String id, ClassDescriptor objectClass, JAXXCompiler compiler) {
+ super(id, objectClass, compiler);
+ fields = new TreeMap<String, String>();
+ }
+
+ public Map<String, String> getFields() {
+ return fields;
+ }
+
+ public void setFields(Map<String, String> fields) {
+ this.fields = fields;
+ }
+
+ @Override
+ public void addProperty(String property, String value) {
+
+ if (BEAN_ATTRIBUTE.equals(property)) {
+ if (value != null && !value.trim().isEmpty()) {
+ bean = value;
+ }
+ return;
+ }
+ if (ERROR_LIST_MODEL_ATTRIBUTE.equals(property)) {
+ if (value != null && !value.trim().isEmpty()) {
+ errorListModel = value;
+ }
+ return;
+ }
+ if (UI_CLASS_ATTRIBUTE.equals(property)) {
+ if (value != null && !value.trim().isEmpty()) {
+ uiClass = value;
+ }
+ return;
+ }
+ if (AUTOFIELD_ATTRIBUTE.equals(property)) {
+ if (value != null && !value.trim().isEmpty()) {
+
+ autoField = (Boolean) TypeManager.convertFromString(value, Boolean.class);
+ }
+ return;
+ }
+ if (STRICT_MODE_ATTRIBUTE.equals(property)) {
+ if (value != null && !value.trim().isEmpty()) {
+
+ strictMode = (Boolean) TypeManager.convertFromString(value, Boolean.class);
+ }
+ return;
+ }
+ //todo should not allowed to find other attributes
+ super.addProperty(property, value);
+ }
+
+ public void addField(String id, String component, JAXXCompiler compiler) {
+ if (fields.containsKey(id)) {
+ compiler.reportError("duplicate field '" + id + "' for validator " + this);
+ } else {
+ if (compiler.getOptions().isVerbose()) {
+ log.info("add field <" + id + ":" + component + ">");
+ }
+ fields.put(id, component);
+ }
+ }
+
+ public String getBean() {
+ return bean;
+ }
+
+ public String getErrorListModel() {
+ return errorListModel;
+ }
+
+ public boolean getAutoField() {
+ return autoField != null && autoField;
+ }
+
+ public boolean getStrictMode() {
+ return strictMode != null && strictMode;
+ }
+
+ public String getUiClass() {
+ return uiClass;
+ }
+
+ public JAXXBeanInfo getBeanDescriptor(JAXXCompiler compiler) {
+ if (beanDescriptor == null && bean != null) {
+ try {
+ ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(compiler.getSymbolTable().getClassTagIds().get(bean));
+ beanDescriptor = getJAXXBeanInfo(beanClassDescriptor);
+ } catch (ClassNotFoundException e) {
+ compiler.reportError("could not load class " + bean);
+ } catch (IntrospectionException e) {
+ compiler.reportError("could not load class " + bean);
+ }
+ }
+ return beanDescriptor;
+ }
+
+ @Override
+ public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler) throws CompilerException {
+ // do nothing
+ compiler.reportError("can not add CompiledObject in the tag '" + BEAN_VALIDATOR_TAG + " (only field tags)");
+ }
+ }
+}
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/BeanValidatorHandler.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java (from rev 948, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/validator/FieldValidatorHandler.java 2008-10-17 20:55:15 UTC (rev 958)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2006 Ethan Nicholas. All rights reserved.
+ * Use is subject to license terms.
+ */
+package jaxx.tags.validator;
+
+import jaxx.CompilerException;
+import jaxx.compiler.JAXXCompiler;
+import jaxx.reflect.ClassDescriptorLoader;
+import jaxx.runtime.validator.BeanValidator;
+import jaxx.tags.TagHandler;
+import jaxx.tags.validator.BeanValidatorHandler.CompiledBeanValidator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Element;
+
+import java.io.IOException;
+
+public class FieldValidatorHandler implements TagHandler {
+
+ public static final String FIELD_VALIDATOR_TAG = "field";
+ public static final String NAME_ATTRIBUTE = "name";
+ public static final String COMPONENT_ATTRIBUTE = "component";
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(FieldValidatorHandler.class);
+
+ public void compileFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ if (compiler.getOptions().isVerbose()) {
+ log.info(tag);
+ }
+ //todo check there is no child
+ }
+
+ public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ if (compiler.getOptions().isVerbose()) {
+ log.info(tag);
+ }
+
+ if (!ClassDescriptorLoader.getClassDescriptor(BeanValidator.class).isAssignableFrom(compiler.getOpenComponent().getObjectClass())) {
+ compiler.reportError(FIELD_VALIDATOR_TAG + " tag may only appear within " + BeanValidatorHandler.BEAN_VALIDATOR_TAG + " tag but was " + tag);
+ return;
+ }
+
+ CompiledBeanValidator validator = (CompiledBeanValidator) compiler.getOpenComponent();
+
+ String name = tag.getAttribute(NAME_ATTRIBUTE);
+ String component = tag.getAttribute(COMPONENT_ATTRIBUTE);
+ if (name == null || name.trim().isEmpty()) {
+ compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + NAME_ATTRIBUTE + " attribute");
+ return;
+ }
+ name = name.trim();
+ if (component == null || component.trim().isEmpty()) {
+ // try to use the name as component
+ if (!compiler.checkReference(tag, name, false, name)) {
+ compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute ["+name+"] for the component, but no such component found");
+ return;
+ }
+ component = name;
+ }
+ component = component.trim();
+
+ // check component exist (again perharps, but if error will known exactly which tag failed...)
+ if (compiler.checkReference(tag, component, true, component)) {
+ // add a field
+ validator.addField(name, component, compiler);
+ }
+
+
+ }
+
+}
\ No newline at end of file
1
0
r957 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 19:44:04 +0000 (Fri, 17 Oct 2008)
New Revision: 957
Added:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/validator/
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java
Log:
introduce Error model
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java 2008-10-17 17:34:35 UTC (rev 956)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java 2008-10-17 19:44:04 UTC (rev 957)
@@ -21,6 +21,7 @@
import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.ValidationAwareSupport;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
@@ -35,13 +36,10 @@
import org.jdesktop.jxlayer.plaf.AbstractLayerUI;
import javax.swing.BorderFactory;
-import javax.swing.DefaultListModel;
import javax.swing.JComponent;
-import javax.swing.JList;
import javax.swing.SwingUtilities;
import java.awt.AlphaComposite;
import java.awt.Color;
-import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics2D;
import java.awt.Insets;
@@ -52,10 +50,8 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -157,11 +153,8 @@
/** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */
protected Map<String, JComponent> fieldRepresentation;
- /** Objet servant a afficher toutes les erreurs */
- protected JList errorList = null;
-
/** Object servant a contenir la liste des erreurs */
- protected DefaultListModel errorListModel;
+ protected BeanValidatorErrorListModel errorListModel;
public BeanValidator() {
pcs = new PropertyChangeSupport(this);
@@ -170,25 +163,15 @@
fieldRepresentation = new HashMap<String, JComponent>();
}
- /**
- * Permet de modifier l'objet permettant d'afficher toutes les errors
- *
- * @param errorList si null arrete d'afficher les errors
- */
- public void setErrorList(JList errorList) {
- this.errorList = errorList;
- }
-
- public JList getErrorList() {
- return errorList;
- }
-
- public DefaultListModel getErrorListModel() {
+ public BeanValidatorErrorListModel getErrorListModel() {
return errorListModel;
}
- public void setErrorListModel(DefaultListModel errorListModel) {
+ public void setErrorListModel(BeanValidatorErrorListModel errorListModel) {
this.errorListModel = errorListModel;
+ if (errorListModel != null) {
+ errorListModel.registerValidator(this);
+ }
}
/**
@@ -261,6 +244,18 @@
pcs.firePropertyChange("bean", oldBean, bean);
}
+ public Map getFieldErrors() {
+ return validationContext.getFieldErrors();
+ }
+
+ public Collection getActionErrors() {
+ return validationContext.getActionErrors();
+ }
+
+ public Collection getActionMessages() {
+ return validationContext.getActionMessages();
+ }
+
/** install layers on required components */
public void installLayers() {
SwingUtilities.invokeLater(new Runnable() {
@@ -308,23 +303,7 @@
}
try {
- List<String> newErrors = new ArrayList<String>();
- Enumeration enumeration = getErrorListModel().elements();
- while (enumeration.hasMoreElements()) {
- Object o = enumeration.nextElement();
- newErrors.add((String) o);
- }
- for (Object o : validationContext.getFieldErrors().entrySet()) {
- Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
- String field = (String) r.getKey();
- List<String> errors = (List<String>) r.getValue();
- JComponent component = fieldRepresentation.get(field);
- for (String error : errors) {
- newErrors.remove(component.getName() + " : " + error);
- }
- }
-
validationSupport.clearErrorsAndMessages();
getValidator().validate(bean, null, validationContext);
@@ -337,21 +316,9 @@
log.info(this + " : " + validationContext.getFieldErrors());
- for (Object o : validationContext.getFieldErrors().entrySet()) {
- Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
- String field = (String) r.getKey();
- List<String> errors = (List<String>) r.getValue();
- JComponent component = fieldRepresentation.get(field);
- for (String error : errors) {
- newErrors.add(component.getName() + " : " + error);
- }
- }
+ // add errors
+ errorListModel.addErrors(this);
- getErrorListModel().clear();
- for (String newError : newErrors) {
- getErrorListModel().addElement(newError);
- }
-
for (String fieldname : fieldRepresentation.keySet()) {
JComponent c = fieldRepresentation.get(fieldname);
//todo: a supprimer mais actuellemnt le layer ne se repaint pas bien, cela n'est pas normal
@@ -377,7 +344,7 @@
Container container = c.getParent();
if (container instanceof JXLayer) {
IconValidationUI ui = new IconValidationUI(fieldname, c.getName(), validationSupport);
- // TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, validationSupport.getFieldErrors());
+ //TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, c.getName(), validationSupport);
ui.setEnabled(true);
JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
jx.setUI(ui);
@@ -389,20 +356,46 @@
protected class Listener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent evt) {
+ // only validate if the property has really changed...
+ Object oldValue = evt.getOldValue();
+ Object newValue = evt.getNewValue();
+ if (oldValue == null && newValue == null) {
+ return;
+ }
+ if ((oldValue != null && oldValue.equals(newValue)) || (newValue != null && newValue.equals(oldValue))) {
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("launch validation from event [name:" + evt.getPropertyName() + " <old:" + oldValue + ", new:" + newValue + ">]");
+ }
validate();
setChanged(true);
}
}
+ /** @return <code>true</code> if errors are detected, <code>false</code> otherwise */
+ public boolean hasErrors() {
+ //todo should also detecte actionErrors ?
+ return validationContext.hasFieldErrors();
+ //return validationContext.hasFieldErrors() || validationContext.hasActionErrors();
+ }
public static class TranslucentValidationUI extends AbstractLayerUI<JComponent> {
- protected String field = null;
- protected Map resultValidation = null;
+ /** bean field */
+ protected String field;
- public TranslucentValidationUI(String field, Map resultValidation) {
+ /** component id */
+ protected String componentId;
+
+ /** validation context */
+ protected ValidationAware validationContext;
+
+ public TranslucentValidationUI(String field, String componentId, ValidationAware validationContext) {
this.field = field;
- this.resultValidation = resultValidation;
+ this.componentId = componentId;
+ this.validationContext = validationContext;
+ log.info("install " + this + "<field:" + field + ", componentId:" + componentId + ">");
}
@Override
@@ -421,7 +414,7 @@
view.getWidth() - insets.left - insets.right,
view.getHeight() - insets.top - insets.bottom));
- g2.setColor(!resultValidation.containsKey(field) ?
+ g2.setColor(!validationContext.getFieldErrors().containsKey(field) ?
Color.GREEN : Color.RED);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .2f));
g2.fillRect(0, 0, l.getWidth(), l.getHeight());
@@ -449,16 +442,18 @@
}
/** bean validation field */
- protected String field = null;
+ protected String field;
/** component id */
- protected String componentId = null;
- protected ValidationAwareSupport resultValidation = null;
+ protected String componentId;
- public IconValidationUI(String field, String componentId, ValidationAwareSupport resultValidation) {
+ /** validation context */
+ protected ValidationAware validationContext;
+
+ public IconValidationUI(String field, String componentId, ValidationAware validationContext) {
this.field = field;
- this.resultValidation = resultValidation;
this.componentId = componentId;
+ this.validationContext = validationContext;
log.info("install " + this + "<field:" + field + ", componentId:" + componentId + ">");
}
@@ -477,14 +472,13 @@
@Override
protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
super.paintLayer(g2, l);
- Component component = l.getComponent(1);
// There is no need to take insets into account for this painter
- if (resultValidation.getFieldErrors().containsKey(field)) {
- log.info("requiredId : " + componentId + " : componentName : " + component.getName());
+ if (validationContext.getFieldErrors().containsKey(field)) {
g2.drawImage(INVALID_ICON, l.getWidth() - INVALID_ICON.getWidth() - 1, 0, null);
// g2.drawImage(INVALID_ICON, 0, 0, null);
}
}
}
+
}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorError.java 2008-10-17 19:44:04 UTC (rev 957)
@@ -0,0 +1,83 @@
+package jaxx.runtime;
+
+import org.codelutin.i18n.I18n;
+
+import javax.swing.JComponent;
+
+/**
+ * The model of an error.
+ *
+ * @author chemit
+ */
+public class BeanValidatorError<T> {
+
+ protected BeanValidator<T> validator;
+
+ protected String fieldName;
+
+ protected String error;
+
+ protected JComponent component;
+
+ public BeanValidator<T> getValidator() {
+ return validator;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public JComponent getComponent() {
+ return component;
+ }
+
+ public void setValidator(BeanValidator<T> validator) {
+ this.validator = validator;
+ }
+
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public void setComponent(JComponent component) {
+ this.component = component;
+ }
+
+ @Override
+ public String toString() {
+ return component.getName() + " : " + I18n._(error);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof BeanValidatorError)) {
+ return false;
+ }
+
+ BeanValidatorError that = (BeanValidatorError) o;
+
+ return component.equals(that.component) && error.equals(that.error) && fieldName.equals(that.fieldName) && validator.equals(that.validator);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ result = validator.hashCode();
+ result = 31 * result + fieldName.hashCode();
+ result = 31 * result + error.hashCode();
+ result = 31 * result + component.hashCode();
+ return result;
+ }
+}
Added: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidatorErrorListModel.java 2008-10-17 19:44:04 UTC (rev 957)
@@ -0,0 +1,138 @@
+package jaxx.runtime;
+
+import javax.swing.DefaultListModel;
+import javax.swing.JComponent;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The model of the list of errors
+ *
+ * @author chemit
+ */
+public class BeanValidatorErrorListModel extends DefaultListModel {
+ private static final long serialVersionUID = 1L;
+
+ /** list of registred validators */
+ protected transient List<BeanValidator<?>> validators;
+
+ /** comporatorof errors */
+ protected transient Comparator<BeanValidatorError> comparator;
+
+ public BeanValidatorErrorListModel() {
+ validators = new ArrayList<BeanValidator<?>>();
+ }
+
+ public void registerValidator(BeanValidator<?> validator) {
+ if (validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is already registred in " + this);
+ }
+ validators.add(validator);
+ }
+
+ public <T> void addErrors(BeanValidator<T> validator) {
+ if (!validators.contains(validator)) {
+ throw new IllegalArgumentException("the validator " + validator + " is not registred in " + this);
+ }
+
+ // new errors for the given validator
+ List<BeanValidatorError> newErrors = new ArrayList<BeanValidatorError>();
+ // old errors for the given validator
+ List<BeanValidatorError> oldErrors = new ArrayList<BeanValidatorError>();
+ // old errors for other validators
+ List<BeanValidatorError> oldOtherErrors = new ArrayList<BeanValidatorError>();
+
+ // split old errors from other validators
+ splitOldErrors(validator, oldErrors, oldOtherErrors);
+
+ // fill new errors
+ fillNewErrors(validator, newErrors);
+
+ // check if something has changed for the given validator
+ if (hasChanged(oldErrors, newErrors)) {
+
+ // reinject other errors
+ newErrors.addAll(oldOtherErrors);
+
+ // sort errors
+ Collections.sort(newErrors, getComparator());
+
+ // clean errors in model
+ clear();
+
+ // reinject in list model, all the errors
+ for (BeanValidatorError error : newErrors) {
+ addElement(error);
+ }
+
+ // notify thaht the model has changed
+ fireContentsChanged(this, 0, getSize() - 1);
+ }
+ }
+
+ protected boolean hasChanged(List<BeanValidatorError> oldErrors, List<BeanValidatorError> newErrors) {
+ if (oldErrors.size() != newErrors.size()) {
+ return true;
+ }
+ for (BeanValidatorError oldError : oldErrors) {
+ if (!newErrors.contains(oldError)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected <T> void fillNewErrors(BeanValidator<T> validator, List<BeanValidatorError> newErrors) {
+ if (validator.hasErrors()) {
+ // inject this validator errors
+ for (Object o : validator.getFieldErrors().entrySet()) {
+ Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
+ BeanValidatorError<T> error;
+ String field = (String) r.getKey();
+
+ JComponent component = validator.getFieldRepresentation(field);
+ for (Object errorString : (List<?>) r.getValue()) {
+ String error1 = (String) errorString;
+ error = new BeanValidatorError<T>();
+ error.setComponent(component);
+ error.setValidator(validator);
+ error.setError(error1);
+ error.setFieldName(field);
+ newErrors.add(error);
+ }
+ }
+ //todo should also do actionErrors
+ }
+ }
+
+ protected <T> void splitOldErrors(BeanValidator<T> validator, List<BeanValidatorError> oldErrors, List<BeanValidatorError> oldOtherErrors) {
+ Enumeration enumeration = elements();
+
+ while (enumeration.hasMoreElements()) {
+ Object o = enumeration.nextElement();
+ BeanValidatorError<?> error = (BeanValidatorError) o;
+ if (!error.getValidator().equals(validator)) {
+ // error from another validator, keep it
+ oldOtherErrors.add(error);
+ } else {
+ oldErrors.add(error);
+ }
+ }
+ }
+
+ protected Comparator<BeanValidatorError> getComparator() {
+ if (comparator == null) {
+ comparator = new Comparator<BeanValidatorError>() {
+ public int compare(BeanValidatorError o1, BeanValidatorError o2) {
+ return o1.toString().compareTo(o2.toString());
+ }
+ };
+ }
+ return comparator;
+ }
+
+}
1
0
r956 - lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 17:34:35 +0000 (Fri, 17 Oct 2008)
New Revision: 956
Modified:
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.css
Log:
refactor css
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.css
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.css 2008-10-17 17:34:03 UTC (rev 955)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.css 2008-10-17 17:34:35 UTC (rev 956)
@@ -1,8 +1,5 @@
JSlider {
paintTicks: true;
-}
-
-JSlider#ratio {
minorTickSpacing: 5;
majorTickSpacing: 10;
}
1
0
r955 - in lutinjaxx/trunk/jaxx-core/src/main/java/jaxx: compiler runtime
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 17:34:03 +0000 (Fri, 17 Oct 2008)
New Revision: 955
Added:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXObject.java
Log:
introduce JaxxValidator contract
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 17:33:22 UTC (rev 954)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 17:34:03 UTC (rev 955)
@@ -608,7 +608,7 @@
// register validator
for (CompiledBeanValidator validator : validators) {
String id = TypeManager.getJavaCode(validator.getId());
- code.append("$validatorIds.add(").append(id).append(");");
+ code.append("validatorIds.add(").append(id).append(");");
code.append(getLineSeparator());
code.append("getValidator(").append(id).append(").installLayers();");
code.append("getValidator(").append(id).append(").validate();");
@@ -696,7 +696,7 @@
}
javaFile.addImport("jaxx.runtime.BeanValidator");
- javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<String>", "$validatorIds", "new ArrayList<String>()"));
+ javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<String>", "validatorIds", "new ArrayList<String>()"));
if (stylesheet != null) {
javaFile.addField(new JavaField(0, "java.util.Map", "$previousValues", "new java.util.HashMap()"));
@@ -705,7 +705,7 @@
javaFile.addMethod(createConstructor(className));
javaFile.addMethod(createInitializer(className));
javaFile.addMethod(new JavaMethod(Modifier.PUBLIC, "BeanValidator<?>", "getValidator", new JavaArgument[]{new JavaArgument("String", "validatorId")},
- null, "return (BeanValidator)($validatorIds.contains(validatorId)?getObjectById(validatorId):null);"));
+ null, "return (BeanValidator)(validatorIds.contains(validatorId)?getObjectById(validatorId):null);"));
for (DataBinding dataBinding : dataBindings) {
if (dataBinding.compile(true)) {
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXObject.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXObject.java 2008-10-17 17:33:22 UTC (rev 954)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXObject.java 2008-10-17 17:34:03 UTC (rev 955)
@@ -5,7 +5,7 @@
package jaxx.runtime;
/** The <code>JAXXObject</code> interface is implemented by all classes produced by the JAXX compiler. */
-public interface JAXXObject extends JAXXContext{
+public interface JAXXObject extends JAXXContext, JAXXValidator {
/**
* Retrieves an object defined in an XML tag by its ID.
*
@@ -16,9 +16,10 @@
/**
* Pretrieves the dictonary of knwon objects indexed by their ids.
+ *
* @return the dictonary of objects.
*/
- public java.util.Map<String,Object> get$objectMap();
+ public java.util.Map<String, Object> get$objectMap();
public void applyDataBinding(String id);
Copied: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java (from rev 948, lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXContext.java)
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java (rev 0)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java 2008-10-17 17:34:03 UTC (rev 955)
@@ -0,0 +1,23 @@
+package jaxx.runtime;
+
+import java.util.List;
+
+/**
+ * The contract of a validator-able object.
+ *
+ * @author chemit
+ */
+public interface JAXXValidator {
+
+ /**
+ * Obtain a validator from his id
+ *
+ * @param validatorId validator id
+ * @return the associated validator, or <code>null</code> if not find
+ */
+ BeanValidator<?> getValidator(String validatorId);
+
+ /** @return the list of ids of all registred validator */
+ List<String> getValidatorIds();
+
+}
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXValidator.java
___________________________________________________________________
Name: svn:mergeinfo
+
1
0
r954 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 17:33:22 +0000 (Fri, 17 Oct 2008)
New Revision: 954
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXContext.java
Log:
contract is public
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXContext.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXContext.java 2008-10-17 17:32:18 UTC (rev 953)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/JAXXContext.java 2008-10-17 17:33:22 UTC (rev 954)
@@ -7,7 +7,7 @@
*
* @author letellier
*/
-interface JAXXContext {
+public interface JAXXContext {
/**
* Map actions objects used by JAXX interface.
1
0
r953 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 17:32:18 +0000 (Fri, 17 Oct 2008)
New Revision: 953
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
Log:
log
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 17:04:05 UTC (rev 952)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 17:32:18 UTC (rev 953)
@@ -236,7 +236,9 @@
if (fields.containsKey(id)) {
compiler.reportError("duplicate field '" + id + "' for validator " + this);
} else {
- log.info("add field <" + id + ":" + component + ">");
+ if (compiler.getOptions().isVerbose()) {
+ log.info("add field <" + id + ":" + component + ">");
+ }
fields.put(id, component);
}
}
1
0
Author: tchemit
Date: 2008-10-17 17:04:05 +0000 (Fri, 17 Oct 2008)
New Revision: 952
Modified:
lutinjaxx/trunk/pom.xml
Log:
can disable examples building with -Ddoexample=false, by default will build them (but not required on dev process :) )
if no example a mvn clean install = 37s, otherwise = 2 min...
Modified: lutinjaxx/trunk/pom.xml
===================================================================
--- lutinjaxx/trunk/pom.xml 2008-10-17 17:02:38 UTC (rev 951)
+++ lutinjaxx/trunk/pom.xml 2008-10-17 17:04:05 UTC (rev 952)
@@ -202,8 +202,14 @@
</scm>
<profiles>
+ <!-- by default example are included, use -Ddoexample=false to disable examples -->
<profile>
- <id>example</id>
+ <activation>
+ <property>
+ <name>doexample</name>
+ <value>!false</value>
+ </property>
+ </activation>
<modules>
<module>jaxx-example</module>
</modules>
1
0
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 17:02:38 +0000 (Fri, 17 Oct 2008)
New Revision: 951
Modified:
lutinjaxx/trunk/jaxx-core/changelog
Log:
changelog
Modified: lutinjaxx/trunk/jaxx-core/changelog
===================================================================
--- lutinjaxx/trunk/jaxx-core/changelog 2008-10-17 17:02:26 UTC (rev 950)
+++ lutinjaxx/trunk/jaxx-core/changelog 2008-10-17 17:02:38 UTC (rev 951)
@@ -1,4 +1,5 @@
ver-0-5 chemit 20081002
+ * 20081017 [chemit] add validator support
* 20081013 [chemit] can generate logger on jaxx files
* 20081011 [chemit] improve site
* 20081011 [chemit] fix bug on JavaFileParser : works again
1
0
r950 - lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 17:02:26 +0000 (Fri, 17 Oct 2008)
New Revision: 950
Modified:
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
Log:
with no error...
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-17 16:48:54 UTC (rev 949)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-17 17:02:26 UTC (rev 950)
@@ -22,7 +22,6 @@
</BeanValidator>
<BeanValidator id='validator3' autoField='true' bean='identity' errorListModel='errors'>
<field name="email" component="email2"/>
- <field name="email" component="email2"/>
</BeanValidator>
<Table fill='both'>
1
0
r949 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 16:48:54 +0000 (Fri, 17 Oct 2008)
New Revision: 949
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
Log:
log only if verbose
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 16:44:54 UTC (rev 948)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 16:48:54 UTC (rev 949)
@@ -53,7 +53,9 @@
@Override
protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
- log.info(tag);
+ if (compiler.getOptions().isVerbose()) {
+ log.info(tag);
+ }
if (!tag.getLocalName().equals(FieldValidatorHandler.FIELD_VALIDATOR_TAG)) {
compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.FIELD_VALIDATOR_TAG + " as children, but found : " + tag.getLocalName());
} else {
@@ -117,9 +119,12 @@
}
protected void registerAutoFieldBean(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
- for (JAXXPropertyDescriptor beanProperty : info.getBeanDescriptor(compiler).getJAXXPropertyDescriptors()) {
+ JAXXBeanInfo beanInfo = info.getBeanDescriptor(compiler);
+ for (JAXXPropertyDescriptor beanProperty : beanInfo.getJAXXPropertyDescriptors()) {
String descriptionName = beanProperty.getName();
- log.info("doAutoField on property " + descriptionName);
+ if (compiler.getOptions().isVerbose()) {
+ log.info("try to bind on bean " + beanInfo.getJAXXBeanDescriptor().getName() + " property " + descriptionName);
+ }
if (beanProperty.getWriteMethodDescriptor() == null) {
// read-only property
continue;
1
0
r948 - in lutinjaxx/trunk/jaxx-example/Validation/src/main: java/examples/Validation resources/examples/Validation
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 16:44:54 +0000 (Fri, 17 Oct 2008)
New Revision: 948
Added:
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java
lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
Modified:
lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
Log:
implements autoField behaviour
add some checking on beans
Copied: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java (from rev 943, lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Model.java)
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java (rev 0)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Identity.java 2008-10-17 16:44:54 UTC (rev 948)
@@ -0,0 +1,79 @@
+package examples.Validation;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+public class Identity {
+
+ protected String firstName = "";
+
+ protected String lastName = "";
+
+ protected String email = "dummy(a)codelutin.com";
+
+ protected int age = 51;
+
+
+ PropertyChangeSupport p;
+
+ public Identity() {
+ p = new PropertyChangeSupport(this);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ p.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ p.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ p.removePropertyChangeListener(propertyName, listener);
+ }
+
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setFirstName(String firstName) {
+ String oldFirstName = this.firstName;
+ this.firstName = firstName;
+ p.firePropertyChange("firstName", oldFirstName, firstName);
+ }
+
+ public void setLastName(String lastName) {
+ String oldLastName = this.lastName;
+ this.lastName = lastName;
+ p.firePropertyChange("lastName", oldLastName, lastName);
+ }
+
+ public void setEmail(String email) {
+ String oldEmail =this.email;
+ this.email = email;
+ p.firePropertyChange("email", oldEmail, email);
+ }
+
+ public void setAge(int age) {
+ int oldAge = this.age;
+ this.age = age;
+ p.firePropertyChange("age", oldAge, age);
+ }
+}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-17 16:44:40 UTC (rev 947)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/java/examples/Validation/Validation.jaxx 2008-10-17 16:44:54 UTC (rev 948)
@@ -1,18 +1,30 @@
<Application title="Validation.jaxx">
<style source="Validation.css"/>
+
+ <!-- models -->
<Model id='model'/>
<Model id='model2'/>
+ <Identity id='identity'/>
+
+ <!-- errors model -->
<DefaultListModel id='errors' onIntervalAdded='ok.setEnabled(errors.size()==0)' onIntervalRemoved='ok.setEnabled(errors.size()==0)'/>
- <BeanValidator id='validator' autoField='true' bean='model' errorListModel='errors'>
- <field name="text" component="text"/>
- <field name="text2" component="text2"/>
- <field name="ratio" component="ratio"/>
+
+ <!-- validators -->
+ <BeanValidator id='validator' bean='model' errorListModel='errors'>
+ <field name="text"/>
+ <field name="text2"/>
+ <field name="ratio"/>
</BeanValidator>
- <BeanValidator id='validator2' autoField='true' bean='model2' errorListModel='errors'>
+ <BeanValidator id='validator2' bean='model2' errorListModel='errors'>
<field name="text" component="_text"/>
<field name="text2" component="_text2"/>
<field name="ratio" component="_ratio"/>
</BeanValidator>
+ <BeanValidator id='validator3' autoField='true' bean='identity' errorListModel='errors'>
+ <field name="email" component="email2"/>
+ <field name="email" component="email2"/>
+ </BeanValidator>
+
<Table fill='both'>
<row>
<cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
@@ -165,6 +177,100 @@
</cell>
</row>
<row>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identify Form")}'
+ layout='{new GridLayout()}' width='250' height='140'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <org.jdesktop.jxlayer.JXLayer>
+ <JTextField id='firstName' text='{identity.getFirstName()}'
+ onKeyReleased='identity.setFirstName(firstName.getText())'/>
+ </org.jdesktop.jxlayer.JXLayer>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <org.jdesktop.jxlayer.JXLayer>
+ <JTextField id='lastName' text='{identity.getLastName()}'
+ onKeyReleased='identity.setLastName(lastName.getText())'/>
+ </org.jdesktop.jxlayer.JXLayer>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <org.jdesktop.jxlayer.JXLayer>
+ <JTextField id='email2' text='{identity.getEmail()}'
+ onKeyReleased='identity.setEmail(email2.getText())'/>
+ </org.jdesktop.jxlayer.JXLayer>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <org.jdesktop.jxlayer.JXLayer>
+ <JSlider id='age' minimum='0' maximum='100' value='{identity.getAge()}'
+ onStateChanged='identity.setAge(age.getValue())'/>
+ </org.jdesktop.jxlayer.JXLayer>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ <cell weightx='1' weighty='1' insets='6, 3, 0, 0'>
+ <JPanel border='{BorderFactory.createTitledBorder("Identity Model")}'
+ layout='{new GridLayout()}' width='250' height='120'>
+ <Table anchor='west' fill='both'>
+ <row>
+ <cell>
+ <JLabel text='FirstName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getFirstName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='LastName:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getLastName()}'/>
+ </cell>
+ </row>
+ <row>
+ <cell>
+ <JLabel text='Email:'/>
+ </cell>
+ <cell weightx='1'>
+ <JLabel text='{identity.getEmail()}'/>
+ </cell>
+ </row>
+
+ <row>
+ <cell>
+ <JLabel text='Age:'/>
+ </cell>
+ <cell>
+ <JLabel text='{identity.getAge()}'/>
+ </cell>
+ </row>
+ </Table>
+ </JPanel>
+ </cell>
+ </row>
+ <row>
<cell columns='2' fill="both">
<JPanel border='{BorderFactory.createTitledBorder("Errors")}' layout='{new GridLayout()}' height='200' width='500'>
<JScrollPane>
Copied: lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml (from rev 943, lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Model-validation.xml)
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml (rev 0)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml 2008-10-17 16:44:54 UTC (rev 948)
@@ -0,0 +1,32 @@
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+ <field name="firstName">
+ <field-validator type="requiredstring" short-circuit="true">
+ <message>You must enter a firstName.</message>
+ </field-validator>
+ </field>
+ <field name="lastName">
+ <field-validator type="requiredstring" short-circuit="true">
+ <message>You must enter a lastName.</message>
+ </field-validator>
+ </field>
+
+ <field name="email">
+ <field-validator type="requiredstring" short-circuit="true">
+ <message>You must enter a value for email.</message>
+ </field-validator>
+ <field-validator type="email" short-circuit="true">
+ <message>Not a valid e-mail.</message>
+ </field-validator>
+ </field>
+
+ <field name="age">
+ <field-validator type="int">
+ <param name="min">18</param>
+ <param name="max">88</param>
+ <message>Age needs to be between ${min} and ${max}</message>
+ </field-validator>
+ </field>
+</validators>
\ No newline at end of file
Property changes on: lutinjaxx/trunk/jaxx-example/Validation/src/main/resources/examples/Validation/Identity-validation.xml
___________________________________________________________________
Name: svn:mergeinfo
+
1
0
r947 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 16:44:40 +0000 (Fri, 17 Oct 2008)
New Revision: 947
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java
Log:
implements autoField behaviour
add some checking on beans
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 16:43:39 UTC (rev 946)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/BeanValidatorHandler.java 2008-10-17 16:44:40 UTC (rev 947)
@@ -7,6 +7,8 @@
import jaxx.CompilerException;
import jaxx.compiler.CompiledObject;
import jaxx.compiler.JAXXCompiler;
+import jaxx.introspection.JAXXBeanInfo;
+import jaxx.introspection.JAXXPropertyDescriptor;
import jaxx.reflect.ClassDescriptor;
import jaxx.reflect.ClassDescriptorLoader;
import jaxx.runtime.BeanValidator;
@@ -16,6 +18,7 @@
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
+import java.beans.IntrospectionException;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
@@ -24,10 +27,10 @@
public class BeanValidatorHandler extends DefaultObjectHandler {
public static final String BEAN_VALIDATOR_TAG = BeanValidator.class.getSimpleName();
-
public static final String BEAN_ATTRIBUTE = "bean";
public static final String ERROR_LIST_MODEL_ATTRIBUTE = "errorListModel";
public static final String AUTOFIELD_ATTRIBUTE = "autoField";
+ public static final String STRICT_MODE_ATTRIBUTE = "strictMode";
/** to use log facility, just put in your code: log.info(\"...\"); */
static Log log = LogFactory.getLog(BeanValidatorHandler.class);
@@ -49,6 +52,16 @@
}
@Override
+ protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
+ log.info(tag);
+ if (!tag.getLocalName().equals(FieldValidatorHandler.FIELD_VALIDATOR_TAG)) {
+ compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.FIELD_VALIDATOR_TAG + " as children, but found : " + tag.getLocalName());
+ } else {
+ compiler.compileFirstPass(tag);
+ }
+ }
+
+ @Override
public void compileSecondPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
super.compileSecondPass(tag, compiler);
@@ -58,54 +71,44 @@
String tmp = info.getErrorListModel();
if (tmp != null) {
- //todo should check object exists
- String code = getSetPropertyCode(info.getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, tmp, compiler);
- info.appendAdditionCode(code);
+ if (compiler.checkReference(tag, tmp, true, ERROR_LIST_MODEL_ATTRIBUTE)) {
+ String code = getSetPropertyCode(info.getJavaCode(), ERROR_LIST_MODEL_ATTRIBUTE, tmp, compiler);
+ info.appendAdditionCode(code);
+ }
}
String bean = info.getBean();
if (bean != null) {
- //todo should check object exists
- String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler);
- info.appendAdditionCode(code);
+ if (compiler.checkReference(tag, bean, true, BEAN_ATTRIBUTE)) {
+ String code = getSetPropertyCode(info.getJavaCode(), BEAN_ATTRIBUTE, bean, compiler);
+ info.appendAdditionCode(code);
+ }
}
- Boolean doAutoField = info.getAutoField();
-
- if (doAutoField != null && doAutoField) {
+ if (info.getAutoField()) {
if (bean == null) {
compiler.reportError("tag '" + tag.getLocalName() + "' need a " + BEAN_ATTRIBUTE + " attribute to use autofield mode");
} else {
- //todo generate auto fields from bean property with matching component
- log.info("doAutoField for bean " + bean);
+ registerAutoFieldBean(tag, compiler, info);
}
}
- for (Entry<String, String> entry : info.getFields().entrySet()) {
- String keyCode = TypeManager.getJavaCode(entry.getKey());
- //todo should check object exists
- info.appendAdditionCode(info.getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + entry.getValue() + ");");
- }
+ // add fieldrepresentation invocations
+ addFieldRepresentations(tag, compiler, info);
+
// register the validator in compiler
compiler.registerValidator(info);
+
+ // close the compiled object
compiler.closeComponent(info);
}
@Override
protected void setDefaults(CompiledObject object, Element tag, JAXXCompiler compiler) {
+ // open the compiled object
compiler.openInvisibleComponent(object);
}
@Override
- protected void compileChildTagFirstPass(Element tag, JAXXCompiler compiler) throws CompilerException, IOException {
- log.info(tag);
- if (!tag.getLocalName().equals(FieldValidatorHandler.FIELD_VALIDATOR_TAG)) {
- compiler.reportError("tag '" + tag.getParentNode().getLocalName() + "' may only contain " + FieldValidatorHandler.FIELD_VALIDATOR_TAG + " as children, but found : " + tag.getLocalName());
- } else {
- compiler.compileFirstPass(tag);
- }
- }
-
- @Override
public void setAttribute(CompiledObject object, String propertyName, String stringValue, boolean inline, JAXXCompiler compiler) {
if (compiler.getOptions().isVerbose()) {
log.info(propertyName + " : " + stringValue + " for " + object);
@@ -113,6 +116,61 @@
object.addProperty(propertyName, stringValue);
}
+ protected void registerAutoFieldBean(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
+ for (JAXXPropertyDescriptor beanProperty : info.getBeanDescriptor(compiler).getJAXXPropertyDescriptors()) {
+ String descriptionName = beanProperty.getName();
+ log.info("doAutoField on property " + descriptionName);
+ if (beanProperty.getWriteMethodDescriptor() == null) {
+ // read-only property
+ continue;
+ }
+ if (info.getFields().containsKey(descriptionName)) {
+ // already defined in field
+ continue;
+ }
+ if (!compiler.checkReference(tag, descriptionName, info.getStrictMode(), null)) {
+ // no editor component found
+ continue;
+ }
+ // ok add the field mapping
+ info.addField(descriptionName, descriptionName, compiler);
+ }
+ }
+
+ protected void addFieldRepresentations(Element tag, JAXXCompiler compiler, CompiledBeanValidator info) {
+ for (Entry<String, String> entry : info.getFields().entrySet()) {
+ String propertyName = entry.getKey();
+ String component = entry.getValue();
+ if (!checkBeanProperty(compiler, info, propertyName)) {
+ // property not find on bean
+ continue;
+ }
+ if (!compiler.checkReference(tag, component, true, null)) {
+ // editor component not find on ui
+ continue;
+ }
+ String keyCode = TypeManager.getJavaCode(propertyName);
+ info.appendAdditionCode(info.getJavaCode() + ".setFieldRepresentation(" + keyCode + ", " + component + ");");
+
+ }
+ }
+
+ protected boolean checkBeanProperty(JAXXCompiler compiler, CompiledBeanValidator info, String propertyName) {
+
+ for (JAXXPropertyDescriptor beanProperty : info.getBeanDescriptor(compiler).getJAXXPropertyDescriptors()) {
+ if (beanProperty.getName().equals(propertyName)) {
+ if (beanProperty.getWriteMethodDescriptor() == null) {
+ // read-onlyproperty
+ compiler.reportError("could not bind the readonly property '" + propertyName + "' on bean [" + info.getBean() + "] ");
+ return false;
+ }
+ return true;
+ }
+ }
+ compiler.reportError("could not find the property '" + propertyName + "' on bean [" + info.getBean() + "] ");
+ return false;
+ }
+
/** @author chemit */
public static class CompiledBeanValidator extends CompiledObject {
@@ -120,6 +178,8 @@
protected String bean;
protected String errorListModel;
protected Boolean autoField;
+ protected Boolean strictMode;
+ protected JAXXBeanInfo beanDescriptor;
public CompiledBeanValidator(String id, ClassDescriptor objectClass, JAXXCompiler compiler) {
super(id, objectClass, compiler);
@@ -156,15 +216,22 @@
}
return;
}
+ if (STRICT_MODE_ATTRIBUTE.equals(property)) {
+ if (value != null && !value.trim().isEmpty()) {
+ strictMode = (Boolean) TypeManager.convertFromString(value, Boolean.class);
+ }
+ return;
+ }
+ //todo should not allowed to find other attributes
super.addProperty(property, value);
}
public void addField(String id, String component, JAXXCompiler compiler) {
if (fields.containsKey(id)) {
- compiler.reportError("duplicate field '" + id + " for validator " + this);
+ compiler.reportError("duplicate field '" + id + "' for validator " + this);
} else {
- log.info("add field <"+id+":"+component+">");
+ log.info("add field <" + id + ":" + component + ">");
fields.put(id, component);
}
}
@@ -177,16 +244,32 @@
return errorListModel;
}
- public Boolean getAutoField() {
- return autoField;
+ public boolean getAutoField() {
+ return autoField != null && autoField;
}
+ public boolean getStrictMode() {
+ return strictMode != null && strictMode;
+ }
+
+ public JAXXBeanInfo getBeanDescriptor(JAXXCompiler compiler) {
+ if (beanDescriptor == null && bean != null) {
+ try {
+ ClassDescriptor beanClassDescriptor = ClassDescriptorLoader.getClassDescriptor(compiler.getSymbolTable().getClassTagIds().get(bean));
+ beanDescriptor = getJAXXBeanInfo(beanClassDescriptor);
+ } catch (ClassNotFoundException e) {
+ compiler.reportError("could not load class " + bean);
+ } catch (IntrospectionException e) {
+ compiler.reportError("could not load class " + bean);
+ }
+ }
+ return beanDescriptor;
+ }
+
@Override
public void addChild(CompiledObject child, String constraints, JAXXCompiler compiler) throws CompilerException {
// do nothing
compiler.reportError("can not add CompiledObject in the tag '" + BEAN_VALIDATOR_TAG + " (only field tags)");
}
-
-
}
}
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java 2008-10-17 16:43:39 UTC (rev 946)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/tags/swing/FieldValidatorHandler.java 2008-10-17 16:44:40 UTC (rev 947)
@@ -52,12 +52,22 @@
}
name = name.trim();
if (component == null || component.trim().isEmpty()) {
- compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute");
- return;
+ // try to use the name as component
+ if (!compiler.checkReference(tag, name, false, name)) {
+ compiler.reportError(FIELD_VALIDATOR_TAG + " tag requires a " + COMPONENT_ATTRIBUTE + " attribute, try to use the name attribute ["+name+"] for the component, but no such component found");
+ return;
+ }
+ component = name;
}
component = component.trim();
- validator.addField(name, component, compiler);
+ // check component exist (again perharps, but if error will known exactly which tag failed...)
+ if (compiler.checkReference(tag, component, true, component)) {
+ // add a field
+ validator.addField(name, component, compiler);
+ }
+
+
}
}
\ No newline at end of file
1
0
r946 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 16:43:39 +0000 (Fri, 17 Oct 2008)
New Revision: 946
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java
Log:
move util method to Util class
reformat + javadoc
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java 2008-10-17 16:43:00 UTC (rev 945)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/BeanValidator.java 2008-10-17 16:43:39 UTC (rev 946)
@@ -48,20 +48,14 @@
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
-import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
/**
@@ -144,28 +138,36 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(BeanValidator.class);
- protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+ protected PropertyChangeSupport pcs;
- protected ValidationAwareSupport validationSupport = new ValidationAwareSupport();
- protected DelegatingValidatorContext validationContext =
- new DelegatingValidatorContext(validationSupport);
+ protected ValidationAwareSupport validationSupport;
+ protected DelegatingValidatorContext validationContext;
- protected transient ActionValidatorManager validator = null;
+ protected transient ActionValidatorManager validator;
- /** indique si le bean a ete modifie depuis sont arrive */
+ /** indique si le bean a ete modifie depuis son arrivee */
protected boolean changed = false;
+
/** le bean a surveiller */
protected T bean = null;
+
/** l'objet qui recoit les notifications de modification du bean */
protected Listener l = new Listener();
+
/** permet de faire le lien en un champs du bean et l'objet qui permet de l'editer */
- protected Map<String, JComponent> fieldRepresentation = new HashMap<String, JComponent>();
+ protected Map<String, JComponent> fieldRepresentation;
+
/** Objet servant a afficher toutes les erreurs */
protected JList errorList = null;
+
/** Object servant a contenir la liste des erreurs */
protected DefaultListModel errorListModel;
public BeanValidator() {
+ pcs = new PropertyChangeSupport(this);
+ validationSupport = new ValidationAwareSupport();
+ validationContext = new DelegatingValidatorContext(validationSupport);
+ fieldRepresentation = new HashMap<String, JComponent>();
}
/**
@@ -193,8 +195,8 @@
* Permet d'indiquer le composant graphique responsable de l'affichage
* d'un attribut du bean
*
- * @param fieldname
- * @param c
+ * @param fieldname the field name in the bean
+ * @param c the editor component for the field
*/
public void setFieldRepresentation(String fieldname, JComponent c) {
JComponent old = fieldRepresentation.put(fieldname, c);
@@ -207,17 +209,15 @@
}
}
-
public JComponent getFieldRepresentation(String fieldname) {
return fieldRepresentation.get(fieldname);
}
-
/**
* Retourne vrai si l'objet bean a ete modifie depuis le dernier
* {@link #setBean}
*
- * @return
+ * @return <code>true</code> if bean was modify since last {@link #setBean(Object)} invocation
*/
public boolean isChanged() {
return changed;
@@ -226,7 +226,7 @@
/**
* Permet de force la remise a false de l'etat de changement du bean
*
- * @param changed
+ * @param changed flag to force reset of property {@link #changed}
*/
public void setChanged(boolean changed) {
boolean oldChanged = this.changed;
@@ -303,67 +303,62 @@
public void validate() {
// on ne valide que si il y a un bean et que le resultat de la validation
// pourra etre affiche quelque part
- if (bean != null && getErrorListModel() != null && fieldRepresentation.size() != 0) {
- try {
- final List<String> newErrors = new ArrayList<String>();
+ if (bean == null || getErrorListModel() == null || fieldRepresentation.size() == 0) {
+ return;
+ }
- Enumeration enumeration = getErrorListModel().elements();
- while (enumeration.hasMoreElements()) {
- Object o = enumeration.nextElement();
- newErrors.add((String) o);
+ try {
+ List<String> newErrors = new ArrayList<String>();
+
+ Enumeration enumeration = getErrorListModel().elements();
+ while (enumeration.hasMoreElements()) {
+ Object o = enumeration.nextElement();
+ newErrors.add((String) o);
+ }
+ for (Object o : validationContext.getFieldErrors().entrySet()) {
+ Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
+ String field = (String) r.getKey();
+ List<String> errors = (List<String>) r.getValue();
+ JComponent component = fieldRepresentation.get(field);
+ for (String error : errors) {
+ newErrors.remove(component.getName() + " : " + error);
}
- for (Object o : validationContext.getFieldErrors().entrySet()) {
- Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
- String field = (String) r.getKey();
- List<String> errors = (List<String>) r.getValue();
- JComponent component = fieldRepresentation.get(field);
- for (String error : errors) {
- newErrors.remove(component.getName() + " : " + error);
- }
- }
+ }
- validationSupport.clearErrorsAndMessages();
+ validationSupport.clearErrorsAndMessages();
- getValidator().validate(bean, null, validationContext);
+ getValidator().validate(bean, null, validationContext);
- if (log.isDebugEnabled()) {
- log.debug("Action errors: " + validationContext.getActionErrors());
- log.debug("Action messages: " + validationContext.getActionMessages());
- log.debug("Field errors: " + validationContext.getFieldErrors());
- }
+ if (log.isDebugEnabled()) {
+ log.debug("Action errors: " + validationContext.getActionErrors());
+ log.debug("Action messages: " + validationContext.getActionMessages());
+ log.debug("Field errors: " + validationContext.getFieldErrors());
+ }
- log.info(this + " : " + validationContext.getFieldErrors());
-
- for (Object o : validationContext.getFieldErrors().entrySet()) {
- Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
- String field = (String) r.getKey();
- List<String> errors = (List<String>) r.getValue();
- JComponent component = fieldRepresentation.get(field);
- for (String error : errors) {
- newErrors.add(component.getName() + " : " + error);
- }
- }
+ log.info(this + " : " + validationContext.getFieldErrors());
- getErrorListModel().clear();
- for (String newError : newErrors) {
- getErrorListModel().addElement(newError);
+ for (Object o : validationContext.getFieldErrors().entrySet()) {
+ Map.Entry<?, ?> r = (Map.Entry<?, ?>) o;
+ String field = (String) r.getKey();
+ List<String> errors = (List<String>) r.getValue();
+ JComponent component = fieldRepresentation.get(field);
+ for (String error : errors) {
+ newErrors.add(component.getName() + " : " + error);
}
+ }
- for (String fieldname : fieldRepresentation.keySet()) {
- JComponent c = fieldRepresentation.get(fieldname);
- //fixme : sinon le layer ne se repain pas bien, cela n'est pas normal
- c.getParent().repaint();
- }
- // TODO: trouver autre chose
- // On est obliger de le refaire ici car avec jaxx, lors du
- // setFieldRepresentation le composant n'a pas encore de pere :(
- /*for (String fieldname : fieldRepresentation.keySet()) {
- JComponent c = fieldRepresentation.get(fieldname);
- setErrorRepresentation(fieldname, null, c);
- }*/
- } catch (ValidationException eee) {
- log.warn("Error during validation", eee);
+ getErrorListModel().clear();
+ for (String newError : newErrors) {
+ getErrorListModel().addElement(newError);
}
+
+ for (String fieldname : fieldRepresentation.keySet()) {
+ JComponent c = fieldRepresentation.get(fieldname);
+ //todo: a supprimer mais actuellemnt le layer ne se repaint pas bien, cela n'est pas normal
+ c.getParent().repaint();
+ }
+ } catch (ValidationException eee) {
+ log.warn("Error during validation", eee);
}
}
@@ -373,7 +368,7 @@
// suppression du jxlayer sous l'ancien composant
Container container = old.getParent();
if (container instanceof JXLayer) {
- JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
+ JXLayer<?> jx = (JXLayer<?>) container;
jx.setUI(null);
}
}
@@ -382,7 +377,7 @@
Container container = c.getParent();
if (container instanceof JXLayer) {
IconValidationUI ui = new IconValidationUI(fieldname, c.getName(), validationSupport);
-// TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, validationSupport.getFieldErrors());
+ // TranslucentValidationUI ui = new TranslucentValidationUI(fieldname, validationSupport.getFieldErrors());
ui.setEnabled(true);
JXLayer<JComponent> jx = (JXLayer<JComponent>) container;
jx.setUI(ui);
@@ -397,67 +392,9 @@
validate();
setChanged(true);
}
-
}
- /**
- * recherche les composants portant le meme nom que les champs de la classe
- * clazz. Cette methode est statique pour pouvoir eventuellement l'utiliser
- * dans un autre context (je pense par exemple a la generation jaxx).
- * <p/>
- * <p/>
- * Si la recherche echoue pour quelque raison que se soit, aucune exception
- * n'est leve, et la map retournee est tout simplement vide ou incomplete
- *
- * @param clazz la classe ou recherche les champs
- * @param container le container ou rechercher les composants d'edition
- * @return
- */
- public static Map<String, JComponent> lookingForEditor(Class clazz, Container container) {
- Map<String, JComponent> result = new HashMap<String, JComponent>();
- try {
- // looking for all component with name set
- Map<String, JComponent> allNamedComponent = new HashMap<String, JComponent>();
- List<Container> todo = new LinkedList<Container>();
- todo.add(container);
- while (todo.size() > 0) {
- for (ListIterator<Container> i = todo.listIterator(); i.hasNext();) {
- Container parent = i.next();
- i.remove();
- for (Component c : parent.getComponents()) {
- if (c instanceof Container) {
- i.add((Container) c);
- String name = c.getName();
- if (c instanceof JComponent &&
- name != null && !"".equals(name)) {
- allNamedComponent.put(name, (JComponent) c);
- }
- }
- }
- }
- }
- // looking for all properties on class
- BeanInfo info = Introspector.getBeanInfo(clazz);
- PropertyDescriptor[] props = info.getPropertyDescriptors();
-
- // find if one properties have same name that component
- for (PropertyDescriptor prop : props) {
- String name = prop.getName();
- if (allNamedComponent.containsKey(name)) {
- result.put(name, allNamedComponent.get(name));
- }
- }
-
- } catch (IntrospectionException eee) {
- log.warn("Can't introspect bean", eee);
- }
-
- System.out.println("Result: " + result);
-
- return result;
- }
-
public static class TranslucentValidationUI extends AbstractLayerUI<JComponent> {
protected String field = null;
@@ -543,9 +480,9 @@
Component component = l.getComponent(1);
// There is no need to take insets into account for this painter
if (resultValidation.getFieldErrors().containsKey(field)) {
- System.out.println("requiredId : " + componentId + " : componentName : " + component.getName());
+ log.info("requiredId : " + componentId + " : componentName : " + component.getName());
g2.drawImage(INVALID_ICON, l.getWidth() - INVALID_ICON.getWidth() - 1, 0, null);
-// g2.drawImage(INVALID_ICON, 0, 0, null);
+ // g2.drawImage(INVALID_ICON, 0, 0, null);
}
}
}
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-10-17 16:43:00 UTC (rev 945)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/Util.java 2008-10-17 16:43:39 UTC (rev 946)
@@ -1,8 +1,16 @@
package jaxx.runtime;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import javax.swing.JComponent;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Dimension;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -13,13 +21,21 @@
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.WeakHashMap;
-import java.util.EventListener;
import java.util.zip.GZIPInputStream;
public class Util {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(Util.class);
+
+
// Maps root objects to lists of event listeners
private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
@@ -45,7 +61,7 @@
try {
byte[] data = new byte[descriptor.length()];
// copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(),0,data,0,data.length);
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
//descriptor.getBytes(0, descriptor.length(), data, 0);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));
return (JAXXObjectDescriptor) in.readObject();
@@ -63,7 +79,7 @@
try {
byte[] data = new byte[descriptor.length()];
// copy low-order bytes into the array. The high-order bytes should all be zero.
- System.arraycopy(descriptor.getBytes(),0,data,0,data.length);
+ System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
//descriptor.getBytes(0, descriptor.length(), data, 0);
ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
return (JAXXObjectDescriptor) in.readObject();
@@ -109,8 +125,9 @@
}
}
}
- if (listenerMethodName != null && listenerMethod == null)
+ if (listenerMethodName != null && listenerMethod == null) {
throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ }
Class[] parameterTypes = listenerMethods.get(0).getParameterTypes();
Class<?> methodContainerClass = methodContainer.getClass();
final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
@@ -164,8 +181,9 @@
dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
} else {
for (DataBindingUpdateListener listener : listeners) {
- if (bindingName.equals(listener.getBindingName()))
+ if (bindingName.equals(listener.getBindingName())) {
return listener;
+ }
}
}
DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
@@ -180,8 +198,9 @@
JComponent jcomponent = (JComponent) component;
jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
- if (jcomponent.isDisplayable())
+ if (jcomponent.isDisplayable()) {
jcomponent.revalidate();
+ }
}
}
@@ -192,8 +211,9 @@
JComponent jcomponent = (JComponent) component;
jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
- if (jcomponent.isDisplayable())
+ if (jcomponent.isDisplayable()) {
jcomponent.revalidate();
+ }
}
}
@@ -250,4 +270,65 @@
src.firePropertyChange(name.trim(), null, "dummy value");
return value;
}
+
+ /**
+ * recherche les composants portant le meme nom que les champs de la classe
+ * clazz. Cette methode est statique pour pouvoir eventuellement l'utiliser
+ * dans un autre context (je pense par exemple a la generation jaxx).
+ * <p/>
+ * <p/>
+ * Si la recherche echoue pour quelque raison que se soit, aucune exception
+ * n'est leve, et la map retournee est tout simplement vide ou incomplete
+ *
+ * @param clazz la classe ou recherche les champs
+ * @param container le container ou rechercher les composants d'edition
+ * @return
+ */
+ public static Map<String, JComponent> lookingForEditor(Class clazz, Container container) {
+ Map<String, JComponent> result = new HashMap<String, JComponent>();
+ try {
+ // looking for all component with name set
+ Map<String, JComponent> allNamedComponent = new HashMap<String, JComponent>();
+ List<Container> todo = new LinkedList<Container>();
+ todo.add(container);
+ while (todo.size() > 0) {
+ for (ListIterator<Container> i = todo.listIterator(); i.hasNext();) {
+ Container parent = i.next();
+ i.remove();
+ for (Component c : parent.getComponents()) {
+ if (c instanceof Container) {
+ i.add((Container) c);
+ String name = c.getName();
+ if (c instanceof JComponent &&
+ name != null && !"".equals(name)) {
+ allNamedComponent.put(name, (JComponent) c);
+ }
+ }
+ }
+ }
+ }
+
+ // looking for all properties on class
+ BeanInfo info = Introspector.getBeanInfo(clazz);
+ PropertyDescriptor[] props = info.getPropertyDescriptors();
+
+ // find if one properties have same name that component
+ for (PropertyDescriptor prop : props) {
+ String name = prop.getName();
+ if (allNamedComponent.containsKey(name)) {
+ result.put(name, allNamedComponent.get(name));
+ }
+ }
+
+ } catch (IntrospectionException eee) {
+ log.warn("Can't introspect bean", eee);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Result: " + result);
+ }
+
+ return result;
+ }
+
}
1
0
r945 - lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 17, 2008
Oct. 17, 2008
Author: tchemit
Date: 2008-10-17 16:43:00 +0000 (Fri, 17 Oct 2008)
New Revision: 945
Modified:
lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
Log:
add method checkReference to check if an object is available on second compil pass
Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 05:07:31 UTC (rev 944)
+++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-10-17 16:43:00 UTC (rev 945)
@@ -695,7 +695,7 @@
javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.Map<String,Object>", "$bindingSources", "new HashMap<String,Object>()"));
}
- javaFile.addImport("jaxx.runtime.BeanValidator");
+ javaFile.addImport("jaxx.runtime.BeanValidator");
javaFile.addField(new JavaField(Modifier.PROTECTED, "java.util.List<String>", "$validatorIds", "new ArrayList<String>()"));
if (stylesheet != null) {
@@ -2144,4 +2144,30 @@
public boolean hasValidator() {
return !validators.isEmpty();
}
+
+ /**
+ * Check that a reference exists in symbol table on second compil pass
+ *
+ * @param tag the current tag
+ * @param reference the required reference
+ * @param strict flag to report an error if reference was not found
+ * @param attribute (if not null reference the attribute where is defined the reference)
+ * @return <code>true</code> if reference was found, <code>false</code> otherwise and add an error in compiler
+ */
+ public boolean checkReference(Element tag, String reference, boolean strict, String attribute) {
+ String component = getSymbolTable().getClassTagIds().get(reference);
+ if (component == null) {
+ if (strict) {
+ String msg;
+ if (attribute != null) {
+ msg = "tag '" + tag.getLocalName() + "' could not find the reference '" + reference + "' on attribute [" + attribute + "]";
+ } else {
+ msg = "tag '" + tag.getLocalName() + "' could not find the reference '" + reference + "'";
+ }
+ reportError(msg);
+ }
+ return false;
+ }
+ return true;
+ }
}
1
0
r942 - in lutinjaxx/trunk: . jaxx-core jaxx-example jaxx-example/Calculator jaxx-example/Counter jaxx-example/LabelStyle jaxx-example/Validation jaxx-swing-action jaxx-util maven-jaxx-plugin
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:40:40 +0000 (Thu, 16 Oct 2008)
New Revision: 942
Modified:
lutinjaxx/trunk/jaxx-core/pom.xml
lutinjaxx/trunk/jaxx-example/Calculator/pom.xml
lutinjaxx/trunk/jaxx-example/Counter/pom.xml
lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml
lutinjaxx/trunk/jaxx-example/Validation/pom.xml
lutinjaxx/trunk/jaxx-example/pom.xml
lutinjaxx/trunk/jaxx-swing-action/pom.xml
lutinjaxx/trunk/jaxx-util/pom.xml
lutinjaxx/trunk/maven-jaxx-plugin/pom.xml
lutinjaxx/trunk/pom.xml
Log:
final pom refactoring (use the inheritate version)
Modified: lutinjaxx/trunk/jaxx-core/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-core/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-core/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -4,6 +4,10 @@
<modelVersion>4.0.0</modelVersion>
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinjaxx</artifactId>
@@ -11,18 +15,7 @@
</parent>
<artifactId>jaxx-core</artifactId>
- <name>jaxx-core</name>
- <packaging>jar</packaging>
- <version>0.5-SNAPSHOT</version>
- <description>Jaxx lutin library core</description>
-
- <build>
- <plugins>
-
- </plugins>
- </build>
-
<dependencies>
<dependency>
@@ -56,6 +49,17 @@
</dependencies>
<!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+ <name>jaxx-core</name>
+ <description>Jaxx lutin library core</description>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+ <packaging>jar</packaging>
+
+ <!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
<scm>
Modified: lutinjaxx/trunk/jaxx-example/Calculator/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Calculator/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-example/Calculator/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -22,8 +22,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>Calculator example</name>
- <!--version>0.5-SNAPSHOT</version-->
- <inceptionYear>2008</inceptionYear>
<description>Jaxx Calculator example</description>
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/Counter/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Counter/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-example/Counter/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -22,8 +22,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>Counter example</name>
- <!--version>0.5-SNAPSHOT</version-->
- <inceptionYear>2008</inceptionYear>
<description>Jaxx Counter example</description>
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -22,8 +22,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>LabelStyle example</name>
- <version>0.5-SNAPSHOT</version>
- <inceptionYear>2008</inceptionYear>
<description>Jaxx LabelStyle example</description>
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/Validation/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-example/Validation/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -22,8 +22,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>Validation example</name>
- <version>0.5-SNAPSHOT</version>
- <inceptionYear>2008</inceptionYear>
<description>Jaxx Validation (with xwork validation) example</description>
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-example/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-example/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -39,8 +39,6 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>jaxx-example</name>
- <version>0.5-SNAPSHOT</version>
- <inceptionYear>2008</inceptionYear>
<description>Jaxx Example super pom</description>
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-swing-action/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-swing-action/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-swing-action/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -4,6 +4,11 @@
<modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinjaxx</artifactId>
@@ -11,11 +16,34 @@
</parent>
<artifactId>jaxx-swing-action</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.codelutin</groupId>
+ <artifactId>jaxx-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.7.ga</version>
+ <scope>compile</scope>
+ </dependency>
+
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
<name>jaxx-swing-action</name>
+ <description>Jaxx lutin library swing extension (tabs and actions)</description>
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
<packaging>jar</packaging>
- <version>0.5-SNAPSHOT</version>
- <description>Jaxx lutin library swing extension (tabs and actions)</description>
<build>
<plugins>
@@ -35,23 +63,6 @@
</plugins>
</build>
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>jaxx-core</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>jboss</groupId>
- <artifactId>javassist</artifactId>
- <version>3.7.ga</version>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/jaxx-util/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-util/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/jaxx-util/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -4,6 +4,9 @@
<modelVersion>4.0.0</modelVersion>
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinjaxx</artifactId>
@@ -11,11 +14,17 @@
</parent>
<artifactId>jaxx-util</artifactId>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
<name>jaxx-util</name>
+ <description>Jaxx lutin library utility</description>
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
<packaging>jar</packaging>
- <version>0.5-SNAPSHOT</version>
- <description>Jaxx lutin library utility</description>
<build>
<plugins>
Modified: lutinjaxx/trunk/maven-jaxx-plugin/pom.xml
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/maven-jaxx-plugin/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -16,7 +16,6 @@
</parent>
<artifactId>maven-jaxx-plugin</artifactId>
- <name>maven-jaxx-plugin</name>
<dependencies>
@@ -77,15 +76,13 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <version>0.5-SNAPSHOT</version>
+ <name>maven-jaxx-plugin</name>
<description>
Maven 2 plugin to generate java source from ui interface definitions
in jaxx format.
</description>
- <inceptionYear>2008</inceptionYear>
-
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
<!-- ************************************************************* -->
Modified: lutinjaxx/trunk/pom.xml
===================================================================
--- lutinjaxx/trunk/pom.xml 2008-10-16 15:39:52 UTC (rev 941)
+++ lutinjaxx/trunk/pom.xml 2008-10-16 15:40:40 UTC (rev 942)
@@ -22,7 +22,7 @@
<module>jaxx-core</module>
<module>jaxx-swing-action</module>
<module>maven-jaxx-plugin</module>
- <module>jaxx-example</module>
+ <!--module>jaxx-example</module-->
</modules>
<dependencies>
@@ -201,4 +201,13 @@
<url>${maven.scm.url}</url>
</scm>
+ <profiles>
+ <profile>
+ <id>example</id>
+ <modules>
+ <module>jaxx-example</module>
+ </modules>
+ </profile>
+ </profiles>
+
</project>
1
0
r941 - lutinjaxx/trunk/src/site/resources/images
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:39:52 +0000 (Thu, 16 Oct 2008)
New Revision: 941
Added:
lutinjaxx/trunk/src/site/resources/images/jrst-logo.png
Log:
add jrst logo
Added: lutinjaxx/trunk/src/site/resources/images/jrst-logo.png
===================================================================
(Binary files differ)
Property changes on: lutinjaxx/trunk/src/site/resources/images/jrst-logo.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
1
0
r940 - lutinjaxx/trunk/jaxx-example/src/site
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:26:03 +0000 (Thu, 16 Oct 2008)
New Revision: 940
Removed:
lutinjaxx/trunk/jaxx-example/src/site/resources/
Log:
remove unused site resources
1
0
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:24:40 +0000 (Thu, 16 Oct 2008)
New Revision: 939
Added:
lutinjaxx/trunk/src/site/resources/images/
Log:
add jrst logo
1
0
Author: tchemit
Date: 2008-10-16 15:05:46 +0000 (Thu, 16 Oct 2008)
New Revision: 938
Modified:
lutinjaxx/trunk/
Log:
svn ignore
Property changes on: lutinjaxx/trunk
___________________________________________________________________
Name: svn:ignore
- *.ipr
*.iws
*.iml
target
+ *.ipr
*.iws
*.iml
target
*.log
1
0
r937 - lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:03:32 +0000 (Thu, 16 Oct 2008)
New Revision: 937
Removed:
lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images/Validation-screenshot.jaxx.png
Log:
make examples works :)
Deleted: lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images/Validation-screenshot.jaxx.png
===================================================================
(Binary files differ)
1
0
r936 - in lutinjaxx/trunk/jaxx-example: . Calculator Calculator/src/main Calculator/src/site/fr/rst Components Components/src/main Components/src/site/fr/rst Counter Counter/src/main Counter/src/site/fr/rst LabelStyle LabelStyle/src/main LabelStyle/src/site/fr/rst Validation Validation/src/main Validation/src/site/fr/rst Validation/src/site/fr/rst/images src/main/jnlp src/site src/site/resources
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:02:52 +0000 (Thu, 16 Oct 2008)
New Revision: 936
Added:
lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images/Validation-screenshot.png
lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/index.rst
lutinjaxx/trunk/jaxx-example/src/main/jnlp/jxlayer.jnlp
lutinjaxx/trunk/jaxx-example/src/site/resources/
lutinjaxx/trunk/jaxx-example/src/site/resources/jaxx.png
Removed:
lutinjaxx/trunk/jaxx-example/Calculator/src/main/jnlp/
lutinjaxx/trunk/jaxx-example/Components/src/main/jnlp/
lutinjaxx/trunk/jaxx-example/Counter/src/main/jnlp/
lutinjaxx/trunk/jaxx-example/LabelStyle/src/main/jnlp/
lutinjaxx/trunk/jaxx-example/Validation/src/main/jnlp/
lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/Validation.jaxx.rst
lutinjaxx/trunk/jaxx-example/src/main/jnlp/template.vm
Modified:
lutinjaxx/trunk/jaxx-example/
lutinjaxx/trunk/jaxx-example/Calculator/pom.xml
lutinjaxx/trunk/jaxx-example/Calculator/src/site/fr/rst/index.rst
lutinjaxx/trunk/jaxx-example/Components/pom.xml
lutinjaxx/trunk/jaxx-example/Components/src/site/fr/rst/index.rst
lutinjaxx/trunk/jaxx-example/Counter/pom.xml
lutinjaxx/trunk/jaxx-example/Counter/src/site/fr/rst/index.rst
lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml
lutinjaxx/trunk/jaxx-example/LabelStyle/src/site/fr/rst/index.rst
lutinjaxx/trunk/jaxx-example/Validation/pom.xml
lutinjaxx/trunk/jaxx-example/pom.xml
lutinjaxx/trunk/jaxx-example/src/main/jnlp/sun.jnlp
Log:
make examples works :)
Property changes on: lutinjaxx/trunk/jaxx-example
___________________________________________________________________
Name: svn:ignore
- target
+ target
velocity.log
Modified: lutinjaxx/trunk/jaxx-example/Calculator/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Calculator/pom.xml 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Calculator/pom.xml 2008-10-16 15:02:52 UTC (rev 936)
@@ -18,24 +18,13 @@
<groupId>org.codelutin.jaxx-example</groupId>
<artifactId>Calculator</artifactId>
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>jaxx-core</artifactId>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
-
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>Calculator example</name>
- <version>0.5-SNAPSHOT</version>
+ <!--version>0.5-SNAPSHOT</version-->
<inceptionYear>2008</inceptionYear>
<description>Jaxx Calculator example</description>
- <!--url>${example.home.url}</url-->
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
@@ -44,33 +33,11 @@
<packaging>jar</packaging>
<build>
- <finalName>${project.artifactId}</finalName>
<plugins>
-
<plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jaxx-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
-
-
- <plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
</plugin>
-
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- </plugin>
</plugins>
</build>
@@ -82,4 +49,5 @@
<developerConnection>${scm.developerConnection.example}</developerConnection>
<url>${scm.url.example}</url>
</scm>
+
</project>
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/Calculator/src/site/fr/rst/index.rst
===================================================================
--- lutinjaxx/trunk/jaxx-example/Calculator/src/site/fr/rst/index.rst 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Calculator/src/site/fr/rst/index.rst 2008-10-16 15:02:52 UTC (rev 936)
@@ -27,4 +27,4 @@
.. |webstart| image:: images/webstart.gif
-.. _following link: bin/launch-Calculator.jnlp
+.. _following link: ./launch-Calculator.jnlp
Modified: lutinjaxx/trunk/jaxx-example/Components/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Components/pom.xml 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Components/pom.xml 2008-10-16 15:02:52 UTC (rev 936)
@@ -18,16 +18,6 @@
<groupId>org.codelutin.jaxx-example</groupId>
<artifactId>Components</artifactId>
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>jaxx-core</artifactId>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
-
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
@@ -35,7 +25,6 @@
<version>0.5-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
<description>Jaxx Components example</description>
- <url>${example.home.url}</url>
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
@@ -44,34 +33,11 @@
<packaging>jar</packaging>
<build>
- <finalName>${project.artifactId}</finalName>
<plugins>
-
<plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jaxx-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
-
- <plugin>
-
- <artifactId>maven-antrun-plugin</artifactId>
- </plugin>
-
- <plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
</plugin>
-
</plugins>
</build>
</project>
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/Components/src/site/fr/rst/index.rst
===================================================================
--- lutinjaxx/trunk/jaxx-example/Components/src/site/fr/rst/index.rst 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Components/src/site/fr/rst/index.rst 2008-10-16 15:02:52 UTC (rev 936)
@@ -30,4 +30,4 @@
.. |webstart| image:: images/webstart.gif
-.. _following link: bin/launch-Components.jnlp
+.. _following link: ./launch-Components.jnlp
Modified: lutinjaxx/trunk/jaxx-example/Counter/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Counter/pom.xml 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Counter/pom.xml 2008-10-16 15:02:52 UTC (rev 936)
@@ -18,23 +18,13 @@
<groupId>org.codelutin.jaxx-example</groupId>
<artifactId>Counter</artifactId>
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>jaxx-core</artifactId>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>Counter example</name>
- <version>0.5-SNAPSHOT</version>
+ <!--version>0.5-SNAPSHOT</version-->
<inceptionYear>2008</inceptionYear>
<description>Jaxx Counter example</description>
- <!--url>${example.home.url}</url-->
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
@@ -43,34 +33,11 @@
<packaging>jar</packaging>
<build>
- <finalName>${project.artifactId}</finalName>
<plugins>
-
<plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jaxx-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
-
-
- <plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
</plugin>
-
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- </plugin>
-
</plugins>
</build>
Modified: lutinjaxx/trunk/jaxx-example/Counter/src/site/fr/rst/index.rst
===================================================================
--- lutinjaxx/trunk/jaxx-example/Counter/src/site/fr/rst/index.rst 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Counter/src/site/fr/rst/index.rst 2008-10-16 15:02:52 UTC (rev 936)
@@ -25,4 +25,4 @@
.. |webstart| image:: images/webstart.gif
-.. _following link: http://buix.labs.libre-entreprise.org/lutinjaxx/maven-jaxx-plugin/examples/…
\ No newline at end of file
+.. _following link: ./launch-Counter.jnlp
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/LabelStyle/pom.xml 2008-10-16 15:02:52 UTC (rev 936)
@@ -18,15 +18,6 @@
<groupId>org.codelutin.jaxx-example</groupId>
<artifactId>LabelStyle</artifactId>
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>jaxx-core</artifactId>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
@@ -34,7 +25,6 @@
<version>0.5-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
<description>Jaxx LabelStyle example</description>
- <url>${example.home.url}</url>
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
@@ -43,33 +33,11 @@
<packaging>jar</packaging>
<build>
- <finalName>${project.artifactId}</finalName>
<plugins>
-
<plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jaxx-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
-
-
- <plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
</plugin>
-
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- </plugin>
</plugins>
</build>
Modified: lutinjaxx/trunk/jaxx-example/LabelStyle/src/site/fr/rst/index.rst
===================================================================
--- lutinjaxx/trunk/jaxx-example/LabelStyle/src/site/fr/rst/index.rst 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/LabelStyle/src/site/fr/rst/index.rst 2008-10-16 15:02:52 UTC (rev 936)
@@ -25,4 +25,4 @@
.. |webstart| image:: images/webstart.gif
-.. _following link: http://buix.labs.libre-entreprise.org/lutinjaxx/maven-jaxx-plugin/examples/…
+.. _following link: ./launch-LabelStyle.jnlp
Modified: lutinjaxx/trunk/jaxx-example/Validation/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/pom.xml 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Validation/pom.xml 2008-10-16 15:02:52 UTC (rev 936)
@@ -18,24 +18,13 @@
<groupId>org.codelutin.jaxx-example</groupId>
<artifactId>Validation</artifactId>
- <dependencies>
-
- <dependency>
- <groupId>org.codelutin</groupId>
- <artifactId>jaxx-core</artifactId>
- <scope>compile</scope>
- </dependency>
-
- </dependencies>
-
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <name>Validattion example</name>
+ <name>Validation example</name>
<version>0.5-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
- <description>Jaxx Validattion (with xwork validation) example</description>
- <!--url>${example.home.url}</url-->
+ <description>Jaxx Validation (with xwork validation) example</description>
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
@@ -43,98 +32,15 @@
<packaging>jar</packaging>
- <properties>
- <maven.jar.main.class>examples.${project.artifactId}.${project.artifactId}</maven.jar.main.class>
- </properties>
<build>
- <finalName>${project.artifactId}</finalName>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jaxx-plugin</artifactId>
- <configuration>
- <src>${basedir}/src/main/java</src>
- <force>true</force>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.swinglabs</groupId>
- <artifactId>jxlayer</artifactId>
- <version>3.0.1</version>
- </dependency>
- </dependencies>
- <!--executions>
- <execution>
- <goals>
- <goal>generate</goal>
- </goals>
- </execution>
- </executions-->
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <configuration>
- <outputDirectory>${project.build.directory}/lib</outputDirectory>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <mainClass>${maven.jar.main.class}</mainClass>
- <classpathPrefix>lib/</classpathPrefix>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
-
<plugins>
-
- <plugin>
- <groupId>org.codelutin</groupId>
- <artifactId>maven-jaxx-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
-
- <plugin>
+ <plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
</plugin>
-
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- </plugin>
-
</plugins>
</build>
- <!--repositories>
- <repository>
- <id>dowload-javanet-repository</id>
- <name>JavaNetRepository</name>
- <url>http://download.java.net/maven/2</url>
- </repository>
- </repositories-->
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Deleted: lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/Validation.jaxx.rst
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/Validation.jaxx.rst 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/Validation.jaxx.rst 2008-10-16 15:02:52 UTC (rev 936)
@@ -1,28 +0,0 @@
-=====================
-Examples/LabelStyles2
-=====================
-
-This example program creates a number of components which are used to control the appearance of a JLabel.
-Everything is performed through data binding; there are no script tags or explicit event handlers anywhere.
-
-Screen shot
------------
-
-.. image:: images/Validation-screenshot.gif
-
-Set it in action
-----------------
-
-|webstart|
-
-To run this example in `Java Web Start`_, click the `following link`_.
-
-
-Source code
------------
-
-.. _Java Web Start: http://java.sun.com/products/javawebstart/
-
-.. |webstart| image:: images/webstart.png
-
-.. _following link: http://buix.labs.libre-entreprise.org/lutinjaxx/maven-jaxx-plugin/examples/…
Copied: lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images/Validation-screenshot.png (from rev 927, lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images/Validation-screenshot.jaxx.png)
===================================================================
(Binary files differ)
Property changes on: lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/images/Validation-screenshot.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Copied: lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/index.rst (from rev 927, lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/Validation.jaxx.rst)
===================================================================
--- lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/index.rst (rev 0)
+++ lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/index.rst 2008-10-16 15:02:52 UTC (rev 936)
@@ -0,0 +1,28 @@
+===================
+Examples/Validation
+===================
+
+This example program creates a number of components which are used to control the appearance of a JLabel.
+Everything is performed through data binding; there are no script tags or explicit event handlers anywhere.
+
+Screen shot
+-----------
+
+.. image:: images/Validation-screenshot.png
+
+Set it in action
+----------------
+
+|webstart|
+
+To run this example in `Java Web Start`_, click the `following link`_.
+
+
+Source code
+-----------
+
+.. _Java Web Start: http://java.sun.com/products/javawebstart/
+
+.. |webstart| image:: images/webstart.gif
+
+.. _following link: ./launch-Validation.jnlp
Property changes on: lutinjaxx/trunk/jaxx-example/Validation/src/site/fr/rst/index.rst
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: lutinjaxx/trunk/jaxx-example/pom.xml
===================================================================
--- lutinjaxx/trunk/jaxx-example/pom.xml 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/pom.xml 2008-10-16 15:02:52 UTC (rev 936)
@@ -34,6 +34,7 @@
<module>LabelStyle</module>
<module>Validation</module>
</modules>
+
<!-- ************************************************************* -->
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
@@ -41,7 +42,6 @@
<version>0.5-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
<description>Jaxx Example super pom</description>
- <url>${example.home.url}</url>
<!-- ************************************************************* -->
<!-- *** Build Settings ****************************************** -->
@@ -51,38 +51,107 @@
<properties>
+ <!-- this property must be defined here, since it can be override by a profile -->
+
<maven.jar.main.class>examples.${project.artifactId}.${project.artifactId}</maven.jar.main.class>
- <example.home.url>${site.home.url}/lutinjaxx/maven-jaxx-plugin/examples</example.home.url>
-
<!-- jnlp -->
- <keystorepath>${keystorepath}</keystorepath>
+ <keystorepath>${codelutin.keystorepath}</keystorepath>
<keystorealias>CodeLutin</keystorealias>
<keystorepass>codelutin</keystorepass>
- <!-- override this property to define scm url property -->
+ <jnlp.build.directory>${project.build.directory}/jnlp</jnlp.build.directory>
+
+ <!-- scm (for sons) -->
<scm.url.example>
http://${labs.host}/plugins/scmsvn/viewcvs.php/lutinjaxx/trunk/jaxx-example/${pom.artifactId}/?root=${labs.project}
</scm.url.example>
- <!-- BEWARE, will be suffixed by /${pom.artifactId} by inheritance -->
<scm.developerConnection.example>
scm:svn:svn+ssh://${username}@${labs.host}/svnroot/${labs.project}/lutinjaxx/trunk/jaxx-example/${pom.artifactId}
</scm.developerConnection.example>
- <!-- BEWARE, will be suffixed by /${pom.artifactId} by inheritance -->
<scm.connection.example>
scm:svn:svn://anonymous@${labs.host}/svnroot/${labs.project}/lutinjaxx/trunk/jaxx-example/${pom.artifactId}
</scm.connection.example>
</properties>
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+ <scm>
+ <connection>${scm.connection.son}</connection>
+ <developerConnection>${scm.developerConnection.son}</developerConnection>
+ <url>${scm.url.son}</url>
+ </scm>
+
<build>
-
<pluginManagement>
<plugins>
<plugin>
+
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <!-- Ajout des libs signe par Sun dans un fichier jnlp separe -->
+ <execution>
+ <id>JnlpSun</id>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="${jnlp.build.directory}"/>
+ <copy file="${project.basedir}/../src/main/jnlp/sun.jnlp"
+ verbose="${maven.verbose}"
+ todir="${jnlp.build.directory}" failonerror="false">
+ <filterset>
+ <filter token="lib" value="javahelp-2.0.02.jar"/>
+ <filter token="url" value="${project.url}"/>
+ </filterset>
+ </copy>
+ <copy file="${project.basedir}/../src/main/jnlp/jxlayer.jnlp"
+ verbose="${maven.verbose}"
+ todir="${jnlp.build.directory}" failonerror="false">
+ <filterset>
+ <filter token="lib" value="jxlayer-3.0.1.jar"/>
+ <filter token="url" value="${project.url}"/>
+ </filterset>
+ </copy>
+ <copy file="${project.build.directory}/lib/javahelp-2.0.02.jar"
+ verbose="${maven.verbose}"
+ todir="${jnlp.build.directory}/lib" failonerror="false"/>
+ <copy file="${project.build.directory}/lib/jxlayer-3.0.1.jar"
+ verbose="${maven.verbose}"
+ todir="${jnlp.build.directory}/lib" failonerror="false"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>JnlpToSite</id>
+ <phase>pre-site</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="${maven.site.gen.dir}/resources"/>
+ <copy todir="${maven.site.gen.dir}/resources" verbose="${maven.verbose}"
+ failonerror="false" overwrite="false">
+ <fileset dir="${jnlp.build.directory}">
+ <include name="**"/>
+ </fileset>
+ </copy>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
<groupId>org.codelutin</groupId>
<artifactId>maven-jaxx-plugin</artifactId>
<version>0.5-SNAPSHOT</version>
@@ -121,62 +190,16 @@
</configuration>
</plugin>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <!-- Ajout des libs signe par Sun dans un fichier jnlp separe -->
- <execution>
- <id>JnlpSun</id>
- <phase>pre-site</phase>
- <configuration>
- <tasks>
- <copy file="${project.basedir}/../src/main/jnlp/sun.jnlp"
- todir="${project.basedir}/target/jnlp" failonerror="false">
- <filterset>
- <filter token="help" value="javahelp-2.0.02.jar"/>
- <filter token="url" value="${project.url}"/>
- </filterset>
- </copy>
- <copy file="${project.build.directory}/lib/javahelp-2.0.02.jar"
- todir="${project.basedir}/target/jnlp/lib" failonerror="false"/>
- </tasks>
- <!--/configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
-
- <execution>
- <id>JnlpToSite</id>
- <phase>pre-site</phase>
- <configuration-->
- <tasks>
- <mkdir dir="${maven.site.gen.dir}/resources/bin"/>
- <copy todir="${maven.site.gen.dir}/resources/bin" verbose="${maven.verbose}"
- failonerror="false" overwrite="false">
- <fileset dir="${project.build.directory}/jnlp">
- <include name="**"/>
- </fileset>
- </copy>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
<plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
- <version>1.0-alpha-2</version>
+ <version>1.0-alpha-2-cl_20081016</version>
<executions>
<execution>
- <phase>pre-site</phase>
+ <phase>package</phase>
<goals>
- <goal>jnlp</goal>
+ <goal>jnlp-inline</goal>
</goals>
</execution>
</executions>
@@ -184,13 +207,19 @@
<dependencies>
<excludes>
<exclude>javax.help:javahelp</exclude>
+ <exclude>org.swinglabs:jxlayer</exclude>
</excludes>
</dependencies>
<libPath>lib</libPath>
- <templateDirectory>${project.basedir}/../src/main/jnlp</templateDirectory>
+ <extensions>
+ <sun>sun.jnlp</sun>
+ <jxlayer>jxlayer.jnlp</jxlayer>
+ </extensions>
<jnlp>
<outputFile>launch-${project.artifactId}.jnlp</outputFile>
<mainClass>${maven.jar.main.class}</mainClass>
+ <allPermissions>true</allPermissions>
+ <offlineAllowed>true</offlineAllowed>
</jnlp>
<sign>
@@ -206,7 +235,7 @@
<dnameL/>
<dnameSt/>
<dnameC/>
- <verify>false</verify>
+ <verify>true</verify>
<keystoreConfig>
<delete>false</delete>
<gen>false</gen>
@@ -221,16 +250,21 @@
</plugin>
</plugins>
+
</pluginManagement>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codelutin</groupId>
+ <artifactId>maven-jaxx-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ </plugin>
+
+ </plugins>
</build>
- <!-- ************************************************************* -->
- <!-- *** Build Environment ************************************** -->
- <!-- ************************************************************* -->
- <scm>
- <connection>${scm.connection.son}</connection>
- <developerConnection>${scm.developerConnection.son}</developerConnection>
- <url>${scm.url.son}</url>
- </scm>
</project>
\ No newline at end of file
Copied: lutinjaxx/trunk/jaxx-example/src/main/jnlp/jxlayer.jnlp (from rev 927, lutinjaxx/trunk/jaxx-example/src/main/jnlp/sun.jnlp)
===================================================================
--- lutinjaxx/trunk/jaxx-example/src/main/jnlp/jxlayer.jnlp (rev 0)
+++ lutinjaxx/trunk/jaxx-example/src/main/jnlp/jxlayer.jnlp 2008-10-16 15:02:52 UTC (rev 936)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp spec="1.0+" codebase="@url@" href="jxlayer.jnlp">
+ <information>
+ <title>Sun MicroSystems</title>
+ <vendor>Sun MicroSystems, Inc.</vendor>
+ <offline-allowed/>
+ </information>
+ <resources>
+ <jar href="lib/@lib@"/>
+ </resources>
+ <component-desc/>
+</jnlp>
\ No newline at end of file
Modified: lutinjaxx/trunk/jaxx-example/src/main/jnlp/sun.jnlp
===================================================================
--- lutinjaxx/trunk/jaxx-example/src/main/jnlp/sun.jnlp 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/src/main/jnlp/sun.jnlp 2008-10-16 15:02:52 UTC (rev 936)
@@ -6,7 +6,7 @@
<offline-allowed/>
</information>
<resources>
- <jar href="lib/@help@"/>
+ <jar href="lib/@lib@"/>
</resources>
<component-desc/>
</jnlp>
\ No newline at end of file
Deleted: lutinjaxx/trunk/jaxx-example/src/main/jnlp/template.vm
===================================================================
--- lutinjaxx/trunk/jaxx-example/src/main/jnlp/template.vm 2008-10-16 15:02:13 UTC (rev 935)
+++ lutinjaxx/trunk/jaxx-example/src/main/jnlp/template.vm 2008-10-16 15:02:52 UTC (rev 936)
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<jnlp
- spec="1.0+"
- codebase="$project.Url/bin" href="$outputFile">
- <information>
- <title>$informationTitle</title>
- <vendor>$informationVendor</vendor>
- <homepage href="$informationHomepage" />
- <description>$informationDescription</description>
- <offline-allowed />
- </information>
- <resources>
- <j2se version="1.5+" max-heap-size="512m"/>
- $dependencies
- <extension name="sun" href="sun.jnlp"/>
- </resources>
- <security>
- <all-permissions />
- </security>
- <application-desc main-class="$mainClass" />
-</jnlp>
Copied: lutinjaxx/trunk/jaxx-example/src/site/resources/jaxx.png (from rev 927, lutinjaxx/trunk/src/site/resources/jaxx.png)
===================================================================
(Binary files differ)
Property changes on: lutinjaxx/trunk/jaxx-example/src/site/resources/jaxx.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Name: svn:mergeinfo
+
1
0
r935 - in lutinjaxx/trunk: jaxx-core/src/site jaxx-core/src/site/fr/rst jaxx-util/src/site maven-jaxx-plugin/src maven-jaxx-plugin/src/site
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 15:02:13 +0000 (Thu, 16 Oct 2008)
New Revision: 935
Removed:
lutinjaxx/trunk/jaxx-core/src/site/fr/rst/examples/
lutinjaxx/trunk/jaxx-core/src/site/fr/rst/exemples.rst
lutinjaxx/trunk/jaxx-core/src/site/resources/
lutinjaxx/trunk/jaxx-core/src/site/site.xml
lutinjaxx/trunk/jaxx-util/src/site/resources/
lutinjaxx/trunk/maven-jaxx-plugin/src/examples/
lutinjaxx/trunk/maven-jaxx-plugin/src/site/resources/
Modified:
lutinjaxx/trunk/maven-jaxx-plugin/src/site/site.xml
Log:
introduce jaxx-example module
remove unused site resources
Deleted: lutinjaxx/trunk/jaxx-core/src/site/fr/rst/exemples.rst
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/site/fr/rst/exemples.rst 2008-10-16 14:56:18 UTC (rev 934)
+++ lutinjaxx/trunk/jaxx-core/src/site/fr/rst/exemples.rst 2008-10-16 15:02:13 UTC (rev 935)
@@ -1,28 +0,0 @@
-========
-Exemples
-========
-
-Here are some simple example programs to give you an idea of what JAXX is all about:
-
- * JAXXEdit - A complete application written using JAXX for the GUI.
-
- * Components_
- Comprehensive demo which displays most of the Swing components. Demonstrates every major feature of JAXX, including data binding, scripting, and CSS stylesheets.
-
- * LabelStyles_ - Uses data binding to edit the appearance of a JLabel. Shows off the power and usefulness of data binding well.
-
- * Calculator_ - Four-function calculator. Based on the XUL Grand Coding Challenge.
-
- * Counter_ - simple data binding and scripting example. Based on the XUL Grand Coding Challenge.
-
- * Validation_ - simple data validation with xworks and jxlayer.
-
-.. _Components: examples/Components.jaxx.html
-
-.. _LabelStyles: examples/LabelStyles.jaxx.html
-
-.. _Calculator: examples/Calculator.jaxx.html
-
-.. _Counter: examples/Counter.jaxx.html
-
-.. _Validation: examples/Validation.jaxx.html
\ No newline at end of file
Deleted: lutinjaxx/trunk/jaxx-core/src/site/site.xml
===================================================================
--- lutinjaxx/trunk/jaxx-core/src/site/site.xml 2008-10-16 14:56:18 UTC (rev 934)
+++ lutinjaxx/trunk/jaxx-core/src/site/site.xml 2008-10-16 15:02:13 UTC (rev 935)
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="${project.name}">
-
- <bannerLeft>
- <name>${project.name}</name>
- <src>jaxx.png</src>
- <href>index.html</href>
- </bannerLeft>
-
- <poweredBy>
- <logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/>
- <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>
- <logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText"
- img="images/restructuredtext-logo.png"/>
- </poweredBy>
-
- <body>
-
- <menu ref="parent"/>
-
- <menu name="Utilisateur">
- <item name="Accueil" href="index.html"/>
- <item name="Exemples" href="exemples.html">
- <item name="Components" href="examples/Components.jaxx.html"/>
- <item name="LabelStyles" href="examples/LabelStyles.jaxx.html"/>
- <item name="Calculator" href="examples/Calculator.jaxx.html"/>
- <item name="Counter" href="examples/Counter.jaxx.html"/>
- </item>
- </menu>
-
- <menu name="Téléchargement">
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}/${project.version}"
- name="Télécharger la dernière version"/>
- <item href="${labs.builder.url}/org/codelutin/${project.artifactId}"
- name="Voir toutes les versions"/>
- </menu>
-
- <menu name="Développeur">
- <item name="A faire" href="Todo.html"/>
- </menu>
-
- <menu ref="reports"/>
-
- </body>
-</project>
Modified: lutinjaxx/trunk/maven-jaxx-plugin/src/site/site.xml
===================================================================
--- lutinjaxx/trunk/maven-jaxx-plugin/src/site/site.xml 2008-10-16 14:56:18 UTC (rev 934)
+++ lutinjaxx/trunk/maven-jaxx-plugin/src/site/site.xml 2008-10-16 15:02:13 UTC (rev 935)
@@ -1,18 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="${project.name}">
-
- <bannerLeft>
- <name>${project.name}</name>
- <src>jaxx.png</src>
- <href>index.html</href>
- </bannerLeft>
-
- <poweredBy>
- <logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/>
- <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>
- <logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText"
- img="images/restructuredtext-logo.png"/>
- </poweredBy>
<body>
@@ -36,8 +23,6 @@
<menu name="Développeur" inherit="top">
<item name="A faire" href="Todo.html"/>
</menu>
-
- <menu ref="reports"/>
-
+
</body>
</project>
1
0
r934 - in lutinjaxx/trunk: . jaxx-swing-action/src/site src/site
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
by tchemit@users.labs.libre-entreprise.org Oct. 16, 2008
Oct. 16, 2008
Author: tchemit
Date: 2008-10-16 14:56:18 +0000 (Thu, 16 Oct 2008)
New Revision: 934
Removed:
lutinjaxx/trunk/jaxx-swing-action/src/site/resources/
Modified:
lutinjaxx/trunk/pom.xml
lutinjaxx/trunk/src/site/site.xml
Log:
introduce jaxx-example module
remove unused site resources
Modified: lutinjaxx/trunk/pom.xml
===================================================================
--- lutinjaxx/trunk/pom.xml 2008-10-15 20:43:58 UTC (rev 933)
+++ lutinjaxx/trunk/pom.xml 2008-10-16 14:56:18 UTC (rev 934)
@@ -22,6 +22,7 @@
<module>jaxx-core</module>
<module>jaxx-swing-action</module>
<module>maven-jaxx-plugin</module>
+ <module>jaxx-example</module>
</modules>
<dependencies>
@@ -200,12 +201,4 @@
<url>${maven.scm.url}</url>
</scm>
- <profiles>
- <profile>
- <id>example</id>
- <modules>
- <module>jaxx-example</module>
- </modules>
- </profile>
- </profiles>
</project>
Modified: lutinjaxx/trunk/src/site/site.xml
===================================================================
--- lutinjaxx/trunk/src/site/site.xml 2008-10-15 20:43:58 UTC (rev 933)
+++ lutinjaxx/trunk/src/site/site.xml 2008-10-16 14:56:18 UTC (rev 934)
@@ -11,7 +11,7 @@
<bannerLeft>
<name>${project.name}</name>
- <src>jaxx.png</src>
+ <src>http://buix.labs.libre-entreprise.org/lutinjaxx/jaxx.png</src>
<href>index.html</href>
</bannerLeft>
@@ -21,10 +21,10 @@
</bannerRight>
<poweredBy>
- <logo href="http://maven.apache.org" name="Maven" img="images/logos/maven-feather.png"/>
- <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="images/jrst-logo.png"/>
+ <logo href="http://maven.apache.org" name="Maven" img="http://buix.labs.libre-entreprise.org/lutinjaxx/images/logos/maven-feather.…"/>
+ <logo href="http://jrst.labs.libre-entreprise.org" name="JRst" img="http://buix.labs.libre-entreprise.org/lutinjaxx/images/jrst-logo.png"/>
<logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText"
- img="images/restructuredtext-logo.png"/>
+ img="http://buix.labs.libre-entreprise.org/lutinjaxx/images/restructuredtext-log…"/>
</poweredBy>
<body>
1
0