Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Energy ADE
ADE Xjc
Commits
9416ebfb
Commit
9416ebfb
authored
Jan 21, 2018
by
Claus Nagel
Browse files
switched to Gradle
parent
e248ab95
Changes
27
Show whitespace changes
Inline
Side-by-side
schemas/CityGML/ade_hooks/ade_hooks.xsd
View file @
9416ebfb
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
*
*
* ade-xjc is part of the citygml4j project
* ade-xjc is part of the citygml4j project
*
*
* Copyright 2013-201
7
Claus Nagel <claus.nagel@gmail.com>
* Copyright 2013-201
8
Claus Nagel <claus.nagel@gmail.com>
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
-->
-->
<xs:schema
xmlns=
"http://www.
igg.tu-berlin.de/
citygml4j/ade_hooks"
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
<xs:schema
xmlns=
"http://www.citygml4j
.org
/ade_hooks"
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
targetNamespace=
"http://www.
igg.tu-berlin.de/
citygml4j/ade_hooks"
targetNamespace=
"http://www.citygml4j
.org
/ade_hooks"
xmlns:core1=
"http://www.opengis.net/citygml/1.0"
xmlns:app1=
"http://www.opengis.net/citygml/appearance/1.0"
xmlns:core1=
"http://www.opengis.net/citygml/1.0"
xmlns:app1=
"http://www.opengis.net/citygml/appearance/1.0"
xmlns:bldg1=
"http://www.opengis.net/citygml/building/1.0"
xmlns:frn1=
"http://www.opengis.net/citygml/cityfurniture/1.0"
xmlns:bldg1=
"http://www.opengis.net/citygml/building/1.0"
xmlns:frn1=
"http://www.opengis.net/citygml/cityfurniture/1.0"
xmlns:grp1=
"http://www.opengis.net/citygml/cityobjectgroup/1.0"
xmlns:luse1=
"http://www.opengis.net/citygml/landuse/1.0"
xmlns:grp1=
"http://www.opengis.net/citygml/cityobjectgroup/1.0"
xmlns:luse1=
"http://www.opengis.net/citygml/landuse/1.0"
...
...
schemas/CityGML/citygml4j_profile.xsd
View file @
9416ebfb
...
@@ -46,5 +46,5 @@
...
@@ -46,5 +46,5 @@
<xs:import
namespace=
"http://www.opengis.net/citygml/waterbody/2.0"
schemaLocation=
"2.0.0/waterBody.xsd"
/>
<xs:import
namespace=
"http://www.opengis.net/citygml/waterbody/2.0"
schemaLocation=
"2.0.0/waterBody.xsd"
/>
<xs:import
namespace=
"http://www.opengis.net/citygml/texturedsurface/2.0"
schemaLocation=
"2.0.0/texturedSurface.xsd"
/>
<xs:import
namespace=
"http://www.opengis.net/citygml/texturedsurface/2.0"
schemaLocation=
"2.0.0/texturedSurface.xsd"
/>
<!-- ade hooks -->
<!-- ade hooks -->
<xs:import
namespace=
"http://www.
igg.tu-berlin.de/
citygml4j/ade_hooks"
schemaLocation=
"ade_hooks/ade_hooks.xsd"
/>
<xs:import
namespace=
"http://www.citygml4j
.org
/ade_hooks"
schemaLocation=
"ade_hooks/ade_hooks.xsd"
/>
</xs:schema>
</xs:schema>
settings.gradle
0 → 100644
View file @
9416ebfb
rootProject
.
name
=
'ade-xjc'
src/org/citygml4j/ade_xjc/ADE
_XJC
.java
→
src/
main/java/
org/citygml4j/ade_xjc/ADE
SchemaCompiler
.java
View file @
9416ebfb
...
@@ -20,6 +20,23 @@
...
@@ -20,6 +20,23 @@
*/
*/
package
org.citygml4j.ade_xjc
;
package
org.citygml4j.ade_xjc
;
import
com.sun.codemodel.JCodeModel
;
import
com.sun.codemodel.writer.FileCodeWriter
;
import
com.sun.codemodel.writer.PrologCodeWriter
;
import
com.sun.tools.xjc.Options
;
import
com.sun.tools.xjc.Plugin
;
import
com.sun.tools.xjc.api.S2JJAXBModel
;
import
com.sun.tools.xjc.api.SchemaCompiler
;
import
com.sun.tools.xjc.api.XJC
;
import
com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl
;
import
org.citygml4j.ade_xjc.Util.URLClassLoader
;
import
org.kohsuke.args4j.Argument
;
import
org.kohsuke.args4j.CmdLineException
;
import
org.kohsuke.args4j.CmdLineParser
;
import
org.kohsuke.args4j.Option
;
import
org.kohsuke.args4j.ParserProperties
;
import
org.xml.sax.InputSource
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -28,7 +45,6 @@ import java.math.BigInteger;
...
@@ -28,7 +45,6 @@ import java.math.BigInteger;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
...
@@ -39,48 +55,22 @@ import java.util.ServiceLoader;
...
@@ -39,48 +55,22 @@ import java.util.ServiceLoader;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
import
org.citygml4j.ade_xjc.Util.URLClassLoader
;
public
class
ADESchemaCompiler
{
import
org.kohsuke.args4j.Argument
;
import
org.kohsuke.args4j.CmdLineException
;
import
org.kohsuke.args4j.CmdLineParser
;
import
org.kohsuke.args4j.Option
;
import
org.kohsuke.args4j.ParserProperties
;
import
org.xml.sax.InputSource
;
import
com.sun.codemodel.JCodeModel
;
import
com.sun.codemodel.writer.FileCodeWriter
;
import
com.sun.codemodel.writer.PrologCodeWriter
;
import
com.sun.tools.xjc.Options
;
import
com.sun.tools.xjc.Plugin
;
import
com.sun.tools.xjc.api.S2JJAXBModel
;
import
com.sun.tools.xjc.api.SchemaCompiler
;
import
com.sun.tools.xjc.api.XJC
;
import
com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl
;
public
class
ADE_XJC
{
private
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
private
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
private
Path
appHome
;
private
Path
workDir
;
// some dirs we will need
private
Path
schema_dir
=
Paths
.
get
(
"schemas"
);
private
Path
plugins_dir
=
Paths
.
get
(
"jaxb-plugins"
);
// some files we will need
private
Path
baseProfileFile
=
schema_dir
.
resolve
(
"CityGML/citygml4j_profile.xsd"
);
private
Path
bindingFile
=
schema_dir
.
resolve
(
"CityGML/binding.xjb"
);
private
Path
adeSchemaFile
=
null
;
// args
@Argument
@Argument
private
List
<
String
>
adeSchemaFileList
=
new
ArrayList
<
String
>();
private
List
<
String
>
adeSchemaFileList
=
new
ArrayList
<>();
@Option
(
name
=
"-package"
,
usage
=
"package for the ADE JAXB classes"
,
metaVar
=
"<packageName>"
)
@Option
(
name
=
"-package"
,
usage
=
"package for the ADE JAXB classes"
,
metaVar
=
"<packageName>"
)
private
String
packageName
=
"ade"
;
private
String
packageName
=
"ade"
;
@Option
(
name
=
"-binding"
,
usage
=
"optional JAXB binding file for ADE XML Schema"
,
metaVar
=
"<fileName>"
)
@Option
(
name
=
"-binding"
,
usage
=
"optional JAXB binding file for ADE XML Schema"
,
metaVar
=
"<fileName>"
)
private
File
adeBindingFile
=
null
;
private
Path
adeBindingFile
;
@Option
(
name
=
"-output"
,
usage
=
"output folder"
,
metaVar
=
"<folderName>"
)
@Option
(
name
=
"-output"
,
usage
=
"output folder"
,
metaVar
=
"<folderName>"
)
private
File
outputFolder
=
new
File
(
"src-gen"
);
private
Path
outputFolder
=
Paths
.
get
(
"src-gen"
);
@Option
(
name
=
"-non-strict"
,
usage
=
"allow changes to contents of subfolder 'schemas'"
)
@Option
(
name
=
"-non-strict"
,
usage
=
"allow changes to contents of subfolder 'schemas'"
)
private
boolean
nonStrict
=
false
;
private
boolean
nonStrict
=
false
;
...
@@ -88,26 +78,24 @@ public class ADE_XJC {
...
@@ -88,26 +78,24 @@ public class ADE_XJC {
@Option
(
name
=
"-clean"
,
usage
=
"clean output folder"
)
@Option
(
name
=
"-clean"
,
usage
=
"clean output folder"
)
private
boolean
clean
;
private
boolean
clean
;
@Option
(
name
=
"-h"
,
aliases
={
"-h
elp
"
},
usage
=
"print this help message and exit"
)
@Option
(
name
=
"-h
elp
"
,
aliases
={
"-h"
},
usage
=
"print this help message and exit"
)
private
boolean
help
;
private
boolean
help
;
@Option
(
name
=
"-version"
,
usage
=
"print product version and exit"
)
@Option
(
name
=
"-version"
,
aliases
={
"-v"
},
usage
=
"print product version and exit"
)
private
boolean
version
;
private
boolean
version
;
@Option
(
name
=
"-X{arg}"
,
usage
=
"one or more arguments for JAXB plugins"
)
@Option
(
name
=
"-X{arg}"
,
usage
=
"one or more arguments for JAXB plugins"
)
private
Boolean
dummy
=
null
;
private
Boolean
dummy
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
new
ADE
_XJC
().
doMain
(
args
);
new
ADE
SchemaCompiler
().
doMain
(
args
);
}
}
private
void
doMain
(
String
[]
_args
)
{
private
void
doMain
(
String
[]
_args
)
{
List
<
String
>
tmp
=
new
ArrayList
<
String
>();
for
(
String
arg
:
_args
)
tmp
.
addAll
(
Arrays
.
asList
(
arg
.
split
(
" +"
)));
Map
<
Boolean
,
List
<
String
>>
args
=
tmp
.
stream
().
collect
(
Collectors
.
partitioningBy
(
arg
->
!
arg
.
startsWith
(
"-X"
)));
CmdLineParser
parser
=
new
CmdLineParser
(
this
,
ParserProperties
.
defaults
().
withUsageWidth
(
80
));
CmdLineParser
parser
=
new
CmdLineParser
(
this
,
ParserProperties
.
defaults
().
withUsageWidth
(
80
));
Map
<
Boolean
,
List
<
String
>>
args
=
Arrays
.
stream
(
_args
)
.
flatMap
(
arg
->
Arrays
.
stream
(
arg
.
split
(
"\\s+"
)))
.
collect
(
Collectors
.
partitioningBy
(
arg
->
!
arg
.
startsWith
(
"-X"
)));
try
{
try
{
parser
.
parseArgument
(
args
.
get
(
Boolean
.
TRUE
));
parser
.
parseArgument
(
args
.
get
(
Boolean
.
TRUE
));
...
@@ -123,8 +111,8 @@ public class ADE_XJC {
...
@@ -123,8 +111,8 @@ public class ADE_XJC {
}
}
if
(
version
)
{
if
(
version
)
{
System
.
out
.
println
(
"ade-xjc
version "
+
this
.
getClass
().
getPackage
().
getImplementationVersion
());
System
.
out
.
println
(
getClass
().
getPackage
().
getImplementationTitle
()
+
"
version "
+
getClass
().
getPackage
().
getImplementationVersion
());
System
.
out
.
println
(
this
.
getClass
().
getPackage
().
getImplementation
Title
());
System
.
out
.
println
(
"XML Schema binding compiler for CityGML ADEs; use with citygml4j version "
+
getClass
().
getPackage
().
getImplementation
Version
());
System
.
exit
(
0
);
System
.
exit
(
0
);
}
}
...
@@ -141,16 +129,29 @@ public class ADE_XJC {
...
@@ -141,16 +129,29 @@ public class ADE_XJC {
}
}
log
(
LogLevel
.
INFO
,
"Starting ade-xjc compiler"
);
log
(
LogLevel
.
INFO
,
"Starting ade-xjc compiler"
);
adeSchemaFile
=
Paths
.
get
(
adeSchemaFileList
.
get
(
0
));
int
status
=
0
;
int
status
=
0
;
initialize
();
try
{
try
{
log
(
LogLevel
.
INFO
,
"Setting up build environment"
);
log
(
LogLevel
.
INFO
,
"Setting up build environment"
);
checkBuildEnvironment
();
Path
schemaDir
=
appHome
.
resolve
(
"schemas"
);
Path
pluginsDir
=
appHome
.
resolve
(
"jaxb-plugins"
);
Path
adeSchemaFile
=
Paths
.
get
(
adeSchemaFileList
.
get
(
0
));
if
(!
adeSchemaFile
.
isAbsolute
())
adeSchemaFile
=
workDir
.
resolve
(
adeSchemaFile
);
if
(!
adeBindingFile
.
isAbsolute
())
adeBindingFile
=
workDir
.
resolve
(
adeBindingFile
);
if
(!
outputFolder
.
isAbsolute
())
outputFolder
=
workDir
.
resolve
(
outputFolder
);
checkBuildEnvironment
(
schemaDir
,
adeSchemaFile
);
if
(
clean
&&
Files
.
exists
(
outputFolder
.
toPath
()
))
{
if
(
clean
&&
Files
.
exists
(
outputFolder
))
{
log
(
LogLevel
.
INFO
,
"Cleaning output folder"
);
log
(
LogLevel
.
INFO
,
"Cleaning output folder"
);
Files
.
walkFileTree
(
outputFolder
.
toPath
()
,
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
,
new
FileDeleter
(
true
));
}
}
createBuildEnvironment
();
createBuildEnvironment
();
...
@@ -163,21 +164,21 @@ public class ADE_XJC {
...
@@ -163,21 +164,21 @@ public class ADE_XJC {
log
(
LogLevel
.
INFO
,
"Using ADE schema "
+
adeSchemaFile
.
toAbsolutePath
().
toString
());
log
(
LogLevel
.
INFO
,
"Using ADE schema "
+
adeSchemaFile
.
toAbsolutePath
().
toString
());
if
(
adeBindingFile
!=
null
)
if
(
adeBindingFile
!=
null
)
log
(
LogLevel
.
INFO
,
"Using JAXB binding "
+
adeBindingFile
.
getCanonicalFile
());
log
(
LogLevel
.
INFO
,
"Using JAXB binding "
+
adeBindingFile
.
toAbsolutePath
());
log
(
LogLevel
.
INFO
,
"Using Java package "
+
packageName
+
" for JAXB classes"
);
log
(
LogLevel
.
INFO
,
"Using Java package "
+
packageName
+
" for JAXB classes"
);
SchemaCompiler
sc
=
XJC
.
createSchemaCompiler
();
SchemaCompiler
sc
=
XJC
.
createSchemaCompiler
();
sc
.
setDefaultPackageName
(
packageName
);
sc
.
setDefaultPackageName
(
packageName
);
if
(!
args
.
get
(
Boolean
.
FALSE
).
isEmpty
()
&&
Files
.
exists
(
plugins
_d
ir
))
{
if
(!
args
.
get
(
Boolean
.
FALSE
).
isEmpty
()
&&
Files
.
exists
(
plugins
D
ir
))
{
log
(
LogLevel
.
INFO
,
"Loading and configuring JAXB plugins"
);
log
(
LogLevel
.
INFO
,
"Loading and configuring JAXB plugins"
);
String
[]
pluginArgs
=
args
.
get
(
Boolean
.
FALSE
).
stream
().
toArray
(
String
[]
::
new
);
String
[]
pluginArgs
=
args
.
get
(
Boolean
.
FALSE
).
toArray
(
new
String
[
0
]);
Options
options
=
((
SchemaCompilerImpl
)
sc
).
getOptions
();
Options
options
=
((
SchemaCompilerImpl
)
sc
).
getOptions
();
URLClassLoader
loader
=
new
URLClassLoader
();
URLClassLoader
loader
=
new
URLClassLoader
();
try
(
Stream
<
Path
>
stream
=
Files
.
walk
(
plugins
_d
ir
).
filter
(
path
->
path
.
getFileName
().
toString
().
toLowerCase
().
endsWith
(
".jar"
)))
{
try
(
Stream
<
Path
>
stream
=
Files
.
walk
(
plugins
D
ir
).
filter
(
path
->
path
.
getFileName
().
toString
().
toLowerCase
().
endsWith
(
".jar"
)))
{
stream
.
forEach
(
path
->
loader
.
addPath
(
path
)
);
stream
.
forEach
(
loader
:
:
addPath
);
}
}
ServiceLoader
<
Plugin
>
plugins
=
ServiceLoader
.
load
(
Plugin
.
class
,
loader
);
ServiceLoader
<
Plugin
>
plugins
=
ServiceLoader
.
load
(
Plugin
.
class
,
loader
);
...
@@ -198,29 +199,30 @@ public class ADE_XJC {
...
@@ -198,29 +199,30 @@ public class ADE_XJC {
sc
.
setErrorListener
(
listener
);
sc
.
setErrorListener
(
listener
);
log
(
LogLevel
.
INFO
,
"Generating JAXB classes. This may take some time..."
);
log
(
LogLevel
.
INFO
,
"Generating JAXB classes. This may take some time..."
);
sc
.
parseSchema
(
new
InputSource
(
baseProfileFile
.
toUri
().
toString
()));
sc
.
parseSchema
(
new
InputSource
(
schemaDir
.
resolve
(
"CityGML"
).
resolve
(
"citygml4j_profile.xsd"
)
.
toUri
().
toString
()));
sc
.
parseSchema
(
new
InputSource
(
binding
File
.
toUri
().
toString
()));
sc
.
parseSchema
(
new
InputSource
(
schemaDir
.
resolve
(
"CityGML"
).
resolve
(
"
binding
.xjb"
)
.
toUri
().
toString
()));
sc
.
parseSchema
(
new
InputSource
(
adeSchemaFile
.
toUri
().
toString
()));
sc
.
parseSchema
(
new
InputSource
(
adeSchemaFile
.
toUri
().
toString
()));
if
(
adeBindingFile
!=
null
)
if
(
adeBindingFile
!=
null
)
sc
.
parseSchema
(
new
InputSource
(
adeBindingFile
.
toU
RI
().
toString
()));
sc
.
parseSchema
(
new
InputSource
(
adeBindingFile
.
toU
ri
().
toString
()));
S2JJAXBModel
model
=
sc
.
bind
();
S2JJAXBModel
model
=
sc
.
bind
();
JCodeModel
code
=
model
.
generateCode
(
null
,
listener
);
JCodeModel
code
=
model
.
generateCode
(
null
,
listener
);
// write classes using a header comment
// write classes using a header comment
PrologCodeWriter
writer
=
new
PrologCodeWriter
(
new
FileCodeWriter
(
outputFolder
,
"UTF-8"
),
PrologCodeWriter
writer
=
new
PrologCodeWriter
(
new
FileCodeWriter
(
outputFolder
.
toFile
()
,
"UTF-8"
),
"Generated with ade-xjc - XML Schema binding compiler for CityGML ADEs, version "
+
this
.
getClass
().
getPackage
().
getImplementationVersion
()
+
"\n"
"Generated with ade-xjc - XML Schema binding compiler for CityGML ADEs, version "
+
this
.
getClass
().
getPackage
().
getImplementationVersion
()
+
"\n"
+
"ade-xjc is part of the citygml4j project, see https://github.com/citygml4j\n"
+
"ade-xjc is part of the citygml4j project, see https://github.com/citygml4j\n"
+
"Any modifications to this file will be lost upon recompilation of the source\n"
+
"Any modifications to this file will be lost upon recompilation of the source\n"
+
"Generated: "
+
new
Date
().
toString
()
+
"\n"
);
+
"Generated: "
+
new
Date
().
toString
()
+
"\n"
);
code
.
build
(
writer
);
code
.
build
(
writer
);
File
packageDir
=
new
File
(
outputFolder
.
getAbsolutePath
());
log
(
LogLevel
.
INFO
,
"JAXB classes successfully written to "
+
outputFolder
.
toAbsolutePath
());
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
(
LogLevel
.
ERROR
,
e
.
getMessage
());
log
(
LogLevel
.
ERROR
,
e
.
getMessage
());
else
log
(
LogLevel
.
ERROR
,
"An unexpected "
+
e
+
" occurred."
);
log
(
LogLevel
.
ERROR
,
"Unable to recover from previous error(s). Aborting."
);
log
(
LogLevel
.
ERROR
,
"Unable to recover from previous error(s). Aborting."
);
status
=
1
;
status
=
1
;
...
@@ -236,60 +238,82 @@ public class ADE_XJC {
...
@@ -236,60 +238,82 @@ public class ADE_XJC {
System
.
exit
(
status
);
System
.
exit
(
status
);
}
}
private
void
initialize
()
{
String
appHomeName
=
System
.
getenv
(
"APP_HOME"
);
String
workDirName
=
System
.
getenv
(
"WORKING_DIR"
);
if
(
appHomeName
==
null
)
{
log
(
LogLevel
.
WARN
,
"Environment variable APP_HOME not set. Using current working directory."
);
appHomeName
=
"."
;
}
if
(
workDirName
==
null
)
{
log
(
LogLevel
.
WARN
,
"Environment variable WORKING_DIR not set. Using current working directory."
);
workDirName
=
"."
;
}
appHome
=
Paths
.
get
(
appHomeName
).
normalize
().
toAbsolutePath
();
if
(!
Files
.
exists
(
appHome
))
{
log
(
LogLevel
.
ERROR
,
"Invalid working directory '"
+
appHomeName
+
"'."
);
System
.
exit
(
1
);
}
workDir
=
Paths
.
get
(
workDirName
).
normalize
().
toAbsolutePath
();
if
(!
Files
.
exists
(
workDir
))
{
log
(
LogLevel
.
ERROR
,
"Invalid working directory '"
+
workDirName
+
"'."
);
System
.
exit
(
1
);
}
}
private
void
createBuildEnvironment
()
throws
Exception
{
private
void
createBuildEnvironment
()
throws
Exception
{
boolean
success
=
true
;
if
(!
Files
.
exists
(
outputFolder
))
Files
.
createDirectories
(
outputFolder
);
if
(
success
&&
!
outputFolder
.
exists
())
{
else
if
(!
Files
.
isDirectory
(
outputFolder
))
{
success
=
outputFolder
.
mkdirs
();
Files
.
delete
(
outputFolder
);
if
(!
success
)
Files
.
createDirectories
(
outputFolder
);
throw
new
Exception
(
"Could not create directory "
+
outputFolder
.
getAbsolutePath
());
}
else
if
(!
outputFolder
.
isDirectory
())
{
success
=
outputFolder
.
delete
();
if
(
success
)
success
=
outputFolder
.
mkdirs
();
else
throw
new
Exception
(
"Could not create directory "
+
outputFolder
.
getAbsolutePath
());
}
}
}
}
private
void
checkBuildEnvironment
(
)
throws
Exception
,
FileNotFoundException
,
NoSuchAlgorithm
Exception
{
private
void
checkBuildEnvironment
(
Path
schemaDir
,
Path
adeSchemaFile
)
throws
Exception
{
if
(!
Files
.
exists
(
schema
_d
ir
))
if
(!
Files
.
exists
(
schema
D
ir
))
throw
new
FileNotFoundException
(
"Failed to open folder "
+
schema
_d
ir
.
toAbsolutePath
().
toString
());
throw
new
FileNotFoundException
(
"Failed to open folder "
+
schema
D
ir
.
toAbsolutePath
().
toString
());
if
(!
nonStrict
)
{
if
(!
nonStrict
)
{
log
(
LogLevel
.
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
_d
ir
.
toFile
(),
md5
);
md5
=
Util
.
dir2md5
(
schema
D
ir
.
toFile
(),
md5
);
if
(!
md5
.
toString
(
16
).
equals
(
"
79facf9d68ad19afacf8d51a58c5f8b6
"
))
if
(!
md5
.
toString
(
16
).
equals
(
"
64fffffdb208ef0382a769611d2ab54
"
))
throw
new
Exception
(
"Contents of subfolder 'schemas' have been altered. Please restore its original state."
);
throw
new
Exception
(
"Contents of subfolder 'schemas' have been altered. Please restore its original state."
);
}
}
if
(!
Files
.
exists
(
adeSchemaFile
)
||
!
Files
.
isRegularFile
(
adeSchemaFile
)
||
!
Files
.
isReadable
(
adeSchemaFile
))
if
(!
Files
.
exists
(
adeSchemaFile
)
||
!
Files
.
isRegularFile
(
adeSchemaFile
)
||
!
Files
.
isReadable
(
adeSchemaFile
))
throw
new
Exception
(
"Could not open ADE schema file "
+
adeSchemaFile
.
toAbsolutePath
().
toString
());
throw
new
Exception
(
"Could not open ADE schema file "
+
adeSchemaFile
.
toAbsolutePath
().
toString
());
if
(
adeBindingFile
!=
null
&&
(!
adeBindingFile
.
exists
()
||
!
adeBindingFile
.
isFile
()
||
!
adeBindingFile
.
canRead
()))
if
(
adeBindingFile
!=
null
&&
(!
Files
.
exists
(
adeBindingFile
)
throw
new
Exception
(
"Could not open ADE binding file "
+
adeBindingFile
.
getAbsolutePath
());
||
!
Files
.
isRegularFile
(
adeBindingFile
)
||
!
Files
.
isReadable
(
adeBindingFile
)))
throw
new
Exception
(
"Could not open ADE binding file "
+
adeBindingFile
.
toAbsolutePath
());
}
}
private
void
cleanBuildEnvironment
(
boolean
cleanAll
)
throws
IOException
{
private
void
cleanBuildEnvironment
(
boolean
cleanAll
)
throws
IOException
{
if
(!
cleanAll
)
{
if
(!
cleanAll
)
{
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"net/opengis/citygml"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"net/opengis/citygml"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"net/opengis/gml"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"net/opengis/gml"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"oasis/names/tc/ciq/xsdschema/xal/_2"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"oasis/names/tc/ciq/xsdschema/xal/_2"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"org/citygml4j"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"org/citygml4j"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"org/w3/_1999/xlink"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"org/w3/_1999/xlink"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"org/w3/_2001/smil20"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"org/w3/_2001/smil20"
),
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"net"
),
new
FileDeleter
(
true
,
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"net"
),
new
FileDeleter
(
true
,
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"org"
),
new
FileDeleter
(
true
,
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"org"
),
new
FileDeleter
(
true
,
true
));
Files
.
walkFileTree
(
Paths
.
get
(
outputFolder
.
getAbsolutePath
(),
"oasis"
),
new
FileDeleter
(
true
,
true
));
Files
.
walkFileTree
(
outputFolder
.
resolve
(
"oasis"
),
new
FileDeleter
(
true
,
true
));
}
else
}
else
Files
.
walkFileTree
(
outputFolder
.
toPath
()
,
new
FileDeleter
(
true
));
Files
.
walkFileTree
(
outputFolder
,
new
FileDeleter
(
true
));
}
}
private
void
printUsage
(
CmdLineParser
parser
,
PrintStream
out
)
{
private
void
printUsage
(
CmdLineParser
parser
,
PrintStream
out
)
{
out
.
println
(
"Usage:
java -jar ade-xjc.jar
[-options] ade.xsd"
);
out
.
println
(
"Usage:
"
+
getClass
().
getPackage
().
getImplementationTitle
()
+
"
[-options] ade.xsd"
);
out
.
println
();
out
.
println
();
out
.
println
(
"where options include:"
);
out
.
println
(
"where options include:"
);
parser
.
printUsage
(
System
.
out
);
parser
.
printUsage
(
System
.
out
);
...
@@ -297,15 +321,7 @@ public class ADE_XJC {
...
@@ -297,15 +321,7 @@ public class ADE_XJC {
}
}
private
void
log
(
LogLevel
level
,
String
msg
)
{
private
void
log
(
LogLevel
level
,
String
msg
)
{
StringBuilder
builder
=
new
StringBuilder
();
System
.
out
.
println
(
"["
+
df
.
format
(
new
Date
())
+
" "
+
level
.
toString
()
+
"] "
+
msg
);
builder
.
append
(
"["
)
.
append
(
df
.
format
(
new
Date
()))
.
append
(
" "
)
.
append
(
level
.
toString
())
.
append
(
"] "
)
.
append
(
msg
);
System
.
out
.
println
(
builder
.
toString
());
}
}
private
enum
LogLevel
{
private
enum
LogLevel
{
...
...
src/org/citygml4j/ade_xjc/FileDeleter.java
→
src/
main/java/
org/citygml4j/ade_xjc/FileDeleter.java
View file @
9416ebfb
...
@@ -32,17 +32,17 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
...
@@ -32,17 +32,17 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
private
boolean
recursive
;
private
boolean
recursive
;
private
boolean
onlyEmptyDirs
;
private
boolean
onlyEmptyDirs
;
public
FileDeleter
(
boolean
recursive
)
{
FileDeleter
(
boolean
recursive
)
{
this
(
recursive
,
false
);
this
(
recursive
,
false
);
}
}
public
FileDeleter
(
boolean
recursive
,
boolean
onlyEmptyDirs
)
{
FileDeleter
(
boolean
recursive
,
boolean
onlyEmptyDirs
)
{
this
.
recursive
=
recursive
;
this
.
recursive
=
recursive
;
this
.
onlyEmptyDirs
=
onlyEmptyDirs
;
this
.
onlyEmptyDirs
=
onlyEmptyDirs
;
}
}
boolean
deleteFile
(
Path
file
)
throws
IOException
{
private
void
deleteFile
(
Path
file
)
throws
IOException
{
return
Files
.
deleteIfExists
(
file
);
Files
.
deleteIfExists
(
file
);
}
}
@Override
@Override
...
@@ -54,7 +54,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
...
@@ -54,7 +54,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
}
}
@Override
@Override
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
throws
IOException
{
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
{
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
...
@@ -77,7 +77,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
...
@@ -77,7 +77,7 @@ public class FileDeleter extends SimpleFileVisitor<Path> {
}
}
@Override
@Override
public
FileVisitResult
visitFileFailed
(
Path
file
,
IOException
exc
)
throws
IOException
{
public
FileVisitResult
visitFileFailed
(
Path
file
,
IOException
exc
)
{
return
FileVisitResult
.
CONTINUE
;
return
FileVisitResult
.
CONTINUE
;
}
}
...
...
src/org/citygml4j/ade_xjc/Util.java
→
src/
main/java/
org/citygml4j/ade_xjc/Util.java
View file @
9416ebfb
...
@@ -21,9 +21,7 @@
...
@@ -21,9 +21,7 @@
package
org.citygml4j.ade_xjc
;
package
org.citygml4j.ade_xjc
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
...
@@ -35,38 +33,30 @@ import java.security.NoSuchAlgorithmException;
...
@@ -35,38 +33,30 @@ import java.security.NoSuchAlgorithmException;
public
class
Util
{
public
class
Util
{
public
static
BigInteger
dir2md5
(
File
file
,
BigInteger
md5
)
throws
NoSuchAlgorithmException
,
FileNotFoundException
{
public
static
BigInteger
dir2md5
(
File
file
,
BigInteger
md5
)
throws
NoSuchAlgorithmException
{
md5
=
string2md5
(
file
.
getName
(),
md5
);
md5
=
string2md5
(
file
.
getName
(),
md5
);
if
(
file
.
isDirectory
())
{
if
(
file
.
isDirectory
())
{
File
[]
children
=
file
.
listFiles
(
new
FileFilter
()
{
File
[]
children
=
file
.
listFiles
(
pathname
->
pathname
.
isDirectory
()
public
boolean
accept
(
File
pathname
)
{
||
pathname
.
getName
().
endsWith
(
"xsd"
)
if
(
pathname
.
isDirectory
())
||
pathname
.
getName
().
endsWith
(
"xjb"
));
return
true
;
if
(
pathname
.
getName
().
endsWith
(
"xsd"
)
||
pathname
.
getName
().
endsWith
(
"xjb"
))
return
true
;
return
false
;
}
});
if
(
children
!=
null
)
{
for
(
File
next
:
children
)
for
(
File
next
:
children
)
md5
=
dir2md5
(
next
,
md5
);
md5
=
dir2md5
(
next
,
md5
);
}
}
else
}
else
md5
=
file2md5
(
file
.
getAbsolutePath
(),
md5
);
md5
=
file2md5
(
file
.
getAbsolutePath
(),
md5
);
return
md5
;
return
md5
;
}
}
p
ublic
static
BigInteger
file2md5
(
String
fileName
,
BigInteger
md5
)
throws
NoSuchAlgorithmException
,
FileNotFoundException
{
p
rivate
static
BigInteger
file2md5
(
String
fileName
,
BigInteger
md5
)
throws
NoSuchAlgorithmException
{
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"MD5"
);
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"MD5"
);
InputStream
is
=
new
FileInputStream
(
new
File
(
fileName
));
byte
[]
buffer
=
new
byte
[
8192
];
byte
[]
buffer
=
new
byte
[
8192
];
int
read
=
0
;
int
read
;
try
{
try
(
InputStream
is
=
new
FileInputStream
(
new
File
(
fileName
)))
{
while
(
(
read
=
is
.
read
(
buffer
))
>
0
)
while
(
(
read
=
is
.
read
(
buffer
))
>
0
)
digest
.
update
(
buffer
,
0
,
read
);
digest
.
update
(
buffer
,
0
,
read
);
...
@@ -75,13 +65,6 @@ public class Util {
...
@@ -75,13 +65,6 @@ public class Util {
return
md5
.
xor
(
new
BigInteger
(
1
,
md5sum
));
return
md5
.
xor
(
new
BigInteger
(
1
,
md5sum
));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Unable to process file for MD5"
,
e
);
throw
new
RuntimeException
(
"Unable to process file for MD5"
,
e
);
}
finally
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Unable to close input stream for MD5 calculation"
,
e
);
}
}
}
}
}
...
@@ -93,8 +76,8 @@ public class Util {
...
@@ -93,8 +76,8 @@ public class Util {
}
}
public
static
class
URLClassLoader
extends
java
.
net
.
URLClassLoader
{
public
static
class
URLClassLoader
extends
java
.
net
.
URLClassLoader
{
protected
URLClassLoader
()
{
URLClassLoader
()
{
super
(
new
URL
[]{},
Util
.
class
.
getClassLoader
());
super
(
new
URL
[]{},
ADESchemaCompiler
.
class
.
getClassLoader
());
}
}
@Override
@Override
...
@@ -102,14 +85,13 @@ public class Util {
...
@@ -102,14 +85,13 @@ public class Util {
super
.
addURL
(
url
);
super
.
addURL
(
url
);
}
}
protected
void
addPath
(
Path
path
)
{
void
addPath
(
Path
path
)
{
try
{
try
{
super
.
addURL
(
path
.
toUri
().
toURL
());
super
.
addURL
(
path
.
toUri
().
toURL
());
}
catch
(
MalformedURLException
e
)
{
}
catch
(
MalformedURLException
e
)
{
//
//
}
}
}
}
}
}
}
}
src/org/citygml4j/ade_xjc/XJCErrorListener.java
→
src/
main/java/
org/citygml4j/ade_xjc/XJCErrorListener.java
View file @
9416ebfb
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment