List of usage examples for org.jdom2 Attribute Attribute
@Deprecated public Attribute(final String name, final String value, final int type)
Attribute
with the specified (local) name, value and type, and does not place the attribute in a Namespace
. From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildModelFromURITokens(Model model) { Element rootPackageElem = null; String[] packageNames = ConfigUtils.toPackageTokens(model.getUri()); Element modelElem = new Element("Model"); modelElem.setNamespace(umlNs);/*w ww.j a va 2s. co m*/ this.xmiElem.addContent(modelElem); modelElem.setAttribute(new Attribute("id", model.getId(), xmiNs)); modelElem.setAttribute(new Attribute("name", packageNames[0])); modelElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(model.getId(), modelElem); // FIXME: duplicating model level docs at package // descendant level if (model.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(modelElem, model.getId(), doc.getBody().getValue()); } // tag the model w/a SDO namespace streotype, else tag the // last package descendant below if (packageNames.length == 1) { Element modelStereotype = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(modelStereotype); modelStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); modelStereotype.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, model.getId())); modelStereotype.setAttribute(new Attribute(SDONamespace.URI, this.destNamespaceURI)); } rootPackageElem = modelElem; for (int i = 1; i < packageNames.length; i++) { Element pkgElem = new Element("packagedElement"); rootPackageElem.addContent(pkgElem); String id = UUID.randomUUID().toString(); pkgElem.setAttribute(new Attribute("type", "uml:Package", xmiNs)); pkgElem.setAttribute(new Attribute("id", id, xmiNs)); pkgElem.setAttribute(new Attribute("name", packageNames[i])); pkgElem.setAttribute(new Attribute("visibility", "public")); elementMap.put(id, pkgElem); if (i == packageNames.length - 1) { Element pkgStereotypeElem = new Element(SDONamespace.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(pkgStereotypeElem); pkgStereotypeElem.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.BASE__PACKAGE, id)); pkgStereotypeElem.setAttribute(new Attribute(SDONamespace.URI, this.destNamespaceURI)); // FIXME: no packages or package-level docs in provisioning model // use model-level docs here if (model.getDocumentations() != null) for (Documentation doc : model.getDocumentations()) { addOwnedComment(pkgElem, id, doc.getBody().getValue()); } } rootPackageElem = pkgElem; } return rootPackageElem; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildClass(Class clss) { if (log.isDebugEnabled()) log.debug("creating class " + clss.getName()); // find parent element Package pkgParent = this.classPackageMap.get(clss); Element parent = this.elementMap.get(pkgParent.getId()); Element clssElem = new Element("packagedElement"); parent.addContent(clssElem);/* w w w .j a va 2s .co m*/ elementMap.put(clss.getId(), clssElem); clssElem.setAttribute(new Attribute("type", "uml:Class", xmiNs)); clssElem.setAttribute(new Attribute("id", clss.getId(), xmiNs)); clssElem.setAttribute(new Attribute("name", clss.getName())); clssElem.setAttribute(new Attribute("visibility", "public")); if (clss.getDocumentations() != null) for (Documentation doc : clss.getDocumentations()) { addOwnedComment(clssElem, clss.getId(), doc.getBody().getValue()); } if (clss.getAlias() != null) { addAlias(clss.getAlias(), clss.getId()); } for (ClassRef baseRef : clss.getSuperClasses()) { Element generalizationElem = new Element("generalization"); generalizationElem.setAttribute(new Attribute("type", "uml:Generalization", xmiNs)); generalizationElem.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); clssElem.addContent(generalizationElem); Class baseClass = classMap.get(baseRef.getUri() + "#" + baseRef.getName()); generalizationElem.setAttribute(new Attribute("general", baseClass.getId())); /* --for an external reference Element generalElem = new Element("general"); generalizationElem.addContent(generalElem); generalElem.setAttribute(new Attribute("type", "uml:Class", xmiNs)); generalElem.setAttribute(new Attribute("type", "uml:Class")); generalElem.setAttribute(new Attribute("href", baseClass.getId())); */ } /* --for an external reference <generalization xmi:type='uml:Generalization' xmi:id='_16_0_1_1707042b_1325701279933_851156_1151'> <general xmi:type='uml:Class' href='plasma-platform-common.mdxml#_16_0_1_1707042b_1318367153137_813743_576'> </general> </generalization> */ if (clss.getBehaviors().size() > 0) addBehaviors(clss, clssElem, clss.getBehaviors()); return clssElem; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
/** * Adds a UML owned opaque behavior ala. below for each provisioning * behavior./* w w w. j av a 2s .c o m*/ * * <ownedBehavior xmi:type='uml:OpaqueBehavior' xmi:id='_17_0_6_1707042b_1376433440849_3356_7405' name='create' visibility='public'> * <body>FOO BAR;</body> * <language>SQL</language> * </ownedBehavior> * * @param clss the * @param clssElem the element * @param behaviors the bahaviors */ private void addBehaviors(Class clss, Element clssElem, List<Behavior> behaviors) { for (Behavior behavior : behaviors) { Element ownedBehavior = new Element("ownedBehavior"); clssElem.addContent(ownedBehavior); ownedBehavior.setAttribute(new Attribute("type", "uml:OpaqueBehavior", xmiNs)); ownedBehavior.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); ownedBehavior.setAttribute(new Attribute("visibility", "public")); ownedBehavior.setAttribute(new Attribute("name", behavior.getType().name())); Element language = new Element("language"); language.setText(behavior.getLanguage()); ownedBehavior.addContent(language); Element body = new Element("body"); Text text = new Text(behavior.getValue()); body.addContent(text); ownedBehavior.addContent(body); } }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private void addAlias(Alias alias, String namedElementId) { Element aliasStereotype = new Element(SDOAlias.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(aliasStereotype); aliasStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); aliasStereotype.setAttribute(new Attribute(SDOAlias.BASE__NAMED_ELEMENT, namedElementId)); if (alias.getPhysicalName() != null) aliasStereotype.setAttribute(new Attribute(SDOAlias.PHYSICAL_NAME, alias.getPhysicalName())); if (alias.getLocalName() != null) aliasStereotype.setAttribute(new Attribute(SDOAlias.LOCAL_NAME, alias.getLocalName().trim())); if (alias.getBusinessName() != null) aliasStereotype.setAttribute(new Attribute(SDOAlias.BUSINESS_NAME, alias.getBusinessName().trim())); }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildProperty(Package pkg, Class clss, Property property, Element parentElem) { if (log.isDebugEnabled()) log.debug("creating property " + property.getName()); Element ownedAttribute = new Element("ownedAttribute"); parentElem.addContent(ownedAttribute); ownedAttribute.setAttribute(new Attribute("type", "uml:Property", xmiNs)); ownedAttribute.setAttribute(new Attribute("id", property.getId(), xmiNs)); ownedAttribute.setAttribute(new Attribute("name", property.getName())); if (property.getVisibility() != null) ownedAttribute.setAttribute(new Attribute("visibility", property.getVisibility().value())); if (property.getDocumentations() != null) for (Documentation doc : property.getDocumentations()) { if (doc.getBody() != null) addOwnedComment(ownedAttribute, property.getId(), doc.getBody().getValue()); }//from w w w .j a v a2 s .co m Element upperValue = new Element("upperValue"); ownedAttribute.addContent(upperValue); upperValue.setAttribute(new Attribute("type", "uml:LiteralUnlimitedNatural", xmiNs)); upperValue.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); upperValue.setAttribute(new Attribute("visibility", "public")); if (property.isMany()) upperValue.setAttribute(new Attribute("value", "*")); else upperValue.setAttribute(new Attribute("value", "1")); Element lowerValue = new Element("lowerValue"); ownedAttribute.addContent(lowerValue); lowerValue.setAttribute(new Attribute("type", "uml:LiteralInteger", xmiNs)); lowerValue.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); lowerValue.setAttribute(new Attribute("visibility", "public")); if (property.isNullable()) lowerValue.setAttribute(new Attribute("value", "0")); else lowerValue.setAttribute(new Attribute("value", "1")); if (property.getType() instanceof DataTypeRef) { Element type = new Element("type"); ownedAttribute.addContent(type); type.setAttribute(new Attribute("type", "uml:DataType", xmiNs)); //type.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); type.setAttribute( new Attribute("href", this.dataTypeHRefPrefix + ((DataTypeRef) property.getType()).getName())); } else { // set reference specific attribs ClassRef targetClassRef = (ClassRef) property.getType(); Class targetClass = classMap.get(targetClassRef.getUri() + "#" + targetClassRef.getName()); ownedAttribute.setAttribute(new Attribute("type", targetClass.getId())); } // add stereotypes in order of "priority" in terms of how we // would like them to appear in UML tools if (property.getKey() != null) { Element keyStereotype = new Element(SDOKey.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(keyStereotype); keyStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); keyStereotype.setAttribute(new Attribute(SDOKey.BASE__PROPERTY, property.getId())); keyStereotype.setAttribute(new Attribute(SDOKey.TYPE, // provisioning key-type is JAXB generated and upper-case property.getKey().getType().name().toLowerCase())); } if (property.getUniqueConstraint() != null) { Element uniqueStereotype = new Element(SDOUniqueConstraint.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(uniqueStereotype); uniqueStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); uniqueStereotype.setAttribute(new Attribute(SDOUniqueConstraint.BASE__PROPERTY, property.getId())); uniqueStereotype.setAttribute( new Attribute(SDOUniqueConstraint.GROUP, property.getUniqueConstraint().getGroup())); } if (property.getAlias() != null) { addAlias(property.getAlias(), property.getId()); } if (property.getSort() != null) { Element sequenceStereotype = new Element(SDOSort.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(sequenceStereotype); sequenceStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); sequenceStereotype.setAttribute(new Attribute(SDOSort.BASE__PROPERTY, property.getId())); sequenceStereotype .setAttribute(new Attribute(SDOSort.KEY, String.valueOf(property.getSort().getKey()))); } if (property.getXmlProperty() != null) { Element xmlPropertyStereotype = new Element(SDOXmlProperty.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(xmlPropertyStereotype); xmlPropertyStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); xmlPropertyStereotype.setAttribute(new Attribute(SDOXmlProperty.BASE__PROPERTY, property.getId())); xmlPropertyStereotype.setAttribute(new Attribute(SDOXmlProperty.NODE_TYPE, property.getXmlProperty().getNodeType().name().toLowerCase())); } if (property.getValueConstraint() != null) { Element valueContStereotype = new Element(SDOValueConstraint.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(valueContStereotype); valueContStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); valueContStereotype.setAttribute(new Attribute(SDOValueConstraint.BASE__PROPERTY, property.getId())); ValueConstraint vc = property.getValueConstraint(); if (vc.getTotalDigits() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.TOTAL_DIGITS, String.valueOf(vc.getTotalDigits()))); if (vc.getFractionDigits() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.FRACTION_DIGITS, String.valueOf(vc.getFractionDigits()))); if (vc.getMaxInclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MAX_INCLUSIVE, String.valueOf(vc.getMaxInclusive()))); if (vc.getMaxExclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MAX_EXCLUSIVE, String.valueOf(vc.getMaxExclusive()))); if (vc.getMaxLength() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MAX_LENGTH, String.valueOf(vc.getMaxLength()))); if (vc.getMinInclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MIN_INCLUSIVE, String.valueOf(vc.getMinInclusive()))); if (vc.getMinExclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MIN_EXCLUSIVE, String.valueOf(vc.getMinExclusive()))); if (vc.getMinLength() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MIN_LENGTH, String.valueOf(vc.getMinLength()))); if (vc.getPattern() != null) valueContStereotype .setAttribute(new Attribute(SDOValueConstraint.PATTERN, String.valueOf(vc.getPattern()))); } if (property.getEnumerationConstraint() != null) { Element enumConstraintStereotype = new Element(SDOEnumerationConstraint.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(enumConstraintStereotype); enumConstraintStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); enumConstraintStereotype .setAttribute(new Attribute(SDOUniqueConstraint.BASE__PROPERTY, property.getId())); EnumerationConstraint constraint = property.getEnumerationConstraint(); EnumerationRef enumRef = constraint.getValue(); String enumRefId = enumRef.getUri() + "#" + enumRef.getName(); Element enumeration = this.enumElementMap.get(enumRefId); if (enumeration == null) { enumeration = this.buildEnumeration(constraint); Element pkgElement = this.elementMap.get(pkg.getId()); pkgElement.addContent(enumeration); this.enumElementMap.put(enumRefId, enumeration); } Attribute enumId = enumeration.getAttribute("id", xmiNs); enumConstraintStereotype.setAttribute(new Attribute(SDOEnumerationConstraint.VALUE, enumId.getValue())); } return ownedAttribute; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildAssociation(Property property, Property targetProperty, Element parentElem, String uuid) { Element associationElem = new Element("packagedElement"); parentElem.addContent(associationElem); associationElementMap.put(property.getId(), associationElem); associationElementMap.put(targetProperty.getId(), associationElem); associationElem.setAttribute(new Attribute("type", "uml:Association", xmiNs)); associationElem.setAttribute(new Attribute("id", uuid, xmiNs)); associationElem.setAttribute(new Attribute("visibility", "public")); Element leftMemberEnd = new Element("memberEnd"); associationElem.addContent(leftMemberEnd); leftMemberEnd.setAttribute(new Attribute("idref", property.getId(), xmiNs)); Element rightMemberEnd = new Element("memberEnd"); associationElem.addContent(rightMemberEnd); rightMemberEnd.setAttribute(new Attribute("idref", targetProperty.getId(), xmiNs)); return associationElem; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildAssociation(Property property, Class targetClass, Element parentElem, String uuid) { Element association = new Element("packagedElement"); parentElem.addContent(association);/*from w w w. j a v a2 s.c o m*/ association.setAttribute(new Attribute("type", "uml:Association", xmiNs)); association.setAttribute(new Attribute("id", uuid, xmiNs)); association.setAttribute(new Attribute("visibility", "public")); Element leftMemberEnd = new Element("memberEnd"); association.addContent(leftMemberEnd); leftMemberEnd.setAttribute(new Attribute("idref", property.getId(), xmiNs)); String rightPropId = UUID.randomUUID().toString(); Element rightMemberEnd = new Element("memberEnd"); association.addContent(rightMemberEnd); rightMemberEnd.setAttribute(new Attribute("idref", rightPropId, xmiNs)); Element navigableOwnedEnd = new Element("navigableOwnedEnd"); association.addContent(navigableOwnedEnd); navigableOwnedEnd.setAttribute(new Attribute("idref", rightPropId, xmiNs)); Element ownedEnd = new Element("ownedEnd"); association.addContent(ownedEnd); ownedEnd.setAttribute(new Attribute("type", "uml:Property", xmiNs)); ownedEnd.setAttribute(new Attribute("id", rightPropId, xmiNs)); ownedEnd.setAttribute(new Attribute("visibility", "private")); ownedEnd.setAttribute(new Attribute("type", targetClass.getId())); // if its external we'll need this goo /* { targetClassId = targetClassInfo.getSharedPackage().getExternalReferenceBase() + "#" + targetClassInfo.getUuid(); Element type = new Element("type"); ownedEnd.addContent(type); type.setAttribute(new Attribute("type", "uml:Class", xmiNs)); type.setAttribute(new Attribute("href", targetClassId)); } */ Element upperValue = new Element("upperValue"); ownedEnd.addContent(upperValue); upperValue.setAttribute(new Attribute("type", "uml:LiteralUnlimitedNatural", xmiNs)); upperValue.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); upperValue.setAttribute(new Attribute("visibility", "public")); upperValue.setAttribute(new Attribute("value", "*")); Element lowerValue = new Element("lowerValue"); ownedEnd.addContent(lowerValue); lowerValue.setAttribute(new Attribute("type", "uml:LiteralInteger", xmiNs)); lowerValue.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); lowerValue.setAttribute(new Attribute("visibility", "public")); return association; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildEnumeration(EnumerationConstraint constraint) { Enumeration enm = this.enumMap.get(constraint.getValue().getUri() + "#" + constraint.getValue().getName()); Element enumerationElem = new Element("packagedElement"); enumerationElem.setAttribute(new Attribute("type", "uml:Enumeration", xmiNs)); String enumId = UUID.randomUUID().toString(); enumerationElem.setAttribute(new Attribute("id", enumId, xmiNs)); enumerationElem.setAttribute(new Attribute("name", enm.getName())); enumerationElem.setAttribute(new Attribute("visibility", "public")); if (enm.getDocumentations() != null) for (Documentation doc : enm.getDocumentations()) { addOwnedComment(enumerationElem, enumId, doc.getBody().getValue()); }/*from w ww . j av a2s . c o m*/ for (EnumerationLiteral lit : enm.getEnumerationLiterals()) { Element literal = new Element("ownedLiteral"); enumerationElem.addContent(literal); literal.setAttribute(new Attribute("type", "uml:EnumerationLiteral", xmiNs)); String literalId = UUID.randomUUID().toString(); literal.setAttribute(new Attribute("id", literalId, xmiNs)); literal.setAttribute(new Attribute("name", lit.getValue())); literal.setAttribute(new Attribute("visibility", "public")); if (lit.getDocumentations() != null) for (Documentation doc : lit.getDocumentations()) { addOwnedComment(literal, literalId, doc.getBody().getValue()); } if (lit.getAlias() != null && lit.getAlias().getPhysicalName() != null) { Element aliasStereotype = new Element(SDOAlias.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(aliasStereotype); aliasStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); aliasStereotype.setAttribute(new Attribute(SDOAlias.BASE__NAMED_ELEMENT, literalId)); aliasStereotype .setAttribute(new Attribute(SDOAlias.PHYSICAL_NAME, lit.getAlias().getPhysicalName())); } } return enumerationElem; }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private void addOwnedComment(Element owner, String ownerId, String commentBody) { Element comment = new Element("ownedComment"); owner.addContent(comment);/* w w w . ja v a 2 s . c o m*/ comment.setAttribute(new Attribute("type", "uml:Comment", xmiNs)); comment.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); Element body = new Element("body"); comment.addContent(body); body.addContent(new CDATA(commentBody)); Element annotatedElement = new Element("annotatedElement"); comment.addContent(annotatedElement); annotatedElement.setAttribute(new Attribute("idref", ownerId, xmiNs)); }
From source file:org.rascalmpl.library.lang.xml.DOM.java
License:Open Source License
private Attribute nodeToAttribute(IConstructor n) { IConstructor ns = (IConstructor) n.get(0); IString name = (IString) n.get(1);//from w ww .j ava 2 s .c o m IString data = (IString) n.get(2); return new Attribute(name.getValue(), data.getValue(), namespaceToNamespace(ns)); }