Example usage for javax.xml.stream XMLStreamWriter writeEmptyElement

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

Introduction

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

Prototype

public void writeEmptyElement(String localName) throws XMLStreamException;

Source Link

Document

Writes an empty element tag to the output

Usage

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates the default values./*  w  ww .j  a  v a2  s  .  c o m*/
 * 
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param defaultValue
 *            {@link String} the default value of the current
 *            {@link Attribute}
 * @param id
 *            {@link String} the id of the current {@link Attribute}
 * @param domain
 *            {@link Domain} the type of the current {@link Attribute}
 * @throws XMLStreamException
 */
private void createDefaultValue(XMLStreamWriter writer, String defaultValue, String id, Domain domain)
        throws XMLStreamException {
    // start defaultValue
    if (domain instanceof LongDomain || domain instanceof EnumDomain) {
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_DEFAULTVALUE);
    } else {
        writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_DEFAULTVALUE);
    }
    if (domain instanceof BooleanDomain) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_LITERALBOOLEAN);
    } else if (domain instanceof IntegerDomain || domain instanceof LongDomain) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_LITERALINTEGER);
    } else if (domain instanceof EnumDomain) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_INSTANCEVALUE);
    } else {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_OPAQUEEXPRESSION);
    }
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id + "_defaultValue");
    if (domain instanceof BooleanDomain || domain instanceof IntegerDomain || domain instanceof LongDomain
            || domain instanceof EnumDomain) {
        if (domain instanceof BooleanDomain) {
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_VALUE,
                    defaultValue.equals("t") ? "true" : "false");
        } else if (domain instanceof EnumDomain) {
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, defaultValue);
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, domain.get_qualifiedName());
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.DEFAULTVALUE_ATTRIBUTE_INSTANCE,
                    domain.get_qualifiedName() + "_" + defaultValue);
        } else {
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_VALUE, defaultValue);
        }

        // create type
        if (domain instanceof BooleanDomain || domain instanceof IntegerDomain) {
            createType(writer, domain);
        }
    } else {
        if (domain instanceof StringDomain) {
            // create type
            createType(writer, domain);
        } else {
            // there has to be created an entry for the current domain in
            // the package primitiveTypes
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                    domain.get_qualifiedName().replaceAll("\\s", "").replaceAll("<", "_").replaceAll(">", "_"));
        }

        // start body
        writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_BODY);
        writer.writeCharacters(defaultValue);
        // end body
        writer.writeEndElement();
    }

    if (!(domain instanceof LongDomain || domain instanceof EnumDomain)) {
        // end defaultValue
        writer.writeEndElement();
    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates the representation of an {@link Attribute}. The represented
 * information are the name, the default value and the type. <br/>
 * If the {@link Attribute} is of type LongDomain, a DoubleDomain, a
 * CollectionDomain or a MapDomain the type is stored in
 * {@link SchemaGraph2XMI#typesToBeDeclaredAtTheEnd} because there has to be
 * created a representation in the primitive types package.
 * /*from w w w. j ava 2s. c o  m*/
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param attributeName
 *            {@link String} the name of the current {@link Attribute}
 * @param defaultValue
 *            {@link String} the default value of the current
 *            {@link Attribute}
 * @param domain
 *            {@link Domain} of the current {@link Attribute}
 * @param id
 *            {@link String} the id of the tag which represents the current
 *            {@link Attribute}
 * @throws XMLStreamException
 */
private void createAttribute(XMLStreamWriter writer, String attributeName, String defaultValue, Domain domain,
        String id) throws XMLStreamException {

    boolean hasDefaultValue = defaultValue != null && !defaultValue.isEmpty();

    // start ownedAttribute
    if (!hasDefaultValue && !(domain instanceof BooleanDomain || domain instanceof IntegerDomain
            || domain instanceof StringDomain)) {
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDATTRIBUTE);
    } else {
        writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDATTRIBUTE);
    }
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_TYPE_VALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, attributeName);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_ATTRIBUTE_VISIBILITY,
            XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_VISIBILITY_VALUE_PRIVATE);

    // create type
    if (domain instanceof BooleanDomain || domain instanceof IntegerDomain || domain instanceof StringDomain) {
        createType(writer, domain);
    } else {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                domain.get_qualifiedName().replaceAll("\\s", "").replaceAll("<", "_").replaceAll(">", "_"));
    }

    // create default value
    if (hasDefaultValue) {
        createDefaultValue(writer, defaultValue, id, domain);
    }

    if (hasDefaultValue || domain instanceof BooleanDomain || domain instanceof IntegerDomain
            || domain instanceof StringDomain) {
        // end ownedAttribute
        writer.writeEndElement();
    }

    // if domain is a LongDomain, a DoubleDomain, a CollectionDomain or a
    // MapDomain there has to be created an entry in the package
    // PrimitiveTypes
    if (domain instanceof LongDomain || domain instanceof DoubleDomain || domain instanceof CollectionDomain
            || domain instanceof MapDomain) {
        typesToBeDeclaredAtTheEnd.add(domain);
    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates the profileApplication tag at the end of the model tag.
 * //from   w w  w .ja  va 2s.co  m
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @throws XMLStreamException
 */
private void createProfileApplication(XMLStreamWriter writer) throws XMLStreamException {
    // start profileApplication
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PROFILEAPPLICATION);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.PROFILEAPPLICATION_TYPE_VALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
            XMIConstants4SchemaGraph2XMI.TAG_PROFILEAPPLICATION + System.currentTimeMillis());

    // create content
    createExtension(writer, null, null);

    // create appliedProfile
    writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_APPLIEDPROFILE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.APPLIEDPROFILE_TYPE_VALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF,
            XMIConstants4SchemaGraph2XMI.APPLIEDPROFILE_HREF_VALUE);

    // end profileApplication
    writer.writeEndElement();
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Defines all attributes of type {@link DoubleDomain}, {@link LongDomain},
 * {@link MapDomain} or {@link CollectionDomain} which are used in the
 * {@link SchemaGraph} i.e. contained in
 * {@link SchemaGraph2XMI#typesToBeDeclaredAtTheEnd}. These definitions are
 * created in a new UML package, called <code>PrimitiveTypes</code>. This is
 * necessary because those {@link Domain}s are not UML primitive types and
 * are not represented by an own <code>packagedElement</code> in the XMI
 * file./*from w  ww  . j  a  v  a  2  s  .  co m*/
 * 
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @throws XMLStreamException
 */
private void createTypes(XMLStreamWriter writer) throws XMLStreamException {
    // start packagedElement
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_PACKAGE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
            XMIConstants4SchemaGraph2XMI.PACKAGE_PRIMITIVETYPES_NAME);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME,
            XMIConstants4SchemaGraph2XMI.PACKAGE_PRIMITIVETYPES_NAME);

    // create entries for domains, which are not defined
    for (Domain domain : typesToBeDeclaredAtTheEnd) {
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
                domain.get_qualifiedName().replaceAll("\\s", "").replaceAll("<", "_").replaceAll(">", "_"));
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME,
                extractSimpleName(domain.get_qualifiedName()));
    }

    // end packagedElement
    writer.writeEndElement();
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates the representation of the {@link EnumDomain}
 * <code>EnumDomain</code>. This representation is a UML enumeration with
 * stereotype <code>&lt;&lt;record&gt;&gt;</code>. The constants of
 * <code>enumDomain</code> are represented as constants of the generated UML
 * enumeration. Further more all {@link Comment}s attached to
 * <code>enumDomain</code> are created.
 * // w  ww . ja  v a 2 s  .  c  o m
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param enumDomain
 *            {@link EnumDomain} the current {@link EnumDomain}
 * @throws XMLStreamException
 */
private void createEnum(XMLStreamWriter writer, EnumDomain enumDomain) throws XMLStreamException {
    // start packagedElement
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_ENUMERATION);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, enumDomain.get_qualifiedName());
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME,
            extractSimpleName(enumDomain.get_qualifiedName()));

    // create comments
    createComments(writer, enumDomain);

    // create enumeration constants
    for (String enumConst : enumDomain.get_enumConstants()) {
        // create ownedLiteral
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDLITERAL);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.OWNEDLITERAL_TYPE_VALUE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
                enumDomain.get_qualifiedName() + "_" + enumConst);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, enumConst);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDLITERAL_ATTRIBUTE_CLASSIFIER,
                enumDomain.get_qualifiedName());
    }

    // end packagedElement
    writer.writeEndElement();
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * This method creates the representation of:
 * <ul>//  www  .j a  v a2s.c  o m
 * <li>the {@link Package} <code>pack</code>, if it is not the
 * defaultPackage,</li>
 * <li>{@link Comment}s which are attached to <code>pack</code>,</li>
 * <li>{@link EnumDomain}s,</li>
 * <li>{@link RecordDomain}s,</li>
 * <li>{@link GraphElementClass}es and</li>
 * <li>{@link Package}s</li>
 * </ul>
 * contained in <code>pack</code>. The creation of other {@link Domain}s
 * except {@link EnumDomain}s and {@link RecordDomain}s are explained at
 * {@link SchemaGraph2XMI#createAttribute(XMLStreamWriter, String, String, Domain, String)}
 * .
 * 
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param pack
 *            {@link Package} the current {@link Package}
 * @throws XMLStreamException
 */
private void createPackage(XMLStreamWriter writer, Package pack) throws XMLStreamException {
    boolean packageTagHasToBeClosed = false;

    if (!isPackageEmpty(pack)) {

        if (!pack.get_qualifiedName().equals(de.uni_koblenz.jgralab.schema.Package.DEFAULTPACKAGE_NAME)) {
            // for the default package there is not created a package tag
            packageTagHasToBeClosed = pack.getFirstAnnotatesIncidence() != null
                    || pack.getFirstContainsDomainIncidence() != null
                    || pack.getFirstContainsGraphElementClassIncidence() != null
                    || pack.getFirstContainsSubPackageIncidence(EdgeDirection.OUT) != null;
            if (packageTagHasToBeClosed) {
                // start package
                writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
            } else {
                // create empty package
                writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
            }
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                    XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                    XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_PACKAGE);
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                    XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, pack.get_qualifiedName());
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME,
                    extractSimpleName(pack.get_qualifiedName()));
        }

        // create comments
        createComments(writer, pack);

        // create domains
        for (ContainsDomain cd : pack.getContainsDomainIncidences()) {
            Domain domain = (Domain) cd.getThat();
            if (!domain.get_qualifiedName()
                    .equals(de.uni_koblenz.jgralab.schema.BooleanDomain.BOOLEANDOMAIN_NAME)
                    && !domain.get_qualifiedName()
                            .equals(de.uni_koblenz.jgralab.schema.DoubleDomain.DOUBLEDOMAIN_NAME)
                    && !domain.get_qualifiedName()
                            .equals(de.uni_koblenz.jgralab.schema.IntegerDomain.INTDOMAIN_NAME)
                    && !domain.get_qualifiedName()
                            .equals(de.uni_koblenz.jgralab.schema.LongDomain.LONGDOMAIN_NAME)
                    && !domain.get_qualifiedName()
                            .equals(de.uni_koblenz.jgralab.schema.StringDomain.STRINGDOMAIN_NAME)) {
                // skip basic domains
                if (domain instanceof EnumDomain) {
                    createEnum(writer, (EnumDomain) domain);
                } else if (domain instanceof RecordDomain) {
                    createRecordDomain(writer, (RecordDomain) domain);
                }
            }
        }

        // create GraphElementClasses
        for (ContainsGraphElementClass cgec : pack.getContainsGraphElementClassIncidences()) {
            GraphElementClass gec = (GraphElementClass) cgec.getThat();
            createAttributedElementClass(writer, gec);
        }

        // create subpackages
        for (ContainsSubPackage csp : pack.getContainsSubPackageIncidences(EdgeDirection.OUT)) {
            // create subpackages
            createPackage(writer, (Package) csp.getThat());
        }

        if (packageTagHasToBeClosed) {
            // close packagedElement
            writer.writeEndElement();
        }
    }
}

