Package org.jibx.schema.elements

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


        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

     */
    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

     * @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

     * @param text schema text
     * @param msg text for wrong number of errors found
     * @throws Exception on unexpected error
     */
    protected void runOneError(String text, String msg) throws Exception {
        SchemaElement schema = readSchema(text, m_validationContext);
        validateSchema(schema, m_validationContext);
        assertTrue(msg, hasProblem(m_validationContext));
    }
View Full Code Here

     * @return schema
     * @throws Exception on unexpected error
     */
    protected SchemaElement prepareSchema(String text) throws Exception {
        m_validationContext.reset();
        SchemaElement schema = readSchema(text, m_validationContext);
        validateSchema(schema, m_validationContext);
        assertFalse(getProblemText(m_validationContext), hasProblem(m_validationContext));
        return schema;
    }
View Full Code Here

     * @param text schema text
     * @return schema
     * @throws Exception on unexpected error
     */
    protected SchemaElement runNoErrors(String text) throws Exception {
        SchemaElement schema = prepareSchema(text);
        verifySchema(text, writeSchema(schema));
        return schema;
    }
View Full Code Here

     * @param resolve resolver for all schema texts
     * @return root schema
     * @throws Exception
     */
    protected SchemaElement loadSchema(TestResolver resolve) throws Exception {
        SchemaElement schema = readSchema(resolve.getContent(), m_validationContext);
        schema.setResolver(resolve);
        m_validationContext.setSchema(resolve.getName(), schema);
        validateSchema(schema, m_validationContext);
        assertFalse(getProblemText(m_validationContext), hasProblem(m_validationContext));
        verifySchema(resolve.getText(), writeSchema(schema));
        return schema;
View Full Code Here

                    // check for no-namespace schema imported into namespace
                    int depth = ictx.getStackDepth();
                    for (int i = 0; i < depth; i++) {
                        Object obj = ictx.getStackObject(i);
                        if (obj instanceof SchemaElement) {
                            SchemaElement schema = (SchemaElement)obj;
                            String ens = schema.getEffectiveNamespace();
                            if (ens != schema.getTargetNamespace()) {
                                return qname.getName();
                            } else {
                                break;
                            }
                        }
View Full Code Here

        // set up validation with in-memory schemas
        org.jibx.schema.validation.ValidationContext vctx = new org.jibx.schema.validation.ValidationContext();
        for (int i = 0; i < holders.size(); i++) {
            SchemaHolder holder = (SchemaHolder)holders.get(i);
            String id = holder.getFileName();
            SchemaElement schema = holder.getSchema();
            schema.setResolver(new MemoryResolver(id));
            vctx.setSchema(id, schema);
        }
        for (Iterator iter = exists.iterator(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            vctx.setSchema(schema.getResolver().getName(), schema);
        }
       
        // validate the schemas and report any problems
        ValidationUtils.validateSchemas(schemas, vctx);
        ArrayList probs = vctx.getProblems();
View Full Code Here

TOP

Related Classes of org.jibx.schema.elements.SchemaElement

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.