Package org.jibx.schema

Examples of org.jibx.schema.UrlResolver


            // 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) {
View Full Code Here


        SchemaElement[] schemas = new SchemaElement[count];
        int fill = 0;
        for (Iterator iter = list.iterator(); iter.hasNext();) {
           
            // unmarshal document to construct schema structure
            UrlResolver resolver = (UrlResolver)iter.next();
            ictx.setDocument(resolver.getContent(), resolver.getName(), null);
            ictx.setUserContext(m_validationContext);
            Object obj = ictx.unmarshalElement();
           
            // set resolver for use during schema processing
            SchemaElement schema = (SchemaElement)obj;
            schemas[fill++] = schema;
            schema.setResolver(resolver);
            String id = resolver.getId();
            m_validationContext.setSchema(id, schema);
           
            // verify schema roundtripping if debug enabled
            if (s_logger.isDebugEnabled()) {
                try {
                   
                    // determine encoding of input document
                    String enc = ((UnmarshallingContext)ictx).getInputEncoding();
                    if (enc == null) {
                        enc = "UTF-8";
                    }
                   
                    // marshal root object back out to document in memory
                    IMarshallingContext mctx = factory.createMarshallingContext();
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    mctx.setIndent(2);
                    mctx.marshalDocument(obj, "UTF-8", null, bos);
                   
                    // compare with original input document
                    InputStreamReader brdr =
                        new InputStreamReader(new ByteArrayInputStream(bos.toByteArray()), "UTF-8");
                    InputStreamReader frdr = new InputStreamReader(resolver.getContent(), enc);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    PrintStream pstream = new PrintStream(baos);
                    DocumentComparator comp = new DocumentComparator(pstream);
                    if (comp.compare(frdr, brdr)) {
                       
View Full Code Here

                filter.setPattern(name);
                s_logger.debug("Matching file names to schemaset pattern '" + name + '\'');
                String[] matches = dir.list(filter);
                for (int j = 0; j < matches.length; j++) {
                    String match = matches[j];
                    fileset.add(new UrlResolver(match, new URL(base, match)));
                    s_logger.debug("Added schema from schemaset pattern match: " + match);
                }
            }
        }
       
        // next check all child customizations
        LazyList childs = custom.getChildren();
        for (int i = 0; i < childs.size(); i++) {
            Object child = childs.get(i);
            if (child instanceof SchemaCustom) {
                String name = ((SchemaCustom)child).getName();
                if (name != null) {
                    try {
                        fileset.add(new UrlResolver(name, new URL(base, name)));
                        s_logger.debug("Added schema from customizations: " + name);
                    } catch (MalformedURLException e) {
                        System.out.println("Error adding schema from customizations: " + name);
                    }
                }
View Full Code Here

                        filter.setPattern(name);
                        s_logger.debug("Matching file names to command line pattern '" + name + '\'');
                        String[] matches = basedir.list(filter);
                        for (int i = 0; i < matches.length; i++) {
                            String match = matches[i];
                            fileset.add(new UrlResolver(match, new URL(base, match)));
                        }
                    }
                } else {
                    if (basedir == null) {
                        URL url = new URL(base, name);
                        s_logger.debug("Adding schema URL from command line: " + url.toExternalForm());
                        fileset.add(new UrlResolver(name, url));
                    } else {
                        File sfile = new File(basedir, name);
                        if (sfile.exists()) {
                            s_logger.debug("Adding schema file from command line: " + sfile.getCanonicalPath());
                            fileset.add(new UrlResolver(name, new URL(base, name)));
                        } else {
                            System.err.println("Schema file from command line not found: " + sfile.getAbsolutePath());
                            err = true;
                        }
                    }
View Full Code Here

            URL base = parms.getSchemaRoot();
            File basedir = parms.getSchemaDir();
            List errors = ResourceMatcher.matchPaths(basedir, base, parms.getExtraArgs(),
                new ResourceMatcher.ReportMatch() {
                    public void foundMatch(String path, URL url) {
                        fileset.add(new UrlResolver(path, url));
                    }
                });
            if (errors.size() > 0) {
                for (Iterator iter = errors.iterator(); iter.hasNext();) {
                    s_logger.error(iter.next());
View Full Code Here

TOP

Related Classes of org.jibx.schema.UrlResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.