Init commit of full project.

This commit is contained in:
Willem Cazander 2012-09-11 13:15:26 +02:00
parent 130d471bd9
commit 787b1174b0
286 changed files with 27010 additions and 1 deletions

View file

@ -1,11 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>x4o</name>
<comment></comment>
<comment>x4o-base, Eclipse with Maven build project.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

5
authors.txt Normal file
View file

@ -0,0 +1,5 @@
X4O was written by:
Willem Cazander <w.cazander@gmail.com>
Contributors:

66
build.txt Normal file
View file

@ -0,0 +1,66 @@
Building X4O
You need a few software packages;
- java sdk 1.5 or higher.
- maven 3 or higher.
-- Create package --
cd project-root/;
mvn clean package;
-- Install local package --
cd project-root/;
mvn clean install;
-- Update schemas in src --
cd project-root/;
mvn clean install;
mvn -Pupdate-schema-cel package;
mvn -Pupdate-schema-eld package;
- Add the license as manual step in xsd files. (todo in ant task)
note: the do 'install' is because of circle plugins.
-- Make release build --
# todo make work
cd project-root/;
mvn clean package;
mvn -B -Dusername=<scm_username> clean install release:clean release:prepare release:perform;
src/build/gnu-up.sh <scm_username> <version>
-- Make site --
cd project-root/;
mvn -Psite-elddoc clean package site site:stage
-- Check for code style --
cd project-root/;
mvn checkstyle:checkstyle
-- Check for licenses --
cd project-root/;
mvn -Pcheck-license license:check
-- Check for versions-updates --
cd project-root/;
mvn versions:display-plugin-updates;
mvn versions:display-dependency-updates;

20
license.txt Normal file
View file

@ -0,0 +1,20 @@
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

415
pom.xml Normal file
View file

@ -0,0 +1,415 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.x4o</groupId>
<artifactId>x4o</artifactId>
<packaging>pom</packaging>
<version>0.8.2-SNAPSHOT</version>
<name>x4o</name>
<description>Creates an easy xml layer for objects and creating your own xml language implementations.</description>
<url>http://www.x4o.org</url>
<inceptionYear>2004</inceptionYear>
<organization>
<name>X4O</name>
<url>http://www.x4o.org/</url>
</organization>
<developers>
<developer>
<id>willem.cazander</id>
<name>Willem Cazander</name>
<email>w.cazander@gmail.com</email>
<organization>X4O.org</organization>
<timezone>+1</timezone>
<roles>
<role>Project Manager</role>
<role>Architect</role>
</roles>
</developer>
</developers>
<licenses>
<license>
<name>BSD</name>
<url>license.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:ssh://git.sv.gnu.org:/srv/git/x4o.git</connection>
<developerConnection>scm:git:ssh://git.sv.gnu.org:/srv/git/x4o.git</developerConnection>
<url>http://git.savannah.gnu.org/cgit/x4o.git</url>
</scm>
<prerequisites>
<maven>3.0.1</maven>
</prerequisites>
<modules>
<module>x4o-core</module>
<module>x4o-elddoc</module>
<module>x4o-meta</module>
<module>x4o-plugin</module>
</modules>
<distributionManagement>
<site>
<id>x4o-site</id>
<url>http://www.x4o.org/</url>
</site>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.javaVersion>1.5</project.build.javaVersion>
<!-- Build plugin versions -->
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
<maven-source-plugin.version>2.1.2</maven-source-plugin.version>
<maven-javadoc-plugin.version>2.8.1</maven-javadoc-plugin.version>
<maven-assembly-plugin.version>2.3</maven-assembly-plugin.version>
<maven-antrun-plugin.version>1.7</maven-antrun-plugin.version>
<maven-site-plugin.version>3.0</maven-site-plugin.version>
<maven-pmd-plugin.version>2.7.1</maven-pmd-plugin.version>
<maven-surefire-plugin.version>2.12</maven-surefire-plugin.version>
<maven-surefire-report-plugin.version>2.12.2</maven-surefire-report-plugin.version>
<maven-checkstyle-plugin.version>2.9.1</maven-checkstyle-plugin.version>
<maven-enforcer-plugin.version>1.0-beta-1</maven-enforcer-plugin.version>
<maven-project-info-reports-plugin.version>2.5</maven-project-info-reports-plugin.version>
<maven-release-plugin.version>2.2.2</maven-release-plugin.version>
<maven-changelog-plugin.version>2.2</maven-changelog-plugin.version>
<maven-jar-plugin.version>2.2</maven-jar-plugin.version>
<maven-license-plugin.version>1.10.b1</maven-license-plugin.version>
<!-- Build non-maven plugin versions -->
<webstart-maven-plugin.version>1.0-beta-1</webstart-maven-plugin.version>
<launch4j-maven-plugin.version>1.3</launch4j-maven-plugin.version>
<cobertura-maven-plugin.version>2.5.1</cobertura-maven-plugin.version>
<taglist-maven-plugin.version>2.4</taglist-maven-plugin.version>
<jdepend-maven-plugin.version>2.0-beta-2</jdepend-maven-plugin.version>
<!-- Build lib versions -->
<ant-contrib.version>1.0b3</ant-contrib.version>
<ant-nodeps.version>1.8.1</ant-nodeps.version>
<ant.version>1.8.4</ant.version>
<ant-testutil.version>1.8.4</ant-testutil.version>
<!-- Build test lib versions -->
<mockito-all.version>1.9.0</mockito-all.version>
<testng.version>6.3.1</testng.version>
<junit.version>4.10</junit.version>
<!-- Application lib versions -->
<java.el.version>1.2</java.el.version>
<juel.version>2.1.0</juel.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${project.build.javaVersion}</source>
<target>${project.build.javaVersion}</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<optimize>true</optimize>
<fork>false</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals><goal>jar-no-fork</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<quiet>true</quiet>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals><goal>jar</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*InteractiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<enableRulesSummary>true</enableRulesSummary>
<configLocation>src/main/config/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven-site-plugin.version}</version>
</plugin>
<!-- Build documention
<plugin>
<groupId>com.agilejava.docbkx</groupId>
<artifactId>docbkx-maven-plugin</artifactId>
<version>2.0.9</version>
<configuration>
<sourceDirectory>src/main/docbook/</sourceDirectory>
<targetDirectory>target/site/docbook/</targetDirectory>
<includes>*.xml</includes>
<xincludeSupported>true</xincludeSupported>
<entities>
<entity><name>version</name><value>${project.version}</value></entity>
</entities>
<chunkedOutput>true</chunkedOutput>
</configuration>
<executions>
<execution>
<id>create-pdf-docs</id>
<phase>site</phase>
<goals><goal>generate-pdf</goal></goals>
<configuration>
<imgSrcPath>file:///${basedir}/src/main/docbook/</imgSrcPath>
</configuration>
</execution>
<execution>
<id>create-html-docs</id>
<phase>site</phase>
<goals><goal>generate-html</goal></goals>
<configuration>
<preProcess>
<copy todir="target/site/docbook/images">
<fileset dir="src/main/docbook/images" />
</copy>
</preProcess>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.docbook</groupId>
<artifactId>docbook-xml</artifactId>
<version>4.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
-->
<!-- Perform maven releases
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<preparationGoals>clean install verify</preparationGoals>
<goals>clean install javadoc:javadoc deploy</goals>
<arguments>-Prelease -DaltDeploymentRepository="${altDeploymentRepository}"</arguments>
</configuration>
</plugin>
-->
</plugins>
<!-- Extensions -->
<extensions>
</extensions>
<!-- PluginManagement -->
<pluginManagement>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>${maven-project-info-reports-plugin.version}</version>
<configuration>
<aggregate>true</aggregate>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<quiet>true</quiet>
<aggregate>true</aggregate>
<linksource>true</linksource>
<minmemory>64m</minmemory>
<maxmemory>512m</maxmemory>
<docfilessubdirs>true</docfilessubdirs>
<linksource>true</linksource>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>aggregate</report>
<report>test-aggregate</report>
<report>fix</report>
<report>test-fix</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura-maven-plugin.version}</version>
<configuration>
<aggregate>true</aggregate>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
<version>${jdepend-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>${maven-pmd-plugin.version}</version>
<configuration>
<aggregate>true</aggregate>
<linkXref>true</linkXref>
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>${project.build.javaVersion}</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<aggregate>true</aggregate>
<enableRulesSummary>true</enableRulesSummary>
<configLocation>src/main/config/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${maven-surefire-report-plugin.version}</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>${maven-changelog-plugin.version}</version>
<inherited>false</inherited>
</plugin>
</plugins>
</reporting>
<profiles>
<profile>
<id>notest</id>
<properties>
<skipTests>true</skipTests>
</properties>
</profile>
<profile>
<id>update-schema-cel</id>
<properties>
<skipTests>true</skipTests>
</properties>
</profile>
<profile>
<id>update-schema-eld</id>
<properties>
<skipTests>true</skipTests>
</properties>
</profile>
<profile>
<id>check-license</id>
<properties>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>${maven-license-plugin.version}</version>
<configuration>
<header>license.txt</header>
<strictCheck>true</strictCheck>
<useDefaultExcludes>true</useDefaultExcludes>
<useDefaultMapping>false</useDefaultMapping>
<aggregate>true</aggregate>
<excludes>
<exclude>**/*~</exclude>
<exclude>**/.git</exclude>
<exclude>**/.git/**</exclude>
<exclude>.gitignore</exclude>
<exclude>**/target/**</exclude>
<exclude>**/test-output/**</exclude>
<exclude>**/release.properties</exclude>
<exclude>**/dependency-reduced-pom.xml</exclude>
<exclude>**/.classpath</exclude>
<exclude>**/.project</exclude>
<exclude>**/.settings/**</exclude>
<exclude>**/*.txt</exclude>
<exclude>**/*.jks</exclude>
<exclude>**/*.sch</exclude>
<exclude>**/*.so</exclude>
<exclude>**/*.dll</exclude>
<exclude>**/*.png</exclude>
<exclude>**/*.pom</exclude>
<exclude>**/.empty</exclude>
<exclude>**/empty-real.xml</exclude>
<exclude>**/empty-test.xml</exclude>
<exclude>**/empty-x4o.xml</exclude>
<exclude>**/empty-xml.xml</exclude>
</excludes>
<mapping>
<java>SLASHSTAR_STYLE</java>
<xml>XML_STYLE</xml>
<eld>XML_STYLE</eld>
<fml>XML_STYLE</fml>
<xsd>XML_STYLE</xsd>
<apt>DOUBLETILDE_STYLE</apt>
<properties>SCRIPT_STYLE</properties>
</mapping>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View file

@ -0,0 +1,172 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<!--
Checkstyle config sun coding conventions:
- the Java Language Specification at http://java.sun.com/docs/books/jls/second_edition/html/index.html
- the Sun Code Conventions at http://java.sun.com/docs/codeconv/
- the Javadoc guidelines at http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
- the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
- some best practices
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.sf.net (or in your downloaded distribution).
-->
<module name="Checker">
<!-- See http://checkstyle.sourceforge.net/config_javadoc.html -->
<!-- Checks is package-info.java is present. -->
<module name="JavadocPackage"/>
<!-- Checks whether files end with a new line. -->
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>
<!-- Checks that property files contain the same keys. -->
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
<module name="Translation"/>
<module name="FileLength">
<property name="max" value="1500"/>
</module>
<module name="TreeWalker">
<!-- cache file -->
<property name="cacheFile" value="${checkstyle.cache.file}"/>
<!-- Check line length -->
<module name="LineLength">
<property name="max" value="200"/>
<property name="ignorePattern" value="^ *\* *[^ ]+$"/>
</module>
<!--check for imports-->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!--check for equals and hashcode-->
<module name="EqualsHashCode"/>
<!--check for final class-->
<module name="FinalClass"/>
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocType">
<property name="scope" value="public"/>
<property name="authorFormat" value="\S"/>
</module>
<module name="JavadocMethod"/>
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle">
<property name="scope" value="public"/>
</module>
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="MethodLength"/>
<module name="ParameterNumber"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<!--
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="TabCharacter"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<module name="ParenPad"/>
-->
<module name="OperatorWrap"/>
<module name="TypecastParenPad"/>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="AvoidInlineConditionals"/>
<module name="DoubleCheckedLocking"/>
<module name="EmptyStatement"/>
<module name="HiddenField"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<!--
<module name="MagicNumber"/>
-->
<module name="MissingSwitchDefault"/>
<module name="RedundantThrows"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="NoFinalizer"/>
<module name="SuperClone"/>
<module name="SuperFinalize"/>
<module name="IllegalCatch"/>
<module name="IllegalThrows"/>
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="TodoComment"/>
<module name="UpperEll"/>
</module>
</module>

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

125
src/main/docbook/manual.xml Normal file
View file

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<book lang="en">
<bookinfo revision="1.0">
<title>X4O Manual</title>
<corpname>X4O.org</corpname>
<corpcredit>X4O.org</corpcredit>
<authorgroup>
<author>
<firstname>Willem</firstname>
<surname>Cazander</surname>
</author>
</authorgroup>
<edition>Manual for x4o version 1.0</edition>
<pubdate>2009</pubdate>
<copyright>
<year>2005</year>
<year>2006</year>
<year>2007</year>
<year>2008</year>
<year>2009</year>
<year>2010</year>
<year>2011</year>
<year>2012</year>
<holder>Willem Cazander</holder>
</copyright>
<revhistory>
<revision>
<revnumber>0.1</revnumber>
<date>1-12-2008</date>
</revision>
<revision>
<revnumber>0.2</revnumber>
<date>24-12-2011</date>
</revision>
</revhistory>
</bookinfo>
<preface>
<beginpage/>
<title>Preface</title>
<para>Welcom in the <application>X4O</application> Manual.
Here we describe how to interface with the x4o language parser.
</para>
</preface>
<chapter lang="en">
<chapterinfo>
<title>Introduction</title>
<keywordset>
<keyword>Introduction</keyword>
</keywordset>
</chapterinfo>
<title>Intoduction</title>
<beginpage/>
<sect1>
<title>Introduction</title>
<para>Welcom in the <application>x4o</application> manual.</para>
<para>
<mediaobject>
<imageobject>
<imagedata fileref="images/logo-x4o.png" />
</imageobject>
</mediaobject>
</para>
<para>X4O is an xml parser libary which makes it easy to map objects to.</para>
</sect1>
</chapter>
<appendix>
<appendixinfo>
<title>Appendix</title>
<keywordset>
<keyword>appendix</keyword>
<keyword>licenece</keyword>
</keywordset>
</appendixinfo>
<title>Appendix</title>
<beginpage/>
<section>
<title>Licence</title>
<para>
BSD licence
</para>
<beginpage/>
</section>
</appendix>
</book>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

41
src/site-child/site.xml Normal file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<project>
<bannerLeft>
<name>${project.name}</name>
<src>images/logo-x4o.png</src>
<href>.</href>
</bannerLeft>
<version position="left"/>
<body>
<links>
<item name="${project.name}" href="${project.url}"/>
</links>
<menu ref="parent"/>
<menu ref="modules"/>
<menu ref="reports"/>
</body>
</project>

45
src/site/apt/download.apt Normal file
View file

@ -0,0 +1,45 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Downloading
* Maven as dependency
+--
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-core</artifactId>
<version>0.8-SNAPSHOT</version>
</dependency>
+--
note: Is not in a repro, build and install(local) yourself for now.
* Download binary release.
Sorry we still have not done any binany releases.
* Downloading source code
Sorry we still have no source access.

View file

@ -0,0 +1,52 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Load Modules
The default language loader of x4o load all 'META-INF/<language>/<language>-modules.xml' in the classpath.
So every extension library has its own modules definition file.
All options are allowed in multiple forms and order.
For xsd file see x4o-core classpath 'META-INF/language/modules-1.0.xsd'.
+--
<?xml version="1.0" encoding="UTF-8"?>
<modules version="1.0"
xmlns="http://language.x4o.org/xml/ns/modules"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd"
>
<language version="1.0">
<eld-resource>foobar-lang.eld</eld-resource>
<eld-resource>foobar-backend-default.eld</eld-resource>
<eld-resource>foobar-backend-old.eld</eld-resource>
<module-loader>org.foo.bar.x4o.FooCustomModuleLoader</module-loader>
<module-loader>org.foo.bar.x4o.BarCustomModuleLoader</module-loader>
<sibling-loader>org.x4o.xml.meta.MetaLanguageSiblingLoader</sibling-loader>
<sibling-loader>org.foo.bar.x4o.HelloWorldQueryLanguageSiblingLoader</sibling-loader>
</language>
<language version="2.0">
<eld-resource>foobar-lang-2.0.eld</eld-resource>
</language>
</modules>
+--

View file

@ -0,0 +1,131 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Sample jr4o
Example which wraps the Jasper reports design object tree to xml.
Example xml document which can be parsed.
+--
<?xml version="1.0" encoding="UTF-8"?>
<report>
<!--
Format is made JR compatible for easy copy/paste except;
- style tags need el.id for reference in docs and dynamic report elements.
- can use multiple reports in one xml
- not all JR tags are supported only the ones needed for ~this report see jr4o-lang.eld file.
-->
<jasperReport name="generic-landscape" columnCount="1" pageWidth="842" pageHeight="595" columnWidth="800" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" orientation="LANDSCAPE">
<style el.id="Arial_Normal" name="Arial_Normal" isDefault="true" fontName="Arial" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false" />
<style el.id="Arial_Bold" name="Arial_Bold" isDefault="false" fontName="Arial" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false" />
<style el.id="Arial_Italic" name="Arial_Italic" isDefault="false" fontName="Arial" size="10" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false" />
<style el.id="Arial_Header" name="Arial_Header" isDefault="false" fontName="Arial" size="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<title tagType="title" height="60">
<line x="0" y="0" width="800" height="1"/>
<textField isBlankWhenNull="true" x="40" y="10" width="276" height="30" style="${Arial_Normal}" fontSize="18">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{title}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" x="40" y="30" width="200" height="30" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{description}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" x="350" y="30" width="150" height="16" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{titleSubject}]]></textFieldExpression>
</textField>
</title>
<columnHeader tagType="columnHeader" height="20">
<dynamicColumnHeader/>
</columnHeader>
<detail tagType="detail" height="20">
<line x="0" y="0" width="800" height="1"/>
<dynamicColumn/>
</detail>
<pageFooter tagType="pageFooter" height="40">
<line x="0" y="10" width="800" height="1"/>
<textField isBlankWhenNull="true" x="20" y="20" width="150" height="16" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{titleSubject}]]></textFieldExpression>
</textField>
<textField x="200" y="20" width="80" height="15" horizontalAlignment="RIGHT">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$R{report.footer.page}+" "+String.valueOf($V{PAGE_NUMBER})+" "]]></textFieldExpression>
</textField>
<textField x="280" y="20" width="100" height="15" evaluationTime="REPORT">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$R{report.footer.pageOf}+String.valueOf($V{PAGE_NUMBER})+" "+$R{report.footer.printed}]]></textFieldExpression>
</textField>
<textField x="370" y="20" width="150" height="15" pattern="dd-MM-yyyy - HH:mm:ss">
<textFieldExpression valueClass="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" x="650" y="20" width="150" height="16" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</pageFooter>
<summary tagType="summary" height="35">
</summary>
</jasperReport>
<jasperReport name="generic-portrait" columnCount="1" pageWidth="595" pageHeight="842" columnWidth="554" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" orientation="LANDSCAPE">
<style el.id="Arial_Normal" name="Arial_Normal" isDefault="true" fontName="Arial" size="10" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false" />
<style el.id="Arial_Bold" name="Arial_Bold" isDefault="false" fontName="Arial" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false" />
<style el.id="Arial_Italic" name="Arial_Italic" isDefault="false" fontName="Arial" size="10" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false" />
<style el.id="Arial_Header" name="Arial_Header" isDefault="false" fontName="Arial" size="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<title tagType="title" height="60">
<line x="0" y="0" width="800" height="1"/>
<textField isBlankWhenNull="true" x="40" y="10" width="276" height="30" style="${Arial_Normal}" fontSize="18">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{title}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" x="40" y="30" width="200" height="30" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{description}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" x="350" y="30" width="150" height="16" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{titleSubject}]]></textFieldExpression>
</textField>
</title>
<columnHeader tagType="columnHeader" height="20">
<dynamicColumnHeader/>
</columnHeader>
<detail tagType="detail" height="20">
<line x="0" y="0" width="800" height="1"/>
<dynamicColumn/>
</detail>
<pageFooter tagType="pageFooter" height="40">
<line x="0" y="10" width="800" height="1"/>
<textField isBlankWhenNull="true" x="20" y="20" width="150" height="16" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{titleSubject}]]></textFieldExpression>
</textField>
<textField x="200" y="20" width="80" height="15" horizontalAlignment="RIGHT">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$R{report.footer.page}+" "+String.valueOf($V{PAGE_NUMBER})+" "]]></textFieldExpression>
</textField>
<textField x="280" y="20" width="100" height="15" evaluationTime="REPORT">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$R{report.footer.pageOf}+String.valueOf($V{PAGE_NUMBER})+" "+$R{report.footer.printed}]]></textFieldExpression>
</textField>
<textField x="370" y="20" width="150" height="15" pattern="dd-MM-yyyy - HH:mm:ss">
<textFieldExpression valueClass="java.util.Date"><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true" x="650" y="20" width="150" height="16" style="${Arial_Normal}">
<textFieldExpression valueClass="java.lang.String"><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</pageFooter>
<summary tagType="summary" height="35">
</summary>
</jasperReport>
</report>
+--

View file

@ -0,0 +1,281 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Sample SwiXml
Lets create an xml example from swixml language.
* Create parser
+--
public class SwiXmlParser extends X4OParser {
public static final String LANGUAGE = "swixml";
public static final String VERSION_2_NS_URI = "http://swixml.x4o.org/xml/ns/swixml-lang";
public static final String SWING_ENGINE_EL_NAME = "swingEngine";
/**
* Protected constructor for language support
*/
protected SwiXmlParser() {
super(LANGUAGE);
}
public SwiXmlParser(SwingEngine engine) {
// Create language by version
super(LANGUAGE);
// Check engine
if (engine==null) {
throw new NullPointerException("Can't parse with null SwingEngine.");
}
// Add engine for callback
addELBeanInstance(SWING_ENGINE_EL_NAME,engine);
// Set empty ns for v2 documents
setProperty(X4OLanguagePropertyKeys.INPUT_EMPTY_NAMESPACE_URI, VERSION_2_NS_URI);
}
public Component getRootComponent() {
return (Component)getDriver().getElementLanguage().getRootElement().getElementObject();
}
static public SwingEngine getSwingEngine(ElementLanguage elementLanguage) {
ValueExpression ee = elementLanguage.getExpressionFactory().createValueExpression(elementLanguage.getELContext(),"${"+SwiXmlParser.SWING_ENGINE_EL_NAME+"}",Object.class);
SwingEngine se = (SwingEngine)ee.getValue(elementLanguage.getELContext());
return se;
}
}
+--
* Create parser support
+--
public class SwiXmlParserSupport2 implements X4OParserSupport {
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
SwiXmlParser parser = new SwiXmlParser();
return parser.loadElementLanguageSupport();
}
}
+--
* Define modules
First load the language in META-INF/swixml/swixml-modules.xml
+--
<?xml version="1.0" encoding="UTF-8"?>
<modules version="1.0"
xmlns="http://language.x4o.org/xml/ns/modules"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd"
>
<language version="1.0">
<eld-resource>swixml-lang.eld</eld-resource>
</language>
</modules>
+--
* Define the element language
+--
<?xml version="1.0" encoding="UTF-8"?>
<root:module
xmlns:root="http://eld.x4o.org/xml/ns/eld-root"
xmlns="http://eld.x4o.org/xml/ns/eld-lang"
xmlns:conv="http://eld.x4o.org/xml/ns/eld-conv"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd"
providerName="swixml.test.x4o.org"
name="Swixml Language"
id="swixml-lang"
>
<bindingHandler id="JComponentBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JComponentBindingHandler"/>
<bindingHandler id="JMenuBarBindingHandler" bean.class="org.x4o.xml.test.swixml.bind.JMenuBarBindingHandler"/>
<classBindingHandler id="JDesktopPane-JInternalFrame" parentClass="javax.swing.JDesktopPane" childClass="javax.swing.JInternalFrame" method="add"/>
<classBindingHandler id="JFrame-JDesktopPane" parentClass="javax.swing.JFrame" childClass="javax.swing.JDesktopPane" method="setContentPane"/>
<classBindingHandler id="JMenuBar-JMenu" parentClass="javax.swing.JMenuBar" childClass="javax.swing.JMenu" method="add"/>
<classBindingHandler id="JMenu-JMenuItem" parentClass="javax.swing.JMenu" childClass="javax.swing.JMenuItem" method="add"/>
<elementInterface id="Component" interfaceClass="java.awt.Component">
<attribute name="bounds">
<conv:stringSplitConverter classTo="java.awt.Rectangle" split="," splitSize="4" singleToMethod="setRect" useNativeType="true">
<conv:stringSplitConverterStep fromMethod="getX" fromOrder="1" toOrder="1"><conv:doubleConverter/></conv:stringSplitConverterStep>
<conv:stringSplitConverterStep fromMethod="getY" fromOrder="2" toOrder="2"><conv:doubleConverter/></conv:stringSplitConverterStep>
<conv:stringSplitConverterStep fromMethod="getWidth" fromOrder="3" toOrder="3"><conv:doubleConverter/></conv:stringSplitConverterStep>
<conv:stringSplitConverterStep fromMethod="getHeight" fromOrder="4" toOrder="4"><conv:doubleConverter/></conv:stringSplitConverterStep>
</conv:stringSplitConverter>
</attribute>
<attribute name="size">
<conv:stringSplitConverter classTo="java.awt.Dimension" split="," splitSize="2" singleToMethod="setSize" useNativeType="true">
<conv:stringSplitConverterStep fromMethod="getHeight" fromOrder="1" toOrder="1"><conv:integerConverter/></conv:stringSplitConverterStep>
<conv:stringSplitConverterStep fromMethod="getWidth" fromOrder="2" toOrder="2"><conv:integerConverter/></conv:stringSplitConverterStep>
</conv:stringSplitConverter>
</attribute>
<attribute name="icon">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.IconConverter"/>
</attribute>
<attribute name="background">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.ColorConverter"/>
</attribute>
<attribute name="location">
<conv:stringSplitConverter classTo="java.awt.Point" split="," splitSize="2" singleToMethod="setLocation" useNativeType="true">
<conv:stringSplitConverterStep fromMethod="getX" fromOrder="1" toOrder="1"><conv:integerConverter/></conv:stringSplitConverterStep>
<conv:stringSplitConverterStep fromMethod="getY" fromOrder="2" toOrder="2"><conv:integerConverter/></conv:stringSplitConverterStep>
</conv:stringSplitConverter>
</attribute>
</elementInterface>
<elementInterface id="JComponent" interfaceClass="javax.swing.JComponent">
<attribute name="layout">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.LayoutConverter"/>
</attribute>
<attribute name="border">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.BorderConverter"/>
</attribute>
</elementInterface>
<namespace
uri="http://swixml.x4o.org/xml/ns/swixml-root"
schemaUri="http://swixml.x4o.org/xml/ns/swixml-root-2.0.xsd"
schemaResource="swixml-root-2.0.xsd"
schemaPrefix="root"
name="Root element"
languageRoot="true"
>
<!-- Single element in language root to create nice tree, for imports in xsd namespace aware generated files. -->
<element tag="frame" objectClass="javax.swing.JFrame"/>
</namespace>
<namespace
uri="http://swixml.x4o.org/xml/ns/swixml-lang"
schemaUri="http://swixml.x4o.org/xml/ns/swixml-lang-2.0.xsd"
schemaResource="swixml-lang-2.0.xsd"
schemaPrefix="sx-lang"
>
<!-- Note frame should not be here(it can but xsd needs root), but else classic xml does not parse without xmlns additions. -->
<element tag="frame" objectClass="javax.swing.JFrame"/>
<element tag="menubar" objectClass="javax.swing.JMenuBar"/>
<element tag="menu" objectClass="javax.swing.JMenu"/>
<element tag="menuitem" objectClass="javax.swing.JMenuItem">
<attribute name="accelerator">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.KeyStrokeConverter"/>
<attributeAlias name="Accelerator"/>
</attribute>
<attribute name="Action" runBeanFill="false"/>
<configurator id="menuitem-action" bean.class="org.x4o.xml.test.swixml.SwiXmlActionConfigurator"/>
</element>
<element tag="separator" />
<element tag="panel" objectClass="javax.swing.JPanel"/>
<element tag="splitpane" objectClass="javax.swing.JSplitPane">
<attribute name="orientation">
<conv:beanConverter bean.class="org.x4o.xml.test.swixml.conv.JSplitPaneOrientationConverter"/>
</attribute>
</element>
<element tag="scrollPane" objectClass="javax.swing.JScrollPane"/>
<element tag="tree" objectClass="javax.swing.JTree"/>
<element tag="button" objectClass="javax.swing.JButton">
<attributeFromBody name="text"/>
</element>
<element tag="table" objectClass="javax.swing.JTable"/>
<element tag="textarea" objectClass="javax.swing.JTextArea"/>
<element tag="label" objectClass="javax.swing.JLabel"/>
<element tag="textfield" objectClass="javax.swing.JTextField"/>
<element tag="desktoppane" objectClass="javax.swing.JDesktopPane"/>
<element tag="internalframe" objectClass="javax.swing.JInternalFrame">
<attribute name="title"><attributeAlias name="Title"/></attribute>
<attribute name="bounds"><attributeAlias name="Bounds"/></attribute>
<attribute name="layout"><attributeAlias name="Layout"/></attribute>
<attribute name="visible"><attributeAlias name="Visible"/></attribute>
<attribute name="resizable"><attributeAlias name="Resizable"/></attribute>
</element>
</namespace>
</root:module>
+--
* JMenuBarBindingHandler
+--
public class JMenuBarBindingHandler extends AbstractElementBindingHandler {
public Class<?> getBindParentClass() {
return JFrame.class;
}
public Class<?>[] getBindChildClasses() {
return new Class[] {JMenuBar.class};
}
public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException {
JMenuBar child = (JMenuBar)childObject;
JFrame frame = (JFrame)parentObject;
frame.getRootPane().setJMenuBar(child);
}
}
+--
* BorderConverter
+--
public class BorderConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 6729812931433525103L;
public Class<?> getObjectClassTo() {
return Border.class;
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Border)obj).toString();
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
if ("LoweredBevelBorder".equals(str)) {
return BorderFactory.createLoweredBevelBorder();
} else {
return BorderFactory.createEmptyBorder();
}
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
BorderConverter result = new BorderConverter();
result.converters=cloneConverters();
return result;
}
}
+--
* Source
This example is found in the x4o-core source package in the test path.

