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.wadl.writer.WadlWriter.java

private static final void writeResource(final Resource resource, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.RESOURCE.getLocalName(), WadlSyntax.NAMESPACE);
    try {/*w  w  w . j  a  va  2s.  c  om*/
        if (resource.getId() != null) {
            xsw.writeAttribute(WadlAttributeName.ID.getLocalName(), resource.getId());
        }
        if (!resource.getType().isEmpty()) {
            xsw.writeAttribute(WadlAttributeName.TYPE.getLocalName(), encodeStringList(resource.getType()));
        }
        final String queryType = resource.getQueryType();
        if (!WadlSyntax.QUERY_TYPE_APPLICATION_X_WWW_FORM_URLENCODED.equals(queryType)) {
            xsw.writeAttribute(WadlAttributeName.QUERY_TYPE.getLocalName(), queryType);
        }
        xsw.writeAttribute(WadlAttributeName.PATH.getLocalName(), resource.getPath());
        writeDocumentation(resource, xsw);
        for (final Param param : resource.getParams()) {
            writeParam(param, xsw);
        }
        for (final Method method : resource.getMethods()) {
            writeMethod(method, xsw);
        }
        for (final Resource nestedResource : resource.getResources()) {
            writeResource(nestedResource, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

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

private static final void writeResources(final Resources resources, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.RESOURCES.getLocalName(), WadlSyntax.NAMESPACE);
    try {/*from w  w w  .j  av a  2s. c  o m*/
        xsw.writeAttribute(WadlAttributeName.BASE.getLocalName(), resources.getBase());
        writeDocumentation(resources, xsw);
        for (final Resource resource : resources.getResources()) {
            writeResource(resource, xsw);
        }
    } finally {
        xsw.writeEndElement();
    }
}

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

private static final void writeResourceType(final ResourceType resourceType, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeStartElement(WADL_PREFIX, WadlElementName.RESOURCE_TYPE.getLocalName(), WadlSyntax.NAMESPACE);
    try {//w w w  . j av  a 2  s .  c  om
        xsw.writeAttribute(WadlAttributeName.ID.getLocalName(), resourceType.getId());
        writeDocumentation(resourceType, xsw);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeGeneralization(final Generalization generalization, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {

    xsw.writeStartElement(PREFIX_UML, XmiElementName.GENERALIZATION.getLocalName(), NAMESPACE_UML);
    writeId(generalization, xsw);/*from  www .j av a 2 s.  c om*/
    xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), generalization.getName());
    writeModelElementTaggedValues(generalization, mapper, xsw);

    xsw.writeStartElement(PREFIX_UML, XmiElementName.GENERALIZATION_DOT_CHILD.getLocalName(), NAMESPACE_UML);
    writeReference(generalization.getChild(), mapper, xsw);
    xsw.writeEndElement();

    xsw.writeStartElement(PREFIX_UML, XmiElementName.GENERALIZATION_DOT_PARENT.getLocalName(), NAMESPACE_UML);
    writeReference(generalization.getParent(), mapper, xsw);
    xsw.writeEndElement();

    xsw.writeEndElement();
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeAssociationEnd(final AssociationEnd end, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(PREFIX_UML, XmiElementName.ASSOCIATION_END.getLocalName(), NAMESPACE_UML);
    writeId(end, xsw);/*from   w  ww  .ja va 2 s .  c  om*/
    xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), end.getName());
    xsw.writeAttribute(XmiAttributeName.IS_NAVIGABLE.getLocalName(), Boolean.toString(end.isNavigable()));
    xsw.writeAttribute(XmiAttributeName.ASSOCIATED_ATTRIBUTE_NAME.getLocalName(),
            end.getAssociatedAttributeName());
    writeModelElementTaggedValues(end, mapper, xsw);
    xsw.writeStartElement(PREFIX_UML, XmiElementName.ASSOCIATION_END_DOT_MULTIPLICITY.getLocalName(),
            NAMESPACE_UML);
    writeMultiplicity(end.getMultiplicity(), xsw);
    xsw.writeEndElement();
    writeAssociationEndParticipant(end.getType(), mapper, xsw);
    xsw.writeEndElement();
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeAttribute(final Attribute attribute, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(PREFIX_UML, XmiElementName.ATTRIBUTE.getLocalName(), NAMESPACE_UML);
    try {// w w w  .  j a  v  a2 s .  co  m
        writeId(attribute, xsw);
        xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), attribute.getName());
        writeModelElementTaggedValues(attribute, mapper, xsw);
        xsw.writeStartElement(PREFIX_UML, XmiElementName.STRUCTURAL_FEATURE_DOT_MULTIPLICITY.getLocalName(),
                NAMESPACE_UML);
        try {
            writeMultiplicity(attribute.getMultiplicity(), xsw);
        } finally {
            xsw.writeEndElement();
        }
        xsw.writeStartElement(PREFIX_UML, XmiElementName.STRUCTURAL_FEATURE_DOT_TYPE.getLocalName(),
                NAMESPACE_UML);
        try {
            writeReference(attribute.getType(), mapper, xsw);
        } finally {
            xsw.writeEndElement();
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeClassType(final ClassType classType, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {
    if (classType.isClassType()) {
        if (classType.isAssociation()) {
            xsw.writeStartElement(PREFIX_UML, XmiElementName.ASSOCIATION_CLASS.getLocalName(), NAMESPACE_UML);
        } else {/* w w w . ja v  a2 s.co m*/
            xsw.writeStartElement(PREFIX_UML, XmiElementName.CLASS.getLocalName(), NAMESPACE_UML);
        }
    } else {
        if (classType.isAssociation()) {
            xsw.writeStartElement(PREFIX_UML, XmiElementName.ASSOCIATION.getLocalName(), NAMESPACE_UML);
        } else {
            throw new AssertionError();
        }
    }
    try {
        writeId(classType, xsw);
        xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), classType.getName());
        writeModelElementTaggedValues(classType, mapper, xsw);
        if (classType.isAssociation()) {
            xsw.writeStartElement(PREFIX_UML, XmiElementName.ASSOCIATION_DOT_CONNECTION.getLocalName(),
                    NAMESPACE_UML);
            try {
                writeAssociationEnd(classType.getLHS(), mapper, xsw);
                writeAssociationEnd(classType.getRHS(), mapper, xsw);
            } finally {
                xsw.writeEndElement();
            }
        }
        xsw.writeStartElement(PREFIX_UML, XmiElementName.CLASSIFIER_DOT_FEATURE.getLocalName(), NAMESPACE_UML);
        try {
            for (final Attribute attribute : classType.getAttributes()) {
                writeAttribute(attribute, mapper, xsw);
            }
        } finally {
            xsw.writeEndElement();
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeDataType(final DataType dataType, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {
    xsw.writeStartElement(PREFIX_UML, XmiElementName.DATA_TYPE.getLocalName(), NAMESPACE_UML);
    try {/*from  w w w  . j  av  a 2s  .co m*/
        writeId(dataType, xsw);
        xsw.writeAttribute(XmiAttributeName.NAME.getLocalName(), dataType.getName());
        xsw.writeAttribute("isAbstract", Boolean.toString(dataType.isAbstract()));
        writeModelElementTaggedValues(dataType, mapper, xsw);
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeEnumType(final EnumType enumType, final ModelIndex mapper,
        final XMLStreamWriter xsw) throws XMLStreamException {
    writeStartElement(XmiElementName.ENUMERATION, xsw);
    try {//  w w w  .j  a  v  a  2 s .com
        writeId(enumType, xsw);
        writeName(enumType, mapper, xsw);
        writeModelElementTaggedValues(enumType, mapper, xsw);
        writeStartElement(XmiElementName.ENUMERATION_LITERAL_GROUP, xsw);
        try {
            for (final EnumLiteral literal : enumType.getLiterals()) {
                writeStartElement(XmiElementName.ENUMERATION_LITERAL, xsw);
                writeId(literal, xsw);
                writeName(literal, mapper, xsw);
                xsw.writeAttribute("isSpecification", Boolean.toString(false));
                xsw.writeEndElement();
            }
        } finally {
            xsw.writeEndElement();
        }
    } finally {
        xsw.writeEndElement();
    }
}

From source file:org.slc.sli.modeling.xmi.writer.XmiWriter.java

private static final void writeId(final HasIdentity hasIdentity, final XMLStreamWriter xsw)
        throws XMLStreamException {
    xsw.writeAttribute(XmiAttributeName.ID.getLocalName(), hasIdentity.getId().toString());
}