Package org.jibx.schema

Examples of org.jibx.schema.ISchemaResolver


        } else {
            try {
               
                // find or load referenced schema
                SchemaElement curschema = vctx.getCurrentSchema();
                ISchemaResolver resolver =
                    curschema.getResolver().resolve(location, null);
                SchemaElement schema = vctx.getSchemaById(resolver.getId());
                if (schema == null) {
                    schema = readSchema(vctx, resolver);
                    vctx.setSchema(resolver.getId(), schema);
                    schema.setResolver(resolver);
                }
                setReferencedSchema(schema);
                if (schema.getEffectiveNamespace() == null) {
                    schema.setEffectiveNamespace(curschema.getEffectiveNamespace());
View Full Code Here


       
        // 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);
            custom.extend(null, m_validationContext);
        }
       
View Full Code Here

        int offset = 0;
        SchemaElement[] schemas = new SchemaElement[count];
        for (Iterator iter = resolves.iterator(); iter.hasNext();) {
           
            // 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);
View Full Code Here

        } else {
            try {
               
                // find or load referenced schema
                SchemaElement curschema = vctx.getCurrentSchema();
                ISchemaResolver resolver =
                    curschema.getResolver().resolve(location, m_namespace);
                SchemaElement schema = vctx.getSchemaById(resolver.getId());
                if (schema == null) {
                    schema = readSchema(vctx, resolver);
                    vctx.setSchema(resolver.getId(), schema);
                    schema.setResolver(resolver);
                }
                setReferencedSchema(schema);
               
            } catch (JiBXException e) {
View Full Code Here

       
        // 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);
            String pname = custom.getPackage();
            PackageHolder holder = null;
            if (pname == null) {
View Full Code Here

     * Get the schema name for logging validation.
     *
     * @return name
     */
    private String getName() {
        ISchemaResolver resolver = getResolver();
        if (resolver == null) {
            return "{no name}";
        } else {
            return resolver.getName();
        }
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.ISchemaResolver

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.