View file

@ -0,0 +1,130 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Start Language
To integrate x4o as parser for your language there needs to be a few minimal steps
be te taken, to have a working language.
* Create parser and support classes.
* Create language modules files.
* Create eld files.
* Create your parser
+--
public class FooBarParser extends X4OParser {
static public String FOOBAR_LANGUAGE = "foobar";
public FooBarParser() throws Exception {
super(FOOBAR_LANGUAGE);
}
}
+--
* Create parser support
+--
public class FooBarParserSupport implements X4OParserSupport {
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
FooBarParser parser = new FooBarParser();
return parser.loadElementLanguageSupport();
}
}
+--
* Create modules
Create the file "META-INF/foobar/foobar-modules.xml" with:
+--
<?xml version="1.0" encoding="UTF-8"?>
<modules version="1.0"
xmlns="http://language.x4o.org/xml/ns/modules"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd"
>
<language version="1.0">
<eld-resource>foobar-lang.eld</eld-resource>
</language>
</modules>
+--
* Create ELD file
Create the file "META-INF/foobar/foobar-lang.eld" with:
+--
<?xml version="1.0" encoding="UTF-8"?>
<root:module
xmlns:root="http://eld.x4o.org/xml/ns/eld-root"
xmlns:eld="http://eld.x4o.org/xml/ns/eld-lang"
xmlns:conv="http://eld.x4o.org/xml/ns/eld-conv"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd"
providerName="foobar.test.x4o.org"
name="FooBar Language"
id="foobar"
>
<eld:classBindingHandler id="test1" bean.class="org.foo.bar.x4o.MyFooBarBindingHandler"/>
<eld:classBindingHandler id="test2" parentClass="org.foo.bar.TestObjectParent" childClass="org.foo.bar.TestObjectChild" method="addTestObjectChild"/>
<eld:elementInterface id="JComponent" interfaceClass="javax.swing.JComponent">
<eld:classBindingHandler id="JComponent-JComponent" parentClass="javax.swing.JComponent" childClass="javax.swing.JComponent" method="add"/>
</eld:elementInterface>
<eld:namespace
uri="http://foobar.test.x4o.org/xml/ns/foobar-root"
schemaUri="http://test.x4o.org/xml/ns/foobar-root-1.0.xsd"
schemaResource="foobar-root-1.0.xsd"
schemaPrefix="root"
name="FooBar Root Namespace"
languageRoot="true"
>
<eld:element tag="root" objectClass="org.foo.bar.TestBeanRoot">
<eld:description>The root element.</eld:description>
</eld:element>
</eld:namespace>
<eld:namespace
uri="http://foobar.test.x4o.org/xml/ns/foobar-lang"
schemaUri="http://foobar.test.x4o.org/xml/ns/foobar-lang-1.0.xsd"
schemaResource="foobar-lang-1.0.xsd"
schemaPrefix="lang"
name="FooBar Language Namespace"
>
<eld:element tag="testBean" objectClass="org.foo.bar.TestBean"/>
<!-- etc -->
</eld:namespace>
</root:module>
+--
Now you can startup the parser to see it work.

View file

@ -0,0 +1,78 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Validation
Schema validation is just new feature and work in progress to have it support all different xml language formats.
With x4o there are currently two options howto validate your documents, it depends if the language is extended.
* Validating parser
+--
TestParser parser = new TestParser();
parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_INPUT, true);
parser.parse(...);
+--
* Generate static languages
Store the generated xsd files in the (resource)classpath of project in META-INF/<language>/<ns-schemaResource>.
These schemas can be created or updates while package project or update manually by build script of profile.
For example see the profile in the pom.xml of the x4o-plugin-ant-schema.
* Validating parser
+--
TestParser parser = new TestParser();
parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_INPUT, true);
parser.parse(...);
+--
* Generate dynamic languages
Generate the xsd files while all the language extensions are loaded in the classpath.
Use the embedded java program in the x4o-core;
+--
java -cp '...jar:x4o-core.jar' org.x4o.xml.eld.xsd.X4OLanguageEldXsdWriter -path /tmp -class org.foo.bar.TestParserSupport
+--
Or use the ant task in the x4o-plugin-ant-schema;
+--
<taskdef name="eldXsdWriter" classname="org.x4o.plugin.ant.eld.xsd.EldXsdWriterTask"/>
<eldXsdWriter destdir="/tmp" supportclass="org.foo.bar.TestParserSupport"/>
+--
* Validating parser
+--
TestParser parser = new TestParser();
parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_INPUT, true);
parser.setProperty(X4OLanguagePropertyKeys.VALIDATION_SCHEMA_PATH, "/tmp");
parser.parse(...);
+--

59
src/site/apt/features.apt Normal file
View file

@ -0,0 +1,59 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
X4O Features
* Advanced XML to Object tree parsing.
* Easy create an extensible xml language.
* Dynamic module system for language loading.
* Fully namespace uri aware.
* Tree objects do not need to be modified for POJO use.
* Recursive language definition parsing.
* Dynamic element configuration language. (ELD)
* Extending ELD language to custom language.
* Global or Interface object configuration.
* Integrated java EL support.
* Comes with basic attribute converter set.
* Multiple phase parsing.
* Almost all classes in X4O are interface based.
* Comes with optional meta language.
* XML Debug output of language parsing steps.
* Basic XSD Schema generation from ELD.

77
src/site/apt/index.apt Normal file
View file

@ -0,0 +1,77 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Overview
X4O is a xml java parser library for development your own xml language.
This is preferable done for unmodified POJO objects so external libraries can be wrapped in xml.
This is done by defining your own element language definitions in one or more xml files, which in
turn are also done by x4o recursively and so it can be extended.
The extension modules are dynamically loaded from the classpath to define new namespaces.
Besides the elements in the namespace, modules also define the object parent child relation
binding interfaces which results in an object tree.
This all can be used to create your own powerful xml parser and (re)define your own xml
language, with using little code and also getting automatic schema generation.
* Features
X4O takes a lot of work out of your hand while creating complex languages and still have fine control
over the parsing of the xml elements.
For more information visit the detailed list of the {{{./features.html}Features}} page.
* Usage
Instructions on how to install X4O can be found {{{./usage.html}here}} and then start your
language {{{./examples/start-language.html}here}}.
* Examples
There are two examples written out;
{{{./examples/sample-swixml.html}Sample SwiXml}}
{{{./examples/sample-jr4o.html}Sample JR4O}}
But to put it simple, x4o translates the xml elements into beans;
+--
<my:fooBean test="hello wold"/>
+--
Creates an instance and sets the name property of this bean;
+--
class FooBean {
private String name=null;
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
}
+--

31
src/site/apt/manual.apt Normal file
View file

@ -0,0 +1,31 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Manual
The manual can be downloaded or viewed online.
HTML: {{{/docbook/manual.html}HTML}}
PDF: {{{/docbook/manual.pdf}PDF}}

96
src/site/apt/usage.apt Normal file
View file

@ -0,0 +1,96 @@
~~
~~ Copyright (c) 2004-2012, Willem Cazander
~~ All rights reserved.
~~
~~ Redistribution and use in source and binary forms, with or without modification, are permitted provided
~~ that the following conditions are met:
~~
~~ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
~~ following disclaimer.
~~ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
~~ the following disclaimer in the documentation and/or other materials provided with the distribution.
~~
~~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
~~ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
~~ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
~~ THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
~~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
~~ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
~~ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
~~ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
~~ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
~~
Usage
* X4O maven modules
* x4o = project base.
* x4o-core = Main x4o library.
* x4o-elddoc = X4O Eld documentation support.
* x4o-meta = X4O Meta sibling language.
* x4o-plugin = X4O external plugins.
* x4o-plugin-ant-elddoc = Ant x4o elddoc task.
* x4o-plugin-ant-schema = Ant x4o schema task.
* Setup as library
Append the core maven dependency;
+--
<dependency>
<groupId>org.x4o</groupId>
<artifactId>x4o-core</artifactId>
<version>0.8.5-SNAPSHOT</version>
</dependency>
+--
Note: currently x4o is not in main maven repro, so build and install local yourself.
* Setup ant task
Append one or both of the x4o eld ant tasks;
+--
<dependency>
<groupId>org.x4o.plugin</groupId>
<artifactId>x4o-plugin-ant-elddoc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.x4o.plugin</groupId>
<artifactId>x4o-plugin-ant-schema</artifactId>
<version>${project.version}</version>
</dependency>
+--
Use in ant and set the supportclass on the language you want todo the task for.
+--
<taskdef name="eldDocWriter" classname="org.x4o.plugin.ant.eld.doc.EldDocWriterTask"/>
<taskdef name="eldXsdWriter" classname="org.x4o.plugin.ant.eld.xsd.EldXsdWriterTask"/>
<target name="test-cel-schema-full" depends="init">
<mkdir dir="${test.dir}/cel-full"/>
<eldXsdWriter
destdir="${test.dir}/cel-full"
supportclass="org.x4o.xml.eld.EldParserSupportCore"
/>
</target>
<target name="test-elddoc-cel" depends="init">
<mkdir dir="${test.dir}/cel"/>
<eldDocWriter
destdir="${test.dir}/cel"
supportclass="org.x4o.xml.eld.EldParserSupportCore"
/>
</target>
+--

66
src/site/fml/faq.fml Normal file
View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<faqs title="Frequently Asked Questions" toplink="false">
<part id="general">
<title>General</title>
<faq id="whats-x4o">
<question>What is X4O</question>
<answer>
<p>X4O is not a language but a framework to create other XML language implementations.</p>
</answer>
</faq>
<faq id="x4o-licence">
<question>What is the linence of X4O</question>
<answer>
<p>X4O has an BSD style licence, to be compatible with wide range of software.</p>
</answer>
</faq>
<faq id="x4o-debug">
<question>How do I turn on debug mode.</question>
<answer>
<p>X4O can write all parsing steps in xml debug output file.<br/>To setup set the following properties before parsing a document.</p>
<pre>
TestParser parser = new TestParser();
parser.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_STREAM, new FileOutputStream(debugFile));
parser.setProperty(X4OLanguagePropertyKeys.DEBUG_OUTPUT_ELD_PARSER, true); // optional
</pre>
</answer>
</faq>
<faq id="x4o-transform">
<question>Can i use x4o for transforming xml</question>
<answer>
<p>No, X4O had no built in xslt support.</p>
<p>But you can implement an transforming language yourself with X4O.</p>
</answer>
</faq>
</part>
</faqs>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

66
src/site/site.xml Normal file
View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2004-2012, Willem Cazander
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided
that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<project>
<bannerLeft>
<name>${project.name}</name>
<src>images/logo-x4o.png</src>
<href>.</href>
</bannerLeft>
<version position="left"/>
<body>
<links>
<item name="X4O" href="${project.url}"/>
</links>
<menu name="Overview">
<item name="Home" href="index.html"/>
<item name="Features" href="features.html"/>
<item name="Usage" href="usage.html"/>
<!--
<item name="Manuel" href="manual.html"/>
-->
<item name="Faq" href="faq.html"/>
<item name="Download" href="download.html"/>
</menu>
<menu name="Examples">
<item name="Startup" href="examples/start-language.html"/>
<item name="Load modules" href="examples/load-modules.html"/>
<item name="Validation" href="examples/validation.html"/>
<item name="Sample swixml" href="examples/sample-swixml.html"/>
<item name="Sample jr4o" href="examples/sample-jr4o.html"/>
</menu>
<menu name="EldDoc">
<item name="cel" href="elddocs/cel/index.html"/>
<item name="eld" href="elddocs/eld/index.html"/>
<item name="junit-test" href="elddocs/junit-test/index.html"/>
<item name="junit-swixml2" href="elddocs/junit-swixml2/index.html"/>
<item name="junit-swixml3" href="elddocs/junit-swixml3/index.html"/>
</menu>
<menu ref="parent"/>
<menu ref="modules"/>
<menu ref="reports"/>
</body>
</project>

76
todo.txt Normal file
View file

@ -0,0 +1,76 @@
-- x4o TODO list --
- fix bind of attributeFromBody on module !
- static field constant converter
- full Xinclude test
- compleet eld doc html/css.
- move loading back into sax phase so version can readout on root tag.
- meta add more ns and jndi ref/etc'
- redo eld/default converters config
- tag aliases
- maven plugin
- code split in api/impl ?
- lang-el-beans.xml loading
- Add XML schema tags to ELD
- Auto generate schemas from eld
- Basic write support (for editor)
- Basic editor support
- Make converter config/loading better
- Single xsd output
- class dtd entity loading
- new ns for entity catalog for class resource
- Add w3c html namespace in eld for description tag
- move Boolean default from code to xml + conf.
-- IDEAS --
- add support javax.xml.xpath for xpath support
- add java.script support
- event listeners on all DOM tree element operations
- custom and merga'ble parse phases for speed
- make element tree jdom api compatible
- change phase enum to generic (text) phases.
- Test if possible to use threadpool for executing phases
-- TODO for version 1.0 --
## NON-CODE
- Add tutorial
- doc eld and x4o lang files
- Create xslt eld to html converter
- split into multiple maven projects
- x4o
- x4o-api
- x4o-core
- x4o-meta
- x4o-plugin
- x4o-plugin-ant-schema
- x4o-plugin-ant-elddoc
- x4o-plugin-mvn-schema
- x4o-plugin-mvn-elddoc
- x4o-plugin-ide-eclipse-editor
- x4o-plugin-ide-eclipse-catalog
##CODE
- Add (super) tag for extending tags of other namespace
- Add EldInfo element
- XMLOverrideEvent
- inboud sax parser !!
- input stream output converter :)
- eld static method binding for EL
- (50%) converters
- more junit tests
- multi and overrides in namespaces
- localoverride
- (DONE) multi phase parsing
- for loop support
- templateing.
- merging of object tree's
- sax with all x4o feutures like templating
- x4o:include option
- Xinclude option
- SAX events as input source
- (70%) XML debug output
- (20%) x4o comment element

18
versions.txt Normal file
View file

@ -0,0 +1,18 @@
=== X4O versions ===
Version 0.8.5:
- Made module loading system.
- Added XSD generator.
- Cleaned xml uri nameing.
- Cleaned language properties.
- refactored ELD tag names.
- Made elddoc ~working.
Version 0.8.2:
- Changed packages to org.x4o
- Made converter two way
- Added debug writer

36
x4o-core/.project Normal file
View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>x4o-core</name>
<comment>x4o-core</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

64
x4o-core/pom.xml Normal file
View file

