Commit 20a05bb4 authored by Claus Nagel's avatar Claus Nagel
Browse files

No commit message

No commit message
parent 0e9858d4
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<classpathentry kind="lib" path="lib/jaxb-xjc.jar"/> <classpathentry kind="lib" path="lib/jaxb-xjc.jar"/>
<classpathentry kind="lib" path="lib/jsr173_1.0_api.jar"/> <classpathentry kind="lib" path="lib/jsr173_1.0_api.jar"/>
<classpathentry kind="lib" path="lib/args4j-2.0.9.jar"/> <classpathentry kind="lib" path="lib/args4j-2.0.9.jar"/>
<classpathentry kind="lib" path="lib/collection-setter-injector.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project name="citygml4j" default="dist" basedir="."> <project name="ade-xjc" default="dist" basedir=".">
<!-- application specific variables --> <!-- application specific variables -->
<property name="app.name" value="ade-xjc" /> <property name="app.name" value="ade-xjc" />
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
<property name="project.basedir" location=".." /> <property name="project.basedir" location=".." />
<property name="src" location="src" /> <property name="src" location="src" />
<property name="lib" location="lib" /> <property name="lib" location="lib" />
<property name="schemas" location="schemas" />
<property name="sample" location="sample" />
<property name="resources" location="resources" /> <property name="resources" location="resources" />
<property name="resources.doc" location="${resources}/doc" /> <property name="resources.doc" location="${resources}/doc" />
<property name="resources.license" location="${resources}/license" /> <property name="resources.license" location="${resources}/license" />
<property name="resources.schemas" location="${resources}/xml/schemas" />
<property name="build" location="build" /> <property name="build" location="build" />
<property name="build.classes" location="${build}/classes" /> <property name="build.classes" location="${build}/classes" />
...@@ -25,6 +27,7 @@ ...@@ -25,6 +27,7 @@
<property name="dist" location="${app.name}-${app.version}" /> <property name="dist" location="${app.name}-${app.version}" />
<property name="dist.license" location="${dist}/license" /> <property name="dist.license" location="${dist}/license" />
<property name="dist.schemas" location="${dist}/schemas" /> <property name="dist.schemas" location="${dist}/schemas" />
<property name="dist.sample" location="${dist}/sample" />
<!-- classpath --> <!-- classpath -->
<path id="classpath"> <path id="classpath">
...@@ -38,21 +41,23 @@ ...@@ -38,21 +41,23 @@
<target name="clean" description="clean up"> <target name="clean" description="clean up">
<!-- delete the ${build} and ${dist} directory trees --> <!-- delete the ${build} and ${dist} directory trees -->
<delete dir="${build}" /> <delete dir="${build}" />
<delete dir="${dist.license}" />
<delete dir="${dist.schemas}" />
<delete dir="${dist.sample}" />
<delete dir="${dist}" /> <delete dir="${dist}" />
</target> </target>
<target name="init" description="init build environment"> <target name="compile" description="compile the source">
<!-- create the build directory structure used by compile --> <delete dir="${build}" />
<mkdir dir="${build.classes}" /> <mkdir dir="${build.classes}" />
</target>
<target name="compile" depends="init" description="compile the source">
<!-- compile the java code from ${src} and ${src-gen} into ${build} --> <!-- compile the java code from ${src} and ${src-gen} into ${build} -->
<javac classpathref="classpath" srcdir="${src}" destdir="${build.classes}" /> <javac classpathref="classpath" srcdir="${src}" destdir="${build.classes}" />
</target> </target>
<target name="dist" depends="clean, compile" description="generate the distribution"> <target name="dist" depends="clean, compile" description="generate the distribution">
<!-- create the distribution directory --> <!-- create the distribution directory -->
<delete dir="${dist}" />
<mkdir dir="${dist}" /> <mkdir dir="${dist}" />
<!-- copy LICENSE template --> <!-- copy LICENSE template -->
...@@ -65,6 +70,11 @@ ...@@ -65,6 +70,11 @@
<fileset dir="${resources.doc}" includes="**/*" /> <fileset dir="${resources.doc}" includes="**/*" />
</copy> </copy>
<!-- copy sample -->
<copy todir="${dist.sample}">
<fileset dir="${sample}" includes="**/*" />
</copy>
<!-- replace tokens in template files --> <!-- replace tokens in template files -->
<replace file="${dist.license}/LICENSE" token="!app.title!" value="${app.title}" /> <replace file="${dist.license}/LICENSE" token="!app.title!" value="${app.title}" />
<replace file="${dist.license}/LICENSE" token="!app.name!" value="${app.name}" /> <replace file="${dist.license}/LICENSE" token="!app.name!" value="${app.name}" />
...@@ -72,12 +82,15 @@ ...@@ -72,12 +82,15 @@
<replace file="${dist}/README" token="!app.title!" value="${app.title}" /> <replace file="${dist}/README" token="!app.title!" value="${app.title}" />
<replace file="${dist}/README" token="!app.jar!" value="${app.jar}" /> <replace file="${dist}/README" token="!app.jar!" value="${app.jar}" />
<replace file="${dist}/README" token="!app.version!" value="${app.version}" /> <replace file="${dist}/README" token="!app.version!" value="${app.version}" />
<replace file="${dist.sample}/build.xml" token="!app.jar!" value="${app.jar}" />
<!-- copy schema files --> <!-- copy schema files -->
<copy todir="${dist.schemas}"> <copy todir="${dist.schemas}">
<fileset dir="${resources.schemas}" includes="**/*" /> <fileset dir="${schemas}" includes="**/*" />
</copy> </copy>
<buildnumber file="build.num"/>
<!-- put everything in ${build} into .jar file --> <!-- put everything in ${build} into .jar file -->
<jar jarfile="${dist}/${app.jar}" basedir="${build.classes}" filesetmanifest="mergewithoutmain"> <jar jarfile="${dist}/${app.jar}" basedir="${build.classes}" filesetmanifest="mergewithoutmain">
<manifest> <manifest>
......
!app.name! v!app.version! - !app.title! !app.name! v!app.version! - !app.title!
This library is free software and comes WITHOUT ANY WARRANTY. This program is free software and comes WITHOUT ANY WARRANTY.
See the file LICENSE for more details. See the file LICENSE for more details.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
1. Licence 1. Licence
---------- ----------
The !app.name! Java class library is free software under The !app.name! is free software under
the GNU Lesser General Public License Version 3.0. See the file LICENSE the GNU Lesser General Public License Version 3.0. See the file LICENSE
for more details. For a copy of the GNU Lesser General Public License see for more details. For a copy of the GNU Lesser General Public License see
the files COPYING and COPYING.LESSER or visit http://www.gnu.org/licenses/. the files COPYING and COPYING.LESSER or visit http://www.gnu.org/licenses/.
...@@ -38,47 +38,43 @@ http://www.igg.tu-berlin.de/ ...@@ -38,47 +38,43 @@ http://www.igg.tu-berlin.de/
3. About 3. About
-------- --------
!app.name! is a Java class library and API for facilitating work with the "!app.name!" is a command line tool and a wrapper for the XML Schema compiler
City Geography Markup Language (CityGML). It makes it easy to read, process, "xjc" shipped with JAXB. !app.name! compiles an arbitrary CityGML ADE Schema
and write CityGML datasets, and to develop CityGML-aware software to a set of corresponding JAXB classes. The resulting classes are automatically
applications. derived from the JAXB classes shipped with citygml4j. Thus, the classes can
easily be used with the citygml4j library. However, this also requires the
Feature list: citygml4j library on your classpath in order to use the compiled classes in
* Full support for CityGML version 1.0.0 and 0.4.0 your application.
* Support for CityGML specific subset of GML 3.1.1
* Support for the eXtensible Address Language (xAL)
* Support for user-defined CityGML Application Domain Extensions (ADE)
CityGML is a common information model for the representation of 3D urban
objects. It is realized as an open data model and XML-based format for the
storage and exchange of virtual 3D city models.
CityGML is implemented as an application schema for the Geography Markup
Language version 3.1.1 (GML3), the extendible international standard for
spatial data exchange issued by the Open Geospatial Consortium (OGC) and
the ISO TC211. CityGML is an official OGC standard and can be used
free of charge.
4. System requirements 4. System requirements
---------------------- ----------------------
* Java JRE or JDK >= 1.5 * Java JRE or JDK >= 1.5
* Java Architecture for XML Binding (JAXB) >= 2.1.10 * citygml4j library version !app.version!
5. How to use it 5. How to use it
---------------- ----------------
Simply modify your Java classpath to include the provided !app.name! is a command line tool. In order to get a list of supported
!app.jar! file. Please make sure also to include the arguments, invoke the tool in a shell environment like this:
required JAXB libraries on your application classpath.
> java -jar !app.jar! -help
The !app.name! compiler requires your ADE schema to point to the official
CityGML and GML schemas provided in the subfolder "schemas". So please
adapt all <xs:import> statements in your ADE schema accordingly before
invoking the !app.name! compiler!
Please find a sample ADE schema together with an ANT build file in the
subfolder "sample".
6. Developers 6. Developers
------------- -------------
Claus Nagel <nagel@igg.tu-berlin.de> Claus Nagel <claus.nagel@tu-berlin.de>
7. Contact 7. Contact
......
The !app.name! !app.title! is free software: The "!app.name!" program is free software:
you can redistribute it and/or modify it under the terms of the you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This library is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see License along with this program. If not, see
<http://www.gnu.org/licenses/>. <http://www.gnu.org/licenses/>.
\ No newline at end of file
...@@ -5,7 +5,10 @@ import java.io.FileNotFoundException; ...@@ -5,7 +5,10 @@ import java.io.FileNotFoundException;
import java.io.PrintStream; import java.io.PrintStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
...@@ -20,7 +23,7 @@ import com.sun.tools.xjc.api.SchemaCompiler; ...@@ -20,7 +23,7 @@ import com.sun.tools.xjc.api.SchemaCompiler;
import com.sun.tools.xjc.api.XJC; import com.sun.tools.xjc.api.XJC;
public class ADE_XJC { public class ADE_XJC {
private static final Logger LOG = Logger.getInstance(); private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
// some dirs we will need // some dirs we will need
private File schema_dir = new File("schemas"); private File schema_dir = new File("schemas");
...@@ -63,8 +66,16 @@ public class ADE_XJC { ...@@ -63,8 +66,16 @@ public class ADE_XJC {
CmdLineParser parser = new CmdLineParser(this); CmdLineParser parser = new CmdLineParser(this);
parser.setUsageWidth(80); parser.setUsageWidth(80);
List<String> tmp = new ArrayList<String>();
for (String arg : args)
tmp.addAll(Arrays.asList(arg.split(" +")));
String[] newArgs = new String[tmp.size()];
for (int i = 0; i < tmp.size(); i++)
newArgs[i] = tmp.get(i);
try { try {
parser.parseArgument(args); parser.parseArgument(newArgs);
} catch (CmdLineException e) { } catch (CmdLineException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
printUsage(parser, System.err); printUsage(parser, System.err);
...@@ -94,33 +105,33 @@ public class ADE_XJC { ...@@ -94,33 +105,33 @@ public class ADE_XJC {
System.exit(1); System.exit(1);
} }
LOG.info("Starting ade-xjc compiler"); log(LogLevel.INFO, "Starting ade-xjc compiler");
adeSchemaFile = new File(adeSchemaFileList.get(0)); adeSchemaFile = new File(adeSchemaFileList.get(0));
int status = 0; int status = 0;
try { try {
LOG.info("Setting up build environment"); log(LogLevel.INFO, "Setting up build environment");
checkBuildEnvironment(); checkBuildEnvironment();
if (clean) { if (clean) {
LOG.info("Cleaning output folder"); log(LogLevel.INFO, "Cleaning output folder");
Util.rmdir(outputFolder); Util.rmdir(outputFolder);
} }
createBuildEnvironment(); createBuildEnvironment();
if (packageName.startsWith("org.citygml4j")) { if (packageName.startsWith("org.citygml4j")) {
LOG.error("The package " + packageName + " is not allowed for the ADE classes"); log(LogLevel.ERROR, "The package " + packageName + " is not allowed for the ADE classes");
LOG.error("Choose a package which is not a subpackage of org.citygml4j. Aborting."); log(LogLevel.ERROR, "Choose a package which is not a subpackage of org.citygml4j. Aborting.");
System.exit(1); System.exit(1);
} }
LOG.info("Using ADE schema " + adeSchemaFile.getCanonicalFile()); log(LogLevel.INFO, "Using ADE schema " + adeSchemaFile.getCanonicalFile());
if (adeBindingFile != null) if (adeBindingFile != null)
LOG.info("Using JAXB binding " + adeBindingFile.getCanonicalFile()); log(LogLevel.INFO, "Using JAXB binding " + adeBindingFile.getCanonicalFile());
LOG.info("Using Java package " + packageName + " for JAXB classes"); log(LogLevel.INFO, "Using Java package " + packageName + " for JAXB classes");
LOG.info("Generating JAXB classes. This may take some time..."); log(LogLevel.INFO, "Generating JAXB classes. This may take some time...");
SchemaCompiler sc = XJC.createSchemaCompiler(); SchemaCompiler sc = XJC.createSchemaCompiler();
sc.setDefaultPackageName(packageName); sc.setDefaultPackageName(packageName);
...@@ -140,12 +151,12 @@ public class ADE_XJC { ...@@ -140,12 +151,12 @@ public class ADE_XJC {
code.build(outputFolder, (PrintStream)null); code.build(outputFolder, (PrintStream)null);
File packageDir = new File(outputFolder.getAbsolutePath()); File packageDir = new File(outputFolder.getAbsolutePath());
LOG.info("JAXB classes successfully written to " + packageDir.getCanonicalPath()); log(LogLevel.INFO, "JAXB classes successfully written to " + packageDir.getCanonicalPath());
} catch (Exception e) { } catch (Exception e) {
if (e.getMessage() != null) if (e.getMessage() != null)
LOG.error(e.getMessage()); log(LogLevel.ERROR, e.getMessage());
LOG.error("Unable to recover from previous error(s). Aborting."); log(LogLevel.ERROR, "Unable to recover from previous error(s). Aborting.");
status = 1; status = 1;
if (clean) if (clean)
...@@ -178,7 +189,7 @@ public class ADE_XJC { ...@@ -178,7 +189,7 @@ public class ADE_XJC {
throw new FileNotFoundException("Could not open folder " + schema_dir.getAbsolutePath()); throw new FileNotFoundException("Could not open folder " + schema_dir.getAbsolutePath());
if (!nonStrict) { if (!nonStrict) {
LOG.info("Running in strict mode. Checking sanity of subfolder 'schemas'"); log(LogLevel.INFO, "Running in strict mode. Checking sanity of subfolder 'schemas'");
BigInteger md5 = new BigInteger("0"); BigInteger md5 = new BigInteger("0");
md5 = Util.dir2md5(schema_dir, md5); md5 = Util.dir2md5(schema_dir, md5);
...@@ -208,4 +219,33 @@ public class ADE_XJC { ...@@ -208,4 +219,33 @@ public class ADE_XJC {
parser.printUsage(System.out); parser.printUsage(System.out);
out.println(); out.println();
} }
private void log(LogLevel level, String msg) {
StringBuilder builder = new StringBuilder();
builder.append("[")
.append(df.format(new Date()))
.append(" ")
.append(level.toString())
.append("] ")
.append(msg);
System.out.println(builder.toString());
}
private enum LogLevel {
INFO("info"),
WARN("warn"),
ERROR("error");
private String value;
LogLevel(String value) {
this.value = value;
}
public String toString() {
return value;
}
}
} }
package org.citygml4j.ade_xjc;
import java.text.DecimalFormat;
import java.util.Calendar;
public class Logger {
private static Logger INSTANCE = new Logger();
private LogLevelType logLevel = LogLevelType.INFO;
private Calendar cal;
private DecimalFormat df = new DecimalFormat("00");
private Logger() {
// just to thwart instantiation
}
public static Logger getInstance() {
return INSTANCE;
}
public void setLogLevel(LogLevelType logLevel) {
this.logLevel = logLevel;
}
public String getPrefix(LogLevelType type) {
cal = Calendar.getInstance();
int h = cal.get(Calendar.HOUR_OF_DAY);
int m = cal.get(Calendar.MINUTE);
int s = cal.get(Calendar.SECOND);
StringBuffer prefix = new StringBuffer();
prefix.append("[");
prefix.append(df.format(h));
prefix.append(":");
prefix.append(df.format(m));
prefix.append(":");
prefix.append(df.format(s));
prefix.append(" ");
prefix.append(type.value);
prefix.append("] ");
return prefix.toString();
}
private void log(LogLevelType type, String msg) {
System.out.println(getPrefix(type) + msg);
}
public void debug(String msg) {
if (logLevel.ordinal() <= LogLevelType.DEBUBG.ordinal())
log(LogLevelType.DEBUBG, msg);
}
public void info(String msg) {
if (logLevel.ordinal() <= LogLevelType.INFO.ordinal())
log(LogLevelType.INFO, msg);
}
public void warn(String msg) {
if (logLevel.ordinal() <= LogLevelType.WARN.ordinal())
log(LogLevelType.WARN, msg);
}
public void error(String msg) {
if (logLevel.ordinal() <= LogLevelType.ERROR.ordinal())
log(LogLevelType.ERROR, msg);
}
public enum LogLevelType {
DEBUBG("DEBUG"),
INFO("INFO"),
WARN("WARN"),
ERROR("ERROR");
private final String value;
LogLevelType(String v) {
value = v;
}
public String value() {
return value;
}
};
}
...@@ -17,8 +17,6 @@ public class Util { ...@@ -17,8 +17,6 @@ public class Util {
if (file.isDirectory()) { if (file.isDirectory()) {
File[] children = file.listFiles(new FileFilter() { File[] children = file.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) { public boolean accept(File pathname) {
if (pathname.isDirectory()) if (pathname.isDirectory())
return true; return true;
......
...@@ -6,22 +6,18 @@ import com.sun.tools.xjc.api.ErrorListener; ...@@ -6,22 +6,18 @@ import com.sun.tools.xjc.api.ErrorListener;
public class XJCErrorListener implements ErrorListener { public class XJCErrorListener implements ErrorListener {
@Override
public void error(SAXParseException ex) { public void error(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@Override
public void fatalError(SAXParseException ex) { public void fatalError(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@Override
public void info(SAXParseException ex) { public void info(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@Override
public void warning(SAXParseException ex) { public void warning(SAXParseException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment