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 namespaceURI, String localName, String value) throws XMLStreamException;

Source Link

Document

Writes an attribute to the output stream

Usage

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

/**
 * Creates the representation of the {@link IncidenceClass} which contains
 * the information for the {@link VertexClass} which is specified by
 * <code>qualifiedNameOfVertexClass</code> e.g. <code>otherIncidence</code>.<br/>
 * The relevant information are: <ui> <li>the rolename,</li> <li>the min
 * value,</li> <li>the max value and</li> <li>composition or shared
 * information.</li> </ui> The default rolename for associations is
 * <code>qualifiedNameOfVertexClass_edgeClass.getQualifiedName()</code> and
 * <code>""</code> for associationClasses.
 * /*from   w ww. j  a  v a 2  s  . c  om*/
 * @param writer
 *            {@link XMLStreamWriter} of the current XMI file
 * @param otherIncidence
 *            {@link IncidenceClass} which contains the information for the
 *            incidence corresponding to the {@link VertexClass} of
 *            <code>qualifiedNameOfVertexClass</code> in the xmi file.
 * @param connectedVertexClass
 *            {@link VertexClass} at the other end of <code>edgeClass</code>
 * @param incidence
 *            {@link IncidenceClass} connected to the {@link VertexClass}
 *            specified by <code>qualifiedNameOfVertexClass</code>
 * @param edgeClass
 *            {@link EdgeClass} which connects the {@link VertexClass}
 *            specified by <code>qualifiedNameOfVertexClass</code> with
 *            <code>connectedVertexClass</code>
 * @param qualifiedNameOfVertexClass
 *            {@link String} the qualified name of the {@link VertexClass}
 *            to which <code>incidence</code> is connected to.
 * @param createOwnedEnd
 *            boolean if set to <code>true</code>, the tag ownedEnd is used
 *            instead of ownedAttribute (ownedEnd has to be created, if you
 *            create an incidence at an association.)
 * @throws XMLStreamException
 */
private void createIncidence(XMLStreamWriter writer, IncidenceClass otherIncidence, EdgeClass edgeClass,
        IncidenceClass incidence, VertexClass connectedVertexClass, String qualifiedNameOfVertexClass,
        boolean createOwnedEnd) throws XMLStreamException {

    String incidenceId = qualifiedNameOfVertexClass + "_incidence_" + edgeClass.get_qualifiedName()
            + (incidence.getFirstComesFromIncidence() != null ? "_from" : "_to");

    // start ownedattribute
    writer.writeStartElement(createOwnedEnd ? XMIConstants4SchemaGraph2XMI.TAG_OWNEDEND
            : 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, incidenceId);
    // set rolenames
    if (otherIncidence.get_roleName() != null && !otherIncidence.get_roleName().isEmpty()) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, otherIncidence.get_roleName());
    } else if (isRoleNameNecessary(edgeClass, connectedVertexClass.get_qualifiedName())) {
        String newRoleName = createNewUniqueRoleName(connectedVertexClass);
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, newRoleName);
        // to find already used rolenames set the newly created rolename
        otherIncidence.set_roleName(newRoleName);
    }
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_ATTRIBUTE_VISIBILITY,
            XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_VISIBILITY_VALUE_PRIVATE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_ATTRIBUTE_TYPE,
            connectedVertexClass.get_qualifiedName());
    // set composite or shared
    if (otherIncidence.get_aggregation() == AggregationKind.SHARED) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_ATTRIBUTE_AGGREGATION,
                XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_ATTRIBUTE_AGGREGATION_VALUE_SHARED);
    } else if (otherIncidence.get_aggregation() == AggregationKind.COMPOSITE) {
        writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_ATTRIBUTE_AGGREGATION,
                XMIConstants4SchemaGraph2XMI.OWNEDATTRIBUTE_ATTRIBUTE_AGGREGATION_VALUE_COMPOSITE);
    }
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.PACKAGEDELEMENT_ATTRIBUTE_ASSOCIATION,
            edgeClass.get_qualifiedName());

    // create upperValue
    writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_UPPERVALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.TYPE_VALUE_LITERALUNLIMITEDNATURAL);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, incidenceId + "_uppervalue");
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_VALUE,
            otherIncidence.get_max() == Integer.MAX_VALUE ? "*" : Integer.toString(otherIncidence.get_max()));

    // create lowerValue
    writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_LOWERVALUE);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE,
            XMIConstants4SchemaGraph2XMI.TYPE_VALUE_LITERALINTEGER);
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI,
            XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, incidenceId + "_lowervalue");
    writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_VALUE,
            incidence.get_min() == Integer.MAX_VALUE ? "*" : Integer.toString(otherIncidence.get_min()));

    // close ownedattribute
    writer.writeEndElement();
}

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

/**
 * This method creates the representation of:
 * <ul>//from  www  . jav  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: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 />/*  www  . j  ava 2s.  c om*/
 * 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:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