@ -0,0 +1,64 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>x4o</artifactId>
<groupId>org.x4o</groupId>
<version>0.8.2-SNAPSHOT</version>
</parent>
<artifactId>x4o-core</artifactId>
<packaging>jar</packaging>
<name>x4o-core</name>
<description>x4o-core</description>
<dependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>${java.el.version}</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-ri</artifactId>
<version>${java.el.version}</version>
</dependency>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel</artifactId>
<version>${juel.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven-site-plugin.version}</version>
<configuration>
<siteDirectory>${project.basedir}/../src/site-child</siteDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,103 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
* AbstractObjectConverter to create ObjectConverters.
*
* @author Willem Cazander
* @version 1.0 Jan 30, 2012
*/
@SuppressWarnings("serial")
abstract public class AbstractObjectConverter implements ObjectConverter {
protected List<ObjectConverter> converters = new ArrayList<ObjectConverter>(5);
abstract public Object convertAfterTo(Object obj, Locale locale) throws ObjectConverterException;
abstract public Object convertAfterBack(Object obj, Locale locale) throws ObjectConverterException;
abstract public ObjectConverter clone() throws CloneNotSupportedException;
protected List<ObjectConverter> cloneConverters() throws CloneNotSupportedException {
List<ObjectConverter> result = new ArrayList<ObjectConverter>(converters.size());
for (ObjectConverter converter:converters) {
result.add(converter.clone());
}
return result;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#convertTo(java.lang.Object, java.util.Locale)
*/
public Object convertTo(Object obj, Locale locale) throws ObjectConverterException {
if (converters.isEmpty()) {
return convertAfterTo(obj,locale);
}
Object result = null;
for (ObjectConverter conv:converters) {
result = conv.convertTo(obj, locale);
}
result = convertAfterTo(obj,locale);
return result;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#convertBack(java.lang.Object, java.util.Locale)
*/
public Object convertBack(Object obj, Locale locale) throws ObjectConverterException {
if (converters.isEmpty()) {
return convertAfterBack(obj,locale);
}
Object result = null;
for (ObjectConverter conv:converters) {
result = conv.convertBack(obj, locale);
}
result = convertAfterBack(obj,locale);
return result;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#getObjectConverters()
*/
public List<ObjectConverter> getObjectConverters() {
return converters;
}
/**
* @see org.x4o.xml.conv.ObjectConverter#addObjectConverter(org.x4o.xml.conv.ObjectConverter)
*/
public void addObjectConverter(ObjectConverter converter) {
converters.add(converter);
}
/**
* @see org.x4o.xml.conv.ObjectConverter#removeObjectConverter(org.x4o.xml.conv.ObjectConverter)
*/
public void removeObjectConverter(ObjectConverter converter) {
converters.remove(converter);
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv;
import java.util.Locale;
/**
* AbstractStringObjectConverter to create ObjectConverters which work with strings.
*
* @author Willem Cazander
* @version 1.0 Jan 30, 2012
*/
@SuppressWarnings("serial")
abstract public class AbstractStringObjectConverter extends AbstractObjectConverter {
/**
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassBack()
*/
public Class<?> getObjectClassBack() {
return String.class;
}
public Object convertAfterTo(Object obj, Locale locale) throws ObjectConverterException {
if (obj instanceof String) {
return convertStringTo((String)obj,locale);
} else {
return convertStringTo(obj.toString(),locale);
}
}
public Object convertAfterBack(Object obj, Locale locale) throws ObjectConverterException {
return convertStringBack(obj,locale);
}
abstract public Object convertStringTo(String str, Locale locale) throws ObjectConverterException;
abstract public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException;
}

View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.x4o.xml.conv.text.BooleanConverter;
import org.x4o.xml.conv.text.ByteConverter;
import org.x4o.xml.conv.text.CharacterConverter;
import org.x4o.xml.conv.text.ClassConverter;
import org.x4o.xml.conv.text.DoubleConverter;
import org.x4o.xml.conv.text.FloatConverter;
import org.x4o.xml.conv.text.IntegerConverter;
import org.x4o.xml.conv.text.LongConverter;
import org.x4o.xml.conv.text.URLConverter;
/**
* DefaultObjectConverterProvider.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class DefaultObjectConverterProvider implements ObjectConverterProvider {
private Map<Class<?>,ObjectConverter> converters = null;
/**
* Create new DefaultObjectConverterProvider.
*/
public DefaultObjectConverterProvider() {
converters = new HashMap<Class<?>,ObjectConverter>(20);
}
/**
* Create new DefaultObjectConverterProvider.
* @param addDefaults When true do the addDefaults().
*/
public DefaultObjectConverterProvider(boolean addDefaults) {
this();
if (addDefaults) {
addDefaults();
}
}
/**
* Adds the default converters.
*/
public void addDefaults() {
addObjectConverter(new BooleanConverter());
addObjectConverter(new ByteConverter());
addObjectConverter(new CharacterConverter());
addObjectConverter(new DoubleConverter());
addObjectConverter(new FloatConverter());
addObjectConverter(new IntegerConverter());
addObjectConverter(new LongConverter());
addObjectConverter(new URLConverter());
addObjectConverter(new ClassConverter());
}
/**
* @param converter The converter to add.
*/
public void addObjectConverter(ObjectConverter converter) {
converters.put(converter.getObjectClassTo(), converter);
}
/**
* @see org.x4o.xml.conv.ObjectConverterProvider#getObjectConverterForClass(java.lang.Class)
*/
public ObjectConverter getObjectConverterForClass(Class<?> clazz) {
return converters.get(clazz);
}
protected Collection<ObjectConverter> getObjectConverters() {
return converters.values();
}
}

View file

@ -0,0 +1,88 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
/**
* The interface to convert objects.
*
* @author Willem Cazander
* @version 1.0 Aug 28, 2008
*/
public interface ObjectConverter extends Cloneable,Serializable {
/**
* @return Returns the class which we can convert to.
*/
Class<?> getObjectClassTo();
/**
* @return Returns the class which we can convert from.
*/
Class<?> getObjectClassBack();
/**
* Convert to the object.
* @param obj The object to convert.
* @param locale The Object convert locale if needed.
* @return Returns the converted object.
* @throws ObjectConverterException
*/
Object convertTo(Object obj,Locale locale) throws ObjectConverterException;
/**
* Convert the object back.
* @param obj The object to convert.
* @param locale The Object convert locale if needed.
* @return Returns the converted object.
* @throws ObjectConverterException
*/
Object convertBack(Object obj,Locale locale) throws ObjectConverterException;
/**
* @return Returns list of child converters.
*/
List<ObjectConverter> getObjectConverters();
/**
* @param converter Adds an child converter.
*/
void addObjectConverter(ObjectConverter converter);
/**
* @param converter Removes this child converter.
*/
void removeObjectConverter(ObjectConverter converter);
/**
* Force impl to have public clone method.
*
* @return An cloned ObjectConverter.
* @throws CloneNotSupportedException If thrown when cloning is not supported.
*/
ObjectConverter clone() throws CloneNotSupportedException;
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv;
/**
* ObjectConverterException is thrown by an ObjectConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class ObjectConverterException extends Exception {
private static final long serialVersionUID = 1L;
private final ObjectConverter converter;
/**
* Creates an ObjectConverterException.
* @param converter The converter which has the exception.
* @param message The exception message.
*/
public ObjectConverterException(ObjectConverter converter,String message) {
super(message);
this.converter=converter;
}
/**
* Creates an ObjectConverterException.
* @param converter The converter which has the exception.
* @param message The exception message.
* @param exception The parent exception.
*/
public ObjectConverterException(ObjectConverter converter,String message,Exception exception) {
super(message,exception);
this.converter=converter;
}
/**
* @return Returns the ObjectConverter of this exception.
*/
public ObjectConverter getObjectConverter() {
return converter;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv;
/**
* ObjectConverterProvider for class.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public interface ObjectConverterProvider {
/**
* Provides an ObjectConvert based on the converted class result.
* @param clazz The result class we want.
* @return The ObjectConverter which can convert for us.
*/
ObjectConverter getObjectConverterForClass(Class<?> clazz);
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Provides interfaces for two way object converters.
*
*
* @since 1.0
*/
package org.x4o.xml.conv;

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* BooleanConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class BooleanConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -6641858854858931768L;
public Class<?> getObjectClassTo() {
return Boolean.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
// WARNING: this alway returns a boolean :''(
return new Boolean(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Boolean)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
BooleanConverter result = new BooleanConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* ByteConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class ByteConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -719929830363810123L;
public Class<?> getObjectClassTo() {
return Byte.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Byte(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Byte)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ByteConverter result = new ByteConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* CharacterConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class CharacterConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -5864405229292234565L;
public Class<?> getObjectClassTo() {
return Character.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Character(str.charAt(0));
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Character)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
CharacterConverter result = new CharacterConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* Converts a String of an className into the the Class object.
*
* @author Willem Cazander
* @version 1.0 Aug 31, 2007
*/
public class ClassConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -1992327327215087127L;
public Class<?> getObjectClassTo() {
return Class.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return X4OLanguageClassLoader.loadClass(str);
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Class<?>)obj).getName();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
ClassConverter result = new ClassConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* DoubleConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class DoubleConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 3283317726435306051L;
public Class<?> getObjectClassTo() {
return Double.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Double(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Double)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
DoubleConverter result = new DoubleConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,102 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* Converts Sring of an Enum into the enum value.
*
* @author Willem Cazander
* @version 1.0 Aug 31, 2007
*/
@SuppressWarnings({"rawtypes","unchecked"})
public class EnumConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 8860785472427794548L;
private String enumClass = null;
private Class enumObjectClass = null;
public Class<?> getObjectClassTo() {
return Enum.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
if (getEnumClass()==null) {
throw new ObjectConverterException(this,"enumClass String attribute is not set.");
}
//if (value instanceof Enum) {
// return value;
//}
String v = str; //value.toString();
try {
if (enumObjectClass==null) {
enumObjectClass = (Class<?>)X4OLanguageClassLoader.loadClass(getEnumClass());
}
if (enumObjectClass==null) {
throw new ObjectConverterException(this,"Could not load enumClass");
}
return Enum.valueOf(enumObjectClass, v);
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Enum<?>)obj).name();
}
/**
* @return the enumClass
*/
public String getEnumClass() {
return enumClass;
}
/**
* @param enumClass the enumClass to set
*/
public void setEnumClass(String enumClass) {
this.enumClass = enumClass;
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
EnumConverter result = new EnumConverter();
result.converters=cloneConverters();
result.enumClass=enumClass;
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* FloatConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class FloatConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 8038640125557062170L;
public Class<?> getObjectClassTo() {
return Float.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Float(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Float)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
FloatConverter result = new FloatConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* IntegerConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class IntegerConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 6618552093124468324L;
public Class<?> getObjectClassTo() {
return Integer.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Integer(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Integer)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
IntegerConverter result = new IntegerConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* LongConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class LongConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 25132217809739854L;
public Class<?> getObjectClassTo() {
return Long.class;
}
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
return new Long(str);
}
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((Long)obj).toString();
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
LongConverter result = new LongConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,268 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* StringSplitConverter.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class StringSplitConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = 418588893457634317L;
private Class<?> classTo = null;
private String split = null;
private Integer splitSize = null;
private String singleToMethod = null;
private Boolean useNativeType = null;
private List<StringSplitConverterStep> stringSplitConverterSteps = null;
public StringSplitConverter() {
stringSplitConverterSteps = new ArrayList<StringSplitConverterStep>(10);
}
public Class<?> getObjectClassTo() {
return classTo;
}
@SuppressWarnings("rawtypes")
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
if (split==null) {
throw new ObjectConverterException(this,"split is not set.");
}
if (splitSize==null) {
throw new ObjectConverterException(this,"splitSize is not set.");
}
if (classTo==null) {
throw new ObjectConverterException(this,"classTo is not set.");
}
String[] strSplit = str.split(split);
if(strSplit.length!=splitSize) {
throw new ObjectConverterException(this,"Split size is wrong; "+strSplit.length+" need: "+splitSize);
}
List<StringSplitConverterStep> steps = getOrderedSteps(true);
if (steps.size()!=splitSize) {
throw new ObjectConverterException(this,"Step size is wrong; "+steps.size()+" need: "+splitSize);
}
try {
Object[] singleMethodValues = new Object[splitSize];
Object object = X4OLanguageClassLoader.newInstance(classTo);
for (int i=0;i<steps.size();i++) {
StringSplitConverterStep step = steps.get(i);
Object stepObject = strSplit[i];
Object stepValue = step.getObjectConverter().convertTo(stepObject, locale);
if (singleToMethod==null) {
Method m = classTo.getMethod(step.getToMethod(), new Class[] {stepValue.getClass()});
m.invoke(object, stepValue);
} else {
singleMethodValues[i] = stepValue;
}
}
if (singleToMethod!=null) {
List<Class> arguClass = new ArrayList<Class>(singleMethodValues.length);
for (int i=0;i<singleMethodValues.length;i++) {
arguClass.add(singleMethodValues[i].getClass());
}
if (useNativeType!=null && useNativeType) {
arguClass = convertToNative(arguClass);
}
Class[] arguArray = new Class[arguClass.size()];
arguArray = arguClass.toArray(arguArray);
Method m = classTo.getMethod(singleToMethod, arguArray);
List<Object> arguValue = new ArrayList<Object>(singleMethodValues.length);
for (int i=0;i<singleMethodValues.length;i++) {
arguValue.add(singleMethodValues[i]);
}
Object[] valueArray = new Object[arguValue.size()];
valueArray = arguValue.toArray(valueArray);
m.invoke(object, valueArray);
}
return object;
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
public String convertStringBack(Object object,Locale locale) throws ObjectConverterException {
List<StringSplitConverterStep> steps = getOrderedSteps(false);
if (steps.size()!=splitSize) {
throw new ObjectConverterException(this,"Step size is wrong; "+steps.size()+" need: "+splitSize);
}
try {
StringBuffer buf = new StringBuffer(200);
for (int i=0;i<steps.size();i++) {
StringSplitConverterStep step = steps.get(i);
Method m = classTo.getMethod(step.getFromMethod(), new Class[] {});
Object stepValue = m.invoke(object, new Object[] {});
Object stepString = step.getObjectConverter().convertBack(stepValue, locale);
buf.append(stepString.toString());
}
return buf.toString();
} catch (Exception e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
StringSplitConverter result = new StringSplitConverter();
result.converters=cloneConverters();
return result;
}
private List<StringSplitConverterStep> getOrderedSteps(boolean isTo) {
List<StringSplitConverterStep> result = new ArrayList<StringSplitConverterStep>(stringSplitConverterSteps.size());
result.addAll(stringSplitConverterSteps);
Collections.sort(stringSplitConverterSteps,new StringSplitConverterStepComparator(isTo));
return result;
}
public class StringSplitConverterStepComparator implements Comparator<StringSplitConverterStep> {
boolean isTo = true;
public StringSplitConverterStepComparator(boolean isTo) { this.isTo=isTo; }
public int compare(StringSplitConverterStep e1, StringSplitConverterStep e2) {
if (isTo) {
return e1.getToOrder().compareTo(e2.getToOrder());
} else {
return e1.getFromOrder().compareTo(e2.getFromOrder());
}
}
}
@SuppressWarnings("rawtypes")
private List<Class> convertToNative(List<Class> types) throws ObjectConverterException {
List<Class> result = new ArrayList<Class>(types.size());
for (int i=0;i<types.size();i++) {
Class<?> clazz = types.get(i);
if (clazz.isAssignableFrom(Integer.class)) {
result.add(Integer.TYPE);
} else if (clazz.isAssignableFrom(Long.class)) {
result.add(Long.TYPE);
} else if (clazz.isAssignableFrom(Float.class)) {
result.add(Float.TYPE);
} else if (clazz.isAssignableFrom(Double.class)) {
result.add(Double.TYPE);
} else if (clazz.isAssignableFrom(Boolean.class)) {
result.add(Boolean.TYPE);
} else {
throw new ObjectConverterException(this,"Can't convert type to native; "+clazz);
}
}
return result;
}
/**
* @return the classTo
*/
public Class<?> getClassTo() {
return classTo;
}
/**
* @param classTo the classTo to set
*/
public void setClassTo(Class<?> classTo) {
this.classTo = classTo;
}
/**
* @return the split
*/
public String getSplit() {
return split;
}
/**
* @param split the split to set
*/
public void setSplit(String split) {
this.split = split;
}
/**
* @return the splitSize
*/
public Integer getSplitSize() {
return splitSize;
}
/**
* @param splitSize the splitSize to set
*/
public void setSplitSize(Integer splitSize) {
this.splitSize = splitSize;
}
/**
* @return the singleToMethod
*/
public String getSingleToMethod() {
return singleToMethod;
}
/**
* @param singleToMethod the singleToMethod to set
*/
public void setSingleToMethod(String singleToMethod) {
this.singleToMethod = singleToMethod;
}
/**
* @return the useNativeType
*/
public Boolean getUseNativeType() {
return useNativeType;
}
/**
* @param useNativeType the useNativeType to set
*/
public void setUseNativeType(Boolean useNativeType) {
this.useNativeType = useNativeType;
}
public void addStringSplitConverterStep(StringSplitConverterStep stringSplitConverterStep) {
stringSplitConverterSteps.add(stringSplitConverterStep);
}
public void removeStringSplitConverterStep(StringSplitConverterStep stringSplitConverterStep) {
stringSplitConverterSteps.remove(stringSplitConverterStep);
}
public List<StringSplitConverterStep> getStringSplitConverterSteps() {
return stringSplitConverterSteps;
}
}

View file

@ -0,0 +1,111 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import org.x4o.xml.conv.ObjectConverter;
/**
* StringSplitConverterStep.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class StringSplitConverterStep {
private ObjectConverter objectConverter = null;
private String fromMethod = null;
private Integer fromOrder = null;
private String toMethod = null;
private Integer toOrder = null;
/**
* @return the objectConverter
*/
public ObjectConverter getObjectConverter() {
return objectConverter;
}
/**
* @param objectConverter the objectConverter to set
*/
public void setObjectConverter(ObjectConverter objectConverter) {
this.objectConverter = objectConverter;
}
/**
* @return the fromMethod
*/
public String getFromMethod() {
return fromMethod;
}
/**
* @param fromMethod the fromMethod to set
*/
public void setFromMethod(String fromMethod) {
this.fromMethod = fromMethod;
}
/**
* @return the fromOrder
*/
public Integer getFromOrder() {
return fromOrder;
}
/**
* @param fromOrder the fromOrder to set
*/
public void setFromOrder(Integer fromOrder) {
this.fromOrder = fromOrder;
}
/**
* @return the toMethod
*/
public String getToMethod() {
return toMethod;
}
/**
* @param toMethod the toMethod to set
*/
public void setToMethod(String toMethod) {
this.toMethod = toMethod;
}
/**
* @return the toOrder
*/
public Integer getToOrder() {
return toOrder;
}
/**
* @param toOrder the toOrder to set
*/
public void setToOrder(Integer toOrder) {
this.toOrder = toOrder;
}
}

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.conv.text;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import org.x4o.xml.conv.AbstractStringObjectConverter;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.ObjectConverterException;
/**
* URLConverter.
*
* @author Willem Cazander
* @version 1.0 Jan 20, 2012
*/
public class URLConverter extends AbstractStringObjectConverter {
private static final long serialVersionUID = -611843641266301893L;
/**
* @see org.x4o.xml.conv.ObjectConverter#getObjectClassTo()
*/
public Class<?> getObjectClassTo() {
return URL.class;
}
/**
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringTo(java.lang.String, java.util.Locale)
*/
public Object convertStringTo(String str, Locale locale) throws ObjectConverterException {
try {
return new URL(str);
} catch (MalformedURLException e) {
throw new ObjectConverterException(this,e.getMessage(),e);
}
}
/**
* @see org.x4o.xml.conv.AbstractStringObjectConverter#convertStringBack(java.lang.Object, java.util.Locale)
*/
public String convertStringBack(Object obj,Locale locale) throws ObjectConverterException {
return ((URL)obj).toString();
}
/**
* @see org.x4o.xml.conv.AbstractObjectConverter#clone()
*/
@Override
public ObjectConverter clone() throws CloneNotSupportedException {
URLConverter result = new URLConverter();
result.converters=cloneConverters();
return result;
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Provides default java text converters.
*
*
* @since 1.0
* @see org.x4o.xml.conv
*/
package org.x4o.xml.conv.text;

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.util.ArrayList;
import java.util.List;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementLanguage;
/**
* An base class for creating X4OPhaseHandlers.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
abstract public class AbstractX4OPhaseHandler implements X4OPhaseHandler {
protected X4OPhase phase = null;
protected List<X4OPhaseListener> X4OPhaseListeners = null;
public AbstractX4OPhaseHandler() {
X4OPhaseListeners = new ArrayList<X4OPhaseListener>(3);
setX4OPhase();
}
/**
* Is called from constuctor
*/
abstract protected void setX4OPhase();
public X4OPhase getX4OPhase() {
return phase;
}
public List<X4OPhaseListener> getX4OPhaseListeners() {
return X4OPhaseListeners;
}
public void addPhaseListener(X4OPhaseListener listener) {
X4OPhaseListeners.add(listener);
}
public void removePhaseListener(X4OPhaseListener listener) {
X4OPhaseListeners.remove(listener);
}
public boolean isElementPhase() {
return true;
}
abstract public void runElementPhase(Element element) throws X4OPhaseException;
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
}
}

View file

@ -0,0 +1,522 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementClassBase;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
/**
* Helps writing the xml debug output of all stuff x4o does.
*
* @author Willem Cazander
* @version 1.0 Jan 15, 2009
*/
public class X4ODebugWriter {
static public final String DEBUG_URI = "http://language.x4o.org/xml/ns/debug-output";
protected DefaultHandler2 debugWriter = null;
public X4ODebugWriter(DefaultHandler2 debugWriter) {
this.debugWriter=debugWriter;
}
protected DefaultHandler2 getDebugWriter() {
return debugWriter;
}
public X4OPhaseListener createDebugX4OPhaseListener() {
return new DebugX4OPhaseListener();
}
class DebugX4OPhaseListener implements X4OPhaseListener {
long startTime = 0;
/**
* @throws X4OPhaseException
* @see org.x4o.xml.core.X4OPhaseListener#preRunPhase(org.x4o.xml.element.ElementLanguage)
*/
public void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
startTime = System.currentTimeMillis();
try {
AttributesImpl atts = new AttributesImpl();
if (elementLanguage!=null) {
atts.addAttribute("", "language","","", elementLanguage.getLanguageConfiguration().getLanguage());
}
debugWriter.startElement (DEBUG_URI, "executePhase", "", atts);
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
debugPhase(phase);
}
public void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
long stopTime = System.currentTimeMillis();
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", phase.getX4OPhase().name());
atts.addAttribute ("", "speed", "", "", (stopTime-startTime)+" ms");
debugWriter.startElement (DEBUG_URI, "executePhaseDone", "", atts);
debugWriter.endElement (DEBUG_URI, "executePhaseDone" , "");
debugWriter.endElement (DEBUG_URI, "executePhase" , "");
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
}
}
public void debugLanguageProperties(ElementLanguage ec) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperties", "", atts);
for (X4OLanguageProperty p:X4OLanguageProperty.values()) {
Object value = ec.getLanguageConfiguration().getLanguageProperty(p);
if (value==null) {
continue;
}
AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "uri", "", "", p.toUri());
atts2.addAttribute ("", "value", "", "", value.toString());
debugWriter.startElement (DEBUG_URI, "X4OLanguageProperty", "", atts2);
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperty", "");
}
debugWriter.endElement(DEBUG_URI, "X4OLanguageProperties", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugLanguageDefaultClasses(ElementLanguage ec) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClasses", "", atts);
X4OLanguageConfiguration conf = ec.getLanguageConfiguration();
debugLanguageDefaultClass("getDefaultElementNamespaceContext",conf.getDefaultElementNamespaceContext());
debugLanguageDefaultClass("getDefaultElementInterface",conf.getDefaultElementInterface());
debugLanguageDefaultClass("getDefaultElement",conf.getDefaultElement());
debugLanguageDefaultClass("getDefaultElementClass",conf.getDefaultElementClass());
debugLanguageDefaultClass("getDefaultElementClassAttribute",conf.getDefaultElementClassAttribute());
debugLanguageDefaultClass("getDefaultElementLanguageModule",conf.getDefaultElementLanguageModule());
debugLanguageDefaultClass("getDefaultElementBodyComment",conf.getDefaultElementBodyComment());
debugLanguageDefaultClass("getDefaultElementBodyCharacters",conf.getDefaultElementBodyCharacters());
debugLanguageDefaultClass("getDefaultElementBodyWhitespace",conf.getDefaultElementBodyWhitespace());
debugLanguageDefaultClass("getDefaultElementNamespaceInstanceProvider",conf.getDefaultElementNamespaceInstanceProvider());
debugLanguageDefaultClass("getDefaultElementAttributeValueParser",conf.getDefaultElementAttributeValueParser());
debugLanguageDefaultClass("getDefaultElementObjectPropertyValue",conf.getDefaultElementObjectPropertyValue());
debugLanguageDefaultClass("getDefaultElementAttributeHandlerComparator",conf.getDefaultElementAttributeHandlerComparator());
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClasses", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
private void debugLanguageDefaultClass(String name,Class<?> clazz) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", name);
atts.addAttribute ("", "className", "", "", clazz.getName());
debugWriter.startElement (DEBUG_URI, "X4OLanguageDefaultClass", "", atts);
debugWriter.endElement(DEBUG_URI, "X4OLanguageDefaultClass", "");
}
public void debugPhaseOrder(List<X4OPhaseHandler> phases) throws X4OPhaseException {
X4OPhaseHandler phase = null;
try {
AttributesImpl atts = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "phaseOrder", "", atts);
for (X4OPhaseHandler phase2:phases) {
phase = phase2;
debugPhase(phase2);
}
debugWriter.endElement(DEBUG_URI, "phaseOrder", "");
} catch (SAXException e) {
// fall back...
if (phase==null) {
if (phases.isEmpty()) {
throw new X4OPhaseException(null,e); /// mmmm
}
phase = phases.get(0);
}
throw new X4OPhaseException(phase,e);
}
}
private void debugPhase(X4OPhaseHandler phase) throws X4OPhaseException {
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", phase.getX4OPhase().name());
atts.addAttribute ("", "runOnce", "", "", phase.getX4OPhase().isRunOnce()+"");
atts.addAttribute ("", "listenersSize", "", "", phase.getX4OPhaseListeners().size()+"");
debugWriter.startElement (DEBUG_URI, "phase", "", atts);
for (X4OPhaseListener l:phase.getX4OPhaseListeners()) {
atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", l.getClass().getName());
debugWriter.startElement (DEBUG_URI, "X4OPhaseListener", "", atts);
debugWriter.endElement(DEBUG_URI, "X4OPhaseListener", "");
}
debugWriter.endElement(DEBUG_URI, "phase", "");
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
}
public void debugElementLanguageModules(ElementLanguage elementLanguage) throws ElementException {
try {
AttributesImpl attsEmpty = new AttributesImpl();
debugWriter.startElement (DEBUG_URI, "ElementLanguageModules", "", attsEmpty);
for (ElementLanguageModule module:elementLanguage.getElementLanguageModules()) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", module.getClass().getName());
atts.addAttribute ("", "name", "", "", module.getName());
atts.addAttribute ("", "providerName", "", "", module.getProviderName());
if (module.getElementLanguageModuleLoader()==null) {
atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", "null");
} else {
atts.addAttribute ("", "elementLanguageModuleLoaderClassName", "", "", module.getElementLanguageModuleLoader().getClass().getName());
}
debugWriter.startElement (DEBUG_URI, "ElementLanguageModule", "", atts);
//module.getElementAttributeHandlers();
//module.getElementBindingHandlers();
//module.getGlobalElementConfigurators();
//module.getElementInterfaces();
//module.getElementNamespaceContexts();
debugElementConfigurator(module.getGlobalElementConfigurators());
debugElementBindingHandler(module.getElementBindingHandlers());
for (ElementAttributeHandler p:module.getElementAttributeHandlers()) {
atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", p.getAttributeName());
atts.addAttribute ("", "description", "", "", p.getDescription());
atts.addAttribute ("", "className", "", "", p.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementAttributeHandler", "", atts);
for (String para:p.getNextAttributes()) {
atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", para);
debugWriter.startElement (DEBUG_URI, "nextAttribute", "", atts);
debugWriter.endElement(DEBUG_URI, "nextAttribute", "");
}
debugWriter.endElement(DEBUG_URI, "elementAttributeHandler", "");
}
for (ElementInterface elementInterface:module.getElementInterfaces()) {
atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", elementInterface.getClass().getName());
atts.addAttribute ("", "description", "", "", elementInterface.getDescription());
atts.addAttribute ("", "interfaceClass", "", "", elementInterface.getInterfaceClass().getName());
debugWriter.startElement (DEBUG_URI, "elementInterface", "", atts);
debugElementBindingHandler(elementInterface.getElementBindingHandlers());
debugElementClassBase(elementInterface);
debugWriter.endElement(DEBUG_URI, "elementInterface", "");
}
for (ElementNamespaceContext enc:module.getElementNamespaceContexts()) {
atts = new AttributesImpl();
atts.addAttribute ("", "uri", "", "", enc.getUri());
atts.addAttribute ("", "description", "", "", enc.getDescription());
atts.addAttribute ("", "schemaUri", "", "", enc.getSchemaUri());
atts.addAttribute ("", "schemaResource", "", "", enc.getSchemaResource());
atts.addAttribute ("", "className", "", "", enc.getClass().getName());
debugWriter.startElement (DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "", atts);
for (ElementClass ec:enc.getElementClasses()) {
debugElementClass(ec);
}
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", eip.getClass().getName());
debugWriter.startElement (DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "", atts);
debugWriter.endElement(DEBUG_URI, ElementNamespaceInstanceProvider.class.getSimpleName(), "");
debugWriter.endElement(DEBUG_URI, ElementNamespaceContext.class.getSimpleName(), "");
}
debugWriter.endElement(DEBUG_URI, "ElementLanguageModule", "");
}
debugWriter.endElement(DEBUG_URI, "ElementLanguageModules", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElement(Element element) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
// atts.addAttribute ("", "tag", "", "", element.getElementClass().getTag());
atts.addAttribute ("", "objectClass", "", "", ""+element.getElementClass().getObjectClass());
boolean rootElement = element.getParent()==null;
if (rootElement) {
atts.addAttribute ("", "isRootElement", "", "", "true");
}
if (element.getElementObject()==null) {
atts.addAttribute ("", "elementObjectClassName", "", "", "null");
} else {
atts.addAttribute ("", "elementObjectClassName", "", "", element.getElementObject().getClass().getName());
AttributesImpl atts2 = new AttributesImpl();
try {
for (Method m:element.getElementObject().getClass().getMethods()) {
if (m.getName().startsWith("get")==false) { //a bit dirty
continue;
}
if (m.getParameterTypes().length>0) {
continue;
}
Object value = m.invoke(element.getElementObject());
if (value!=null) {
//atts2.addAttribute ("", m.getName()+".className", "", "", value.getClass().getName());
if (value instanceof String) {
atts2.addAttribute ("", m.getName(), "", "", value.toString());
}
if (value instanceof Number) {
atts2.addAttribute ("", m.getName(), "", "", value.toString());
}
if (value instanceof Collection<?>) {
atts2.addAttribute ("", m.getName()+".size", "", "", ""+((Collection<?>)value).size());
}
if (value instanceof Map<?,?>) {
atts2.addAttribute ("", m.getName()+".size", "", "", ""+((Map<?,?>)value).size());
}
}
}
} catch (Exception e) {
atts.addAttribute ("", "exceptionWhileGetingBeanValues", "", "", e.getMessage());
}
debugWriter.startElement (DEBUG_URI, "elementObject", "", atts2);
debugWriter.endElement(DEBUG_URI, "elementObject", "");
}
StringBuffer elementPath = getElementPath(element,new StringBuffer());
atts.addAttribute ("", "elementPath", "", "", elementPath.toString());
debugWriter.startElement (DEBUG_URI, "element", "", atts);
debugWriter.endElement(DEBUG_URI, "element", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
/**
* Todo move after xpath support
* @param element
* @param buff
* @return
*/
private StringBuffer getElementPath(Element element,StringBuffer buff) {
if (element.getParent()==null) {
buff.append('/'); // root slash
buff.append(element.getElementClass().getTag());
return buff;
}
buff = getElementPath(element.getParent(),buff);
buff.append('/');
buff.append(element.getElementClass().getTag());
return buff;
}
public void debugPhaseMessage(String message,Class<?> clazz) throws ElementException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "class", "", "", clazz.getName()+"");
try {
debugWriter.startElement (DEBUG_URI, "message", "", atts);
char[] msg = message.toCharArray();
debugWriter.characters(msg,0,msg.length);
debugWriter.endElement(DEBUG_URI, "message", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElementConfigurator(ElementConfigurator ec,Element element) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
atts.addAttribute ("", "configAction", "", "", ec.isConfigAction()+"");
atts.addAttribute ("", "description", "", "", ec.getDescription());
atts.addAttribute ("", "className", "", "", ec.getClass().getName());
debugWriter.startElement (DEBUG_URI, "runElementConfigurator", "", atts);
debugElement(element);
debugWriter.endElement(DEBUG_URI, "runElementConfigurator", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElementBindingHandler(ElementBindingHandler ebh,Element element) throws ElementException {
try {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
atts.addAttribute ("", "description", "", "", ebh.getDescription());
atts.addAttribute ("", "className", "", "", ebh.getClass().getName()+"");
atts.addAttribute ("", "parentClass", "", "", element.getParent().getElementObject().getClass()+"");
atts.addAttribute ("", "childClass", "", "", element.getElementObject().getClass()+"");
debugWriter.startElement (DEBUG_URI, "doBind", "", atts);
debugElement(element);
debugWriter.endElement(DEBUG_URI, "doBind", "");
} catch (SAXException e) {
throw new ElementException(e);
}
}
public void debugElementLanguage(ElementLanguage elementLanguage) throws SAXException {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
atts.addAttribute ("", "language", "", "", elementLanguage.getLanguageConfiguration().getLanguage());
atts.addAttribute ("", "languageVersion", "", "", elementLanguage.getLanguageConfiguration().getLanguageVersion());
atts.addAttribute ("", "className", "", "", elementLanguage.getClass().getName()+"");
atts.addAttribute ("", "currentX4OPhase", "", "", elementLanguage.getCurrentX4OPhase().name());
debugWriter.startElement (DEBUG_URI, "printElementLanguage", "", atts);
debugWriter.endElement(DEBUG_URI, "printElementLanguage", "");
}
private void debugElementClass(ElementClass elementClass) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "tag", "", "", elementClass.getTag());
atts.addAttribute ("", "description", "", "", elementClass.getDescription());
atts.addAttribute ("", "objectClassName", "", "", ""+elementClass.getObjectClass());
atts.addAttribute ("", "className", "", "", elementClass.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementClass", "", atts);
for (String phase:elementClass.getSkipPhases()) {
atts = new AttributesImpl();
atts.addAttribute ("", "phase", "", "", ""+phase);
debugWriter.startElement(DEBUG_URI, "elementSkipPhase", "", atts);
debugWriter.endElement(DEBUG_URI, "elementSkipPhase", "");
}
debugElementConfigurator(elementClass.getElementConfigurators());
debugElementClassBase(elementClass);
debugWriter.endElement(DEBUG_URI, "elementClass", "");
}
private void debugElementClassBase(ElementClassBase elementClassBase) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementClassBase.getDescription());
atts.addAttribute ("", "className", "", "", elementClassBase.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementClassBase", "", atts);
debugElementConfigurator(elementClassBase.getElementConfigurators());
debugElementClassAttributes(elementClassBase.getElementClassAttributes());
debugWriter.endElement(DEBUG_URI, "elementClassBase", "");
}
private void debugElementConfigurator(List<ElementConfigurator> elementConfigurators) throws SAXException {
for (ElementConfigurator elementConfigurator:elementConfigurators) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "description", "", "", elementConfigurator.getDescription());
atts.addAttribute ("", "className", "", "", elementConfigurator.getClass().getName());
debugWriter.startElement (DEBUG_URI, "elementConfigurator", "", atts);
debugWriter.endElement(DEBUG_URI, "elementConfigurator", "");
}
}
private void debugElementClassAttributes(Collection<ElementClassAttribute> elementClassAttributes) throws SAXException {
for (ElementClassAttribute elementClassAttribute:elementClassAttributes) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "attributeName", "", "", elementClassAttribute.getName());
atts.addAttribute ("", "description", "", "", elementClassAttribute.getDescription());
atts.addAttribute ("", "className", "", "", elementClassAttribute.getClass().getName());
atts.addAttribute ("", "defaultValue", "", "", ""+elementClassAttribute.getDefaultValue());
atts.addAttribute ("", "runBeanFill", "", "", ""+elementClassAttribute.getRunBeanFill());
atts.addAttribute ("", "runConverters", "", "", ""+elementClassAttribute.getRunConverters());
//atts.addAttribute ("", "runInterfaces", "", "", ""+elementClassAttribute.getRunInterfaces());
atts.addAttribute ("", "runResolveEL", "", "", ""+elementClassAttribute.getRunResolveEL());
debugWriter.startElement(DEBUG_URI, "elementClassAttribute", "", atts);
if (elementClassAttribute.getObjectConverter()!=null) {
debugObjectConverter(elementClassAttribute.getObjectConverter());
}
for (String alias:elementClassAttribute.getAttributeAliases()) {
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ""+alias);
debugWriter.startElement(DEBUG_URI, "attributeAlias", "", atts);
debugWriter.endElement(DEBUG_URI, "attributeAlias", "");
}
debugWriter.endElement(DEBUG_URI, "elementClassAttribute", "");
}
}
private void debugObjectConverter(ObjectConverter objectConverter) throws SAXException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "objectClassTo", "", "", objectConverter.getObjectClassTo().getName());
atts.addAttribute ("", "objectClassBack", "", "", objectConverter.getObjectClassBack().getName());
atts.addAttribute ("", "className", "", "", objectConverter.getClass().getName());
debugWriter.startElement (DEBUG_URI, "objectConverter", "", atts);
debugWriter.endElement(DEBUG_URI, "objectConverter", "");
}
private void debugElementBindingHandler(List<ElementBindingHandler> elementBindingHandlers) throws SAXException {
for (ElementBindingHandler bind:elementBindingHandlers) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "className", "", "", bind.getClass().getName());
atts.addAttribute ("", "description", "", "", bind.getDescription());
atts.addAttribute ("", "bindParentClass", "", "", bind.getBindParentClass().toString());
debugWriter.startElement (DEBUG_URI, "elementBindingHandler", "", atts);
for (Class<?> clazz:bind.getBindChildClasses()) {
AttributesImpl atts2 = new AttributesImpl();
atts2.addAttribute ("", "className", "", "", clazz.getName());
debugWriter.startElement (DEBUG_URI, "elementBindingHandlerChildClass", "", atts2);
debugWriter.endElement (DEBUG_URI, "elementBindingHandlerChildClass", "");
}
debugWriter.endElement(DEBUG_URI, "elementBindingHandler", "");
}
}
}

View file

@ -0,0 +1,328 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.sax.XMLWriter;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
/**
* X4ODriver can load language and parse files
*
* @author Willem Cazander
* @version 1.0 Aug 9, 2012
*/
public class X4ODriver implements X4OParserSupport {
/** The logger to log to. */
private Logger logger = null;
/** The ElementLanguage which hold all language config. */
protected ElementLanguage elementLanguage = null;
/** Keep is here for if we want to reuse the parser instance. */
private X4OPhaseManager phaseManager = null;
//private X4OPhaseHandler configOptionalPhase = null;
/** Defines the default version if none is defined. */
public final static String DEFAULT_LANGUAGE_VERSION = "1.0";
/**
* Creates an X4ODriver for this config
*
* @param languageConfig The X4O languageConfig to create this parser for..
*/
public X4ODriver(X4OLanguageConfiguration languageConfig) {
if (languageConfig==null) {
throw new NullPointerException("Can't start with null X4OLanguageConfiguration");
}
elementLanguage = languageConfig.createElementLanguage(); // store also language config
logger = Logger.getLogger(X4OParser.class.getName());
logger.fine("Creating X4O driver for language: "+languageConfig.getLanguage());
}
/**
* Returns the ElementLanguage
* @return returns the ElementLanguage.
*/
public ElementLanguage getElementLanguage() {
return elementLanguage;
}
/**
* Creates and configs an X4OPhaseManager to parse a language.
*
* @return An configured X4OPhaseManager
* @throws X4OPhaseException
*/
protected X4OPhaseManager createX4OPhaseManager() throws X4OPhaseException {
X4OPhaseHandlerFactory factory = new X4OPhaseHandlerFactory(elementLanguage);
X4OPhaseManager manager = new X4OPhaseManager(elementLanguage);
// main startup
//manager.addX4OPhaseHandler(factory.createContextsPhase());
manager.addX4OPhaseHandler(factory.startupX4OPhase());
manager.addX4OPhaseHandler(factory.createLanguagePhase());
manager.addX4OPhaseHandler(factory.createLanguageSiblingsPhase());
manager.addX4OPhaseHandler(factory.parseSAXStreamPhase());
// inject and opt phase
manager.addX4OPhaseHandler(factory.configGlobalElBeansPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
/*
if (configOptionalPhase!=null) {
if (X4OPhase.configOptionalPhase.equals(configOptionalPhase.getX4OPhase())==false) {
throw new X4OPhaseException(configOptionalPhase,new IllegalStateException("createConfigOptionalPhase() did not return an X4OPhase.configOptionalPhase x4o phase."));
}
manager.addX4OPhaseHandler(configOptionalPhase);
}
*/
// meta start point
manager.addX4OPhaseHandler(factory.startX4OPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// config
manager.addX4OPhaseHandler(factory.configElementPhase());
manager.addX4OPhaseHandler(factory.configElementInterfacePhase());
manager.addX4OPhaseHandler(factory.configGlobalElementPhase());
manager.addX4OPhaseHandler(factory.configGlobalAttributePhase());
// run all attribute events
manager.addX4OPhaseHandler(factory.runAttributesPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// templating
manager.addX4OPhaseHandler(factory.fillTemplatingPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// transforming
manager.addX4OPhaseHandler(factory.transformPhase());
manager.addX4OPhaseHandler(factory.runDirtyElementPhase(manager));
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// binding elements
manager.addX4OPhaseHandler(factory.bindElementPhase());
// runing and releasing
manager.addX4OPhaseHandler(factory.runPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
manager.addX4OPhaseHandler(factory.runDirtyElementLastPhase(manager));
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
// after release phase Element Tree is not avible anymore
manager.addX4OPhaseHandler(factory.releasePhase());
// Add debug phase listener to all phases
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
for (X4OPhaseHandler h:manager.getPhases()) {
h.addPhaseListener(elementLanguage.getLanguageConfiguration().getX4ODebugWriter().createDebugX4OPhaseListener());
}
}
// We are done we the manager
return manager;
}
protected X4OPhaseManager createX4OPhaseManagerSupport() throws X4OPhaseException {
X4OPhaseHandlerFactory factory = new X4OPhaseHandlerFactory(elementLanguage);
X4OPhaseManager manager = new X4OPhaseManager(elementLanguage);
manager.addX4OPhaseHandler(factory.createLanguagePhase());
manager.addX4OPhaseHandler(factory.createLanguageSiblingsPhase());
manager.addX4OPhaseHandler(factory.configGlobalElBeansPhase());
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {manager.addX4OPhaseHandler(factory.debugPhase());}
return manager;
}
/**
* Parses the input stream as a X4O document.
*/
public void parseInput() throws ParserConfigurationException,SAXException,IOException {
if (elementLanguage.getLanguageConfiguration().getLanguage()==null) {
throw new ParserConfigurationException("parserConfig is broken getLanguage() returns null.");
}
// init debugWriter if enabled
boolean startedDebugWriter = false;
Object debugOutputHandler = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_HANDLER);
Object debugOutputStream = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.DEBUG_OUTPUT_STREAM);
if (elementLanguage.getLanguageConfiguration().getX4ODebugWriter()==null) {
DefaultHandler2 xmlDebugWriter = null;
if (debugOutputHandler instanceof DefaultHandler2) {
xmlDebugWriter = (DefaultHandler2)debugOutputHandler;
} else if (debugOutputStream instanceof OutputStream) {
xmlDebugWriter = new XMLWriter((OutputStream)debugOutputStream);
}
if (xmlDebugWriter!=null) {
xmlDebugWriter.startDocument();
xmlDebugWriter.startPrefixMapping("debug", X4ODebugWriter.DEBUG_URI);
X4ODebugWriter debugWriter = new X4ODebugWriter(xmlDebugWriter);
elementLanguage.getLanguageConfiguration().setX4ODebugWriter(debugWriter);
startedDebugWriter = true;
}
}
// debug language
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "language", "", "", elementLanguage.getLanguageConfiguration().getLanguage());
atts.addAttribute ("", "currentTimeMillis", "", "", System.currentTimeMillis()+"");
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "", atts);
}
// start parsing language
try {
if (phaseManager==null) {
phaseManager = createX4OPhaseManager();
}
phaseManager.runPhases();
} catch (Exception e) {
// also debug exceptions
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "message", "", "", e.getMessage());
if (e instanceof X4OPhaseException) {
atts.addAttribute ("", "phase", "", "", ((X4OPhaseException)e).getX4OPhaseHandler().getX4OPhase().name());
}
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().startElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "", atts);
StringWriter writer = new StringWriter();
PrintWriter printer = new PrintWriter(writer);
printer.append('\n');
if (e.getCause()==null) {
e.printStackTrace(printer);
} else {
e.getCause().printStackTrace(printer);
}
char[] stack = writer.getBuffer().toString().toCharArray();
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().characters(stack, 0, stack.length);
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "exceptionStackTrace", "");
} catch (Exception ee) {
ee.printStackTrace();
}
}
// unwrap exception
if (e.getCause() instanceof ParserConfigurationException) {
throw (ParserConfigurationException)e.getCause();
}
if (e.getCause() instanceof SAXException) {
throw (SAXException)e.getCause();
}
if (e.getCause() instanceof IOException) {
throw (IOException)e.getCause();
}
if (e.getCause()==null) {
throw new SAXException(e);
} else {
throw new SAXException((Exception)e.getCause());
}
} finally {
// close all our resources.
//if (inputStream!=null) {
// inputStream.close();
//}
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "X4ODriver", "");
}
if (startedDebugWriter && elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()) {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endPrefixMapping("debug");
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().getDebugWriter().endDocument();
if (debugOutputStream instanceof OutputStream) {
OutputStream outputStream = (OutputStream)debugOutputStream;
outputStream.flush();
outputStream.close(); // need this here ?
}
}
}
}
/**
* Loads the language and returns the ElementLanguage.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
try {
X4OPhaseManager loadLanguageManager = createX4OPhaseManagerSupport();
loadLanguageManager.runPhases();
return elementLanguage;
} catch (Exception e) {
throw new X4OParserSupportException(e);
}
}
/**
* Run a manual release phase to clean the parsing object tree.
*
* @throws X4OPhaseException
*/
public void doReleasePhaseManual() throws X4OPhaseException {
if (phaseManager==null) {
throw new IllegalStateException("Can't release with null phaseManager.");
}
phaseManager.doReleasePhaseManual();
}
/**
* Sets an X4O Language property.
* @param key The key of the property to set.
* @param value The vlue of the property to set.
*/
public void setProperty(String key,Object value) {
if (phaseManager!=null) {
throw new IllegalStateException("Can't set property after phaseManager is created.");
}
elementLanguage.getLanguageConfiguration().setLanguageProperty(X4OLanguageProperty.valueByUri(key), value);
}
/**
* Returns the value an X4O Language property.
* @param key The key of the property to get the value for.
* @return Returns null or the value of the property.
*/
public Object getProperty(String key) {
return elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.valueByUri(key));
}
}

