// build set of schemas provided on command line
final Set resolves = new HashSet();
List errors = ResourceMatcher.matchPaths(new File("."), null, parms.getUseSchemas(),
new ResourceMatcher.ReportMatch() {
public void foundMatch(String path, URL url) {
resolves.add(new UrlResolver(path, url));
}
});
if (errors.size() > 0) {
for (Iterator iter = errors.iterator(); iter.hasNext();) {
System.err.println(iter.next());
}
System.exit(1);
}
// load and validate schemas
ValidationContext vctx = new ValidationContext();
ValidationUtils.load(resolves, null, vctx);
ProblemMultiHandler handler = new ProblemMultiHandler();
handler.addHandler(new ProblemConsoleLister());
handler.addHandler(new ProblemLogLister(s_logger));
if (vctx.reportProblems(handler)) {
System.exit(2);
}
// build maps from qualified names to schema holders, and from schema to resolver (necessary since a new
// resolver will be set during the WSDL generation processing)
final Map elemschemas = new HashMap();
final Map typeschemas = new HashMap();
final Set exists = new HashSet();
TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
for (Iterator iter = resolves.iterator(); iter.hasNext();) {
SchemaElement schema = vctx.getSchemaById(((ISchemaResolver)iter.next()).getId());
exists.add(schema);
final SchemaHolder holder = new SchemaHolder(schema);
SchemaVisitor visitor = new SchemaVisitor() {
public boolean visit(SchemaBase node) {
return false;
}
public boolean visit(ComplexTypeElement node) {
typeschemas.put(node.getQName(), holder);
return false;
}
public boolean visit(ElementElement node) {
elemschemas.put(node.getQName(), holder);
return false;
}
};
wlkr.walkChildren(schema, visitor);
}
// build set of binding definitions provided on command line
final Set bindings = new HashSet();
errors = ResourceMatcher.matchPaths(new File("."), null, parms.getUseBindings(),
new ResourceMatcher.ReportMatch() {
public void foundMatch(String path, URL url) {
bindings.add(url);
}
});
if (errors.size() > 0) {
for (Iterator iter = errors.iterator(); iter.hasNext();) {
System.err.println(iter.next());
}
System.exit(3);
}
// build maps of type and element mappings from bindings
Map classelems = new HashMap();
Map classtypes = new HashMap();
for (Iterator iter = bindings.iterator(); iter.hasNext();) {
URL url = (URL)iter.next();
processPregeneratedBinding(url, classelems, classtypes);
}
// generate services, bindings, and WSDLs
Jibx2Wsdl inst = new Jibx2Wsdl(parms);
ArrayList extras = new ArrayList(parms.getExtraTypes());
ArrayList classes = parms.getGlobal().getUnmarshalledClasses();
for (int i = 0; i < classes.size(); i++) {
ClassCustom clas = (ClassCustom)classes.get(i);
if (clas.isForceMapping()) {
extras.add(clas.getName());
}
}
List wsdls = inst.generate(parms.getExtraArgs(), extras, classelems, elemschemas, classtypes, typeschemas,
exists);
if (wsdls != null) {
// write the schemas and WSDLS
SchemaGen.writeSchemas(parms.getGeneratePath(), inst.m_uriSchemaMap.values());
WsdlWriter writer = new WsdlWriter();
for (Iterator iter = wsdls.iterator(); iter.hasNext();) {
Definitions def = (Definitions)iter.next();
File file = new File(parms.getGeneratePath(), def.getServiceName() + ".wsdl");
writer.writeWSDL(def, new FileOutputStream(file));
}
// find existing schemas referenced (directly or indirectly) from WSDL schemas
final Set needschemas = new HashSet();
SchemaVisitor visitor = new SchemaVisitor() {
private int m_existsDepth;
public void exit(SchemaElement node) {
if (exists.contains(node)) {
m_existsDepth--;
}
}
public boolean visit(SchemaBase node) {
return false;
}
public boolean visit(SchemaElement node) {
if (exists.contains(node)) {
m_existsDepth++;
}
return true;
}
public boolean visit(SchemaLocationBase node) {
SchemaElement schema = node.getReferencedSchema();
if (needschemas.contains(schema)) {
return false;
} else {
if (m_existsDepth > 0 || exists.contains(schema)) {
needschemas.add(schema);
}
return true;
}
}
};
for (int i = 0; i < wsdls.size(); i++) {
Definitions def = (Definitions)wsdls.get(i);
ArrayList schemas = def.getSchemas();
for (int j = 0; j < schemas.size(); j++) {
wlkr.walkChildren((SchemaBase)schemas.get(0), visitor);
}
}
// copy all referenced schemas to target directory
byte[] buff = new byte[4096];
for (Iterator iter = needschemas.iterator(); iter.hasNext();) {
SchemaElement schema = (SchemaElement)iter.next();
UrlResolver resolver = (UrlResolver)schema.getResolver();
InputStream is = resolver.getUrl().openStream();
File file = new File(parms.getGeneratePath(), resolver.getName());
FileOutputStream os = new FileOutputStream(file);
int actual;
while ((actual = is.read(buff)) > 0) {
os.write(buff, 0, actual);
}
schema.setResolver(new MemoryResolver(resolver.getName()));
}
}
} else {
if (args.length > 0) {