Search in sources :

Example 1 with StreamSerializer

use of com.sun.xml.txw2.output.StreamSerializer in project metro-jax-ws by eclipse-ee4j.

the class WsgenTool method generateWsgenReport.

/**
 * Generates a small XML file that captures the key activity of wsgen,
 * so that test harness can pick up artifacts.
 */
private void generateWsgenReport(Class<?> endpointClass, AbstractSEIModelImpl rtModel, File wsdlFile, Map<String, File> schemaFiles) {
    try {
        ReportOutput.Report report = TXW.create(ReportOutput.Report.class, new StreamSerializer(new BufferedOutputStream(new FileOutputStream(options.wsgenReport))));
        report.wsdl(wsdlFile.getAbsolutePath());
        ReportOutput.writeQName(rtModel.getServiceQName(), report.service());
        ReportOutput.writeQName(rtModel.getPortName(), report.port());
        ReportOutput.writeQName(rtModel.getPortTypeName(), report.portType());
        report.implClass(endpointClass.getName());
        for (Map.Entry<String, File> e : schemaFiles.entrySet()) {
            ReportOutput.Schema s = report.schema();
            s.ns(e.getKey());
            s.location(e.getValue().getAbsolutePath());
        }
        report.commit();
    } catch (IOException e) {
        // this is code for the test, so we can be lousy in the error handling
        throw new Error(e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) StreamSerializer(com.sun.xml.txw2.output.StreamSerializer) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 2 with StreamSerializer

use of com.sun.xml.txw2.output.StreamSerializer in project jaxb-ri by eclipse-ee4j.

the class PluginImpl method run.

/**
 * Capture all the generated classes from global schema components
 * and generate them in an episode file.
 */
@Override
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) throws SAXException {
    OutputStream episodeFileOutputStream = null;
    try {
        // reorganize qualifying components by their namespaces to
        // generate the list nicely
        Map<XSSchema, PerSchemaOutlineAdaptors> perSchema = new LinkedHashMap<>();
        boolean hasComponentInNoNamespace = false;
        // Combine classes and enums into a single list
        List<OutlineAdaptor> outlines = new ArrayList<>();
        for (ClassOutline co : model.getClasses()) {
            XSComponent sc = co.target.getSchemaComponent();
            String fullName = co.implClass.fullName();
            String packageName = co.implClass.getPackage().name();
            OutlineAdaptor adaptor = new OutlineAdaptor(sc, OutlineAdaptor.OutlineType.CLASS, fullName, packageName);
            outlines.add(adaptor);
        }
        for (EnumOutline eo : model.getEnums()) {
            XSComponent sc = eo.target.getSchemaComponent();
            String fullName = eo.clazz.fullName();
            String packageName = eo.clazz.getPackage().name();
            OutlineAdaptor adaptor = new OutlineAdaptor(sc, OutlineAdaptor.OutlineType.ENUM, fullName, packageName);
            outlines.add(adaptor);
        }
        for (OutlineAdaptor oa : outlines) {
            XSComponent sc = oa.schemaComponent;
            if (sc == null)
                continue;
            if (!(sc instanceof XSDeclaration))
                continue;
            XSDeclaration decl = (XSDeclaration) sc;
            if (decl.isLocal())
                // local components cannot be referenced from outside, so no need to list.
                continue;
            PerSchemaOutlineAdaptors list = perSchema.get(decl.getOwnerSchema());
            if (list == null) {
                list = new PerSchemaOutlineAdaptors();
                perSchema.put(decl.getOwnerSchema(), list);
            }
            list.add(oa);
            if (decl.getTargetNamespace().equals(""))
                hasComponentInNoNamespace = true;
        }
        episodeFileOutputStream = new FileOutputStream(episodeFile);
        Bindings bindings = TXW.create(Bindings.class, new StreamSerializer(episodeFileOutputStream, "UTF-8"));
        if (// otherwise jaxb binding NS should be the default namespace
        hasComponentInNoNamespace)
            bindings._namespace(Const.JAXB_NSURI, "jaxb");
        else
            bindings._namespace(Const.JAXB_NSURI, "");
        bindings.version("3.0");
        bindings._comment("\n\n" + opt.getPrologComment() + "\n  ");
        // generate listing per schema
        for (Map.Entry<XSSchema, PerSchemaOutlineAdaptors> e : perSchema.entrySet()) {
            PerSchemaOutlineAdaptors ps = e.getValue();
            Bindings group = bindings.bindings();
            String tns = e.getKey().getTargetNamespace();
            if (!tns.equals(""))
                group._namespace(tns, "tns");
            group.scd("x-schema::" + (tns.equals("") ? "" : "tns"));
            SchemaBindings schemaBindings = group.schemaBindings();
            schemaBindings.map(false);
            if (ps.packageNames.size() == 1) {
                final String packageName = ps.packageNames.iterator().next();
                if (packageName != null && packageName.length() > 0) {
                    schemaBindings._package().name(packageName);
                }
            }
            for (OutlineAdaptor oa : ps.outlineAdaptors) {
                Bindings child = group.bindings();
                oa.buildBindings(child);
            }
            group.commit(true);
        }
        bindings.commit();
        return true;
    } catch (IOException e) {
        errorHandler.error(new SAXParseException("Failed to write to " + episodeFile, null, e));
        return false;
    } finally {
        if (episodeFileOutputStream != null) {
            try {
                episodeFileOutputStream.close();
            } catch (IOException e) {
                errorHandler.error(new SAXParseException("Failed to close file handle for " + episodeFile, null, e));
            }
        }
    }
}
Also used : EnumOutline(com.sun.tools.xjc.outline.EnumOutline) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) XSComponent(com.sun.xml.xsom.XSComponent) SchemaBindings(org.glassfish.jaxb.core.v2.schemagen.episode.SchemaBindings) Bindings(org.glassfish.jaxb.core.v2.schemagen.episode.Bindings) XSSchema(com.sun.xml.xsom.XSSchema) LinkedHashMap(java.util.LinkedHashMap) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) SAXParseException(org.xml.sax.SAXParseException) FileOutputStream(java.io.FileOutputStream) StreamSerializer(com.sun.xml.txw2.output.StreamSerializer) XSDeclaration(com.sun.xml.xsom.XSDeclaration) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SchemaBindings(org.glassfish.jaxb.core.v2.schemagen.episode.SchemaBindings)

Aggregations

StreamSerializer (com.sun.xml.txw2.output.StreamSerializer)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ClassOutline (com.sun.tools.xjc.outline.ClassOutline)1 EnumOutline (com.sun.tools.xjc.outline.EnumOutline)1 XSComponent (com.sun.xml.xsom.XSComponent)1 XSDeclaration (com.sun.xml.xsom.XSDeclaration)1 XSSchema (com.sun.xml.xsom.XSSchema)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Bindings (org.glassfish.jaxb.core.v2.schemagen.episode.Bindings)1 SchemaBindings (org.glassfish.jaxb.core.v2.schemagen.episode.SchemaBindings)1 SAXParseException (org.xml.sax.SAXParseException)1