View file

@ -0,0 +1,167 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* X4OEntityResolver resolves internel entities and proxy to external defined ones.
*
* Resolve order;
* 1) validation base path dir
* 2) external resolver
* 3) lookup for language in classpath.
* 4) throw exception
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class X4OEntityResolver implements EntityResolver {
private Logger logger = null;
private URL basePath = null;
private ElementLanguage elementLanguage = null;
private Map<String,String> schemaResources = null;
private Map<String,String> schemaPathResources = null;
protected X4OEntityResolver(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't provide entities with null ElementLanguage.");
}
this.logger=Logger.getLogger(X4OEntityResolver.class.getName());
this.elementLanguage=elementLanguage;
this.basePath=(URL)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_BASE_PATH);
this.schemaResources=new HashMap<String,String>(20);
this.schemaPathResources=new HashMap<String,String>(20);
for (ElementLanguageModule mod:elementLanguage.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
if (ns.getSchemaUri()==null) {
continue;
}
if (ns.getSchemaResource()==null) {
continue;
}
StringBuffer buf = new StringBuffer(30);
buf.append(elementLanguage.getLanguageConfiguration().getLanguageResourcePathPrefix());
buf.append('/');
buf.append(elementLanguage.getLanguageConfiguration().getLanguage());
buf.append('/');
buf.append(ns.getSchemaResource());
schemaResources.put( ns.getSchemaUri(), buf.toString() );
buf = new StringBuffer(30);
buf.append(elementLanguage.getLanguageConfiguration().getLanguage());
buf.append(File.separatorChar);
buf.append(ns.getSchemaResource());
schemaPathResources.put( ns.getSchemaUri(), buf.toString() );
}
}
}
public InputSource resolveEntity(String publicId, String systemId) throws IOException,SAXException {
logger.finer("Fetch sysId: "+systemId+" pubId: "+publicId);
// Check if other resolver has resource
EntityResolver resolver = (EntityResolver)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.CONFIG_ENTITY_RESOLVER);
if (resolver!=null) {
InputSource result = resolver.resolveEntity(publicId, systemId);
if (result!=null) {
return result;
}
}
// Check if we have it on user defined schema base path
if (schemaPathResources.containsKey(systemId)) {
File schemaBasePath = (File)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.VALIDATION_SCHEMA_PATH);
if (schemaBasePath!=null && schemaBasePath.exists()) {
String schemeResource = schemaResources.get(systemId);
File schemaFile = new File(schemaBasePath.getAbsolutePath()+File.separatorChar+schemeResource);
if (schemaFile.exists()) {
if (schemaFile.canRead()==false) {
throw new SAXException("Can't read schema file: "+schemaFile);
}
try {
InputSource in = new InputSource(new FileInputStream(schemaFile));
in.setPublicId(publicId);
in.setSystemId(systemId);
return in;
} catch (IOException e) {
throw new IOException("Could not open: "+schemaFile+" error: "+e.getMessage(),e);
}
}
}
}
// Check if we have it on the classpath.
if (schemaResources.containsKey(systemId)) {
String schemeResource = schemaResources.get(systemId);
ClassLoader cl = X4OLanguageClassLoader.getClassLoader();
URL resource = cl.getResource(schemeResource);
if (resource!=null) {
try {
InputSource in = new InputSource(resource.openStream());
in.setPublicId(publicId);
in.setSystemId(systemId);
return in;
} catch (IOException e) {
throw new IOException("Could not open: "+resource+" error: "+e.getMessage(),e);
}
}
}
if (basePath!=null && systemId!=null) {
if (systemId.startsWith(basePath.toExternalForm())) {
logger.finer("Base reference basePath: "+basePath+" systemId: "+systemId);
try {
InputSource in = new InputSource(new URL(systemId).openStream());
in.setPublicId(publicId);
in.setSystemId(systemId);
return in;
} catch (IOException e) {
throw new IOException("Could not open: "+systemId+" error: "+e.getMessage(),e);
}
}
}
// always throw to remove all network fetches.
throw new SAXException("SystemId not found: "+systemId);
}
}

View file

@ -0,0 +1,124 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* X4OErrorHandler prints the SAX2 Errors and Warsnings when parsing xml.
*
* @author Willem Cazander
* @version 1.0 Feb 8, 2007
*/
public class X4OErrorHandler implements ErrorHandler {
private ElementLanguage elementLanguage = null;
private ErrorHandler errorHandler = null;
/**
* Construct a new SAXErrorPrinter
* @param elementLanguage The elementLanguage to get errors to.
*/
public X4OErrorHandler(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't debug and proxy errors with null elementLanguage.");
}
this.elementLanguage=elementLanguage;
this.errorHandler=(ErrorHandler)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.CONFIG_ERROR_HANDLER);
}
/**
* Prints the error message to debug output.
*/
private void printError(boolean isError, SAXParseException exception) throws SAXException {
if (elementLanguage.getLanguageConfiguration().hasX4ODebugWriter()==false) {
return;
}
String message = printErrorString(isError,exception);
try {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().debugPhaseMessage(message, X4OErrorHandler.class);
} catch (ElementException e) {
throw new SAXException(e);
}
}
/**
* Prints the error message to string.
*/
private String printErrorString(boolean isError, SAXParseException exception) {
StringBuffer buf = new StringBuffer(50);
buf.append(exception.getSystemId());
buf.append(":");
buf.append(exception.getLineNumber());
buf.append(":");
buf.append(exception.getColumnNumber());
buf.append(" ");
buf.append((isError?"Error: ":"Warning: "));
buf.append(exception.getMessage());
return buf.toString();
}
// ========= ErrorHandler
/**
* Receive notification of a SAX warning.
*/
public void warning(SAXParseException exception) throws SAXException {
printError(false, exception);
if (errorHandler!=null) {
errorHandler.warning(exception);
} else {
throw new SAXException(printErrorString(false,exception));
}
}
/**
* Receive notification of a SAX recoverable error.
*/
public void error(SAXParseException exception) throws SAXException {
printError(true, exception);
if (errorHandler!=null) {
errorHandler.error(exception);
} else {
throw new SAXException(printErrorString(true,exception));
}
}
/**
* Receive notification of a SAX non-recoverable error.
*/
public void fatalError(SAXParseException exception) throws SAXException {
printError(true, exception);
if (errorHandler!=null) {
errorHandler.fatalError(exception);
} else {
throw new SAXException(printErrorString(true,exception));
}
}
}

View file

@ -0,0 +1,143 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import org.x4o.xml.core.config.X4OLanguageConfiguration;
import org.x4o.xml.core.config.X4OLanguagePropertyKeys;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.impl.config.DefaultX4OLanguageConfiguration;
import org.x4o.xml.sax.AbstractXMLParser;
import org.xml.sax.SAXException;
/**
* This is the starting point of the XML X4O parsing.
*
* @author Willem Cazander
* @version 1.0 Aug 11, 2005
*/
public class X4OParser extends AbstractXMLParser implements X4OParserSupport {
private X4ODriver driver = null;
/**
* Creates an X4OParser object.
*
* @param language The X4O language to create this parser for..
*/
public X4OParser(String language) {
this(language,X4ODriver.DEFAULT_LANGUAGE_VERSION);
}
public X4OParser(String language,String languageVersion) {
this(new DefaultX4OLanguageConfiguration(language,languageVersion));
}
protected X4OParser(X4OLanguageConfiguration config) {
this(new X4ODriver(config));
}
protected X4OParser(X4ODriver driver) {
if (driver==null) {
throw new NullPointerException("Can't start X4OParser with null X4ODriver.");
}
this.driver = driver;
}
protected X4ODriver getDriver() {
return driver;
}
/**
* @see org.x4o.xml.sax.AbstractXMLParser#parse(java.io.InputStream,java.lang.String,java.net.URL)
*/
@Override
public void parse(InputStream input,String systemId,URL basePath) throws ParserConfigurationException,SAXException, IOException {
driver.setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_STREAM, input);
driver.setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_SYSTEM_ID, systemId);
driver.setProperty(X4OLanguagePropertyKeys.INPUT_SOURCE_BASE_PATH, basePath);
driver.parseInput();
}
/**
* Run a manual release phase to clean the parsing object tree.
*
* @throws X4OPhaseException
*/
public void doReleasePhaseManual() throws X4OPhaseException {
driver.doReleasePhaseManual();
}
/**
* Sets an X4O Language property.
* @param key The key of the property to set.
* @param value The vlue of the property to set.
*/
public void setProperty(String key,Object value) {
driver.setProperty(key, value);
}
/**
* Returns the value an X4O Language property.
* @param key The key of the property to get the value for.
* @return Returns null or the value of the property.
*/
public Object getProperty(String key) {
return driver.getProperty(key);
}
/**
* Loads the support ElementLanguage from the driver.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
return driver.loadElementLanguageSupport();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void addELBeanInstance(String name,Object bean) {
if (name==null) {
throw new NullPointerException("Can't add null name.");
}
if (name.isEmpty()) {
throw new NullPointerException("Can't add empty name.");
}
if (bean==null) {
throw new NullPointerException("Can't add null bean.");
}
Map map = (Map)getProperty(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP);
if (map==null) {
map = new HashMap<String,Object>(20);
setProperty(X4OLanguagePropertyKeys.EL_BEAN_INSTANCE_MAP, map);
}
map.put(name,bean);
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import org.x4o.xml.element.ElementLanguage;
/**
* X4OParserSupport is interface for language features without integration with parsing code.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public interface X4OParserSupport {
/**
* Loads the language ElementLanguage to provide support.
*
* @return Returns the ElementLanguage.
* @throws X4OParserSupportException
*/
ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException;
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
/**
* X4OParserSupportException is exception when executing an language supporting feature.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class X4OParserSupportException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10L;
/**
* Constructs an X4OWriteSchemaException without a detail message.
*/
public X4OParserSupportException() {
super();
}
/**
* Constructs an X4OWriteSchemaException with a detail message.
* @param message The message of this Exception
*/
public X4OParserSupportException(String message) {
super(message);
}
/**
* Creates an X4OWriteSchemaException from a parent exception.
* @param e The error exception.
*/
public X4OParserSupportException(Exception e) {
super(e);
}
/**
* Constructs an X4OWriteSchemaException with a detail message.
* @param message The message of this Exception
* @param e The error exception.
*/
public X4OParserSupportException(String message,Exception e) {
super(message,e);
}
}

View file

@ -0,0 +1,124 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
/**
* Defines the different phases of the x4o xml parser.
*
* @author Willem Cazander
* @version 1.0 Sep 1, 2008
*/
public enum X4OPhase {
/** Defines this meta startup phase */
startupX4OPhase(true),
/** Load all meta info of the language we are creating. */
createLanguagePhase(true),
/** Load all siblings languages. */
createLanguageSiblingsPhase(true),
/** Parse the xml from sax events. */
parseSAXStreamPhase(true),
/** Optional extra config phase for injecting bean instances into the EL context. */
configGlobalElBeansPhase(true),
/** emty meta phase to refer to that sax is ready and element s are waiting for processing */
startX4OPhase(true),
/** re runnable phases which config xml to beans and binds them together */
configElementPhase,
configElementInterfacePhase,
configGlobalElementPhase,
configGlobalAttributePhase,
/** Fill the bean attributes from the Element xml attributes. */
runAttributesPhase,
/** Fill in the x4o templating objects. */
fillTemplatingPhase,
/** transform phase , modifies the Element Tree. */
transformPhase,
/** Run the phases which needs to be runned again from a phase. */
runDirtyElementPhase(true),
/** Binds objects together */
bindElementPhase,
/** Run action stuff, we are ready with it. */
runPhase(true),
/** Rerun all needed phases for all element that requested it. */
runDirtyElementLastPhase,
/** Releases all Elements, which clears attributes and childeren etc.. */
releasePhase(true),
/** write all phases and stuff to debug sax stream */
debugPhase;
/** Defines which phase we start, when context is created. */
public static final X4OPhase FIRST_PHASE = startupX4OPhase;
/** The order in which the phases are executed */
static final X4OPhase[] PHASE_ORDER = { startupX4OPhase,
createLanguagePhase,createLanguageSiblingsPhase,
parseSAXStreamPhase,configGlobalElBeansPhase,
startX4OPhase,
configElementPhase,configElementInterfacePhase,configGlobalElementPhase,
configGlobalAttributePhase,runAttributesPhase,fillTemplatingPhase,
transformPhase,runDirtyElementPhase,bindElementPhase,
runPhase,runDirtyElementLastPhase,
releasePhase
};
/** Boolean indicating that this phase only may be run'ed once. */
private boolean runOnce = false;
/**
* Creates an X4O Phase
*/
private X4OPhase() {
}
/**
* Creates an X4O Phase
* @param runOnce Flag indicating that this phase is runnable multiple times.
*/
private X4OPhase(boolean runOnce) {
this.runOnce=runOnce;
}
/**
* Returns a flag indicating that this phase is runnable multiple times.
* @return True if phase is restricted to run once.
*/
public boolean isRunOnce() {
return runOnce;
}
}

View file

@ -0,0 +1,77 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
/**
* Is throw when there is en Exception within an Element.
*
* @author Willem Cazander
* @version 1.0 Jan 1, 2009
*/
public class X4OPhaseException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10l;
private X4OPhaseHandler exceptionPhase = null;
/**
* Creates an ElementException from a parent exception.
* @param exceptionPhase The handler which throwed.
* @param e The Exception.
*/
public X4OPhaseException(X4OPhaseHandler exceptionPhase,Exception e) {
super(e);
this.exceptionPhase=exceptionPhase;
}
/**
* Creates an ElementException from a parent exception.
* @param exceptionPhase The handler which throwed.
* @param message The message of the error.
*/
public X4OPhaseException(X4OPhaseHandler exceptionPhase,String message) {
super(message);
this.exceptionPhase=exceptionPhase;
}
/**
* Creates an ElementException from a parent exception.
* @param exceptionPhase The handler which throwed.
* @param message The message of the error.
* @param e The Exception.
*/
public X4OPhaseException(X4OPhaseHandler exceptionPhase,String message,Exception e) {
super(message,e);
this.exceptionPhase=exceptionPhase;
}
/**
* Returns the X4OPhaseHandler which created this Exception
* @return An X4OPhaseHandler
*/
public X4OPhaseHandler getX4OPhaseHandler() {
return exceptionPhase;
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.util.List;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementLanguage;
/**
* This is the starting point of the XML X4O parsing.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
public interface X4OPhaseHandler {
/**
* Returns the X4OPhase for which this handler was written.
* @return Returns the phase for which this handler works.
*/
X4OPhase getX4OPhase();
/**
* Runs this phase.
* @param elementLanguage
* @throws X4OPhaseException
*/
void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException;
/**
* Returns all X4OPhaseListeners which where added.
* @return All X4OPhaseListeners.
*/
List<X4OPhaseListener> getX4OPhaseListeners();
/**
* Adds an X4OPhaseListener
* @param listener
*/
void addPhaseListener(X4OPhaseListener listener);
/**
* Removes an X4OPhaseListener
* @param listener
*/
void removePhaseListener(X4OPhaseListener listener);
/**
* runPhase is called but should do nothig.
* When elementPhase is enables x4o tries to merge all element phases so
* we don't need to loop element tree to often.
* @return True if to run in config.
*/
boolean isElementPhase();
/**
* Run this phase for this Element.
* @param element
* @throws X4OPhaseException
*/
void runElementPhase(Element element) throws X4OPhaseException;
}