private static void serializeSymbols(EodDataProvider eodDataProvider, XMLStreamWriter writer) {

    try {// ww  w  . j  a va  2  s  .  com
        writer.writeStartElement(XML_NAMESPACE_URI, SYMBOLS_LOCALNAME);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE);
        writer.writeCharacters(NEWLINE);
        serialize(eodDataProvider.getSymbols(TEST_EXCHANGE), SYMBOL_QNAME, writer);
        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
    } catch (XMLStreamException xse) {
        logger.error(xse.toString());
        logger.error(xse);
    } catch (EodDataProviderException edpe) {

        logger.error(edpe.toString());
        logger.error(edpe);

    } finally {

        if (eodDataProvider != null) {

            // eodDataProvider.close();

        }

    }

}

From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

private static void serializeQuotes(EodDataProvider eodDataProvider, XMLStreamWriter writer) {

    try {//  www  . jav a 2 s.  c o  m
        writer.writeStartElement(XML_NAMESPACE_URI, QUOTES_LOCALNAME);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTSYMBOL_ATTRNAME, TEST_SYMBOL);
        writer.writeCharacters(NEWLINE);

        Calendar startCalendar = Calendar.getInstance();
        startCalendar.add(Calendar.YEAR, HISTORY_YEAR_OFFSET);
        //    startCalendar.add(Calendar.MONTH, HISTORY_MONTH_OFFSET);

        Calendar endCalendar = Calendar.getInstance();

        serialize(eodDataProvider.getQuotes(TEST_EXCHANGE, TEST_SYMBOL, startCalendar, endCalendar,
                DEFAULT_FREQUENCY), QUOTE_QNAME, writer);
        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
    } catch (XMLStreamException xse) {
        logger.error(xse.toString());
        logger.error(xse);
    } catch (EodDataProviderException edpe) {

        logger.error(edpe.toString());
        logger.error(edpe);

    } finally {

        if (eodDataProvider != null) {

            // eodDataProvider.close();

        }

    }

}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

private static void addTypeAttribute(XMLStreamWriter xmlStreamWriter, String type) throws XMLStreamException {
    String prefix = xmlStreamWriter.getPrefix(Constants.XSI_NAMESPACE);
    if (prefix == null) {
        prefix = BeanUtil.getUniquePrefix();
        xmlStreamWriter.writeNamespace(prefix, Constants.XSI_NAMESPACE);
        xmlStreamWriter.setPrefix(prefix, Constants.XSI_NAMESPACE);
    }//from  w ww . j a  v  a  2  s . c o  m

    prefix = xmlStreamWriter.getPrefix(Constants.XSD_NAMESPACE);
    if (prefix == null) {
        prefix = BeanUtil.getUniquePrefix();
        xmlStreamWriter.writeNamespace(prefix, Constants.XSD_NAMESPACE);
        xmlStreamWriter.setPrefix(prefix, Constants.XSD_NAMESPACE);
    }

    String attributeValue = null;
    if (prefix.equals("")) {
        attributeValue = type;
    } else {
        attributeValue = prefix + ":" + type;
    }

    xmlStreamWriter.writeAttribute(Constants.XSI_NAMESPACE, "type", attributeValue);
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void entity(final XMLStreamWriter writer, final Entity entity)
        throws XMLStreamException, EdmPrimitiveTypeException {
    if (entity.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entity.getBaseURI().toASCIIString());
    }/*  w ww . j  a va2s.  c om*/

    if (serverMode && StringUtils.isNotBlank(entity.getETag())) {
        writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_ETAG, entity.getETag());
    }

    if (entity.getId() != null) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entity.getId().toASCIIString());
        writer.writeEndElement();
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
    writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME);
    if (StringUtils.isNotBlank(entity.getType())) {
        writer.writeAttribute(Constants.ATOM_ATTR_TERM,
                new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external());
    }
    writer.writeEndElement();

    common(writer, entity);

    if (serverMode) {
        if (entity.getEditLink() != null) {
            links(writer, Collections.singletonList(entity.getEditLink()));
        }

        if (entity.getSelfLink() != null) {
            links(writer, Collections.singletonList(entity.getSelfLink()));
        }
    }

    links(writer, entity.getAssociationLinks());
    if (serverMode) {
        links(writer, entity.getNavigationLinks());
    } else {
        writeNavigationLinks(writer, entity.getNavigationLinks());
        writeNavigationLinks(writer, entity.getNavigationBindings());
    }
    links(writer, entity.getMediaEditLinks());

    if (serverMode) {
        for (Operation operation : entity.getOperations()) {
            writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_ACTION);
            writer.writeAttribute(Constants.ATTR_METADATA, operation.getMetadataAnchor());
            writer.writeAttribute(Constants.ATTR_TITLE, operation.getTitle());
            writer.writeAttribute(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
            writer.writeEndElement();
        }
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
    if (entity.isMediaEntity()) {
        if (StringUtils.isNotBlank(entity.getMediaContentType())) {
            writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
        }
        if (entity.getMediaContentSource() != null) {
            writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toASCIIString());
        }
        writer.writeEndElement();

        writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES);
        properties(writer, entity.getProperties());
    } else {
        writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML.toContentTypeString());
        writer.writeStartElement(namespaceMetadata, Constants.PROPERTIES);
        properties(writer, entity.getProperties());
        writer.writeEndElement();
    }
    writer.writeEndElement();

    for (Annotation annotation : entity.getAnnotations()) {
        annotation(writer, annotation, null);
    }
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private void entitySet(final XMLStreamWriter writer, final EntityCollection entitySet)
        throws XMLStreamException, EdmPrimitiveTypeException {
    if (entitySet.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entitySet.getBaseURI().toASCIIString());
    }//from   w  ww  .ja v a2s  .c  o m

    if (entitySet.getCount() != null) {
        writer.writeStartElement(namespaceMetadata, Constants.ATOM_ELEM_COUNT);
        writer.writeCharacters(Integer.toString(entitySet.getCount()));
        writer.writeEndElement();
    }

    if (entitySet.getId() != null) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entitySet.getId().toASCIIString());
        writer.writeEndElement();
    }

    common(writer, entitySet);

    for (Entity entity : entitySet) {
        if (entity.getType() == null && entity.getProperties().isEmpty()) {
            entityRef(writer, entity);
        } else {
            writer.writeStartElement(Constants.ATOM_ELEM_ENTRY);
            entity(writer, entity);
            writer.writeEndElement();
        }
    }

    if (serverMode) {
        if (entitySet.getNext() != null) {
            final Link next = new Link();
            next.setRel(Constants.NEXT_LINK_REL);
            next.setHref(entitySet.getNext().toASCIIString());

            links(writer, Collections.<Link>singletonList(next));
        }
        if (entitySet.getDeltaLink() != null) {
            final Link next = new Link();
            next.setRel(Constants.NS_DELTA_LINK_REL);
            next.setHref(entitySet.getDeltaLink().toASCIIString());

            links(writer, Collections.<Link>singletonList(next));
        }
    }
}

