Package org.exolab.castor.xml.schema

Examples of org.exolab.castor.xml.schema.Schema


     * @throws IOException
     * @throws SAXException
     * @throws FileNotFoundException
     */
    public void testUnmarshallSchema() throws FileNotFoundException, SAXException, IOException {
        Schema schema = unmarshalSchema("schema-entity.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();
View Full Code Here


     * jdo-specific content in it's annotations.
     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallNonJdoSchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-entity-non-jdo.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();
View Full Code Here

     * jdo-specific content in it's annotations.
     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallMixedSchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-entity-mixed.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();
View Full Code Here

     * declaration of author holds a one-to-many object.
     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallOneToManySchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-one-to-many.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();
View Full Code Here

     * element declaration of title also holds a column object.
     * @throws IOException
     * @throws SAXException
     */
    public void testUnmarshallOneToOneSchema() throws SAXException, IOException {
        Schema schema = unmarshalSchema("schema-one-to-one.xsd");
        ComplexType bookType = schema.getComplexType("bookType");
        Enumeration annotations = bookType.getAnnotations();
        Annotation annotation = (Annotation) annotations.nextElement();
        Enumeration appInfos = annotation.getAppInfo();
        AppInfo appInfo = (AppInfo) appInfos.nextElement();
        List jdoContent = appInfo.getJdoContent();
View Full Code Here

        parser.setDocumentHandler(handler);
        parser.setErrorHandler(handler);

        parser.parse(new InputSource(getClass().getResource(schemaName).toExternalForm()));

        Schema schema = schemaUnmarshaller.getSchema();
        return schema;
    }
View Full Code Here

       //-- parse text of DTD document
       DTDdocument dtd = parseDTD(reader);

       //-- convert DTD document object into its corresponding Schema object
       Schema schema = convertDTDObjectToSchemaObject(dtd);

       //-- marshal Schema object into its corresponding XML document
       marshalSchema(schema, writer);

    } //-- convertDTDtoSchema
View Full Code Here

     */
    public static Schema convertDTDObjectToSchemaObject (DTDdocument dtd)
                                                  throws DTDException,
                                                  SchemaException {

       Schema schema = new Schema();

       String name = dtd.getName();
       if (name != null && !name.equals("")) schema.setId(name);

       // convert Notation declarations
       Enumeration dtdNotations = dtd.getNotations();

       while (dtdNotations.hasMoreElements()) {
          dtdNotations.nextElement();
          // do nothing for now as the Castor Schema object model does not
          // support Notation declarations
       } //-- convert Notations declarations

       // convert General Entity declarations.
       // XML Schema does not provide facilities analogous to General Entity
       // declarations in XML DTD, so we convert each General Entity declaration
       // to Documentation subelement of XML Schema document annotaion.
       Enumeration dtdGeneralEntities = dtd.getGeneralEntities();
       if (dtdGeneralEntities.hasMoreElements()) {
          GeneralEntity ge;
          Annotation annotation = new Annotation();
          Documentation documentation;
          String text;

          while (dtdGeneralEntities.hasMoreElements()) {
             ge = (GeneralEntity)dtdGeneralEntities.nextElement();
             documentation = new Documentation();

             text = "General Entity Declaration";
             documentation.add(text);
             documentation.add(ge);
             annotation.addDocumentation(documentation);
          }

          schema.addAnnotation(annotation);
       }
       //-- convert General Entity declarations

       // convert Element declarations
       Enumeration dtdElements = dtd.getElements();
       Element dtdElement; // DTD Element declaration
       ElementDecl schemaElement; // Schema Element declaration

       while (dtdElements.hasMoreElements()) {
          dtdElement = (Element)dtdElements.nextElement();
          schemaElement = convertDTDElementToSchemaElement(dtdElement, schema);
          schema.addElementDecl(schemaElement);
       } //-- convert Element declarations

       return schema;

    } //-- convertDTDObjectToSchemaObject
View Full Code Here

        try {
            XMLInstance2Schema schemaGenerator = new XMLInstance2Schema();
            if (_defaultGroupingAsAll) {
                schemaGenerator.setDefaultGroupingAsAll();
            }
            Schema schema = schemaGenerator.createSchema(filePath);
            String outputFileName = outputFilePath;
            if (outputFileName == null) {
                outputFileName = deriveOutputFilePath(filePath);
            }
           FileWriter dstWriter = new FileWriter(outputFileName);
View Full Code Here

        if (namespace.equals(schema.getTargetNamespace()) )
            throw new SchemaException("the 'namespace' attribute in the <import> element cannot be the same of the targetNamespace of the global schema");

        //-- Schema object to hold import schema
        boolean addSchema = false;
        Schema importedSchema = schema.getImportedSchema(namespace, true);

        //-- Have we already imported this XML Schema file?
        if (state.processed(schemaLocation)) {
           if (importedSchema == null)
               schema.addImportedSchema(state.getSchema(schemaLocation));
           return;
        }

        boolean alreadyLoaded = false;
        if (importedSchema == null) {
            if (uri instanceof SchemaLocation) {
                importedSchema = ((SchemaLocation)uri).getSchema();
                schema.addImportedSchema(importedSchema);
                alreadyLoaded = true;
            }
            else {
                importedSchema = new Schema();
                addSchema = true;
            }
        }
        else {
            // check schema location, if different, allow merge
            if (hasLocation) {
                String tmpLocation = importedSchema.getSchemaLocation();
                alreadyLoaded = schemaLocation.equals(tmpLocation) || importedSchema.includeProcessed(schemaLocation);
                //-- keep track of the original schemaLocation as an include
                if(! alreadyLoaded) {
                    importedSchema.addInclude(tmpLocation);
                }
            } else {
                //-- only namespace can be used, no way to distinguish
                //-- multiple imports...mark as alreadyLoaded
                //-- see W3C XML Schema 1.0 Recommendation (part 1)
                //-- section 4.2.3...
                //-- <quote>... Given that the schemaLocation [attribute] is only
                //--   a hint, it is open to applications to ignore all but the
                //--   first <import> for a given namespace, regardless of the
                //--   <em>actual value</em> of schemaLocation, but such a strategy
                //--   risks missing useful information when new schemaLocations
                //--  are offered.</quote>
                alreadyLoaded = true;
            }
        }

        state.markAsProcessed(schemaLocation, importedSchema);

        if (alreadyLoaded) return;

        //-- Parser Schema
        Parser parser = null;
        try {
            parser = getSchemaContext().getParser();
        }
        catch(RuntimeException rte) {}
        if (parser == null) {
            throw new SchemaException("Error failed to create parser for import");
        }
    //-- Create Schema object and setup unmarshaller
    SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(getSchemaContext(), state);
          schemaUnmarshaller.setURIResolver(getURIResolver());
    schemaUnmarshaller.setSchema(importedSchema);
    Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
    parser.setDocumentHandler(handler);
    parser.setErrorHandler(handler);

        try {
            InputSource source = new InputSource(uri.getReader());
            source.setSystemId(uri.getAbsoluteURI());
            parser.parse(source);
        }
        catch(java.io.IOException ioe) {
            throw new SchemaException("Error reading import file '"+schemaLocation+"': "+ ioe);
        }
        catch(org.xml.sax.SAXException sx) {
            throw new SchemaException(sx);
        }

        //-- Add schema to list of imported schemas (if not already present)
        if (addSchema)
        {
            importedSchema.setSchemaLocation(schemaLocation);
            schema.addImportedSchema(importedSchema);
        }
    }
View Full Code Here

TOP

Related Classes of org.exolab.castor.xml.schema.Schema

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.