View file

@ -0,0 +1,951 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.el.ValueExpression;
import org.x4o.xml.conv.ObjectConverterException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.core.config.X4OLanguageLoader;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementAttributeValueParser;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementLanguageModuleLoaderSibling;
import org.x4o.xml.element.ElementNamespaceContext;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* Factory which can create X4OPhaseHandlers for all the predefined phases used in default x4o language parsing.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
public class X4OPhaseHandlerFactory {
private Logger logger = null;
private ElementLanguage elementLanguage = null;
private List<RunConfigurator> runConf = null;
public X4OPhaseHandlerFactory(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't start factory with null elementLanguage.");
}
this.elementLanguage=elementLanguage;
logger = Logger.getLogger(X4OPhaseHandlerFactory.class.getName());
runConf = new ArrayList<RunConfigurator>(10);
}
class RunConfigurator {
Element element;
ElementConfigurator elementConfigurator;
RunConfigurator(Element element,ElementConfigurator elementConfigurator) {
this.element=element;
this.elementConfigurator=elementConfigurator;
}
}
private void runElementConfigurators(List<ElementConfigurator> ecs,Element e,X4OPhaseHandler phase) throws X4OPhaseException {
int size = ecs.size();
for (int i=0;i<size;i++) {
ElementConfigurator ec = ecs.get(i);
if (ec.isConfigAction()) {
runConf.add(new RunConfigurator(e,ec));
return;
}
try {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementConfigurator(ec,e);
}
ec.doConfigElement(e);
// may request rerun of config
if (ec.isConfigAction()) {
runConf.add(new RunConfigurator(e,ec));
}
} catch (ElementException ee) {
throw new X4OPhaseException(phase,ee);
}
}
}
private void debugPhaseMessage(String message,X4OPhaseHandler phaseHandler) throws X4OPhaseException {
if (hasX4ODebugWriter()) {
try {
getX4ODebugWriter().debugPhaseMessage(message,phaseHandler.getClass());
} catch (ElementException ee) {
throw new X4OPhaseException(phaseHandler,ee);
}
}
}
private boolean hasX4ODebugWriter() {
return elementLanguage.getLanguageConfiguration().hasX4ODebugWriter();
}
private X4ODebugWriter getX4ODebugWriter() {
return elementLanguage.getLanguageConfiguration().getX4ODebugWriter();
}
/**
* Creates the startupX4OPhase which is a empty meta phase.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler startupX4OPhase() {
class CreateStartX4OPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.startupX4OPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
// print the properties and classes for this language/config
if (hasX4ODebugWriter()) {
try {
getX4ODebugWriter().debugLanguageProperties(elementLanguage);
getX4ODebugWriter().debugLanguageDefaultClasses(elementLanguage);
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}
}
}
};
X4OPhaseHandler result = new CreateStartX4OPhase();
return result;
}
/**
* Loads all the modules a language.
* Then creates the ElementProviders
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler createLanguagePhase() {
class CreateLanguagePhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.createLanguagePhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
debugPhaseMessage("Loading main language: "+elementLanguage.getLanguageConfiguration().getLanguage(),this);
X4OLanguageLoader loader = (X4OLanguageLoader)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultX4OLanguageLoader());
loader.loadLanguage(elementLanguage,elementLanguage.getLanguageConfiguration().getLanguage(),elementLanguage.getLanguageConfiguration().getLanguageVersion());
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementLanguageModules(elementLanguage);
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new CreateLanguagePhase();
return result;
}
/**
* Loads all sibling languages.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler createLanguageSiblingsPhase() {
class CreateLanguageSiblingsPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.createLanguageSiblingsPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
List<ElementLanguageModuleLoaderSibling> siblingLoaders = new ArrayList<ElementLanguageModuleLoaderSibling>(3);
for (ElementLanguageModule module:elementLanguage.getElementLanguageModules()) {
if (module.getElementLanguageModuleLoader() instanceof ElementLanguageModuleLoaderSibling) {
siblingLoaders.add((ElementLanguageModuleLoaderSibling)module.getElementLanguageModuleLoader());
}
}
if (siblingLoaders.isEmpty()==false) {
X4OLanguageLoader loader = (X4OLanguageLoader)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultX4OLanguageLoader());
for (ElementLanguageModuleLoaderSibling siblingLoader:siblingLoaders) {
debugPhaseMessage("Loading sibling langauge loader: "+siblingLoader,this);
siblingLoader.loadLanguageSibling(elementLanguage, loader);
}
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementLanguageModules(elementLanguage);
}
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new CreateLanguageSiblingsPhase();
return result;
}
/**
* Parses the xml resource(s) and creates an Element tree.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler parseSAXStreamPhase() {
class CreateSAXStreamPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.parseSAXStreamPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
//XMLParserConfiguration config = new XIncludeAwareParserConfiguration();
//config.setProperty("http://apache.org/xml/properties/internal/grammar-pool",myFullGrammarPool);
//SAXParser parser = new SAXParser(config);
// Create Sax parser with x4o tag handler
X4OTagHandler xth = new X4OTagHandler(elementLanguage);
XMLReader saxParser = XMLReaderFactory.createXMLReader();
saxParser.setErrorHandler(new X4OErrorHandler(elementLanguage));
saxParser.setEntityResolver(new X4OEntityResolver(elementLanguage));
saxParser.setContentHandler(xth);
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", xth);
saxParser.setProperty("http://xml.org/sax/properties/declaration-handler",xth);
// Set properties and optional
Map<String,Object> saxParserProperties = elementLanguage.getLanguageConfiguration().getSAXParserProperties();
for (Map.Entry<String,Object> entry:saxParserProperties.entrySet()) {
String name = entry.getKey();
Object value= entry.getValue();
saxParser.setProperty(name, value);
debugPhaseMessage("Set SAX property: "+name+" to: "+value,this);
}
Map<String,Object> saxParserPropertiesOptional = elementLanguage.getLanguageConfiguration().getSAXParserPropertiesOptional();
for (Map.Entry<String,Object> entry:saxParserPropertiesOptional.entrySet()) {
String name = entry.getKey();
Object value= entry.getValue();
try {
saxParser.setProperty(name, value);
debugPhaseMessage("Set SAX optional property: "+name+" to: "+value,this);
} catch (SAXException e) {
debugPhaseMessage("Could not set optional SAX property: "+name+" to: "+value+" error: "+e.getMessage(),this);
}
}
// Set sax features and optional
Map<String, Boolean> features = elementLanguage.getLanguageConfiguration().getSAXParserFeatures();
for (String key:features.keySet()) {
Boolean value=features.get(key);
saxParser.setFeature(key, value);
debugPhaseMessage("Set SAX feature: "+key+" to: "+value,this);
}
Map<String, Boolean> featuresOptional = elementLanguage.getLanguageConfiguration().getSAXParserFeaturesOptional();
for (String key:featuresOptional.keySet()) {
Boolean value=featuresOptional.get(key);
try {
saxParser.setFeature(key, value);
debugPhaseMessage("Set SAX optional feature: "+key+" to: "+value,this);
} catch (SAXException e) {
debugPhaseMessage("Could not set optional SAX feature: "+key+" to: "+value+" error: "+e.getMessage(),this);
}
}
// check for required features
List<String> requiredFeatures = elementLanguage.getLanguageConfiguration().getSAXParserFeaturesRequired();
for (String requiredFeature:requiredFeatures) {
debugPhaseMessage("Checking required SAX feature: "+requiredFeature,this);
if (saxParser.getFeature(requiredFeature)==false) {
Exception e = new IllegalStateException("Missing required feature: "+requiredFeature);
throw new X4OPhaseException(this,e);
}
}
// Finally start parsing the xml input stream
Object requestInputSource = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_OBJECT);
InputSource input = null;
InputStream inputStream = null;
if (requestInputSource instanceof InputSource) {
input = (InputSource)requestInputSource;
} else {
inputStream = (InputStream)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_STREAM);
input = new InputSource(inputStream);
}
Object requestInputEncoding = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_ENCODING);
if (requestInputEncoding!=null && requestInputEncoding instanceof String) {
input.setEncoding(requestInputEncoding.toString());
}
Object requestSystemId = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_SOURCE_SYSTEM_ID);
if (requestSystemId!=null && requestSystemId instanceof String) {
input.setSystemId(requestSystemId.toString());
}
try {
saxParser.parse(input);
} finally {
if (inputStream!=null) {
inputStream.close();
}
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new CreateSAXStreamPhase();
return result;
}
/**
* Creates the startX4OPhase which is a empty meta phase.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler startX4OPhase() {
class CreateStartX4OPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.startX4OPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
// empty because this is a meta phase.
}
};
X4OPhaseHandler result = new CreateStartX4OPhase();
return result;
}
/**
* Creates the configGlobalElBeansPhase which adds beans to the el context.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configGlobalElBeansPhase() {
class ConfigGlobalElBeansPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configGlobalElBeansPhase;
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// not used.
}
@SuppressWarnings("rawtypes")
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
Map beanMap = (Map)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (beanMap==null) {
return;
}
for (Object elName:beanMap.keySet()) {
Object o = beanMap.get(elName);
ValueExpression ve = elementLanguage.getExpressionFactory().createValueExpression(elementLanguage.getELContext(),"${"+elName+"}", o.getClass());
ve.setValue(elementLanguage.getELContext(), o);
debugPhaseMessage("Setting el bean: ${"+elName+"} to: "+o.getClass().getName(),this);
}
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
};
X4OPhaseHandler result = new ConfigGlobalElBeansPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configElementPhase() {
class ConfigElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// First phase is to rename attributes, maybe move so sax phase
for (ElementClassAttribute eca:element.getElementClass().getElementClassAttributes()) {
List<String> aliases = eca.getAttributeAliases();
if (aliases.isEmpty()) {
continue;
}
for (String alias:aliases) {
if (element.getAttributes().containsKey(alias)) {
String attributeValue = element.getAttributes().get(alias);
element.getAttributes().put(eca.getName(), attributeValue);
element.getAttributes().remove(alias);
}
}
}
logger.finest("Do ElementClass Config Configurators: "+element.getElementClass().getElementConfigurators().size());
runElementConfigurators(element.getElementClass().getElementConfigurators(),element,this);
}
};
X4OPhaseHandler result = new ConfigElementPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configElementInterfacePhase() {
class ConfigElementInterfacePhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configElementInterfacePhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.getElementObject()==null) {
logger.finest("Null elementObject skipping, interfaces");
return;
}
for (ElementInterface ei:element.getElementLanguage().findElementInterfaces(element.getElementObject())) {
logger.finest("Do ElementInterface Config Configurators: "+element.getElementClass().getElementConfigurators().size());
runElementConfigurators(ei.getElementConfigurators(),element,this);
}
}
};
X4OPhaseHandler result = new ConfigElementInterfacePhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configGlobalElementPhase() {
class ConfigGlobalElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.configGlobalElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
for (ElementLanguageModule mod:element.getElementLanguage().getElementLanguageModules()) {
logger.finest("Do Element Config Global Configurators: "+mod.getGlobalElementConfigurators().size());
runElementConfigurators(mod.getGlobalElementConfigurators(),element,this);
}
}
};
X4OPhaseHandler result = new ConfigGlobalElementPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler configGlobalAttributePhase() {
class ConfigGlobalAttributePhase extends AbstractX4OPhaseHandler {
Comparator<ElementAttributeHandler> elementAttributeHandlerComparator = null;
protected void setX4OPhase() {
phase = X4OPhase.configGlobalAttributePhase;
}
@SuppressWarnings("unchecked")
public void runElementPhase(Element element) throws X4OPhaseException {
if (elementAttributeHandlerComparator==null) {
try {
elementAttributeHandlerComparator = (Comparator<ElementAttributeHandler>)X4OLanguageClassLoader.newInstance(element.getElementLanguage().getLanguageConfiguration().getDefaultElementAttributeHandlerComparator());
} catch (Exception e) {
throw new X4OPhaseException(this,e);
}
}
// do global parameters
logger.finest("Do Element Global AttributeHandlers.");
List<ElementAttributeHandler> handlers = new ArrayList<ElementAttributeHandler>();
for (ElementLanguageModule mod:element.getElementLanguage().getElementLanguageModules()) {
for (ElementAttributeHandler global:mod.getElementAttributeHandlers()) {
String attribute = element.getAttributes().get(global.getAttributeName());
if (attribute!=null) {
handlers.add(global);
}
}
}
Collections.sort(handlers,elementAttributeHandlerComparator);
List<ElementConfigurator> handlers2 = new ArrayList<ElementConfigurator>(handlers.size());
handlers2.addAll(handlers);
runElementConfigurators(handlers2,element,this);
}
};
X4OPhaseHandler result = new ConfigGlobalAttributePhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runAttributesPhase() {
class RunAttributesPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.runAttributesPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
// we only can config ElementObjects
if (element.getElementObject()==null) {
return;
}
// do config
Map<String,String> attr = element.getAttributes();
ElementAttributeValueParser attrParser = element.getElementLanguage().getElementAttributeValueParser();
Boolean autoAttributes = element.getElementClass().getAutoAttributes();
if (autoAttributes==null) {
autoAttributes = true;
}
try {
for (String name:attr.keySet()) {
String valueString = (String)attr.get(name);
if (valueString==null) {
continue;
}
Object value = valueString;
ElementClassAttribute attrClass = element.getElementClass().getElementClassAttributeByName(name);
if (attrClass!=null) {
if (attrClass.getRunResolveEL()==null || attrClass.getRunResolveEL()) {
if (attrParser.isELParameter(name, valueString, element)) {
value = attrParser.getELParameterValue(valueString, element);
}
}
if (attrClass.getRunConverters()==null || attrClass.getRunConverters()) {
value = attrParser.getConvertedParameterValue(name, value, element);
}
if (attrClass.getRunBeanFill()==null || attrClass.getRunBeanFill()) {
element.getElementLanguage().getElementObjectPropertyValue().setProperty(element.getElementObject(), name, value);
}
} else if (autoAttributes) {
value = attrParser.getParameterValue(name,valueString,element);
element.getElementLanguage().getElementObjectPropertyValue().setProperty(element.getElementObject(), name, value);
} else {
continue; // skip all non auto attribute non attribute defined xml attributes, or throw exception ?
}
}
// check for defaults
for (ElementClassAttribute attrClass:element.getElementClass().getElementClassAttributes()) {
if (attrClass.getDefaultValue()!=null && attr.containsKey(attrClass.getName())==false) {
Object value = null;
if (attrClass.getDefaultValue() instanceof String) {
value = attrParser.getParameterValue(attrClass.getName(),(String)attrClass.getDefaultValue(),element);
} else {
value = attrClass.getDefaultValue();
}
if (attrClass.getRunBeanFill()==null || attrClass.getRunBeanFill()) {
element.getElementLanguage().getElementObjectPropertyValue().setProperty(element.getElementObject(), attrClass.getName(), value);
}
}
}
} catch (ObjectConverterException oce) {
throw new X4OPhaseException(this,"Error while converting parameters: "+oce.getMessage(),oce);
} catch (ElementException e) {
throw new X4OPhaseException(this,"Error while setting parameters: "+e.getMessage(),e);
}
}
};
X4OPhaseHandler result = new RunAttributesPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler fillTemplatingPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.fillTemplatingPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
};
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler transformPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.transformPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.isTransformingTree()==false) {
return;
}
try {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElement(element);
}
element.doElementRun();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}
}
};
return result;
}
/**
*
* @param manager The phasemanager.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runDirtyElementPhase(final X4OPhaseManager manager) {
class RunDirtyElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.runDirtyElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
Map<Element,X4OPhase> dirtyElements = element.getElementLanguage().getDirtyElements();
if (dirtyElements.isEmpty()) {
return;
}
debugPhaseMessage("Dirty elements: "+dirtyElements.size(), this);
for (Element e:dirtyElements.keySet()) {
X4OPhase p = dirtyElements.get(e);
manager.runPhasesForElement(e, p);
}
element.getElementLanguage().getDirtyElements().clear();
}
};
X4OPhaseHandler result = new RunDirtyElementPhase();
return result;
}
/**
*
* @param manager The phasemanager.
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runDirtyElementLastPhase(final X4OPhaseManager manager) {
class RunDirtyElementLastPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.runDirtyElementLastPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
Map<Element,X4OPhase> dirtyElements = element.getElementLanguage().getDirtyElements();
if (dirtyElements.isEmpty()) {
return;
}
debugPhaseMessage("Dirty elements last: "+dirtyElements.size(), this);
for (Element e:dirtyElements.keySet()) {
X4OPhase p = dirtyElements.get(e);
manager.runPhasesForElement(e, p);
}
element.getElementLanguage().getDirtyElements().clear();
}
};
X4OPhaseHandler result = new RunDirtyElementLastPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler bindElementPhase() {
class BindElementPhase extends AbstractX4OPhaseHandler {
protected void setX4OPhase() {
phase = X4OPhase.bindElementPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
Element parentElement = element.getParent();
if(parentElement==null) {
logger.finest("No parent element, so no binding needed.");
return;
}
Object parentObject = parentElement.getElementObject();
if(parentObject==null) {
logger.finest("No parent object, so no binding needed.");
return;
}
Object childObject = element.getElementObject();
if (childObject==null) {
logger.finest("No child object, so no binding needed.");
return;
}
List<ElementBindingHandler> binds = element.getElementLanguage().findElementBindingHandlers(parentObject, childObject);
logger.finest("Calling bindings handlers; "+binds.size());
try {
for (ElementBindingHandler binding:binds) {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementBindingHandler(binding,element);
}
binding.doBind(parentObject,childObject,element);
}
} catch (ElementException e) {
throw new X4OPhaseException(this,"Error while binding",e);
}
}
};
X4OPhaseHandler result = new BindElementPhase();
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler runPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.runPhase;
}
public void runElementPhase(Element element) throws X4OPhaseException {
if (element.isTransformingTree()) {
return; // has already runned.
}
try {
//if (parser.hasX4ODebugWriter()) {
// parser.getX4ODebugWriter().debugElement(element);
//}
element.doElementRun();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
}
}
};
class RunConfiguratorPhaseListener implements X4OPhaseListener {
/**
* @see org.x4o.xml.core.X4OPhaseListener#preRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
}
/**
* @see org.x4o.xml.core.X4OPhaseListener#endRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
for (RunConfigurator conf:runConf) {
try {
if (hasX4ODebugWriter()) {
getX4ODebugWriter().debugElementConfigurator(conf.elementConfigurator,conf.element);
}
conf.elementConfigurator.doConfigElement(conf.element);
} catch (ElementException e) {
throw new X4OPhaseException(phase,e);
}
}
}
}
result.addPhaseListener(new RunConfiguratorPhaseListener());
return result;
}
/**
*
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler releasePhase() {
// for debug output
class ReleasePhaseListener implements X4OPhaseListener {
private int elementsReleased = 0;
/**
* @see org.x4o.xml.core.X4OPhaseListener#preRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
elementsReleased=0;
}
/**
* @see org.x4o.xml.core.X4OPhaseListener#endRunPhase(org.x4o.xml.core.X4OPhaseHandler, org.x4o.xml.element.ElementLanguage)
*/
public void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException {
if (hasX4ODebugWriter()==false) {
return;
}
try {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "elements", "", "", elementsReleased+"");
getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "executeReleases", "", atts);
getX4ODebugWriter().getDebugWriter().endElement (X4ODebugWriter.DEBUG_URI, "executeReleases" , "");
} catch (SAXException e) {
throw new X4OPhaseException(phase,e);
}
}
public void addReleasedElement() {
elementsReleased++;
}
}
final ReleasePhaseListener releaseCounter = new ReleasePhaseListener();
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.releasePhase;
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
}
public void runElementPhase(Element element) throws X4OPhaseException {
try {
element.release();
} catch (ElementException e) {
throw new X4OPhaseException(this,e);
} finally {
releaseCounter.addReleasedElement();
}
}
};
result.addPhaseListener(releaseCounter);
return result;
}
/**
* Creates an debug phase
* @return The X4OPhaseHandler for this phase.
*/
public X4OPhaseHandler debugPhase() {
X4OPhaseHandler result = new AbstractX4OPhaseHandler() {
protected void setX4OPhase() {
phase = X4OPhase.debugPhase;
// safety check
if (hasX4ODebugWriter()==false) {
throw new NullPointerException("Use debugPhase only when X4OParser.debugWriter is filled.");
}
}
public boolean isElementPhase() {
return false;
}
public void runElementPhase(Element element) throws X4OPhaseException {
}
public void runPhase(ElementLanguage elementLanguage) throws X4OPhaseException {
try {
AttributesImpl atts = new AttributesImpl();
//atts.addAttribute ("", key, "", "", value);
//atts.addAttribute ("", "verbose", "", "", "true");
getX4ODebugWriter().getDebugWriter().startElement (X4ODebugWriter.DEBUG_URI, "printElementTree", "", atts);
startedPrefix.clear();
printXML(elementLanguage.getRootElement());
for (String prefix:startedPrefix) {
getX4ODebugWriter().getDebugWriter().endPrefixMapping(prefix);
}
getX4ODebugWriter().getDebugWriter().endElement(X4ODebugWriter.DEBUG_URI, "printElementTree", "");
getX4ODebugWriter().debugElementLanguage(elementLanguage);
} catch (SAXException e) {
throw new X4OPhaseException(this,e);
}
}
List<String> startedPrefix = new ArrayList<String>(10);
// note: slow version
private String getNamespaceForElement(Element e) {
for (ElementLanguageModule mod:e.getElementLanguage().getElementLanguageModules()) {
for (ElementNamespaceContext enc:mod.getElementNamespaceContexts()) {
List<ElementClass> l = enc.getElementClasses();
if (l.contains(e.getElementClass())) {
return enc.getUri();
}
}
}
return null;
}
private void printXML(Element element) throws SAXException {
if (element==null) {
throw new SAXException("Can't print debug xml of null element.");
}
DefaultHandler2 handler = getX4ODebugWriter().getDebugWriter();
if (element.getElementType().equals(Element.ElementType.comment)) {
char[] msg = ((String)element.getElementObject()).toCharArray();
handler.comment(msg,0,msg.length);
return;
}
if (element.getElementType().equals(Element.ElementType.characters)) {
char[] msg = ((String)element.getElementObject()).toCharArray();
handler.characters(msg,0,msg.length);
return;
}
if (element.getElementClass()==null) {
throw new SAXException("Element without ElementClass is not valid: "+element+" obj: "+element.getElementObject());
}
AttributesImpl atts = new AttributesImpl();
for (String key:element.getAttributes().keySet()) {
String value = element.getAttributes().get(key);
//uri, localName, xml1.0name, type, value
atts.addAttribute ("", key, "", "", value);
}
String nameSpace = getNamespaceForElement(element);
String prefix = element.getElementLanguage().findElementNamespaceContext(nameSpace).getPrefixMapping();
if (startedPrefix.contains(prefix)==false) {
handler.startPrefixMapping(prefix, nameSpace);
startedPrefix.add(prefix);
}
handler.startElement (nameSpace, element.getElementClass().getTag(), "", atts);
for (Element e:element.getAllChilderen()) {
printXML(e);
}
handler.endElement (nameSpace, element.getElementClass().getTag(), "");
}
};
return result;
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import org.x4o.xml.element.ElementLanguage;
/**
* An X4OPhaseListener can be placed on an X4OPhaseHandler and is called
* before and after the phase has runned.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2008
*/
public interface X4OPhaseListener {
/**
* Gets called before the X4OPhaseHandler is run.
* @param phase The phase to be run.
* @param elementLanguage The elementLanguage of the driver.
* @throws X4OPhaseException Is throws when listeners has error.
*/
void preRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException;
/**
* Gets called after the X4OPhaseHandler is runned.
* @param phase The phase just run.
* @param elementLanguage The elementLanguage of the driver.
* @throws X4OPhaseException Is throws when listeners has error.
*/
void endRunPhase(X4OPhaseHandler phase,ElementLanguage elementLanguage) throws X4OPhaseException;
}

View file

@ -0,0 +1,291 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementLanguage;
/**
* X4OPhaseManager stores the X4OPhaseHandler and puts them in the right order
* and will execute the phases when runPhases is called.
*
* @author Willem Cazander
* @version 1.0 Jan 6, 2008
*/
public class X4OPhaseManager {
/** The X4OPhaseHandler */
private List<X4OPhaseHandler> x4oPhases = null;
private ElementLanguage elementLanguage = null;
private X4OPhase stopPhase = null;
private boolean skipReleasePhase = false;
private boolean skipRunPhase = false;
private boolean skipSiblingsPhase = false;
/**
* Local package constuctor
*/
public X4OPhaseManager(ElementLanguage elementLanguage) {
if (elementLanguage==null) {
throw new NullPointerException("Can't manage phases with null elementLanguage in constuctor.");
}
x4oPhases = new ArrayList<X4OPhaseHandler>(15);
this.elementLanguage = elementLanguage;
// Manual
skipReleasePhase = elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RELEASE);
skipRunPhase = elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_RUN);
skipSiblingsPhase = elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.PHASE_SKIP_SIBLINGS);
// Check if we need to stop after a certain phase
Object stopPhaseObject = elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.PHASE_STOP_AFTER);
if (stopPhaseObject instanceof X4OPhase) {
stopPhase = (X4OPhase)stopPhaseObject;
}
}
/**
* Adds an X4OPhaseHandler.
* @param phase The X4OPhaseHandler to add.
*/
public void addX4OPhaseHandler(X4OPhaseHandler phase) {
if (phase==null) {
throw new NullPointerException("Can't add null phase handler.");
}
// context is created in first phase.
if (X4OPhase.FIRST_PHASE.equals(elementLanguage.getCurrentX4OPhase())==false) {
throw new IllegalStateException("Can't add new phases after first phase is completed.");
}
x4oPhases.add(phase);
}
/**
* Returns all the X4OPhaseHandlers.
* @return Returns all X4OPhaseHandlers.
*/
protected List<X4OPhaseHandler> getPhases() {
return x4oPhases;
}
/**
* Returns all the X4OPhaseHandlers in ordered list.
* @return Returns all X4OPhaseHandler is order.
*/
protected List<X4OPhaseHandler> getOrderedPhases() {
List<X4OPhaseHandler> result = new ArrayList<X4OPhaseHandler>(x4oPhases);
Collections.sort(result,new X4OPhaseHandlerComparator());
return result;
}
/**
* Runs all the phases in the right order.
* @throws X4OPhaseException
*/
public void runPhases() throws X4OPhaseException {
// sort for the order
List<X4OPhaseHandler> x4oPhasesOrder = getOrderedPhases();
// debug output
if (elementLanguage.getLanguageConfiguration().getX4ODebugWriter()!=null) {
elementLanguage.getLanguageConfiguration().getX4ODebugWriter().debugPhaseOrder(x4oPhases);
}
// run the phases in ordered order
for (X4OPhaseHandler phaseHandler:x4oPhasesOrder) {
if (skipReleasePhase && X4OPhase.releasePhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip always release phase when requested by property
}
if (skipRunPhase && X4OPhase.runPhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip run phase on request
}
if (skipSiblingsPhase && X4OPhase.createLanguageSiblingsPhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip loading sibling languages
}
// debug output
elementLanguage.setCurrentX4OPhase(phaseHandler.getX4OPhase());
// run listeners
for (X4OPhaseListener l:phaseHandler.getX4OPhaseListeners()) {
l.preRunPhase(phaseHandler, elementLanguage);
}
// always run endRunPhase for valid debug xml
try {
// do the run interface
phaseHandler.runPhase(elementLanguage);
// run the element phase if possible
executePhaseElement(phaseHandler);
} finally {
// run the listeners again
for (X4OPhaseListener l:phaseHandler.getX4OPhaseListeners()) {
l.endRunPhase(phaseHandler, elementLanguage);
}
}
if (stopPhase!=null && stopPhase.equals(phaseHandler.getX4OPhase())) {
return; // we are done
}
}
}
public void runPhasesForElement(Element e,X4OPhase p) throws X4OPhaseException {
// sort for the order
List<X4OPhaseHandler> x4oPhasesOrder = getOrderedPhases();
for (X4OPhaseHandler phaseHandler:x4oPhasesOrder) {
if (phaseHandler.getX4OPhase().equals(p)==false) {
continue; // we start running all phases from specified phase
}
if (X4OPhase.releasePhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip always release phase in dirty extra runs.
}
if (skipRunPhase && X4OPhase.runPhase.equals(phaseHandler.getX4OPhase())) {
continue; // skip run phase on request
}
// set phase
elementLanguage.setCurrentX4OPhase(phaseHandler.getX4OPhase());
// do the run interface
phaseHandler.runPhase(elementLanguage);
// run the element phase if possible
executePhaseElement(phaseHandler);
if (stopPhase!=null && stopPhase.equals(phaseHandler.getX4OPhase())) {
return; // we are done
}
}
}
public void doReleasePhaseManual() throws X4OPhaseException {
if (skipReleasePhase==false) {
throw new IllegalStateException("No manual release requested.");
}
if (elementLanguage.getRootElement()==null) {
return; // no root element , empty xml document ?
}
if (elementLanguage.getRootElement().getElementClass()==null) {
throw new IllegalStateException("Release phase has already been runned.");
}
X4OPhaseHandler h = null;
for (X4OPhaseHandler phase:x4oPhases) {
if (phase.getX4OPhase().equals(X4OPhase.releasePhase)) {
h = phase;
break;
}
}
if (h==null) {
throw new IllegalStateException("No release phase found in manager to run.");
}
// set phase
elementLanguage.setCurrentX4OPhase(h.getX4OPhase());
// do the run interface
h.runPhase(elementLanguage);
// run the element phase if possible
executePhaseElement(h);
}
class X4OPhaseHandlerComparator implements Comparator<X4OPhaseHandler> {
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(X4OPhaseHandler e1, X4OPhaseHandler e2) {
X4OPhase p1 = e1.getX4OPhase();
X4OPhase p2 = e2.getX4OPhase();
if (p1==p2) {
return 0;
}
if (p1==X4OPhase.debugPhase) {
return 0;
}
if (p2==X4OPhase.debugPhase) {
return 0;
}
int i1 = phaseOrder(p1);
int i2 = phaseOrder(p2);
if (i1>i2) {
return 1;
}
if (i1<i2) {
return -1;
}
return 0;
}
private int phaseOrder(X4OPhase check) {
int result=0;
for (X4OPhase p:X4OPhase.PHASE_ORDER) {
if (p==check) {
return result;
}
result++;
}
return -1;
}
}
private void executePhaseElement(X4OPhaseHandler phase) throws X4OPhaseException {
if (elementLanguage.getRootElement()==null) {
return;
}
executePhaseTree(elementLanguage.getRootElement(),phase);
}
/**
* todo: rewrite to itterator for big deep trees
*
* @param element
* @param phase
* @throws X4OPhaseException
*/
private void executePhaseTree(Element element,X4OPhaseHandler phase) throws X4OPhaseException {
if (element.getElementClass().getSkipPhases().contains(phase.getX4OPhase().name())==false) {
phase.runElementPhase(element);
}
for (Element e:element.getChilderen()) {
executePhaseTree(e,phase);
}
}
}