From source file:org.gaul.s3proxy.S3ProxyHandler.java

private void handleListMultipartUploads(HttpServletRequest request, HttpServletResponse response,
        BlobStore blobStore, String container) throws IOException, S3Exception {
    if (request.getParameter("delimiter") != null || request.getParameter("prefix") != null
            || request.getParameter("max-uploads") != null || request.getParameter("key-marker") != null
            || request.getParameter("upload-id-marker") != null) {
        throw new UnsupportedOperationException();
    }/*from  w  ww.j a va2s. co  m*/

    List<MultipartUpload> uploads = blobStore.listMultipartUploads(container);

    try (Writer writer = response.getWriter()) {
        XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(writer);
        xml.writeStartDocument();
        xml.writeStartElement("ListMultipartUploadsResult");
        xml.writeDefaultNamespace(AWS_XMLNS);

        writeSimpleElement(xml, "Bucket", container);

        // TODO: bogus values
        xml.writeEmptyElement("KeyMarker");
        xml.writeEmptyElement("UploadIdMarker");
        xml.writeEmptyElement("NextKeyMarker");
        xml.writeEmptyElement("NextUploadIdMarker");
        xml.writeEmptyElement("Delimiter");
        xml.writeEmptyElement("Prefix");
        writeSimpleElement(xml, "MaxUploads", "1000");
        writeSimpleElement(xml, "IsTruncated", "false");

        for (MultipartUpload upload : uploads) {
            xml.writeStartElement("Upload");

            writeSimpleElement(xml, "Key", upload.blobName());
            writeSimpleElement(xml, "UploadId", upload.id());
            writeInitiatorStanza(xml);
            writeOwnerStanza(xml);
            writeSimpleElement(xml, "StorageClass", "STANDARD");

            // TODO: bogus value
            writeSimpleElement(xml, "Initiated",
                    blobStore.getContext().utils().date().iso8601DateFormat(new Date()));

            xml.writeEndElement();
        }

        // TODO: CommonPrefixes

        xml.writeEndElement();

        xml.flush();
    } catch (XMLStreamException xse) {
        throw new IOException(xse);
    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * Creates the representation of the {@link AttributedElementClass}
 * <code>aeclass</code>.<br />
 * A {@link GraphClass} is represented as a UML class with stereotype
 * <code>&lt;&lt;graphclass&gt;&gt;</code>.<br />
 * A {@link VertexClass} is represented as a UML class.<br />
 * An {@link EdgeClass} is represented as a UML association, if it has no
 * attributes and otherwise as a UML associationClass.<br />
 * Furthermore the attribute abstract is generated, if the
 * {@link VertexClass} or {@link EdgeClass} is abstract. {@link Comment}s,
 * {@link Constraint}s, generalization and {@link Attribute}s are
 * represented as well.<br />/* w ww. j  a  v a2  s  . c  o m*/
 * The {@link IncidenceClass} representations are created if needed. To get
 * more information if it is needed, have a look at
 * {@link SchemaGraph2XMI#createIncidences(XMLStreamWriter, EdgeClass)} and
 * {@link SchemaGraph2XMI#createIncidences(XMLStreamWriter, VertexClass)}.
 * 
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param aeclass
 *            {@link AttributedElementClass} the current
 *            {@link AttributedElementClass}
 * @throws XMLStreamException
 */
private void createAttributedElementClass(XMLStreamWriter writer, AttributedElementClass aeclass)
        throws XMLStreamException {

    // if aeclass is a GraphElementClass without any attributes, comments
    // and constraints then an empty tag is created. Furthermore an
    // EdgeClass could only be empty if the associations are created
    // bidirectional.
    boolean isEmptyGraphElementClass = aeclass.getFirstAnnotatesIncidence() == null
            && aeclass.getFirstHasAttributeIncidence() == null
            && aeclass.getFirstHasConstraintIncidence() == null
            && (aeclass instanceof GraphElementClass && !((GraphElementClass) aeclass).is_abstract())
            && (aeclass instanceof VertexClass
                    && ((VertexClass) aeclass)
                            .getFirstSpecializesVertexClassIncidence(EdgeDirection.OUT) == null
                    && !hasChildIncidence((VertexClass) aeclass)
                    || aeclass instanceof EdgeClass
                            && ((EdgeClass) aeclass)
                                    .getFirstSpecializesEdgeClassIncidence(EdgeDirection.OUT) == null
                            && isBidirectional);

    // start packagedElement
    if (isEmptyGraphElementClass) {
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
    } else {
        writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_PACKAGEDELEMENT);
    }
    // set type
    if (aeclass instanceof EdgeClass) {
        if (aeclass.getFirstHasAttributeIncidence() == null) {
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                    XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                    XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_ASSOCIATION);
        } else {
            writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                    XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                    XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_ASSOCIATIONCLASS);
        }
    } else {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_TYPE_VALUE_CLASS);
    }
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, aeclass.get_qualifiedName());
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME,
            extractSimpleName(aeclass.get_qualifiedName()));

    // set EdgeClass specific memberEnd
    if (aeclass instanceof EdgeClass) {
        EdgeClass ec = (EdgeClass) aeclass;
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_ATTRIBUTE_MEMBEREND,
                ((VertexClass) ((IncidenceClass) ec.getFirstComesFromIncidence().getThat())
                        .getFirstEndsAtIncidence().getThat()).get_qualifiedName() + "_incidence_"
                        + ec.get_qualifiedName() + "_from "
                        + ((VertexClass) ((IncidenceClass) ec.getFirstGoesToIncidence().getThat())
                                .getFirstEndsAtIncidence().getThat()).get_qualifiedName()
                        + "_incidence_" + ec.get_qualifiedName() + "_to");
    }

    // set abstract
    if (aeclass instanceof GraphElementClass && ((GraphElementClass) aeclass).is_abstract()) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_ATTRIBUTE_ISABSTRACT,
                XMIConstants4SchemaGraph2XMI.ATTRIBUTE_VALUE_TRUE);
        createExtension(writer, aeclass, "abstract");
    }

    // create <<graphclass>> for graph classes
    if (aeclass instanceof GraphClass) {
        createExtension(writer, aeclass, "graphclass");
    }

    // create comments
    createComments(writer, aeclass);

    // create constraints
    createConstraints(writer, aeclass);

    // create generalization
    if (aeclass instanceof VertexClass) {
        for (SpecializesVertexClass svc : ((VertexClass) aeclass)
                .getSpecializesVertexClassIncidences(EdgeDirection.OUT)) {
            createGeneralization(writer, "generalization_" + aeclass.get_qualifiedName(),
                    ((VertexClass) svc.getThat()).get_qualifiedName());
        }
    } else if (aeclass instanceof EdgeClass) {
        for (SpecializesEdgeClass svc : ((EdgeClass) aeclass)
                .getSpecializesEdgeClassIncidences(EdgeDirection.OUT)) {
            createGeneralization(writer, "generalization_" + aeclass.get_qualifiedName(),
                    ((EdgeClass) svc.getThat()).get_qualifiedName());
        }
    }

    // create attributes
    createAttributes(writer, aeclass);

    // create incidences of EdgeClasses at VertexClass aeclass
    if (aeclass instanceof VertexClass) {
        createIncidences(writer, (VertexClass) aeclass);
    } else if (aeclass instanceof EdgeClass) {
        createIncidences(writer, (EdgeClass) aeclass);
    }

    // close packagedElement
    if (!isEmptyGraphElementClass) {
        writer.writeEndElement();
    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java

/**
 * This method creates an <code>extension</code> tag. It is used in profile
 * application and to create stereotypes of the form
 * <code>&lt;&lt;keyValue&gt;&gt;</code>. In the first case a
 * <code>references</code> child is created in the other a
 * <code>details</code> child. To create the first one <code>nelement</code>
 * has to be <code>null</code>.
 * //from w  ww  . j a v  a 2s . c o  m
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param nelement
 *            {@link NamedElement} if null <code>references</code> is
 *            created otherwise the stereotype <code>keyValue</code>.
 * @param keyValue
 *            {@link String} the stereotype to be created
 * @throws XMLStreamException
 */
private void createExtension(XMLStreamWriter writer, NamedElement nelement, String keyValue)
        throws XMLStreamException {
    // start Extension
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_TAG_EXTENSION);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_EXTENDER,
            XMIConstants4SchemaGraph2XMI.NAMESPACE_ECORE);

    // start eAnnotations
    writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.EANNOTATIONS_TYPE_VALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
            nelement != null
                    ? nelement.get_qualifiedName() + "_" + XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS
                    : XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS + System.currentTimeMillis());
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.EANNOTATIONS_ATTRIBUTE_SOURCE,
            XMIConstants4SchemaGraph2XMI.EANNOTATIONS_ATTRIBUTE_SOURCE_VALUE);

    if (nelement != null) {
        // write details
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_DETAILS);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.DETAILS_ATTRIBUTE_TYPE_VALUE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID,
                nelement.get_qualifiedName() + "_" + XMIConstants4SchemaGraph2XMI.TAG_DETAILS);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.DETAILS_ATTRIBUTE_KEY, keyValue);
    } else {
        // write references
        writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_REFERENCES);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
                XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
                XMIConstants4SchemaGraph2XMI.REFERENCES_TYPE_VALUE);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF,
                XMIConstants4SchemaGraph2XMI.REFERENCES_HREF_VALUE);
    }

    // close eAnnotations
    writer.writeEndElement();

    // close Extension
    writer.writeEndElement();
}

