// set flag for unwrapping
boolean unwrap = !codeGenConfig.isParametersWrapped();
// initialize the binding information
BindingElement binding = null;
if (file == null) {
// unwrapped can be used without a binding, but wrapped requires one
if (!unwrap) {
throw new RuntimeException("JiBX wrapped support requires a binding definition to be provided using the -E" +
JiBXExtension.BINDING_PATH_OPTION + " {file-path} parameter");
}
} else {
// Read the JiBX binding definition into memory. The binding definition
// is only prevalidated so as not to require the user to have all
// the referenced classes in the classpath, though this does make for
// added work in finding the namespaces.
ValidationContext vctx = BindingElement.newValidationContext();
binding = BindingElement.readBinding(new FileInputStream(file), path, vctx);
binding.setBaseUrl(file.toURL());
vctx.setBindingRoot(binding);
IncludePrevalidationVisitor ipv = new IncludePrevalidationVisitor(vctx);
vctx.tourTree(binding, ipv);
if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
throw new RuntimeException("invalid jibx binding definition file " + path);
}
}
// create table with all built-in format definitions
Map simpleTypeMap = new HashMap();
buildFormat("byte", "byte",
"org.jibx.runtime.Utility.serializeByte",
"org.jibx.runtime.Utility.parseByte", "0", simpleTypeMap);
buildFormat("unsignedShort", "char",
"org.jibx.runtime.Utility.serializeChar",
"org.jibx.runtime.Utility.parseChar", "0", simpleTypeMap);
buildFormat("double", "double",
"org.jibx.runtime.Utility.serializeDouble",
"org.jibx.runtime.Utility.parseDouble", "0.0", simpleTypeMap);
buildFormat("float", "float",
"org.jibx.runtime.Utility.serializeFloat",
"org.jibx.runtime.Utility.parseFloat", "0.0", simpleTypeMap);
buildFormat("int", "int",
"org.jibx.runtime.Utility.serializeInt",
"org.jibx.runtime.Utility.parseInt", "0", simpleTypeMap);
buildFormat("long", "long",
"org.jibx.runtime.Utility.serializeLong",
"org.jibx.runtime.Utility.parseLong", "0", simpleTypeMap);
buildFormat("short", "short",
"org.jibx.runtime.Utility.serializeShort",
"org.jibx.runtime.Utility.parseShort", "0", simpleTypeMap);
buildFormat("boolean", "boolean",
"org.jibx.runtime.Utility.serializeBoolean",
"org.jibx.runtime.Utility.parseBoolean", "false",
simpleTypeMap);
buildFormat("dateTime", "java.util.Date",
"org.jibx.runtime.Utility.serializeDateTime",
"org.jibx.runtime.Utility.deserializeDateTime", null,
simpleTypeMap);
buildFormat("date", "java.sql.Date",
"org.jibx.runtime.Utility.serializeSqlDate",
"org.jibx.runtime.Utility.deserializeSqlDate", null,
simpleTypeMap);
buildFormat("time", "java.sql.Time",
"org.jibx.runtime.Utility.serializeSqlTime",
"org.jibx.runtime.Utility.deserializeSqlTime", null,
simpleTypeMap);
buildFormat("base64Binary", "byte[]",
"org.jibx.runtime.Utility.serializeBase64",
"org.jibx.runtime.Utility.deserializeBase64", null,
simpleTypeMap);
buildFormat("string","java.lang.String", null, null, null,
simpleTypeMap);
// collect all the top-level mapping and format definitions
Map elementMap = new HashMap();
Map complexTypeMap = new HashMap();
Map bindingMap = new HashMap();
if (binding != null) {
collectTopLevelComponents(binding, null, elementMap,
complexTypeMap, simpleTypeMap, bindingMap);
}
// make sure classes will be generated for abstract mappings
if (unwrap && complexTypeMap.size() > 0 && !binding.isForceClasses()) {
throw new RuntimeException("unwrapped binding must use force-classes='true' option in " + path);
}
// force off inappropriate option (set by error in options handling)
codeGenConfig.setPackClasses(false);