View file

@ -0,0 +1,294 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.Element.ElementType;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.sax.AttributeMap;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.ext.DefaultHandler2;
import java.util.Map;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* This class handels all the X4O tags.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public class X4OTagHandler extends DefaultHandler2 {
/** The logger to log to */
private Logger logger = null;
private boolean loggerFinest = false;
/** The Locator for parse errors */
private Locator locator = null;
/** The element Stack */
private Stack<Element> elementStack = null;
/** The elememtContext */
private ElementLanguage elementLanguage = null;
/** Store the override element */
private Element overrideSaxElement = null;
/** Store the override element handler */
private DefaultHandler2 overrideSaxHandler = null;
/**
* Creates an X4OTagHandler
* which can receice sax xml events and converts them into the Element* interfaces events.
*/
public X4OTagHandler(ElementLanguage elementLanguage) {
logger = Logger.getLogger(X4OTagHandler.class.getName());
loggerFinest = logger.isLoggable(Level.FINEST);
elementStack = new Stack<Element>();
this.elementLanguage = elementLanguage;
}
/**
* @see org.xml.sax.helpers.DefaultHandler#setDocumentLocator(org.xml.sax.Locator)
*/
@Override
public void setDocumentLocator(Locator locator) {
this.locator=locator;
}
/**
* @see org.xml.sax.helpers.DefaultHandler#startPrefixMapping(java.lang.String, java.lang.String)
*/
@Override
public void startPrefixMapping(String prefix, String namespaceUri) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.startPrefixMapping(prefix, namespaceUri);
return;
}
if ("http://www.w3.org/2001/XMLSchema-instance".equals(namespaceUri)) {
return; // skip schema ns if non validating
}
if ("http://www.w3.org/2001/XInclude".equals(namespaceUri)) {
return; // skip xinclude ns.
}
ElementNamespaceContext enc = elementLanguage.findElementNamespaceContext(namespaceUri);
if (enc==null) {
throw new SAXException("Can't find namespace uri: "+namespaceUri+" in language: "+elementLanguage.getLanguageConfiguration().getLanguage());
}
enc.setPrefixMapping(prefix);
}
/**
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(String namespaceUri, String tag, String qName,Attributes attributes) throws SAXException {
if (loggerFinest) {
logger.finest("XMLTAG-START: "+namespaceUri+":"+tag);
}
if (overrideSaxHandler!=null) {
overrideSaxHandler.startElement(namespaceUri, tag, qName, attributes);
return;
}
ElementNamespaceContext enc = elementLanguage.findElementNamespaceContext(namespaceUri);
if (enc==null) {
if ("".equals(namespaceUri)) {
String configEmptryUri = (String)elementLanguage.getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.INPUT_EMPTY_NAMESPACE_URI);
if (configEmptryUri!=null) {
namespaceUri = configEmptryUri;
enc = elementLanguage.findElementNamespaceContext(namespaceUri);
}
if (enc==null) {
throw new SAXParseException("No ElementNamespaceContext found for empty namespace.",locator);
}
enc.setPrefixMapping("");
}
if (enc==null) {
throw new SAXParseException("No ElementProvider found for namespace: "+namespaceUri,locator);
}
}
ElementNamespaceInstanceProvider eip = enc.getElementNamespaceInstanceProvider();
Element element = null;
try {
element = eip.createElementInstance(tag);
} catch (Exception e) {
throw new SAXParseException("Error while creating element: "+e.getMessage(),locator,e);
}
enc.addElementClass(element.getElementClass());
// next bind them togeter.
if (elementStack.empty()) {
elementLanguage.setRootElement(element); // root element !!
} else {
Element parent = elementStack.peek();
element.setParent(parent); // set parent element
parent.addChild(element);
}
// create attribute map
Map<String,String> map = new AttributeMap<String,String>(attributes);
element.getAttributes().putAll(map);
elementStack.push(element);
try {
element.doElementStart();
} catch (ElementException ee) {
throw new SAXParseException("Error while configing element: "+ee.getMessage(),locator,ee);
}
if (ElementType.overrideSax.equals(element.getElementType())) {
overrideSaxElement = element;
overrideSaxHandler = (DefaultHandler2)element.getElementObject();
}
}
/**
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void endElement(String namespaceUri, String tag,String qName) throws SAXException {
if (loggerFinest) {
logger.finest("XMLTAG-END: "+namespaceUri+":"+tag);
}
if (overrideSaxHandler!=null) {
if (overrideSaxElement.getElementClass().getTag().equals(tag)) {
overrideSaxHandler.endDocument();
overrideSaxHandler = null;
overrideSaxElement = null; // elementStack code make sure doElementEnd is runned on override element.
} else {
overrideSaxHandler.endElement(namespaceUri, tag, qName);
return;
}
}
if (elementStack.empty()) {
return;
}
Element element = elementStack.pop();
try {
element.doElementEnd();
} catch (ElementException ee) {
throw new SAXParseException("Error while configing element: '"+tag+"' "+ee.getMessage(),locator,ee);
}
}
/**
* Gets called to pass the text between XML-tags and converts it to a String.
* When this string is 0 length then nothing is done.
* If there are no element on the stact noting is done.
*
* @see org.xml.sax.helpers.DefaultHandler#characters(char[],int,int)
*/
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.characters(ch, start, length);
return;
}
if (length==0) {
return; // no text
}
String text = new String(ch,start,length);
if (text.isEmpty()) {
return; // no text
}
if (elementStack.empty()) {
return; // no element
}
Element e = elementStack.peek();
try {
e.doCharacters(text);
} catch (ElementException ee) {
throw new SAXParseException("Error while doCharacters element: '"+e.getElementClass().getTag()+"' "+ee.getMessage(),locator,ee);
}
}
/**
* @see org.xml.sax.helpers.DefaultHandler#ignorableWhitespace(char[], int, int)
*/
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.ignorableWhitespace(ch, start, length);
return;
}
String text = new String(ch);
text = text.substring(start, start + length);
if (text.length()==0) {
return; // no text
}
if (elementStack.empty()) {
return; // no element
}
Element e = elementStack.peek();
try {
e.doIgnorableWhitespace(text);
} catch (ElementException ee) {
throw new SAXParseException("Error while doIgnorableWhitespace element: '"+e.getElementClass().getTag()+"' "+ee.getMessage(),locator,ee);
}
}
/**
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
*/
@Override
public void comment(char[] ch, int start, int length) throws SAXException {
if (overrideSaxHandler!=null) {
overrideSaxHandler.comment(ch, start, length);
return;
}
String text = new String(ch);
text = text.substring(start, start + length);
if (text.length()==0) {
return; // no text
}
if (elementStack.empty()) {
return; // no element
}
Element e = elementStack.peek();
try {
e.doComment(text);
} catch (ElementException ee) {
throw new SAXParseException("Error while doComment element: '"+e.getElementClass().getTag()+"' "+ee.getMessage(),locator,ee);
}
}
/**
* @see org.xml.sax.helpers.DefaultHandler#processingInstruction(java.lang.String, java.lang.String)
*/
@Override
public void processingInstruction(String target, String data) throws SAXException {
logger.fine("Skipping process instuctions: "+target+" data: "+data);
}
}

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
/**
* X4OLanguageClassLoader is short hand for safe class loading.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public class X4OLanguageClassLoader {
/**
* Gets the thread classloader or the normal classloader.
* @return Returns the ClassLoader.
*/
public static ClassLoader getClassLoader() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = X4OLanguageClassLoader.class.getClassLoader();
}
return cl;
}
/**
* Loads a Class from the ContextClassLoader and if that is not set, then
* uses the class of the String className instance.
*
* @param className The class name to load
* @return The loaded class
* @throws ClassNotFoundException if class not loaded.
*/
public static Class<?> loadClass(String className) throws ClassNotFoundException {
return getClassLoader().loadClass(className);
}
/**
* Creates new instance of clazz.
* @param clazz The class to make object from.
* @return The object of the clazz.
* @throws InstantiationException When className has no default constructor.
* @throws IllegalAccessException When class loading has security error.
*/
public static Object newInstance(Class<?> clazz) throws InstantiationException, IllegalAccessException {
return clazz.newInstance();
}
/**
* Creates new instance of className.
* @param className The className to create object from.
* @return The object of the className.
* @throws ClassNotFoundException When className is not found.
* @throws InstantiationException When className has no default constructor.
* @throws IllegalAccessException When class loading has security error.
*/
public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return newInstance(loadClass(className));
}
}

View file

