Example usage for javax.xml.stream XMLStreamWriter writeAttribute

List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeAttribute.

Prototype

public void writeAttribute(String localName, String value) throws XMLStreamException;

Source Link

Document

Writes an attribute to the output stream without a prefix.

Usage

From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java

private static final void writeFormDefaultForElements(final boolean qualified, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeAttribute(XsdAttributeName.ELEMENT_FORM_DEFAULT.getLocalName(),
            qualified ? QUALIFIED : UNQUALIFIED);
}

From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java

private static final void writeNameOfSchemaType(final String name, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeAttribute(XsdAttributeName.NAME.getLocalName(), name);
}

From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java

/**
 * Writes the UML model to the XML stream in XSD format.
 *
 * @param model/*  ww  w .j a va 2  s.c o  m*/
 *            The UML model.
 * @param xsw
 *            The XML stream.
 * @throws XMLStreamException
 *             if anything bad happens.
 */
private static final void writeSchema(final List<PsmDocument<Type>> elements, final ModelIndex lookup,
        final Uml2XsdPlugin plugin, final XMLStreamWriter xsw) throws XMLStreamException {
    writeStartElement(XsdElementName.SCHEMA, xsw);
    try {
        xsw.writeNamespace(PREFIX_XS, NAMESPACE_XS);
        final Map<String, String> prefixMappings = plugin.declarePrefixMappings();
        for (final Map.Entry<String, String> entry : prefixMappings.entrySet()) {
            final String namespace = entry.getValue();
            if (namespace == null) {
                throw new IllegalArgumentException("namespace declared by plugin is null.");
            }
            if (namespace.trim().length() == 0) {
                throw new IllegalArgumentException("namespace declared by plugin is the empty string.");
            }
            xsw.writeNamespace(entry.getKey(), namespace);
        }

        final String targetNamespace = plugin.getTargetNamespace();
        if (targetNamespace == null) {
            throw new IllegalArgumentException("targetNamespace declared by plugin is null.");
        }
        if (targetNamespace.trim().length() > 0) {
            xsw.writeAttribute("targetNamespace", targetNamespace);
            writeFormDefaultForElements(plugin.isElementFormDefaultQualified(), xsw);
            writeFormDefaultForAttributes(plugin.isAttributeFormDefaultQualified(), xsw);
        }

        for (final PsmDocument<Type> element : elements) {
            writeTopLevelElement(element, lookup, plugin, xsw);
        }
        for (final SimpleType simpleType : sort(combine(lookup.getDataTypes().values(), lookup.getEnumTypes()),
                TypeComparator.SINGLETON)) {
            writeSimpleType(simpleType, lookup, plugin, xsw);
        }
        for (final ClassType enumType : sort(lookup.getClassTypes().values(), TypeComparator.SINGLETON)) {
            // DE2424 exclude creating a ComplexType with no name
            if ("".equals(enumType.getName()) == false) {
                writeComplexType(enumType, lookup, plugin, xsw);
            }
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.tools.xsdgen.Uml2XsdWriter.java

private static final void writeValueAttribute(final String value, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeAttribute(XsdAttributeName.VALUE.getLocalName(), value);
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeFault(final Representation representation, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.FAULT.getLocalName(), WadlSyntax.NAMESPACE);
    try {//ww w.ja va  2 s.c o  m
        xsw.writeAttribute(WadlAttributeName.MEDIA_TYPE.getLocalName(), representation.getMediaType());
        if (representation.getId() != null) {
            xsw.writeAttribute(WadlAttributeName.ID.getLocalName(), representation.getId());
        }
        final QName element = representation.getElementName();
        xsw.writeAttribute(WadlAttributeName.ELEMENT.getLocalName(), toLexicalForm(element, xsw));
        writeDocumentation(representation, xsw);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeInclude(final Include include, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.INCLUDE.getLocalName(), WadlSyntax.NAMESPACE);
    try {/*from   ww w .  ja va 2 s . c  o m*/
        xsw.writeAttribute(WadlAttributeName.HREF.getLocalName(), include.getHref());
        writeDocumentation(include, xsw);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeMethod(final Method method, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.METHOD.getLocalName(), WadlSyntax.NAMESPACE);
    try {/*from w  w w.  j  a  v a  2 s. c om*/
        xsw.writeAttribute(WadlAttributeName.NAME.getLocalName(), method.getVerb());
        xsw.writeAttribute(WadlAttributeName.ID.getLocalName(), method.getId());
        writeDocumentation(method, xsw);
        if (method.getRequest() != null) {
            writeRequest(method.getRequest(), xsw);
        }
        for (final Response response : method.getResponses()) {
            writeResponse(response, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeOption(final Option option, final XMLStreamWriter xsw)
        throws XMLStreamException {
    if (option == null) {
        throw new IllegalArgumentException("option");
    }/*from  www .  j  a  va 2 s .c  om*/
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.OPTION.getLocalName(), WadlSyntax.NAMESPACE);
    try {
        xsw.writeAttribute(WadlAttributeName.VALUE.getLocalName(), option.getValue());
        writeDocumentation(option, xsw);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeParam(final Param param, final XMLStreamWriter xsw) throws XMLStreamException {
    if (param == null) {
        throw new IllegalArgumentException("param");
    }//w  ww.  j av a  2  s .c  om
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.PARAM.getLocalName(), WadlSyntax.NAMESPACE);
    try {
        xsw.writeAttribute(WadlAttributeName.NAME.getLocalName(), param.getName());
        xsw.writeAttribute(WadlAttributeName.STYLE.getLocalName(), encodeParamStyle(param.getStyle()));
        if (param.getId() != null) {
            xsw.writeAttribute(WadlAttributeName.ID.getLocalName(), param.getId());
        }
        final QName type = param.getType();
        xsw.writeAttribute(WadlAttributeName.TYPE.getLocalName(), toLexicalForm(type, xsw));
        if (param.getDefault() != null) {
            xsw.writeAttribute(WadlAttributeName.DEFAULT_VALUE.getLocalName(), param.getDefault());
        }
        if (param.getRequired()) {
            xsw.writeAttribute(WadlAttributeName.REQUIRED.getLocalName(),
                    Boolean.toString(param.getRequired()));
        }
        if (param.getRepeating()) {
            xsw.writeAttribute(WadlAttributeName.REPEATING.getLocalName(),
                    Boolean.toString(param.getRepeating()));
        }
        if (param.getFixed() != null) {
            xsw.writeAttribute(WadlAttributeName.FIXED.getLocalName(), param.getFixed());
        }
        if (param.getPath() != null) {
            xsw.writeAttribute(WadlAttributeName.PATH.getLocalName(), param.getPath());
        }
        writeDocumentation(param, xsw);
        for (final Option option : param.getOptions()) {
            writeOption(option, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.wadl.writer.WadlWriter.java

private static final void writeRepresentation(final Representation representation, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.REPRESENTATION.getLocalName(), WadlSyntax.NAMESPACE);
    try {/*from  w  ww. jav  a  2  s.com*/
        xsw.writeAttribute(WadlAttributeName.MEDIA_TYPE.getLocalName(), representation.getMediaType());
        if (representation.getId() != null) {
            xsw.writeAttribute(WadlAttributeName.ID.getLocalName(), representation.getId());
        }
        final QName element = representation.getElementName();
        if (element != null) {
            xsw.writeAttribute(WadlAttributeName.ELEMENT.getLocalName(), toLexicalForm(element, xsw));
        }
        writeDocumentation(representation, xsw);
    } finally {
        xsw.writeEndElement();
    }
}