Examples of SchemaElement


Examples of org.jibx.schema.elements.SchemaElement

            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)) {
                       
                        // report schema roundtripped successfully
                        s_logger.debug("Successfully roundtripped schema " + id);
                       
                    } else {
                       
                        // report problems in roundtripping schema
                        s_logger.debug("Errors in roundtripping schema " + id);
                        pstream.flush();
                        s_logger.debug(baos.toString());
                       
                    }
                   
                } catch (XmlPullParserException e) {
                    s_logger.debug("Error during schema roundtripping", e);
                }
            }
        }
       
        // to correctly handle namespaces for includes, process namespaced schemas first
        Set schemaset = new HashSet(count);
        ArrayList ordereds = new ArrayList();
        m_validationContext.clearTraversed();
        for (int i = 0; i < count; i++) {
            SchemaElement schema = schemas[i];
            if (schema.getTargetNamespace() != null) {
               
                // add namespaced schema to both reached set and processing order list
                ordereds.add(schema);
                schemaset.add(schema);
               
                // add any child include and imports only to reached set
                FilteredSegmentList childs = schema.getSchemaChildren();
                for (int j = 0; j < childs.size(); j++) {
                    Object child = childs.get(j);
                    if (child instanceof SchemaLocationBase) {
                        schemaset.add(((SchemaLocationBase)child).getReferencedSchema());
                    }
                }
            }
        }
       
        // add any schemas not already covered
        for (int i = 0; i < count; i++) {
            SchemaElement schema = schemas[i];
            if (!schemaset.contains(schema)) {
                ordereds.add(schema);
            }
        }
       
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

        }
       
        // link each schema to a customization, creating a default customization if necessary
        int count = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            ISchemaResolver resolver = schema.getResolver();
            s_logger.debug("Assigning customization for schema " + ++count + ": " + resolver.getName());
            SchemasetCustom owner = findSchemaset(schema, m_global);
            SchemaCustom custom = owner.forceCustomization(resolver.getName(), resolver.getId(), schema,
                m_validationContext);
            custom.validate(m_validationContext);
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

     */
    private boolean processExtensions() {
       
        // first clear all the cross reference information
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            int count = schema.getChildCount();
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object obj = child.getExtension();
                if (obj instanceof GlobalExtension) {
                    ((GlobalExtension)obj).resetDependencies();
                }
            }
        }
       
        // process each loaded schema for deletions and cross referencing
        int index = 0;
        m_validationContext.clearTraversed();
        boolean modified = false;
        // Level level = TreeWalker.setLogging(s_logger.getLevel());
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            m_validationContext.enterSchema(schema);
            s_logger.debug("Applying extensions to schema " + ++index + ": " + schema.getResolver().getName());
            int count = schema.getChildCount();
            boolean instmod = false;
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object obj = child.getExtension();
                if (obj instanceof GlobalExtension) {
                   
                    // apply extension to global definition element
                    ComponentExtension exten = (ComponentExtension)obj;
                    if (exten.isRemoved()) {
                       
                        // just eliminate this definition from the schema
                        schema.detachChild(i);
                        instmod = true;
                       
                    } else {
                       
                        // process the definition to remove references to deleted components
                        exten.applyAndCountUsage(m_validationContext);
                       
                    }
                }
            }
            if (instmod) {
                schema.compactChildren();
                modified = true;
            }
            m_validationContext.exitSchema();
           
        }
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

        while (processExtensions() || modified) {
           
            // normalize all the schema definitions
            modified = false;
            for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
                SchemaElement schema = (SchemaElement)iter.next();
                int count = schema.getChildCount();
                boolean instmod = false;
                for (int i = 0; i < count; i++) {
                    SchemaBase child = schema.getChild(i);
                    Object obj = child.getExtension();
                    if (obj instanceof GlobalExtension) {
                        GlobalExtension global = (GlobalExtension)obj;
                        global.normalize();
                        if (global.isRemoved()) {
                           
                            // just eliminate this definition from the schema
                            schema.detachChild(i);
                            instmod = true;
                           
                        }
                    }
                }
                if (instmod) {
                    schema.compactChildren();
                    modified = true;
                }
            }
           
        }
       
        // finish by flagging global definitions requiring separate classes
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            SchemaCustom custom = findSchemaset(schema, m_global).getCustomization(schema.getResolver().getId());
            if (custom.isGenerateAll()) {
                int count = schema.getChildCount();
                for (int i = 0; i < count; i++) {
                    SchemaBase comp = schema.getChild(i);
                    if (comp.type() == SchemaBase.ELEMENT_TYPE || comp.type() == SchemaBase.COMPLEXTYPE_TYPE) {
                        Object obj = comp.getExtension();
                        if (obj instanceof GlobalExtension) {
                            ((GlobalExtension)obj).setIncluded(true);
                            if (s_logger.isDebugEnabled()) {
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

    public void pruneDefinitions() {
       
        // start by recursively checking for removable global definitions
        int index = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            s_logger.debug("Checking for unused definitions in schema " + ++index + ": "
                + schema.getResolver().getName());
            int count = schema.getChildCount();
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object exten = child.getExtension();
                if (exten instanceof GlobalExtension) {
                   
                    // check if global definition is unused and not specifically required
                    ((GlobalExtension)exten).checkRemovable();
                   
                }
            }
        }
       
        // next remove all the definitions flagged in the first step
        index = 0;
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            s_logger.debug("Deleting unused definitions in schema " + ++index + ": " + schema.getResolver().getName());
            int count = schema.getChildCount();
            boolean modified = false;
            for (int i = 0; i < count; i++) {
                SchemaBase child = schema.getChild(i);
                Object exten = child.getExtension();
                if (exten instanceof GlobalExtension && ((ComponentExtension)exten).isRemoved()) {
                   
                    // remove the definition from schema
                    schema.detachChild(i);
                    modified = true;
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug(" Removed definition " + ((INamed)child).getQName());
                    }
                   
                }
            }
            if (modified) {
                schema.compactChildren();
            }
        }
    }
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

     * @throws JiBXException on error in marshalling
     * @throws IOException on error writing
     */
    private void writeSchemas(File destdir) throws JiBXException, IOException {
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            File file = new File(destdir, schema.getResolver().getName());
            OutputStream stream = new FileOutputStream(file);
            Writer writer = new OutputStreamWriter(stream, "utf-8");
            IBindingFactory factory = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class);
            IMarshallingContext ictx = factory.createMarshallingContext();
            ictx.setOutput(writer);
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

           
            // unmarshal document to construct schema structure
            ISchemaResolver resolver = (ISchemaResolver)iter.next();
            ictx.setDocument(resolver.getContent(), resolver.getName(), null);
            ictx.setUserContext(vctx);
            SchemaElement schema = new SchemaElement();
            ((IUnmarshallable)schema).unmarshal(ictx);
           
            // set resolver for use during schema processing
            schemas[offset++] = schema;
            schema.setResolver(resolver);
            String id = resolver.getId();
            vctx.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(schema, "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)) {
                       
                        // report schema roundtripped successfully
                        s_logger.debug("Successfully roundtripped schema " + id);
                       
                    } else {
                       
                        // report problems in roundtripping schema
                        s_logger.debug("Errors in roundtripping schema " + id);
                        pstream.flush();
                        s_logger.debug(baos.toString());
                       
                    }
                   
                } catch (XmlPullParserException e) {
                    s_logger.debug("Error during schema roundtripping", e);
                }
            }
        }
       
        // to correctly handle namespaces for includes, process namespaced schemas first
        ArrayList ordereds = new ArrayList();
        vctx.clearTraversed();
        for (int i = 0; i < count; i++) {
            SchemaElement schema = schemas[i];
            if (schema.getTargetNamespace() != null) {
                ordereds.add(schema);
            }
        }
       
        // check for no namespaced schemas, but effective namespace supplied
        if (ordereds.size() == 0 && uri != null) {
           
            // generate a schema to include all the no-namespace schemas into namespace
            SchemaElement schema = new SchemaElement();
            schema.setTargetNamespace(uri);
            SyntheticSchemaResolver resolver = new SyntheticSchemaResolver();
            for (int i = 0; i < count; i++) {
                SchemaElement inclschema = schemas[i];
                inclschema.setEffectiveNamespace(uri);
                IncludeElement include = new IncludeElement();
                ISchemaResolver inclresolver = inclschema.getResolver();
                include.setLocation(inclresolver.getId());
                resolver.addResolver(inclresolver);
                schema.getSchemaChildren().add(include);
            }
            schema.setResolver(resolver);
            ordereds.add(schema);
        }
       
        // add no-namespace schemas to list
        for (int i = 0; i < count; i++) {
            SchemaElement schema = schemas[i];
            if (schema.getTargetNamespace() == null) {
                ordereds.add(schema);
            }
        }
       
        // validate the schemas in order
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

        Object key = m_nameRegister.findType(new QName("urn:anything", name));
        assertEquals("Usage count error on type '" + name + '\'', count, map.getCount(key));
    }
   
    public void testComplexReferenced() throws Exception {
        SchemaElement root = runNoErrors(REFERENCE_SCHEMA);
        if (!hasProblem(m_validationContext)) {
            UsageFinder usage = new UsageFinder();
            usage.countSchemaTree(root);
            ReferenceCountMap map = usage.getUsageMap();
            checkTypeUsage("simple1", map, 1);
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

     */
    protected SchemaElement readSchema(InputStream is, ValidationContext vctx) throws Exception {
        final IUnmarshallingContext ictx = m_bindingFactory.createUnmarshallingContext();
        ictx.setDocument(is, null);
        ictx.setUserContext(vctx);
        SchemaElement schema = (SchemaElement)ictx.unmarshalElement();
        m_nameRegister = schema.getRegister();
        return schema;
    }
View Full Code Here

Examples of org.jibx.schema.elements.SchemaElement

     * @param count number of errors expected
     * @param msg text for wrong number of errors found
     * @throws Exception on unexpected error
     */
    protected void runErrors(String text, int count, String msg) throws Exception {
        SchemaElement schema = readSchema(text, m_validationContext);
        validateSchema(schema, m_validationContext);
        assertEquals(msg, count, m_validationContext.getProblems().size());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.