@ -0,0 +1,147 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
import java.util.List;
import java.util.Map;
import org.x4o.xml.core.X4ODebugWriter;
import org.x4o.xml.element.ElementLanguage;
/**
* X4OLanguageConfiguration first used interface in x4o parser which does the hard config of the x4o xml parsing.
*
* @author Willem Cazander
* @version 1.0 27 Oct 2009
*/
public interface X4OLanguageConfiguration {
/** Prefix where we load all language definitions from. */
public final static String DEFAULT_LANG_PATH_PREFIX = "META-INF";
/** The modules file to startup the language definition process. */
public final static String DEFAULT_LANG_MODULES_FILE = "-modules.xml";
/**
* Returns the language for which this ElementLanguage is created.
* @return Returns the language.
*/
String getLanguage();
/**
* @return Returns the languageVersion of the parsing of this language.
*/
String getLanguageVersion();
/**
* @return Returns the path prefix for loading language resources.
*/
String getLanguageResourcePathPrefix();
/**
* @return Returns the filename (postfix) of the modules definition file.
*/
String getLanguageResourceModulesFileName();
Object getLanguageProperty(X4OLanguageProperty property);
void setLanguageProperty(X4OLanguageProperty property,Object object);
boolean getLanguagePropertyBoolean(X4OLanguageProperty property);
int getLanguagePropertyInteger(X4OLanguageProperty property);
// Core interfaces are also in class for text reference without instance
public Class<?> getDefaultElementNamespaceContext();
public Class<?> getDefaultElementInterface();
public Class<?> getDefaultElement();
public Class<?> getDefaultElementClass();
public Class<?> getDefaultElementClassAttribute();
// Other needed interfaces in class form also
public Class<?> getDefaultElementLanguageModule();
public Class<?> getDefaultElementBodyComment();
public Class<?> getDefaultElementBodyCharacters();
public Class<?> getDefaultElementBodyWhitespace();
public Class<?> getDefaultElementNamespaceInstanceProvider();
public Class<?> getDefaultElementAttributeValueParser();
public Class<?> getDefaultElementObjectPropertyValue();
public Class<?> getDefaultElementAttributeHandlerComparator();
/**
* @return Returns the X4OLanguageVersionFilter which filters the best version to use.
*/
public Class<?> getDefaultX4OLanguageVersionFilter();
/**
* @return Returns the X4OLanguageLoader which loads languages into the element context.
*/
public Class<?> getDefaultX4OLanguageLoader();
/**
* Creates and filles the inital element language used to store the language.
* @return The newly created ElementLanguage.
*/
public ElementLanguage createElementLanguage();
/**
* @return Returns Map of SAX properties which are set.
*/
public Map<String,Object> getSAXParserProperties();
/**
* @return Returns Map of SAX properties which are optional set.
*/
public Map<String,Object> getSAXParserPropertiesOptional();
/**
* @return Returns Map of SAX features which are set on the xml parser.
*/
public Map<String,Boolean> getSAXParserFeatures();
/**
* @return Returns Map of SAX features which are optional set.
*/
public Map<String, Boolean> getSAXParserFeaturesOptional();
/**
* @return Returns List of SAX features which are required for xml parsing.
*/
public List<String> getSAXParserFeaturesRequired();
/**
* @return Returns null or an X4ODebugWriter to write parsing steps and debug data to.
*/
public X4ODebugWriter getX4ODebugWriter();
/**
* @return Returns true if this config has a debug writer.
*/
public boolean hasX4ODebugWriter();
/**
* @param debugWriter The debug writer to set
*/
public void setX4ODebugWriter(X4ODebugWriter debugWriter);
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
import org.x4o.xml.element.ElementLanguage;
/**
* Loads the language into the contexts.
*
* @author Willem Cazander
* @version 1.0 28 Oct 2009
*/
public interface X4OLanguageLoader {
/**
* Loads the language modules.
* @param elementLanguage The elementLanguage to load the module in.
* @param language The language to load.
* @param languageVersion The language version to load.
* @throws X4OLanguageLoaderException When there is an error.
*/
void loadLanguage(ElementLanguage elementLanguage,String language,String languageVersion) throws X4OLanguageLoaderException;
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
/**
* Is throw when there is en Exception within an Element.
*
* @author Willem Cazander
* @version 1.0 Oct 28, 2009
*/
public class X4OLanguageLoaderException extends Exception {
/** The serial version uid */
static final long serialVersionUID = 10L;
/**
* Constructs an X4OLanguageLoaderException without a detail message.
*/
public X4OLanguageLoaderException() {
super();
}
/**
* Constructs an X4OLanguageLoaderException with a detail message.
* @param message The message of this Exception
*/
public X4OLanguageLoaderException(String message) {
super(message);
}
/**
* Creates an X4OLanguageLoaderException from a parent exception.
* @param e The exception.
*/
public X4OLanguageLoaderException(Exception e) {
super(e);
}
/**
* Constructs an X4OLanguageLoaderException with a detail message.
* @param message The message of this Exception
* @param e The exception.
*/
public X4OLanguageLoaderException(String message,Exception e) {
super(message,e);
}
}

View file

@ -0,0 +1,224 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.Map;
import javax.el.ExpressionFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.ext.DefaultHandler2;
/**
* X4OLanguageProperty holds the language parser properties keys
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public enum X4OLanguageProperty {
/** Read-Only property returning the language we are working with. */
LANGUAGE_NAME("language/name"),
/** Read-Only property returning the version of the language. */
LANGUAGE_VERSION("language/version"),
/** When set to OutputStream xml debug is written to it. note: when output-handler is set this property is ignored. */
DEBUG_OUTPUT_STREAM("debug/output-stream",OutputStream.class),
/** When set to DefaultHandler2 xml debug events are fired to the object. */
DEBUG_OUTPUT_HANDLER("debug/output-handler",DefaultHandler2.class),
/** When set to true print also phases for parsing eld files. */
DEBUG_OUTPUT_ELD_PARSER("debug/output-eld-parser",Boolean.class,false),
/** When set to true print full element tree per phase. */
//DEBUG_OUTPUT_TREE_PER_PHASE("debug/output-tree-per-phase",Boolean.class),
/** SAX parser input buffer size: 512-16k defaults to 8k. */
INPUT_BUFFER_SIZE("input/buffer-size",Integer.class,4096*2),
/** When set it allows parsing of non-namespace aware documents. */
INPUT_EMPTY_NAMESPACE_URI("input/empty-namespace-uri"),
/** The input stream to parse, note is skipped when object is set. */
INPUT_SOURCE_STREAM("input/source/stream",InputStream.class),
/** When set it overrides automatic encoding detection of sax parser. */
INPUT_SOURCE_ENCODING("input/source/encoding"),
/** When set use this InputSource instance for parsing. */
INPUT_SOURCE_OBJECT("input/source/object",InputSource.class),
/** Sets the system-id to the input source. */
INPUT_SOURCE_SYSTEM_ID("input/source/system-id",String.class),
/** Sets the base path to resolve external input sources. */
INPUT_SOURCE_BASE_PATH("input/source/base-path",URL.class),
/** Set for custom handling of validation errors. */
CONFIG_ERROR_HANDLER("config/error-handler",ErrorHandler.class),
/** Resolve more entities from local sources. */
CONFIG_ENTITY_RESOLVER("config/entity-resolver",EntityResolver.class),
//CONFIG_CACHE_HANDLER("config/cache-handler"),
//CONFIG_MODULE_PROVIDER("config/module-provider"),
//CONFIG_LOCK_PROPERTIES("config/lock-properties"),
/** The beans in this map are set into the EL context for reference. */
EL_BEAN_INSTANCE_MAP("el/bean-instance-map",Map.class),
//EL_CONTEXT_INSTANCE("el/context-instance"),
/** When set this instance is used in ElementLanguage. */
EL_FACTORY_INSTANCE("el/factory-instance",ExpressionFactory.class),
//EL_INSTANCE_FACTORY("phase/skip-elb-init",Boolean.class),
/** When set to an X4OPhase then parsing stops after completing the set phase. */
PHASE_STOP_AFTER("phase/stop-after",Boolean.class),
/** When set to true skip the release phase. */
PHASE_SKIP_RELEASE("phase/skip-release",Boolean.class,false),
/** When set to true skip the run phase. */
PHASE_SKIP_RUN("phase/skip-run",Boolean.class,false),
/** When set to true skip the load siblings language phase. */
PHASE_SKIP_SIBLINGS("phase/skip-siblings",Boolean.class,false),
/** When set this path is searched for xsd schema files in the language sub directory. */
VALIDATION_SCHEMA_PATH("validation/schema-path",File.class),
/** When set to true then input xml is validated. */
VALIDATION_INPUT("validation/input",Boolean.class,false),
/** When set to true then input xsd xml grammer is validated. */
VALIDATION_INPUT_XSD("validation/input/xsd",Boolean.class,false),
/** When set to true then eld xml is validated. */
VALIDATION_ELD("validation/eld",Boolean.class,false),
/** When set to true than eld xsd xml grammer is also validated. */
VALIDATION_ELD_XSD("validation/eld/xsd",Boolean.class,false);
private final static String URI_PREFIX = "http://language.x4o.org/xml/properties/";
private final String uriName;
private final Class<?>[] classTypes;
private final Object defaultValue;
private X4OLanguageProperty(String uriName) {
this(uriName,String.class);
}
private X4OLanguageProperty(String uriName,Class<?> classType) {
this(uriName,new Class[]{classType},null);
}
private X4OLanguageProperty(String uriName,Class<?> classType,Object defaultValue) {
this(uriName,new Class[]{classType},defaultValue);
}
private X4OLanguageProperty(String uriName,Class<?>[] classTypes,Object defaultValue) {
this.uriName=URI_PREFIX+uriName;
this.classTypes=classTypes;
this.defaultValue=defaultValue;
}
/**
* Returns the uri defined by this property.
* @return The uri defined by this property.
*/
public String toUri() {
return uriName;
}
/**
* Returns the default value for this property.
* @return The default value for this property.
*/
public Object getDefaultValue() {
return defaultValue;
}
/**
* Checks if the object is valid to set on this property.
* This is done by checking the allowed class types if they are assignable from the value class.
* @param value The object to check.
* @return Returns true when Object value is allowed to be set.
*/
public boolean isValueValid(Object value) {
if (LANGUAGE_NAME.equals(this) | LANGUAGE_VERSION.equals(this)) {
return false; // read only are not valid to set.
}
if (value==null) {
return true;
}
Class<?> valueClass = value.getClass();
for (Class<?> c:classTypes) {
if (c.isAssignableFrom(valueClass)) {
return true;
}
}
return false;
}
/**
* Search the enum for the value defined by the given uri.
* @param uri The uri to search for.
* @return Return the property for the given uri.
* @throws IllegalArgumentException when uri is not found.
*/
static public X4OLanguageProperty valueByUri(String uri) {
if (uri==null) {
throw new NullPointerException("Can't search null uri.");
}
if (uri.isEmpty()) {
throw new IllegalArgumentException("Can't search empty uri.");
}
if (uri.startsWith(URI_PREFIX)==false) {
throw new IllegalArgumentException("Can't search for other name local prefix: "+URI_PREFIX+" found: "+uri);
}
for (X4OLanguageProperty p:values()) {
if (uri.equals(p.toUri())) {
return p;
}
}
throw new IllegalArgumentException("Could not find language property for uri key: "+uri);
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
/**
* X4OLanguagePropertyKeys is shortcut to the the properties by uri.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public class X4OLanguagePropertyKeys {
public final static String LANGUAGE_NAME = X4OLanguageProperty.LANGUAGE_NAME.toUri();
public final static String LANGUAGE_VERSION = X4OLanguageProperty.LANGUAGE_VERSION.toUri();
public final static String DEBUG_OUTPUT_STREAM = X4OLanguageProperty.DEBUG_OUTPUT_STREAM.toUri();
public final static String DEBUG_OUTPUT_HANDLER = X4OLanguageProperty.DEBUG_OUTPUT_HANDLER.toUri();
public final static String DEBUG_OUTPUT_ELD_PARSER = X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER.toUri();
public final static String INPUT_BUFFER_SIZE = X4OLanguageProperty.INPUT_BUFFER_SIZE.toUri();
public final static String INPUT_EMPTY_NAMESPACE_URI = X4OLanguageProperty.INPUT_EMPTY_NAMESPACE_URI.toUri();
public final static String INPUT_SOURCE_STREAM = X4OLanguageProperty.INPUT_SOURCE_STREAM.toUri();
public final static String INPUT_SOURCE_ENCODING = X4OLanguageProperty.INPUT_SOURCE_ENCODING.toUri();
public final static String INPUT_SOURCE_OBJECT = X4OLanguageProperty.INPUT_SOURCE_OBJECT.toUri();
public final static String INPUT_SOURCE_SYSTEM_ID = X4OLanguageProperty.INPUT_SOURCE_SYSTEM_ID.toUri();
public final static String INPUT_SOURCE_BASE_PATH = X4OLanguageProperty.INPUT_SOURCE_BASE_PATH.toUri();
public final static String CONFIG_ERROR_HANDLER = X4OLanguageProperty.CONFIG_ERROR_HANDLER.toUri();
public final static String CONFIG_ENTITY_RESOLVER = X4OLanguageProperty.CONFIG_ENTITY_RESOLVER.toUri();
public final static String EL_BEAN_INSTANCE_MAP = X4OLanguageProperty.EL_BEAN_INSTANCE_MAP.toUri();
public final static String EL_FACTORY_INSTANCE = X4OLanguageProperty.EL_FACTORY_INSTANCE.toUri();
public final static String PHASE_STOP_AFTER = X4OLanguageProperty.PHASE_STOP_AFTER.toUri();
public final static String PHASE_SKIP_RELEASE = X4OLanguageProperty.PHASE_SKIP_RELEASE.toUri();
public final static String PHASE_SKIP_RUN = X4OLanguageProperty.PHASE_SKIP_RUN.toUri();
public final static String PHASE_SKIP_SIBLINGS = X4OLanguageProperty.PHASE_SKIP_SIBLINGS.toUri();
public final static String VALIDATION_SCHEMA_PATH = X4OLanguageProperty.VALIDATION_SCHEMA_PATH.toUri();
public final static String VALIDATION_INPUT = X4OLanguageProperty.VALIDATION_INPUT.toUri();
public final static String VALIDATION_INPUT_XSD = X4OLanguageProperty.VALIDATION_INPUT_XSD.toUri();
public final static String VALIDATION_ELD = X4OLanguageProperty.VALIDATION_ELD.toUri();
public final static String VALIDATION_ELD_XSD = X4OLanguageProperty.VALIDATION_ELD_XSD.toUri();
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.core.config;
import java.util.List;
/**
* X4OLanguageVersionFilter fitlers the best version to use of the modules to load.
*
* @author Willem Cazander
* @version 1.0 6 Aug 2012
*/
public interface X4OLanguageVersionFilter {
/**
* Finds the version to load or returns null if no match is found.
*
* @param languageVersion The languageVersion to requested.
* @param versions The versions provided by the module.
* @return The version to load.
*/
String filterVersion(String languageVersion,List<String> versions);
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The core config interfaces and key definitions.
*
*
* @since 1.0
*/
package org.x4o.xml.core.config;

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The core classes which startup the language.
*
* @since 1.0
*/
package org.x4o.xml.core;

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld;
import java.util.logging.Logger;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementLanguageModuleLoader;
import org.x4o.xml.element.ElementLanguageModuleLoaderException;
/**
* De default X4OElementConfigurator.
*
* @author Willem Cazander
* @version 1.0 Aug 17, 2005
*/
public class EldModuleLoader implements ElementLanguageModuleLoader {
private Logger logger = null;
private String eldResource = null;
private boolean isEldCore = false;
public EldModuleLoader(String eldResource,boolean isEldCore) {
if (eldResource==null) {
throw new NullPointerException("Can't load null eld resource.");
}
logger = Logger.getLogger(EldModuleLoader.class.getName());
this.eldResource=eldResource;
this.isEldCore=isEldCore;
}
/**
* @see org.x4o.xml.element.ElementLanguageModuleLoader#loadLanguageModule(org.x4o.xml.element.ElementLanguage, org.x4o.xml.element.ElementLanguageModule)
*/
public void loadLanguageModule(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) throws ElementLanguageModuleLoaderException {
logger.fine("Loading name eld file from resource: "+eldResource);
try {
EldParser parser = new EldParser(elementLanguage,elementLanguageModule,isEldCore);
parser.parseResource(eldResource);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage()+" while parsing: "+eldResource,e);
}
}
}

View file

@ -0,0 +1,285 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.x4o.xml.conv.text.ClassConverter;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.eld.lang.BeanElement;
import org.x4o.xml.eld.lang.DescriptionElement;
import org.x4o.xml.eld.lang.ElementClassAddParentElement;
import org.x4o.xml.eld.lang.ElementClassAttributeBindingHandler;
import org.x4o.xml.eld.lang.ElementClassBindingHandler;
import org.x4o.xml.eld.lang.ElementInterfaceBindingHandler;
import org.x4o.xml.eld.lang.ElementModuleBindingHandler;
import org.x4o.xml.eld.lang.ElementNamespaceContextBindingHandler;
import org.x4o.xml.eld.lang.ModuleElement;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementLanguageModuleLoader;
import org.x4o.xml.element.ElementLanguageModuleLoaderException;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
import org.x4o.xml.impl.DefaultElementClass;
/**
* EldModuleLoaderCore provides a few basic elements for the core eld x4o language.
*
* @author Willem Cazander
* @version 1.0 Jan 11, 2009
*/
public class EldModuleLoaderCore implements ElementLanguageModuleLoader {
private Logger logger = null;
private static final String _CEL_XMLNS = "http://cel.x4o.org/xml/ns/";
private static final String _CEL_CORE = "cel-core";
private static final String _CEL_ROOT = "cel-root";
private static final String _CEL_XSD_FILE = "-1.0.xsd";
private static final String CEL_CORE_URI = _CEL_XMLNS+_CEL_CORE;
private static final String CEL_ROOT_URI = _CEL_XMLNS+_CEL_ROOT;
private static final String CEL_CORE_XSD_URI = CEL_CORE_URI+_CEL_XSD_FILE;
private static final String CEL_ROOT_XSD_URI = CEL_ROOT_URI+_CEL_XSD_FILE;
private static final String CEL_CORE_XSD_FILE = _CEL_CORE+_CEL_XSD_FILE;
private static final String CEL_ROOT_XSD_FILE = _CEL_ROOT+_CEL_XSD_FILE;
public EldModuleLoaderCore() {
logger = Logger.getLogger(EldModuleLoaderCore.class.getName());
}
/**
* @see org.x4o.xml.element.ElementLanguageModuleLoader#loadLanguageModule(org.x4o.xml.element.ElementLanguage, org.x4o.xml.element.ElementLanguageModule)
*/
public void loadLanguageModule(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) throws ElementLanguageModuleLoaderException {
elementLanguageModule.setId("cel-module");
elementLanguageModule.setName("Core Element Languag Module");
elementLanguageModule.setProviderName("cel.x4o.org");
List<ElementClass> elementClassList = new ArrayList<ElementClass>(10);
elementClassList.add(new DefaultElementClass("attribute",elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute()));
elementClassList.add(new DefaultElementClass("classConverter",ClassConverter.class));
createElementClasses(elementClassList,elementLanguage); // adds all meta info
ElementClassAttribute attr;
DefaultElementClass ns = new DefaultElementClass("namespace",elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceContext());
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("uri");
attr.setRequired(true);
ns.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ns);
DefaultElementClass dec = new DefaultElementClass("element",elementLanguage.getLanguageConfiguration().getDefaultElementClass());
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("objectClass");
attr.setObjectConverter(new ClassConverter());
dec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("elementClass");
attr.setObjectConverter(new ClassConverter());
dec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(dec);
DefaultElementClass ec = new DefaultElementClass("elementInterface",elementLanguage.getLanguageConfiguration().getDefaultElementInterface());
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("interfaceClass");
attr.setObjectConverter(new ClassConverter());
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
logger.finer("Creating eldcore namespace.");
ElementNamespaceContext namespace;
try {
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceContext());
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setUri(CEL_CORE_URI);
namespace.setSchemaUri(CEL_CORE_XSD_URI);
namespace.setSchemaResource(CEL_CORE_XSD_FILE);
namespace.setSchemaPrefix(_CEL_CORE);
logger.finer("Loading elementClassList size: "+elementClassList.size());
for (ElementClass ecL:elementClassList) {
namespace.addElementClass(ecL);
}
addBindingHandler("cel-class-bind",new ElementClassBindingHandler(),elementLanguageModule);
addBindingHandler("cel-module-bind",new ElementModuleBindingHandler(),elementLanguageModule);
addBindingHandler("cel-class-attr-bind",new ElementClassAttributeBindingHandler(),elementLanguageModule);
addBindingHandler("cel-interface-bind",new ElementInterfaceBindingHandler(),elementLanguageModule);
addBindingHandler("cel-namespace-bind",new ElementNamespaceContextBindingHandler(),elementLanguageModule);
try {
namespace.getElementNamespaceInstanceProvider().start(elementLanguage, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(namespace);
// And define root
try {
namespace = (ElementNamespaceContext)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceContext());
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
try {
namespace.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
namespace.setUri(CEL_ROOT_URI);
namespace.setSchemaUri(CEL_ROOT_XSD_URI);
namespace.setSchemaResource(CEL_ROOT_XSD_FILE);
namespace.setSchemaPrefix(_CEL_ROOT);
namespace.addElementClass(new DefaultElementClass("module",elementLanguage.getLanguageConfiguration().getDefaultElementLanguageModule(),ModuleElement.class));
namespace.setLanguageRoot(true); // Only define single language root so xsd is (mostly) not cicle import.
try {
namespace.getElementNamespaceInstanceProvider().start(elementLanguage, namespace);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementLanguageModuleLoaderException(this,"Error starting instance provider: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(namespace);
}
/**
* Adds only Element class beans which need extra meta info for schema.
*
* @param elementClassList The list to fill.
* @throws ElementLanguageModuleLoaderException
*/
private void createElementClasses(List<ElementClass> elementClassList,ElementLanguage elementLanguage) throws ElementLanguageModuleLoaderException {
ElementClass ec = null;
ElementClassAttribute attr = null;
ec = new DefaultElementClass("bindingHandler",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "elementInterface");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("id");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
ec = new DefaultElementClass("attributeHandler",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
ec = new DefaultElementClass("configurator",null,BeanElement.class);
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "elementInterface");
ec.addElementParent("", "element");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("bean.class");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("configAction");
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
ec = new DefaultElementClass("description",null,DescriptionElement.class);
ec.setSchemaContentBase("string");
ec.addElementParent(CEL_ROOT_URI, "module");
ec.addElementParent("", "attributeHandler");
ec.addElementParent("", "bindingHandler");
ec.addElementParent("", "configurator");
ec.addElementParent("", "elementInterface");
ec.addElementParent("", "element");
elementClassList.add(ec);
ec = new DefaultElementClass("elementParent",null,ElementClassAddParentElement.class);
ec.addElementParent("", "element");
try {
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("tag");
attr.setRequired(true);
ec.addElementClassAttribute(attr);
attr = (ElementClassAttribute)X4OLanguageClassLoader.newInstance(elementLanguage.getLanguageConfiguration().getDefaultElementClassAttribute());
attr.setName("uri");
ec.addElementClassAttribute(attr);
} catch (Exception e) {
throw new ElementLanguageModuleLoaderException(this,e.getMessage(),e);
}
elementClassList.add(ec);
}
private void addBindingHandler(String id,ElementBindingHandler handler,ElementLanguageModule elementLanguageModule) {
handler.setId(id);
elementLanguageModule.addElementBindingHandler(handler);
}
}

View file

@ -0,0 +1,94 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld;
import org.x4o.xml.core.X4ODriver;
import org.x4o.xml.core.X4OParser;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
/**
* An Element Language Definition X4O parser.
* This eld parser config parent x4o parser with the eld x4o parser.
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2005
*/
public class EldParser extends X4OParser {
/** Defines the identifier of the ELD x4o language. */
public static final String ELD_VERSION = X4ODriver.DEFAULT_LANGUAGE_VERSION;
/** Defines the identifier of the 'Element Language Description' language. */
public static final String ELD_LANGUAGE = "eld";
/** Defines the identifier of the 'Core Element Language' language. */
public static final String CEL_LANGUAGE = "cel";
protected EldParser() {
this(false);
}
protected EldParser(boolean isEldCore) {
super(isEldCore?CEL_LANGUAGE:ELD_LANGUAGE,ELD_VERSION);
}
/**
* getDriver for unit tests
*/
protected X4ODriver getDriver() {
return super.getDriver();
}
/**
* Start the second x4o parsing for eld files.
* @param elementLanguage The elementLanguage to fill.
* @param elementLanguageModule The elementLanguageModule from to fill.
*/
public EldParser(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule) {
this(false);
if (elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
getDriver().getElementLanguage().getLanguageConfiguration().setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter()); // move to ..
}
addELBeanInstance(PARENT_LANGUAGE_CONFIGURATION, elementLanguage.getLanguageConfiguration());
addELBeanInstance(PARENT_LANGUAGE_ELEMENT_LANGUAGE, elementLanguage);
addELBeanInstance(PARENT_ELEMENT_LANGUAGE_MODULE, elementLanguageModule);
}
public EldParser(ElementLanguage elementLanguage,ElementLanguageModule elementLanguageModule,boolean isEldCore) {
this(isEldCore);
if (elementLanguage.getLanguageConfiguration().getLanguagePropertyBoolean(X4OLanguageProperty.DEBUG_OUTPUT_ELD_PARSER)) {
getDriver().getElementLanguage().getLanguageConfiguration().setX4ODebugWriter(elementLanguage.getLanguageConfiguration().getX4ODebugWriter());
}
addELBeanInstance(PARENT_LANGUAGE_CONFIGURATION, elementLanguage.getLanguageConfiguration());
addELBeanInstance(PARENT_LANGUAGE_ELEMENT_LANGUAGE, elementLanguage);
addELBeanInstance(PARENT_ELEMENT_LANGUAGE_MODULE, elementLanguageModule);
}
public final static String PARENT_LANGUAGE_CONFIGURATION = "parentLanguageConfiguration";
public final static String PARENT_ELEMENT_LANGUAGE_MODULE = "parentElementLanguageModule";
public final static String PARENT_LANGUAGE_ELEMENT_LANGUAGE = "parentLanguageElementLanguage";
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld;
import org.x4o.xml.core.X4OParserSupport;
import org.x4o.xml.core.X4OParserSupportException;
import org.x4o.xml.element.ElementLanguage;
/**
* EldParserSupport can write the eld schema.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class EldParserSupport implements X4OParserSupport {
/**
* Loads the ElementLanguage of this language parser for support.
* @return The loaded ElementLanguage.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
EldParser parser = new EldParser(false);
return parser.loadElementLanguageSupport();
}
}

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld;
import org.x4o.xml.core.X4OParserSupport;
import org.x4o.xml.core.X4OParserSupportException;
import org.x4o.xml.element.ElementLanguage;
/**
* EldParserSupportCore can write the cel schema.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class EldParserSupportCore implements X4OParserSupport {
/**
* Loads the ElementLanguage of this language parser for support.
* @return The loaded ElementLanguage.
* @see org.x4o.xml.core.X4OParserSupport#loadElementLanguageSupport()
*/
public ElementLanguage loadElementLanguageSupport() throws X4OParserSupportException {
EldParser parser = new EldParser(true);
return parser.loadElementLanguageSupport();
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementException;
/**
* AttributeAliasElement add the defines alias to the parent element attribute.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2006
*/
public class AttributeAliasElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
String alias = getAttributes().get("name");
if (alias==null) {
throw new ElementException("'name' attribute is not set on: "+getElementClass().getTag());
}
if (getParent().getElementObject() instanceof ElementClassAttribute) {
((ElementClassAttribute)getParent().getElementObject()).addAttributeAlias(alias);
} else {
throw new ElementException("Wrong parent class is not ElementClassAttribute but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,111 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import java.util.List;
import org.x4o.xml.element.AbstractElementConfigurator;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.Element.ElementType;
import org.x4o.xml.element.ElementConfiguratorException;
/**
* AttributeFromBodyConfigurator sets the body as attribute.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2012
*/
public class AttributeFromBodyConfigurator extends AbstractElementConfigurator {
private String name = null;
private String bodyType = null;
/**
* @see org.x4o.xml.element.ElementConfigurator#doConfigElement(org.x4o.xml.element.Element)
*/
public void doConfigElement(Element element) throws ElementConfiguratorException {
if (name==null) {
throw new ElementConfiguratorException(this,"name attribute is not set.");
}
if (name.isEmpty()) {
throw new ElementConfiguratorException(this,"name attribute is empty.");
}
if (bodyType==null) {
bodyType = "characters";
}
String value = null;
if ("characters".equals(bodyType)) {
value = fetchBodyType(element,ElementType.characters);
} else if ("comment".equals(bodyType)) {
value = fetchBodyType(element,ElementType.comment);
} else if ("ignorableWhitespace".equals(bodyType)) {
value = fetchBodyType(element,ElementType.ignorableWhitespace);
} else {
throw new ElementConfiguratorException(this,"bodyType attribute value is unknown; "+bodyType);
}
if (value.isEmpty()) {
return;
}
element.getAttributes().put(name, value);
}
private String fetchBodyType(Element element,ElementType elementType) {
StringBuffer buf = new StringBuffer(300);
List<Element> childsAll = element.getAllChilderen();
List<Element> childs = ElementType.filterElements(childsAll, elementType);
for (int i=0;i<childs.size();i++) {
Element e = childs.get(i);
buf.append(e.getElementObject().toString());
}
return buf.toString();
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the bodyType
*/
public String getBodyType() {
return bodyType;
}
/**
* @param bodyType the bodyType to set
*/
public void setBodyType(String bodyType) {
this.bodyType = bodyType;
}
}

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
/**
* An BeanElement.<br>
* This BeanElement fills it elementObject from source with the bean.class attribute.
*
* @author Willem Cazander
* @version 1.0 Jan 21, 2007
*/
public class BeanElement extends AbstractElement {
private List<Object> constructorArguments = null;
public BeanElement() {
constructorArguments = new ArrayList<Object>(3);
}
@Override
public void doElementStart() throws ElementException {
String className = getAttributes().get("bean.class");
if("".equals(className) | className==null) { throw new ElementException("Set the bean.class attribute"); }
try {
Class<?> beanClass = X4OLanguageClassLoader.loadClass(className);
if (constructorArguments.isEmpty()) {
setElementObject(beanClass.newInstance());
} else {
Class<?>[] arguClass = new Class<?>[constructorArguments.size()];
constructorArguments.toArray(arguClass);
Constructor<?> c = beanClass.getConstructor(arguClass);
setElementObject(c.newInstance(constructorArguments));
}
} catch (Exception e) {
throw new ElementException(e);
}
}
public void addConstuctorArgument(Object argu) {
if (argu==null) {
throw new NullPointerException("Can't add null argument for constructor.");
}
constructorArguments.add(argu);
}
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementMetaBase;
import org.x4o.xml.element.ElementException;
/**
* Fills all the ElementDescription which the description
*
*
*
* @author Willem Cazander
* @version 1.0 Jan 13, 2009
*/
public class DescriptionElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementStart()
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()==null) {
throw new ElementException("can't be a root tag");
}
if (getParent().getElementObject() instanceof ElementMetaBase == false) {
throw new ElementException("Wrong parent class is not ElementDescription");
}
}
/**
* @see org.x4o.xml.element.AbstractElement#doCharacters(java.lang.String)
*/
@Override
public void doCharacters(String characters) throws ElementException {
super.doCharacters(characters);
setElementObject(characters);
}
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
if (getElementObject()==null) {
throw new ElementException("description is not set.");
}
if (getParent().getElementObject() instanceof ElementMetaBase) {
((ElementMetaBase)getParent().getElementObject()).setDescription(getElementObject().toString());
} else {
throw new ElementException("Wrong parent class is not ElementClass");
}
}
}

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementException;
/**
* ElementClassAddParentElement adds an parent tag to ElementClass for xsd.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementClassAddParentElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
String tag = getAttributes().get("tag");
if (tag==null) {
throw new ElementException("'tag' attribute is not set on: "+getElementClass().getTag());
}
String namespaceUri = getAttributes().get("uri");
if (namespaceUri==null) {
namespaceUri = ""; // current namespace ?
}
if (getParent().getElementObject() instanceof ElementClass) {
((ElementClass)getParent().getElementObject()).addElementParent(namespaceUri,tag);
} else {
throw new ElementException("Wrong parent class is not ElementClass but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClassAttribute;
/**
* ElementClassAttributeBindingHandler adds the object converter.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementClassAttributeBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ObjectConverter.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementClassAttribute.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementClassAttribute parent = (ElementClassAttribute)parentObject;
if (childObject instanceof ObjectConverter) {
parent.setObjectConverter((ObjectConverter)childObject);
}
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
/**
* This ElementBindingHandler adds the ElementClassAttributeConverter and the
* ElementConfigurator to the ElementClass.
*
* @author Willem Cazander
* @version 1.0 Jan 31, 2007
*/
public class ElementClassBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClassAttribute.class,
ElementConfigurator.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementClass.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementClass parent = (ElementClass)parentObject;
if (childObject instanceof ElementClassAttribute) {
parent.addElementClassAttribute((ElementClassAttribute)childObject);
}
if (childObject instanceof ElementConfigurator) {
parent.addElementConfigurators((ElementConfigurator)childObject);
}
}
}

View file

@ -0,0 +1,77 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementInterface;
/**
* ElementInterfaceBindingHandler binds all childs into the interface.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementInterfaceBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClassAttribute.class,
ElementConfigurator.class,
ElementBindingHandler.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementInterface.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementInterface parent = (ElementInterface)parentObject;
if (childObject instanceof ElementBindingHandler) {
parent.addElementBindingHandler((ElementBindingHandler)childObject);
}
if (childObject instanceof ElementClassAttribute) {
parent.addElementClassAttribute((ElementClassAttribute)childObject);
}
if (childObject instanceof ElementConfigurator) {
parent.addElementConfigurators((ElementConfigurator)childObject);
}
}
}

View file

@ -0,0 +1,134 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import java.util.Map;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.eld.EldParser;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementConfigurator;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementInterface;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.element.ElementNamespaceInstanceProvider;
import org.x4o.xml.element.ElementNamespaceInstanceProviderException;
/**
* An ParentLanguageElementConfigurator.
*
* This binds the main interfaces of the ELD language to an other Element
*
* @author Willem Cazander
* @version 1.0 Jan 19, 2007
*/
public class ElementModuleBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementInterface.class,
ElementNamespaceContext.class,
ElementBindingHandler.class,
ElementAttributeHandler.class,
ElementConfigurator.class,
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementLanguageModule.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
@SuppressWarnings("rawtypes")
Map m = (Map)childElement.getElementLanguage().getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (m==null) {
return;
}
ElementLanguage x4oParsingContext = (ElementLanguage)m.get(EldParser.PARENT_LANGUAGE_ELEMENT_LANGUAGE);
//ElementLanguageModule elementLanguageModule = (ElementLanguageModule)m.get(EldParser.PARENT_ELEMENT_LANGUAGE_MODULE);
ElementLanguageModule elementLanguageModule = (ElementLanguageModule)parentObject;
if (x4oParsingContext==null) {
return;
}
if (elementLanguageModule==null) {
return;
}
if (childObject instanceof ElementInterface) {
ElementInterface elementInterface = (ElementInterface)childObject;
elementLanguageModule.addElementInterface(elementInterface);
return;
}
if (childObject instanceof ElementNamespaceContext) {
ElementNamespaceContext elementNamespaceContext = (ElementNamespaceContext)childObject;
try {
elementNamespaceContext.setElementNamespaceInstanceProvider((ElementNamespaceInstanceProvider)X4OLanguageClassLoader.newInstance(childElement.getElementLanguage().getLanguageConfiguration().getDefaultElementNamespaceInstanceProvider()));
} catch (Exception e) {
throw new ElementBindingHandlerException("Error loading: "+e.getMessage(),e);
}
try {
elementNamespaceContext.getElementNamespaceInstanceProvider().start(x4oParsingContext, elementNamespaceContext);
} catch (ElementNamespaceInstanceProviderException e) {
throw new ElementBindingHandlerException("Error starting: "+e.getMessage(),e);
}
elementLanguageModule.addElementNamespaceContext(elementNamespaceContext);
return;
}
if (childObject instanceof ElementBindingHandler) {
ElementBindingHandler elementBindingHandler = (ElementBindingHandler)childObject;
elementLanguageModule.addElementBindingHandler(elementBindingHandler);
return;
}
if (childObject instanceof ElementAttributeHandler) {
ElementAttributeHandler elementAttributeHandler = (ElementAttributeHandler)childObject;
elementLanguageModule.addElementAttributeHandler(elementAttributeHandler);
return;
}
if (childObject instanceof ElementConfigurator) {
ElementConfigurator elementConfigurator = (ElementConfigurator)childObject;
elementLanguageModule.addGlobalElementConfigurator(elementConfigurator);
return;
}
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementNamespaceContext;
/**
* ElementNamespaceContextBindingHandler binds ElementClass into namespace.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class ElementNamespaceContextBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ElementClass.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return ElementNamespaceContext.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
ElementNamespaceContext parent = (ElementNamespaceContext)parentObject;
if (childObject instanceof ElementClass) {
parent.addElementClass((ElementClass)childObject);
}
return;
}
}

View file

@ -0,0 +1,120 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import java.lang.reflect.Method;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* Binds to objects together with a method found by reflection.
*
* @author Willem Cazander
* @version 1.0 Nov 21, 2007
*/
public class ElementRefectionBindingHandler extends AbstractElementBindingHandler {
private Class<?> parentClass = null;
private Class<?> childClass = null;
private String method = null;
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return parentClass;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return new Class[] {childClass};
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject, Element childElement) throws ElementBindingHandlerException {
if (parentClass==null | childClass==null | method==null) {
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" method="+method+".");
}
Method[] ms = parentObject.getClass().getMethods();
for (Method m:ms) {
if (method.equalsIgnoreCase(m.getName())) {
try {
m.invoke(parentObject, childObject);
} catch (Exception e) {
throw new ElementBindingHandlerException("Error in binding beans: "+e.getMessage(),e);
}
return;
}
}
}
/**
* @return the parentClass
*/
public Class<?> getParentClass() {
return parentClass;
}
/**
* @param parentClass the parentClass to set
*/
public void setParentClass(Class<?> parentClass) {
this.parentClass = parentClass;
}
/**
* @return the childClass
*/
public Class<?> getChildClass() {
return childClass;
}
/**
* @param childClass the childClass to set
*/
public void setChildClass(Class<?> childClass) {
this.childClass = childClass;
}
/**
* @return the method
*/
public String getMethod() {
return method;
}
/**
* @param method the method to set
*/
public void setMethod(String method) {
this.method = method;
}
}

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import java.util.Map;
import org.x4o.xml.core.config.X4OLanguageProperty;
import org.x4o.xml.eld.EldParser;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementLanguageModule;
/**
* ModuleElement put in an instance from parent language module.
*
*
* @author Willem Cazander
* @version 1.0 Aug 20, 2012
*/
public class ModuleElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementStart()
*/
@Override
public void doElementStart() throws ElementException {
if (getParent()!=null) {
throw new ElementException("Need to be root tag");
}
@SuppressWarnings("rawtypes")
Map m = (Map)getElementLanguage().getLanguageConfiguration().getLanguageProperty(X4OLanguageProperty.EL_BEAN_INSTANCE_MAP);
if (m==null) {
return;
}
ElementLanguageModule elementLanguageModule = (ElementLanguageModule)m.get(EldParser.PARENT_ELEMENT_LANGUAGE_MODULE);
setElementObject(elementLanguageModule);
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementException;
/**
* NextAttributeElement.<br>
* Parses the attributeName and adds it to the ElementClass
*
* @author Willem Cazander
* @version 1.0 Feb 19, 2007
*/
public class NextAttributeElement extends AbstractElement {
@Override
public void doElementRun() throws ElementException {
String param = getAttributes().get("attributeName");
if (param==null) {
throw new ElementException("attributeName may not be null");
}
if (getParent()==null) {
throw new ElementException("can't be a root tag");
}
if (getParent().getElementObject() instanceof ElementAttributeHandler) {
((ElementAttributeHandler)getParent().getElementObject()).addNextAttribute(param);
} else {
throw new ElementException("Wrong parent class");
}
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.element.AbstractElement;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementException;
/**
* SkipPhaseElement add skip phases to elements.
*
* @author Willem Cazander
* @version 1.0 Aug 26, 2012
*/
public class SkipPhaseElement extends AbstractElement {
/**
* @see org.x4o.xml.element.AbstractElement#doElementEnd()
*/
@Override
public void doElementEnd() throws ElementException {
String phase = getAttributes().get("name");
if (phase==null) {
throw new ElementException("'name' attribute is not set on: "+getElementClass().getTag());
}
if (getParent().getElementObject() instanceof ElementClass) {
((ElementClass)getParent().getElementObject()).addSkipPhase(phase);
} else {
throw new ElementException("Wrong parent class is not ElementClassAttribute but: "+getParent().getElementObject());
}
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.conv.text.StringSplitConverter;
import org.x4o.xml.conv.text.StringSplitConverterStep;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* StringSplitConverterBindingHandler binds the string split converter step to parent.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class StringSplitConverterBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
StringSplitConverterStep.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return StringSplitConverter.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
StringSplitConverter parent = (StringSplitConverter)parentObject;
if (childObject instanceof StringSplitConverterStep) {
parent.addStringSplitConverterStep((StringSplitConverterStep)childObject);
}
}
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.lang;
import org.x4o.xml.conv.ObjectConverter;
import org.x4o.xml.conv.text.StringSplitConverterStep;
import org.x4o.xml.element.AbstractElementBindingHandler;
import org.x4o.xml.element.Element;
import org.x4o.xml.element.ElementBindingHandlerException;
/**
* StringSplitConverterStepBindingHandler binds the object converter to the step.
*
* @author Willem Cazander
* @version 1.0 Aug 21, 2012
*/
public class StringSplitConverterStepBindingHandler extends AbstractElementBindingHandler {
private final static Class<?>[] CLASSES_CHILD = new Class[] {
ObjectConverter.class
};
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindParentClass()
*/
public Class<?> getBindParentClass() {
return StringSplitConverterStep.class;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
*/
public Class<?>[] getBindChildClasses() {
return CLASSES_CHILD;
}
/**
* @see org.x4o.xml.element.ElementBindingHandler#doBind(java.lang.Object, java.lang.Object, org.x4o.xml.element.Element)
*/
public void doBind(Object parentObject, Object childObject,Element childElement) throws ElementBindingHandlerException {
StringSplitConverterStep parent = (StringSplitConverterStep)parentObject;
if (childObject instanceof ObjectConverter) {
parent.setObjectConverter((ObjectConverter)childObject);
}
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The X4O ELD Language x4o classes.
*
*
* @since 1.0
*/
package org.x4o.xml.eld.lang;

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The X4O Element Language Definition parser.
*
*
* @since 1.0
*/
package org.x4o.xml.eld;

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.xsd;
import java.io.File;
import java.io.FileOutputStream;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.x4o.xml.sax.XMLWriter;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
/**
* EldSchemaGenerator Creates XML Schema for a namespace uri from a x4o language driver.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2012
*/
public class EldXsdXmlGenerator {
private ElementLanguage context = null;
public EldXsdXmlGenerator(ElementLanguage context) {
this.context=context;
}
private void checkNamespace(ElementNamespaceContext ns) {
if (ns.getSchemaResource()==null) {
throw new NullPointerException("Can't generate xsd for namespace without schemaResource uri: "+ns.getUri());
}
if (ns.getSchemaResource().isEmpty()) {
throw new NullPointerException("Can't generate xsd for namespace with empty schemaResource uri: "+ns.getUri());
}
}
public void writeSchema(File basePath,String namespace) throws ElementException {
try {
if (namespace!=null) {
ElementNamespaceContext ns = context.findElementNamespaceContext(namespace);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespace);
}
checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try {
XMLWriter out = new XMLWriter(fio);
generateSchema(ns.getUri(), out);
} finally {
fio.close();
}
return;
}
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
checkNamespace(ns);
FileOutputStream fio = new FileOutputStream(new File(basePath.getAbsolutePath()+File.separatorChar+ns.getSchemaResource()));
try {
XMLWriter out = new XMLWriter(fio);
generateSchema(ns.getUri(), out);
} finally {
fio.close();
}
}
}
} catch (Exception e) {
throw new ElementException(e); // todo rm
}
}
public void generateSchema(String namespaceUri,DefaultHandler2 xmlWriter) throws SAXException {
ElementNamespaceContext ns = context.findElementNamespaceContext(namespaceUri);
if (ns==null) {
throw new NullPointerException("Could not find namespace: "+namespaceUri);
}
EldXsdXmlWriter xsdWriter = new EldXsdXmlWriter(xmlWriter,context);
xsdWriter.startNamespaces(namespaceUri);
xsdWriter.startSchema(ns,context);
for (ElementClass ec:ns.getElementClasses()) {
xsdWriter.writeElementClass(ec,ns);
}
for (ElementClass ec:ns.getElementClasses()) {
xsdWriter.writeElement(ec,ns);
}
xsdWriter.endSchema();
}
}

View file

@ -0,0 +1,442 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.xsd;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.x4o.xml.element.ElementAttributeHandler;
import org.x4o.xml.element.ElementBindingHandler;
import org.x4o.xml.element.ElementClass;
import org.x4o.xml.element.ElementClassAttribute;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementLanguageModule;
import org.x4o.xml.element.ElementNamespaceContext;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DefaultHandler2;
import org.xml.sax.helpers.AttributesImpl;
/**
* EldXsdXmlWriter Creates the schema from an eld resource.
*
* Note: this is still writing a bit quick and hacky.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2012
*/
public class EldXsdXmlWriter {
static public final String SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
protected ElementLanguage context = null;
protected DefaultHandler2 xmlWriter = null;
protected String writeNamespace = null;
protected Map<String, String> namespaces = null;
public EldXsdXmlWriter(DefaultHandler2 xmlWriter,ElementLanguage context) {
this.xmlWriter=xmlWriter;
this.context=context;
this.namespaces=new HashMap<String,String>(10);
}
private void startNamespace(String uri,String prefixNamespace) {
String prefix = namespaces.get(uri);
if (prefix!=null) {
return;
}
if (uri.equals(writeNamespace)) {
namespaces.put(uri, "this");
return;
}
if (prefixNamespace!=null) {
namespaces.put(uri, prefixNamespace); // let user define it
return;
}
StringBuilder buf = new StringBuilder(20);
for (char c:uri.toLowerCase().toCharArray()) {
if (Character.isLetter(c)) {
buf.append(c);
}
if (Character.isDigit(c)) {
buf.append(c);
}
}
prefix = buf.toString();
if (prefix.startsWith("http")) {
prefix = prefix.substring(4);
}
if (prefix.startsWith("uri")) {
prefix = prefix.substring(3);
}
if (prefix.startsWith("url")) {
prefix = prefix.substring(3);
}
namespaces.put(uri, prefix);
}
public void startNamespaces(String namespaceUri) {
this.writeNamespace=namespaceUri;
this.namespaces.clear();
// redo this mess, add nice find for binding handlers
for (ElementLanguageModule modContext:context.getElementLanguageModules()) {
for (ElementNamespaceContext nsContext:modContext.getElementNamespaceContexts()) {
for (ElementClass ec:nsContext.getElementClasses()) {
Class<?> objectClass = null;
if (ec.getObjectClass()!=null) {
objectClass = ec.getObjectClass();
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
for (ElementClass checkClass:ns.getElementClasses()) {
if (checkClass.getObjectClass()==null) {
continue;
}
Class<?> checkObjectClass = checkClass.getObjectClass();
List<ElementBindingHandler> b = context.findElementBindingHandlers(objectClass,checkObjectClass);
if (b.isEmpty()==false) {
startNamespace(ns.getUri(),ns.getSchemaPrefix());
}
}
}
}
}
}
}
}
}
private static final String COMMENT_SEPERATOR = " ==================================================================== ";
private static final String COMMENT_TEXT = "=====";
public void startSchema(ElementNamespaceContext ns,ElementLanguage elementLanguage) throws SAXException {
xmlWriter.startDocument();
// this is a mess;
char[] msg;
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
msg = COMMENT_SEPERATOR.toCharArray();
xmlWriter.comment(msg,0,msg.length);
String desc = "Automatic generated schema for language: "+elementLanguage.getLanguageConfiguration().getLanguage();
int space = COMMENT_SEPERATOR.length()-desc.length()-(2*COMMENT_TEXT.length())-4;
StringBuffer b = new StringBuffer(COMMENT_SEPERATOR.length());
b.append(" ");
b.append(COMMENT_TEXT);
b.append(" ");
b.append(desc);
for (int i=0;i<space;i++) {
b.append(' ');
}
b.append(COMMENT_TEXT);
b.append(" ");
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
msg = b.toString().toCharArray();
xmlWriter.comment(msg,0,msg.length);
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
msg = COMMENT_SEPERATOR.toCharArray();
xmlWriter.comment(msg,0,msg.length);
msg = "\n".toCharArray();
xmlWriter.ignorableWhitespace(msg,0,msg.length);
ElementLanguageModule module = null;
for (ElementLanguageModule elm:elementLanguage.getElementLanguageModules()) {
ElementNamespaceContext s = elm.getElementNamespaceContext(ns.getUri());
if (s!=null) {
module = elm;
break;
}
}
b = new StringBuffer(COMMENT_SEPERATOR.length());
b.append("\n\tProviderName:\t");
b.append(module.getProviderName());
b.append("\n\tModuleName:\t\t");
b.append(module.getName());
b.append("\n\tNamespaces:\t\t");
b.append(module.getElementNamespaceContexts().size());
b.append("\n\tNamespace:\t\t");
b.append(ns.getUri());
b.append("\n\tCreated on:\t\t");
b.append(new Date());
b.append("\n");
msg = b.toString().toCharArray();
xmlWriter.comment(msg,0,msg.length);
xmlWriter.startPrefixMapping("", SCHEMA_URI);
for (String uri:namespaces.keySet()) {
String prefix = namespaces.get(uri);
xmlWriter.startPrefixMapping(prefix, uri);
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "version", "", "", "1.0");
atts.addAttribute ("", "elementFormDefault", "", "", "qualified");
atts.addAttribute ("", "attributeFormDefault", "", "", "unqualified");
atts.addAttribute ("", "targetNamespace", "", "", ns.getUri());
xmlWriter.startElement (SCHEMA_URI, "schema", "", atts);
for (String uri:namespaces.keySet()) {
if (ns.getUri().equals(uri)) {
continue;
}
ElementNamespaceContext nsContext = context.findElementNamespaceContext(uri);
atts = new AttributesImpl();
atts.addAttribute ("", "namespace", "", "", nsContext.getUri());
atts.addAttribute ("", "schemaLocation", "", "", nsContext.getSchemaResource());
xmlWriter.startElement (SCHEMA_URI, "import", "", atts);
xmlWriter.endElement (SCHEMA_URI, "import", "");
}
}
public void endSchema() throws SAXException {
xmlWriter.endElement (SCHEMA_URI, "schema" , "");
xmlWriter.endDocument();
}
public void writeElementClass(ElementClass ec,ElementNamespaceContext nsWrite) throws SAXException {
AttributesImpl atts = new AttributesImpl();
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
atts.addAttribute ("", "name", "", "", ec.getTag());
xmlWriter.startElement (SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
atts = new AttributesImpl();
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
} else {
atts.addAttribute ("", "name", "", "", ec.getTag()+"Type");
xmlWriter.startElement (SCHEMA_URI, "complexType", "", atts);
}
if (ec.getSchemaContentBase()!=null) {
atts = new AttributesImpl();
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
if (ec.getSchemaContentMixed()!=null && ec.getSchemaContentMixed()) {
atts.addAttribute ("", "mixed", "", "", "true");
}
xmlWriter.startElement (SCHEMA_URI, "complexContent", "", atts);
} else {
xmlWriter.startElement (SCHEMA_URI, "simpleContent", "", atts);
}
atts = new AttributesImpl();
atts.addAttribute ("", "base", "", "", ec.getSchemaContentBase());
xmlWriter.startElement (SCHEMA_URI, "extension", "", atts);
}
if (ec.getSchemaContentBase()==null) {
atts = new AttributesImpl();
atts.addAttribute ("", "minOccurs", "", "", "0"); // make unordered elements
atts.addAttribute ("", "maxOccurs", "", "", "unbounded");
xmlWriter.startElement (SCHEMA_URI, "choice", "", atts);
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementNamespaceContext ns:mod.getElementNamespaceContexts()) {
writeElementClassNamespaces(ec,nsWrite,ns);
}
}
xmlWriter.endElement(SCHEMA_URI, "choice", "");
}
List<String> attrNames = new ArrayList<String>(30);
for (ElementClassAttribute eca:ec.getElementClassAttributes()) {
attrNames.add(eca.getName());
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eca.getName());
atts.addAttribute ("", "type", "", "", "string");
if (eca.getRequired()!=null && eca.getRequired()) {
atts.addAttribute ("", "use", "", "", "required");
}
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
}
for (ElementLanguageModule mod:context.getElementLanguageModules()) {
for (ElementAttributeHandler eah:mod.getElementAttributeHandlers()) {
attrNames.add(eah.getAttributeName());
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", eah.getAttributeName());
atts.addAttribute ("", "type", "", "", "string");
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
}
}
if (ec.getAutoAttributes()!=null && ec.getAutoAttributes()==false) {
// oke
} else {
if (ec.getObjectClass()!=null) {
for (Method m:ec.getObjectClass().getMethods()) {
if (m.getName().startsWith("set")) {
String n = m.getName().substring(3);
if (m.getParameterTypes().length==0) {
continue; // set without parameters
}
if (n.length()<2) {
continue;
}
n = n.substring(0,1).toLowerCase()+n.substring(1,n.length());
if (attrNames.contains(n)) {
continue;
}
atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", n);
Class<?> type = m.getParameterTypes()[0]; // TODO make full list for auto attribute type resolving.
if (type.equals(Object.class)) {
atts.addAttribute ("", "type", "", "", "string");// object is always string because is always assignable
} else if (type.isAssignableFrom(Boolean.class) | type.isAssignableFrom(Boolean.TYPE)) {
atts.addAttribute ("", "type", "", "", "boolean");
} else if (type.isAssignableFrom(Integer.class) | type.isAssignableFrom(Integer.TYPE)) {
atts.addAttribute ("", "type", "", "", "integer");
} else if (type.isAssignableFrom(Long.class) | type.isAssignableFrom(Long.TYPE)) {
atts.addAttribute ("", "type", "", "", "long");
} else if (type.isAssignableFrom(Float.class) | type.isAssignableFrom(Float.TYPE)) {
atts.addAttribute ("", "type", "", "", "float");
} else if (type.isAssignableFrom(Double.class) | type.isAssignableFrom(Double.TYPE)) {
atts.addAttribute ("", "type", "", "", "double");
} else {
atts.addAttribute ("", "type", "", "", "string");
}
xmlWriter.startElement (SCHEMA_URI, "attribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "attribute", "");
}
}
} else {
atts = new AttributesImpl();
xmlWriter.startElement (SCHEMA_URI, "anyAttribute", "", atts);
xmlWriter.endElement(SCHEMA_URI, "anyAttribute", "");
}
}
if (ec.getSchemaContentBase()!=null) {
xmlWriter.endElement(SCHEMA_URI, "extension", "");
if (ec.getSchemaContentComplex()!=null && ec.getSchemaContentComplex()) {
xmlWriter.endElement(SCHEMA_URI, "complexContent", "");
} else {
xmlWriter.endElement(SCHEMA_URI, "simpleContent", "");
}
}
xmlWriter.endElement(SCHEMA_URI, "complexType", "");
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
xmlWriter.endElement(SCHEMA_URI, "element", "");
}
}
private void writeElementClassNamespaces(ElementClass ec,ElementNamespaceContext nsWrite,ElementNamespaceContext ns) throws SAXException {
AttributesImpl atts = new AttributesImpl();
List<String> refElements = new ArrayList<String>(20);
for (ElementClass checkClass:ns.getElementClasses()) {
List<String> parents = checkClass.getElementParents(nsWrite.getUri());
if (parents!=null) {
if (parents!=null) {
if (parents.contains(ec.getTag())) {
refElements.add(checkClass.getTag());
}
}
}
if (nsWrite.getUri().equals(ns.getUri())) {
parents = checkClass.getElementParents("");
if (parents!=null) {
if (parents.contains(ec.getTag())) {
refElements.add(checkClass.getTag());
}
}
}
if (ec.getObjectClass()==null) {
continue;
}
if (checkClass.getObjectClass()==null) {
continue;
}
Class<?> objectClass = ec.getObjectClass();
Class<?> checkObjectClass = checkClass.getObjectClass();
List<ElementBindingHandler> b = context.findElementBindingHandlers(objectClass,checkObjectClass);
if (b.isEmpty()==false) {
refElements.add(checkClass.getTag());
}
}
if (refElements.isEmpty()==false) {
Set<String> s = new HashSet<String>(refElements.size());
s.addAll(refElements);
List<String> r = new ArrayList<String>(s.size());
r.addAll(s);
Collections.sort(r);
String prefix = namespaces.get(ns.getUri());
for (String refElement:r) {
atts = new AttributesImpl();
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
atts.addAttribute ("", "ref", "", "", prefix+":"+refElement);
} else if (nsWrite.getUri().equals(ns.getUri())==false) {
atts.addAttribute ("", "ref", "", "", prefix+":"+refElement);
} else {
atts.addAttribute ("", "name", "", "", refElement);
atts.addAttribute ("", "type", "", "", prefix+":"+refElement+"Type");
}
xmlWriter.startElement (SCHEMA_URI, "element", "", atts);
xmlWriter.endElement (SCHEMA_URI, "element", "");
}
}
}
public void writeElement(ElementClass ec,ElementNamespaceContext nsWrite) throws SAXException {
if (nsWrite.getLanguageRoot()!=null && nsWrite.getLanguageRoot()) {
return; // is done in writeElementClass
}
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", ec.getTag());
atts.addAttribute ("", "type", "", "", "this:"+ec.getTag()+"Type");
xmlWriter.startElement(SCHEMA_URI, "element", "", atts); // Only in the language root xsd there is an element.
if (ec.getDescription()!=null) {
atts = new AttributesImpl();
xmlWriter.startElement(SCHEMA_URI, "annotation", "", atts);
atts = new AttributesImpl();
atts.addAttribute ("", "xml:lang", "", "", "en");
xmlWriter.startElement(SCHEMA_URI, "documentation", "", atts);
char[] msg = ec.getDescription().toCharArray();
xmlWriter.characters(msg,0,msg.length);
xmlWriter.endElement(SCHEMA_URI, "documentation", "");
xmlWriter.endElement(SCHEMA_URI, "annotation", "");
}
xmlWriter.endElement(SCHEMA_URI, "element", "");
}
}

