Package com.sun.xml.internal.bind.v2.schemagen.xmlschema

Examples of com.sun.xml.internal.bind.v2.schemagen.xmlschema.Schema


         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                if(useMimeNs)
                    schema._namespace(WellKnownNamespace.XML_MIME_URI,"xmime");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }
                if(useMimeNs) {
                    schema._import().namespace(WellKnownNamespace.XML_MIME_URI).schemaLocation("http://www.w3.org/2005/05/xmlmime");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here


        /**
         * Writes the schema document to the specified result.
         */
        private void writeTo(Result result, Map<Namespace,Result> out) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    imp.schemaLocation(relativize(out.get(n).getSystemId(),result.getSystemId()));
                    schema._pcdata(newline);
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,NonElement<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    writeTypeRef(a,e.getValue(),"type");
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                IOException ioe = new IOException(e.getMessage());
                ioe.initCause(e);
                throw ioe;
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

/*      */     private void writeTo(Result result, Map<XmlSchemaGenerator<T, C, F, M>.Namespace, String> systemIds)
/*      */       throws IOException
/*      */     {
/*      */       try
/*      */       {
/*  572 */         Schema schema = (Schema)TXW.create(Schema.class, ResultFactory.createSerializer(result));
/*      */
/*  575 */         Map xmlNs = XmlSchemaGenerator.this.types.getXmlNs(this.uri);
/*      */
/*  577 */         for (Map.Entry e : xmlNs.entrySet()) {
/*  578 */           schema._namespace((String)e.getValue(), (String)e.getKey());
/*      */         }
/*      */
/*  581 */         if (this.useSwaRef) {
/*  582 */           schema._namespace("http://ws-i.org/profiles/basic/1.1/xsd", "swaRef");
/*      */         }
/*  584 */         this.attributeFormDefault = Form.get(XmlSchemaGenerator.this.types.getAttributeFormDefault(this.uri));
/*  585 */         this.attributeFormDefault.declare("attributeFormDefault", schema);
/*      */
/*  587 */         this.elementFormDefault = Form.get(XmlSchemaGenerator.this.types.getElementFormDefault(this.uri));
/*      */
/*  589 */         this.elementFormDefault.declare("elementFormDefault", schema);
/*      */
/*  594 */         if ((!xmlNs.containsValue("http://www.w3.org/2001/XMLSchema")) && (!xmlNs.containsKey("xs")))
/*      */         {
/*  596 */           schema._namespace("http://www.w3.org/2001/XMLSchema", "xs");
/*  597 */         }schema.version("1.0");
/*      */
/*  599 */         if (this.uri.length() != 0) {
/*  600 */           schema.targetNamespace(this.uri);
/*      */         }
/*      */
/*  604 */         for (Namespace ns : this.depends) {
/*  605 */           schema._namespace(ns.uri);
/*      */         }
/*      */
/*  608 */         if ((this.selfReference) && (this.uri.length() != 0))
/*      */         {
/*  611 */           schema._namespace(this.uri, "tns");
/*      */         }
/*      */
/*  614 */         schema._pcdata("\n");
/*      */
/*  617 */         for (Namespace n : this.depends) {
/*  618 */           Import imp = schema._import();
/*  619 */           if (n.uri.length() != 0)
/*  620 */             imp.namespace(n.uri);
/*  621 */           String refSystemId = (String)systemIds.get(n);
/*  622 */           if ((refSystemId != null) && (!refSystemId.equals("")))
/*      */           {
/*  624 */             imp.schemaLocation(XmlSchemaGenerator.relativize(refSystemId, result.getSystemId()));
/*      */           }
/*  626 */           schema._pcdata("\n");
/*      */         }
/*  628 */         if (this.useSwaRef) {
/*  629 */           schema._import().namespace("http://ws-i.org/profiles/basic/1.1/xsd").schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
/*      */         }
/*      */
/*  633 */         for (Map.Entry e : this.elementDecls.entrySet()) {
/*  634 */           ((ElementDeclaration)e.getValue()).writeTo((String)e.getKey(), schema);
/*  635 */           schema._pcdata("\n");
/*      */         }
/*  637 */         for (ClassInfo c : this.classes) {
/*  638 */           if (c.getTypeName() == null)
/*      */           {
/*      */             continue;
/*      */           }
/*  642 */           if (this.uri.equals(c.getTypeName().getNamespaceURI()))
/*  643 */             writeClass(c, schema);
/*  644 */           schema._pcdata("\n");
/*      */         }
/*  646 */         for (EnumLeafInfo e : this.enums) {
/*  647 */           if (e.getTypeName() == null)
/*      */           {
/*      */             continue;
/*      */           }
/*  651 */           if (this.uri.equals(e.getTypeName().getNamespaceURI()))
/*  652 */             writeEnum(e, schema);
/*  653 */           schema._pcdata("\n");
/*      */         }
/*  655 */         for (ArrayInfo a : this.arrays) {
/*  656 */           writeArray(a, schema);
/*  657 */           schema._pcdata("\n");
/*      */         }
/*  659 */         for (Map.Entry e : this.attributeDecls.entrySet()) {
/*  660 */           TopLevelAttribute a = schema.attribute();
/*  661 */           a.name((String)e.getKey());
/*  662 */           if (e.getValue() == null)
/*  663 */             writeTypeRef(a, XmlSchemaGenerator.this.stringType, "type");
/*      */           else
/*  665 */             writeAttributeTypeRef((AttributePropertyInfo)e.getValue(), a);
/*  666 */           schema._pcdata("\n");
/*      */         }
/*      */
/*  670 */         schema.commit();
/*      */       } catch (TxwException e) {
/*  672 */         XmlSchemaGenerator.logger.log(Level.INFO, e.getMessage(), e);
/*  673 */         throw new IOException(e.getMessage());
/*      */       }
/*      */     }
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                if(useMimeNs)
                    schema._namespace(WellKnownNamespace.XML_MIME_URI,"xmime");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }
                if(useMimeNs) {
                    schema._import().namespace(WellKnownNamespace.XML_MIME_URI).schemaLocation("http://www.w3.org/2005/05/xmlmime");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

         * @param systemIds
         *      System IDs of the other schema documents. "" indicates 'implied'.
         */
        private void writeTo(Result result, Map<Namespace,String> systemIds) throws IOException {
            try {
                Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));

                // additional namespace declarations to be made.
                Map<String, String> xmlNs = types.getXmlNs(uri);

                for (Map.Entry<String, String> e : xmlNs.entrySet()) {
                    schema._namespace(e.getValue(),e.getKey());
                }

                if(useSwaRef)
                    schema._namespace(WellKnownNamespace.SWA_URI,"swaRef");

                if(useMimeNs)
                    schema._namespace(WellKnownNamespace.XML_MIME_URI,"xmime");

                attributeFormDefault = Form.get(types.getAttributeFormDefault(uri));
                attributeFormDefault.declare("attributeFormDefault",schema);

                elementFormDefault = Form.get(types.getElementFormDefault(uri));
                // TODO: if elementFormDefault is UNSET, figure out the right default value to use
                elementFormDefault.declare("elementFormDefault",schema);


                // declare XML Schema namespace to be xs, but allow the user to override it.
                // if 'xs' is used for other things, we'll just let TXW assign a random prefix
                if(!xmlNs.containsValue(WellKnownNamespace.XML_SCHEMA)
                && !xmlNs.containsKey("xs"))
                    schema._namespace(WellKnownNamespace.XML_SCHEMA,"xs");
                schema.version("1.0");

                if(uri.length()!=0)
                    schema.targetNamespace(uri);

                // declare prefixes for them at this level, so that we can avoid redundant
                // namespace declarations
                for (Namespace ns : depends) {
                    schema._namespace(ns.uri);
                }

                if(selfReference && uri.length()!=0) {
                    // use common 'tns' prefix for the own namespace
                    // if self-reference is needed
                    schema._namespace(uri,"tns");
                }

                schema._pcdata(newline);

                // refer to other schemas
                for( Namespace n : depends ) {
                    Import imp = schema._import();
                    if(n.uri.length()!=0)
                        imp.namespace(n.uri);
                    String refSystemId = systemIds.get(n);
                    if(refSystemId!=null && !refSystemId.equals("")) {
                        // "" means implied. null if the SchemaOutputResolver said "don't generate!"
                        imp.schemaLocation(relativize(refSystemId,result.getSystemId()));
                    }
                    schema._pcdata(newline);
                }
                if(useSwaRef) {
                    schema._import().namespace(WellKnownNamespace.SWA_URI).schemaLocation("http://ws-i.org/profiles/basic/1.1/swaref.xsd");
                }
                if(useMimeNs) {
                    schema._import().namespace(WellKnownNamespace.XML_MIME_URI).schemaLocation("http://www.w3.org/2005/05/xmlmime");
                }

                // then write each component
                for (Map.Entry<String,ElementDeclaration> e : elementDecls.entrySet()) {
                    e.getValue().writeTo(e.getKey(),schema);
                    schema._pcdata(newline);
                }
                for (ClassInfo<T, C> c : classes) {
                    if (c.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(c.getTypeName().getNamespaceURI()))
                        writeClass(c, schema);
                    schema._pcdata(newline);
                }
                for (EnumLeafInfo<T, C> e : enums) {
                    if (e.getTypeName()==null) {
                        // don't generate anything if it's an anonymous type
                        continue;
                    }
                    if(uri.equals(e.getTypeName().getNamespaceURI()))
                        writeEnum(e,schema);
                    schema._pcdata(newline);
                }
                for (ArrayInfo<T, C> a : arrays) {
                    writeArray(a,schema);
                    schema._pcdata(newline);
                }
                for (Map.Entry<String,AttributePropertyInfo<T,C>> e : attributeDecls.entrySet()) {
                    TopLevelAttribute a = schema.attribute();
                    a.name(e.getKey());
                    if(e.getValue()==null)
                        writeTypeRef(a,stringType,"type");
                    else
                        writeAttributeTypeRef(e.getValue(),a);
                    schema._pcdata(newline);
                }

                // close the schema
                schema.commit();
            } catch( TxwException e ) {
                logger.log(Level.INFO,e.getMessage(),e);
                throw new IOException(e.getMessage());
            }
        }
View Full Code Here

TOP

Related Classes of com.sun.xml.internal.bind.v2.schemagen.xmlschema.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.