From source file:org.elasticsearch.discovery.ec2.Ec2DiscoveryClusterFormationTests.java

/**
 * Creates mock EC2 endpoint providing the list of started nodes to the DescribeInstances API call
 *///from   w  w w .j  a v  a 2  s.  c  o m
@BeforeClass
public static void startHttpd() throws Exception {
    logDir = createTempDir();
    httpServer = MockHttpServer
            .createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 0), 0);

    httpServer.createContext("/", (s) -> {
        Headers headers = s.getResponseHeaders();
        headers.add("Content-Type", "text/xml; charset=UTF-8");
        String action = null;
        for (NameValuePair parse : URLEncodedUtils.parse(IOUtils.toString(s.getRequestBody()),
                StandardCharsets.UTF_8)) {
            if ("Action".equals(parse.getName())) {
                action = parse.getValue();
                break;
            }
        }
        assertThat(action, equalTo("DescribeInstances"));

        XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
        xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
        StringWriter out = new StringWriter();
        XMLStreamWriter sw;
        try {
            sw = xmlOutputFactory.createXMLStreamWriter(out);
            sw.writeStartDocument();

            String namespace = "http://ec2.amazonaws.com/doc/2013-02-01/";
            sw.setDefaultNamespace(namespace);
            sw.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "DescribeInstancesResponse", namespace);
            {
                sw.writeStartElement("requestId");
                sw.writeCharacters(UUID.randomUUID().toString());
                sw.writeEndElement();

                sw.writeStartElement("reservationSet");
                {
                    Path[] files = FileSystemUtils.files(logDir);
                    for (int i = 0; i < files.length; i++) {
                        Path resolve = files[i].resolve("transport.ports");
                        if (Files.exists(resolve)) {
                            List<String> addresses = Files.readAllLines(resolve);
                            Collections.shuffle(addresses, random());

                            sw.writeStartElement("item");
                            {
                                sw.writeStartElement("reservationId");
                                sw.writeCharacters(UUID.randomUUID().toString());
                                sw.writeEndElement();

                                sw.writeStartElement("instancesSet");
                                {
                                    sw.writeStartElement("item");
                                    {
                                        sw.writeStartElement("instanceId");
                                        sw.writeCharacters(UUID.randomUUID().toString());
                                        sw.writeEndElement();

                                        sw.writeStartElement("imageId");
                                        sw.writeCharacters(UUID.randomUUID().toString());
                                        sw.writeEndElement();

                                        sw.writeStartElement("instanceState");
                                        {
                                            sw.writeStartElement("code");
                                            sw.writeCharacters("16");
                                            sw.writeEndElement();

                                            sw.writeStartElement("name");
                                            sw.writeCharacters("running");
                                            sw.writeEndElement();
                                        }
                                        sw.writeEndElement();

                                        sw.writeStartElement("privateDnsName");
                                        sw.writeCharacters(addresses.get(0));
                                        sw.writeEndElement();

                                        sw.writeStartElement("dnsName");
                                        sw.writeCharacters(addresses.get(0));
                                        sw.writeEndElement();

                                        sw.writeStartElement("instanceType");
                                        sw.writeCharacters("m1.medium");
                                        sw.writeEndElement();

                                        sw.writeStartElement("placement");
                                        {
                                            sw.writeStartElement("availabilityZone");
                                            sw.writeCharacters("use-east-1e");
                                            sw.writeEndElement();

                                            sw.writeEmptyElement("groupName");

                                            sw.writeStartElement("tenancy");
                                            sw.writeCharacters("default");
                                            sw.writeEndElement();
                                        }
                                        sw.writeEndElement();

                                        sw.writeStartElement("privateIpAddress");
                                        sw.writeCharacters(addresses.get(0));
                                        sw.writeEndElement();

                                        sw.writeStartElement("ipAddress");
                                        sw.writeCharacters(addresses.get(0));
                                        sw.writeEndElement();
                                    }
                                    sw.writeEndElement();
                                }
                                sw.writeEndElement();
                            }
                            sw.writeEndElement();
                        }
                    }
                }
                sw.writeEndElement();
            }
            sw.writeEndElement();

            sw.writeEndDocument();
            sw.flush();

            final byte[] responseAsBytes = out.toString().getBytes(StandardCharsets.UTF_8);
            s.sendResponseHeaders(200, responseAsBytes.length);
            OutputStream responseBody = s.getResponseBody();
            responseBody.write(responseAsBytes);
            responseBody.close();
        } catch (XMLStreamException e) {
            Loggers.getLogger(Ec2DiscoveryClusterFormationTests.class).error("Failed serializing XML", e);
            throw new RuntimeException(e);
        }
    });

    httpServer.start();
}