View file

@ -0,0 +1,167 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.eld.xsd;
import java.io.File;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.x4o.xml.core.X4OParserSupport;
import org.x4o.xml.core.X4OParserSupportException;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
import org.x4o.xml.element.ElementLanguage;
import org.x4o.xml.element.ElementException;
/**
* X4OLanguageSchemaWriter is support class to write schema files from eld.
*
* @author Willem Cazander
* @version 1.0 Aug 22, 2012
*/
public class X4OLanguageEldXsdWriter {
private Class<?> languageParserSupport = null;
private String languageNamespaceUri = null;
private File basePath;
@SuppressWarnings("unchecked")
static public void main(String argu[]) {
X4OLanguageEldXsdWriter languageSchema = new X4OLanguageEldXsdWriter();
List<String> arguList = Arrays.asList(argu);
Iterator<String> arguIterator = arguList.iterator();
while (arguIterator.hasNext()) {
String arg = arguIterator.next();
if ("-path".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.out.println("No argument for -path given.");
System.exit(1);
return;
}
File schemaBasePath = new File(arguIterator.next());
if (schemaBasePath.exists()==false) {
System.out.println("path does not exists; "+schemaBasePath);
System.exit(1);
return;
}
languageSchema.setBasePath(schemaBasePath);
continue;
}
if ("-uri".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.out.println("No argument for -uri given.");
System.exit(1);
return;
}
languageSchema.setLanguageNamespaceUri(arguIterator.next());
continue;
}
if ("-class".equals(arg)) {
if (arguIterator.hasNext()==false) {
System.out.println("No argument for -class given.");
System.exit(1);
return;
}
String apiClass = arguIterator.next();
try {
languageSchema.setLanguageParserSupport((Class<X4OParserSupport>) X4OLanguageClassLoader.loadClass(apiClass));
} catch (ClassNotFoundException e) {
System.out.println("Schema api class is not found: "+apiClass);
System.exit(1);
return;
}
continue;
}
}
try {
languageSchema.execute();
} catch (X4OParserSupportException e) {
System.out.println("Error while schema writing: "+e.getMessage());
e.printStackTrace();
System.exit(1);
return;
}
}
public void execute() throws X4OParserSupportException {
try {
// Get the support context
X4OParserSupport languageSupport = (X4OParserSupport)getLanguageParserSupport().newInstance();
ElementLanguage context = languageSupport.loadElementLanguageSupport();
// Start xsd generator
EldXsdXmlGenerator xsd = new EldXsdXmlGenerator(context);
xsd.writeSchema(getBasePath(), getLanguageNamespaceUri());
} catch (InstantiationException e) {
throw new X4OParserSupportException(e);
} catch (IllegalAccessException e) {
throw new X4OParserSupportException(e);
} catch (ElementException e) {
throw new X4OParserSupportException(e);
}
}
/**
* @return the languageParserSupport
*/
public Class<?> getLanguageParserSupport() {
return languageParserSupport;
}
/**
* @param languageParserSupport the languageParserSupport to set
*/
public void setLanguageParserSupport(Class<?> languageParserSupport) {
this.languageParserSupport = languageParserSupport;
}
/**
* @return the languageNamespaceUri
*/
public String getLanguageNamespaceUri() {
return languageNamespaceUri;
}
/**
* @param languageNamespaceUri the languageNamespaceUri to set
*/
public void setLanguageNamespaceUri(String languageNamespaceUri) {
this.languageNamespaceUri = languageNamespaceUri;
}
/**
* @return the basePath
*/
public File getBasePath() {
return basePath;
}
/**
* @param basePath the basePath to set
*/
public void setBasePath(File basePath) {
this.basePath = basePath;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The X4O ELD to XSD Schema generator classes.
*
*
* @since 1.0
*/
package org.x4o.xml.eld.xsd;

View file

@ -0,0 +1,243 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.element;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.x4o.xml.core.config.X4OLanguageClassLoader;
/**
* An AbstractElement.
*
* @author Willem Cazander
* @version 1.0 Aug 8, 2005
*/
abstract public class AbstractElement implements Element {
/** The parent Element */
private Element parent = null;
/** The config object */
private Object elementObject = null;
/** The language parsing context */
private ElementLanguage elementLanguage = null;
/** The ElementClass */
private ElementClass elementClass = null;
/** The attributes */
private Map<String,String> attributes = new HashMap<String,String>(10);
/** The Childeren */
private List<Element> childeren = new ArrayList<Element>(10);
/** All Childeren */
private List<Element> allChilderen = new ArrayList<Element>(10);
/**
* @see Element#doElementStart()
*/
public void doElementStart() throws ElementException {
}
/**
* @see Element#doElementEnd()
*/
public void doElementEnd() throws ElementException {
}
/**
* @see Element#doElementRun()
*/
public void doElementRun() throws ElementException {
}
/**
* @see Element#setParent(Element)
*/
public void setParent(Element element) {
parent = element;
}
/**
* @see Element#getParent()
*/
public Element getParent() {
return parent;
}
/**
* Cleans the attributes and elements(class) and context.
* @see Element#release()
*/
public void release() throws ElementException {
getAttributes().clear();
setElementClass(null);
setParent(null);
setElementLanguage(null);
attributes.clear();
childeren.clear(); // we do not release childeren, x4o does that
allChilderen.clear();
}
/**
* @see Element#getElementObject()
*/
public Object getElementObject() {
return elementObject;
}
/**
* @see Element#setElementObject(Object)
*/
public void setElementObject(Object object) {
elementObject=object;
}
/**
* @see Element#setElementLanguage(ElementLanguage)
*/
public void setElementLanguage(ElementLanguage elementLanguage) {
this.elementLanguage=elementLanguage;
}
/**
* @see Element#getElementLanguage()
*/
public ElementLanguage getElementLanguage() {
return elementLanguage;
}
/**
* @see org.x4o.xml.element.Element#doCharacters(java.lang.String)
*/
public void doCharacters(String characters) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getElementLanguage().getLanguageConfiguration().getDefaultElementBodyCharacters());
e.setElementObject(characters);
addChild(e);
} catch (Exception exception) {
throw new ElementException(exception);
}
}
/**
* @see org.x4o.xml.element.Element#doComment(java.lang.String)
*/
public void doComment(String comment) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getElementLanguage().getLanguageConfiguration().getDefaultElementBodyComment());
e.setElementObject(comment);
addChild(e);
} catch (Exception exception) {
throw new ElementException(exception);
}
}
/**
* @see org.x4o.xml.element.Element#doIgnorableWhitespace(java.lang.String)
*/
public void doIgnorableWhitespace(String space) throws ElementException {
try {
Element e = (Element)X4OLanguageClassLoader.newInstance(getElementLanguage().getLanguageConfiguration().getDefaultElementBodyWhitespace());
e.setElementObject(space);
addChild(e);
} catch (Exception exception) {
throw new ElementException(exception);
}
}
/**
* @see org.x4o.xml.element.Element#setElementClass(ElementClass)
*/
public void setElementClass(ElementClass elementClass) {
this.elementClass=elementClass;
}
/**
* @see org.x4o.xml.element.Element#getElementClass()
*/
public ElementClass getElementClass() {
return elementClass;
}
/**
* @see org.x4o.xml.element.Element#getAttributes()
*/
public Map<String, String> getAttributes() {
return attributes;
}
/**
* @see org.x4o.xml.element.Element#setAttribute(java.lang.String, java.lang.String)
*/
public void setAttribute(String name,String value) {
attributes.put(name, value);
}
/**
* @see org.x4o.xml.element.Element#getChilderen()
*/
public List<Element> getChilderen() {
return childeren;
}
/**
* @see org.x4o.xml.element.Element#addChild(Element)
*/
public void addChild(Element element) {
allChilderen.add(element);
if (ElementType.element.equals(element.getElementType())) {
childeren.add(element);
}
}
/**
* @see org.x4o.xml.element.Element#removeChild(Element)
*/
public void removeChild(Element element) {
childeren.remove(element);
allChilderen.remove(element);
}
/**
* @see org.x4o.xml.element.Element#getAllChilderen()
*/
public List<Element> getAllChilderen() {
return allChilderen;
}
/**
* @see org.x4o.xml.element.Element#getElementType()
*/
public ElementType getElementType() {
return ElementType.element;
}
/**
* Defaults to false.
* @see org.x4o.xml.element.Element#isTransformingTree()
*/
public boolean isTransformingTree() {
return false;
}
}

View file

@ -0,0 +1,80 @@
/*
* Copyright (c) 2004-2012, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.x4o.xml.element;
import java.util.ArrayList;
import java.util.List;
/**
* An AbstractElementAttributeHandler.
*
* @author Willem Cazander
* @version 1.0 Aug 10, 2006
*/
abstract public class AbstractElementAttributeHandler extends AbstractElementConfigurator implements ElementAttributeHandler {
private String attributeName = null;
private List<String> nextAttributes = new ArrayList<String>(2);
/**
* @see org.x4o.xml.element.ElementAttributeHandler#addNextAttribute(java.lang.String)
*/
public void addNextAttribute(String attribute) {
if (attribute==null) {
throw new NullPointerException("Can add null attribute for loading.");
}
nextAttributes.add(attribute);
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#removeNextAttribute(java.lang.String)
*/
public void removeNextAttribute(String attribute) {
if (attribute==null) {
throw new NullPointerException("Can remove null attribute for loading.");
}
nextAttributes.remove(attribute);
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#getNextAttributes()
*/
public List<String> getNextAttributes() {
return nextAttributes;
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#getAttributeName()
*/
public String getAttributeName() {
return attributeName;
}
/**
* @see org.x4o.xml.element.ElementAttributeHandler#setAttributeName(java.lang.String)
*/
public void setAttributeName(String attributeName) {
this.attributeName=attributeName;
}
}

Some files were not shown because too many files have changed in this diff Show more