From source file:org.apache.olingo.client.core.serialization.AtomSerializer.java

private <T> void addContextInfo(final XMLStreamWriter writer, final ResWrap<T> container)
        throws XMLStreamException {

    if (container.getContextURL() != null) {
        final ContextURL contextURL = ContextURLParser.parse(container.getContextURL());
        final URI base = contextURL.getServiceRoot();
        if (container.getPayload() instanceof EntityCollection) {
            ((EntityCollection) container.getPayload()).setBaseURI(base);
        }//from   w ww  . j av a 2s . c o m
        if (container.getPayload() instanceof Entity) {
            ((Entity) container.getPayload()).setBaseURI(base);
        }

        writer.writeAttribute(namespaceMetadata, Constants.CONTEXT, container.getContextURL().toASCIIString());
    }

    if (StringUtils.isNotBlank(container.getMetadataETag())) {
        writer.writeAttribute(namespaceMetadata, Constants.ATOM_ATTR_METADATAETAG, container.getMetadataETag());
    }
}

From source file:org.apache.olingo.commons.core.data.AtomSerializer.java

private void entry(final XMLStreamWriter writer, final Entry entry) throws XMLStreamException {
    if (entry.getBaseURI() != null) {
        writer.writeAttribute(XMLConstants.XML_NS_URI, Constants.ATTR_XML_BASE,
                entry.getBaseURI().toASCIIString());
    }/*from www .j  a  va 2s  . co  m*/

    if (StringUtils.isNotBlank(entry.getId())) {
        writer.writeStartElement(Constants.ATOM_ELEM_ID);
        writer.writeCharacters(entry.getId());
        writer.writeEndElement();
    }

    writer.writeStartElement(Constants.ATOM_ELEM_CATEGORY);
    writer.writeAttribute(Constants.ATOM_ATTR_SCHEME,
            version.getNamespaceMap().get(ODataServiceVersion.NS_SCHEME));
    writer.writeAttribute(Constants.ATOM_ATTR_TERM, entry.getType());
    writer.writeEndElement();

    if (entry instanceof AbstractAtomObject) {
        common(writer, (AbstractAtomObject) entry);
    }

    links(writer, entry.getAssociationLinks());
    links(writer, entry.getNavigationLinks());
    links(writer, entry.getMediaEditLinks());

    writer.writeStartElement(Constants.ATOM_ELEM_CONTENT);
    if (entry.isMediaEntry()) {
        if (StringUtils.isNotBlank(entry.getMediaContentType())) {
            writer.writeAttribute(Constants.ATTR_TYPE, entry.getMediaContentType());
        }
        if (StringUtils.isNotBlank(entry.getMediaContentSource())) {
            writer.writeAttribute(Constants.ATOM_ATTR_SRC, entry.getMediaContentSource());
        }
        writer.writeEndElement();

        writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
                Constants.PROPERTIES);
        properties(writer, entry.getProperties());
    } else {
        writer.writeAttribute(Constants.ATTR_TYPE, ContentType.APPLICATION_XML);
        writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA),
                Constants.PROPERTIES);
        properties(writer, entry.getProperties());
        writer.writeEndElement();
    }
    writer.writeEndElement();
}