List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException;
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><<record>></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. * // ww w .jav a2 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
private void createGeneralization(XMLStreamWriter writer, String id, String idOfSpecializedClass) throws XMLStreamException { // create generalization writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_GENERALIZATION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.GENERALIZATION_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.GENERALIZATION_ATTRIBUTE_GENERAL, idOfSpecializedClass); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the representation of one comment. * /*w ww.j a v a2 s .c o m*/ * @param writer * {@link XMLStreamWriter} of the current XMI file * @param comment * {@link Comment} which should be represented * @param id * {@link String} the id of the created <code>ownedComment</code> * tag, which represents <code>comment</code> * @param annotatedElement * {@link String} qualified name of the {@link NamedElement} * which is commented * @throws XMLStreamException */ private void createComment(XMLStreamWriter writer, Comment comment, String id, String annotatedElement) throws XMLStreamException { // start ownedComment writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDCOMMENT); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.OWNEDCOMMENT_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDCOMMENT_ATTRIBUTE_ANNOTATEDELEMENT, annotatedElement); // start body writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_BODY); // write content writer.writeCharacters(XMIConstants4SchemaGraph2XMI.COMMENT_START + comment.get_text().replaceAll(Pattern.quote("\n"), XMIConstants4SchemaGraph2XMI.COMMENT_NEWLINE) + XMIConstants4SchemaGraph2XMI.COMMENT_END); // end body writer.writeEndElement(); // end ownedComment writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the <code>type</code> tag used for attributes and default values. * /*from w w w .j a v a2 s . c o m*/ * @param writer * {@link XMLStreamWriter} of the current XMI file * @param domain * {@link Domain} the type of the current {@link Attribute} * @throws XMLStreamException */ private void createType(XMLStreamWriter writer, Domain domain) throws XMLStreamException { // create type writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_TYPE); if (domain instanceof BooleanDomain) { // BooleanDomain writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF, XMIConstants4SchemaGraph2XMI.TYPE_HREF_VALUE_BOOLEAN); } else if (domain instanceof IntegerDomain) { // IntegerDomain writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF, XMIConstants4SchemaGraph2XMI.TYPE_HREF_VALUE_INTEGER); } else { // StringDomain writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.TYPE_VALUE_PRIMITIVETYPE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF, XMIConstants4SchemaGraph2XMI.TYPE_HREF_VALUE_STRING); } }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates an constraint with the content <code>constraintContent</code>. * //w w w. ja va 2 s . co m * @param writer * {@link XMLStreamWriter} of the current XMI file * @param constraintContent * {@link String} the content of the constraint which will be * created * @param id * {@link String} the id of the created <code>ownedRule</code> * tag, which represents <code>constraint</code> * @param constrainedElement * {@link String} qualified name of the * {@link AttributedElementClass} which is constrained * @throws XMLStreamException */ private void createConstraint(XMLStreamWriter writer, String constraintContent, String id, String constrainedElement) throws XMLStreamException { // start ownedRule writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_OWNEDRULE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.OWNEDRULE_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.OWNEDRULE_ATTRIBUTE_CONSTRAINEDELEMENT, constrainedElement); // start specification writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_SPECIFICATION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.TYPE_VALUE_OPAQUEEXPRESSION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, id + "_" + XMIConstants4SchemaGraph2XMI.TAG_SPECIFICATION); // start and end language writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_LANGUAGE); writer.writeEndElement(); // start body writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_BODY); writer.writeCharacters(constraintContent); // end body writer.writeEndElement(); // end specification writer.writeEndElement(); // end ownedRule writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the root <code>XMI</code> tag of the whole document. It calls * {@link SchemaGraph2XMI#createModelElement(XMLStreamWriter, SchemaGraph)} * to create its content.//from ww w.jav a2 s. c o m * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException */ private void createRootElement(XMLStreamWriter writer, SchemaGraph schemaGraph) throws XMLStreamException { // start root element writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_XMI, XMIConstants4SchemaGraph2XMI.XMI_TAG_XMI, XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_VERSION, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_VERSION_VALUE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_XSI, XMIConstants4SchemaGraph2XMI.NAMESPACE_XSI); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_EECORE, XMIConstants4SchemaGraph2XMI.NAMESPACE_EECORE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_ECORE, XMIConstants4SchemaGraph2XMI.NAMESPACE_ECORE); writer.setPrefix(XMIConstants4SchemaGraph2XMI.NAMESPACE_PREFIX_UML, XMIConstants4SchemaGraph2XMI.NAMESPACE_UML); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XSI, XMIConstants4SchemaGraph2XMI.XSI_ATTRIBUTE_SCHEMALOCATION, XMIConstants4SchemaGraph2XMI.SCHEMALOCATION); // create model element createModelElement(writer, schemaGraph); // close root element writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the <code>Model</code> tag and its content consisting of * <ul>//from w ww . j a v a 2s.c o m * <li>the {@link GraphClass},</li> * <li>the defaultPackage and its content,</li> * <li>the representation of the domains in * {@link SchemaGraph2XMI#typesToBeDeclaredAtTheEnd} and</li> * <li>and the profile application</li> * </ul> * by calling the corresponding methods. * * @param writer * {@link XMLStreamWriter} of the current XMI file * @param schemaGraph * {@link SchemaGraph} to be converted into an XMI * @throws XMLStreamException */ private void createModelElement(XMLStreamWriter writer, SchemaGraph schemaGraph) throws XMLStreamException { de.uni_koblenz.jgralab.grumlschema.structure.Schema schema = schemaGraph.getFirstSchema(); // start model writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_UML, XMIConstants4SchemaGraph2XMI.UML_TAG_MODEL); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, schema.get_packagePrefix() + "." + schema.get_name()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_NAME, schema.get_packagePrefix() + "." + schema.get_name()); // convert graph class createAttributedElementClass(writer, schemaGraph.getFirstGraphClass()); createPackage(writer, (Package) schemaGraph.getFirstSchema().getFirstContainsDefaultPackageIncidence().getThat()); // create Types if (!typesToBeDeclaredAtTheEnd.isEmpty()) { createTypes(writer); } // create profileApplication createProfileApplication(writer); // end model writer.writeEndElement(); }
From source file:eionet.cr.util.odp.ODPDatasetsPacker.java
/** * @param writer// ww w . j a v a 2 s . c om * @throws XMLStreamException */ private void writeManifestHeader(XMLStreamWriter writer) throws XMLStreamException { // Start the XML document writer.writeStartDocument(ENCODING, "1.0"); // Register all relevant namespaces. registerNamespaces(MANIFEST_FILE_NAMESPACES, writer); // Write root element start tag (i.e. <ecodp:manifest>) writer.writeStartElement(Namespace.ECODP.getUri(), "manifest"); // Write namespace prefixes in the root element start tag. for (Namespace namespace : MANIFEST_FILE_NAMESPACES) { writer.writeNamespace(namespace.getPrefix(), namespace.getUri()); } // It's ok to instantiate SimpleDateFormat every time here, since this method gets called once per package generation. String packageId = PACKAGE_ID_PREFIX + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String generationDateTime = Util.virtuosoDateToString(new Date()); writer.writeAttribute(Namespace.ECODP.getUri(), "creation-date-time", generationDateTime); writer.writeAttribute(Namespace.ECODP.getUri(), "package-id", packageId); writer.writeAttribute(Namespace.ECODP.getUri(), "priority", "normal"); writer.writeAttribute(Namespace.ECODP.getUri(), "publisher", "http://publications.europa.eu/resource/authority/corporate-body/CNECT"); writer.writeAttribute(Namespace.ECODP.getUri(), "version", "1.0"); writer.writeAttribute(Namespace.XSI.getUri(), "schemaLocation", "http://open-data.europa.eu/ontologies/protocol-v1.0/odp-protocol.xsd"); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * Creates the default values./*from w ww . j a v a 2 s . c om*/ * * @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. * /* w ww .j av a2 s . c om*/ * @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); } }