Documentation
¶
Overview ¶
Package xmi reads UML 2.x models serialized as XMI, as SysML v1 tools export them, into a generic element tree with the stereotypes applied to it.
The reader is deliberately tolerant of the serialization's dialect: the UML, XMI and profile namespaces differ between the OMG normative XMI and the Eclipse UML2 serialization Papyrus writes, so elements are classified by the local part of their xmi:type and stereotype applications by the local part of their element name. A zip archive holding the model, such as a MagicDraw .mdzip project, is opened in place and its model entries read as one document.
The tree carries no UML semantics of its own; internal/core/migrate interprets it as a SysML v1 model.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct {
// ID is the xmi:id, or the href for a proxy of an external element.
ID string
// Type is the local name of the xmi:type, such as "Class" or "Property".
// A proxy carries the type its reference declared, or "".
Type string
// Role is the XML element name that owns this element in its parent, such
// as "packagedElement" or "ownedAttribute"; empty for a root.
Role string
// Name is the element's name attribute; a proxy takes the href fragment
// when it reads as a name.
Name string
// Href is set on a proxy for an element of another document.
Href string
// QualifiedName is the name a tool records beside an href for the element it
// points to (MagicDraw's referentPath); "" when the document gives none.
QualifiedName string
// Attrs holds the XML attributes other than xmi:id and xmi:type, keyed by
// local name; references appear as their raw id text.
Attrs map[string]string
// Text is the element's character content, which stereotype tag values
// and opaque expression bodies are written as.
Text string
Parent *Element
Children []*Element
// Stereotypes are the stereotype applications whose base is this element.
Stereotypes []*Stereotype
// contains filtered or unexported fields
}
Element is one node of the model: a UML element with an xmi:id, or a proxy for an element in another document that an href points at.
func (*Element) HasStereotype ¶
HasStereotype reports whether any of the named stereotypes applies to e.
func (*Element) Path ¶
Path returns the names from the root to e, for diagnostics; anonymous elements contribute their type in angle brackets.
func (*Element) Stereotype ¶
func (e *Element) Stereotype(name string) *Stereotype
Stereotype returns e's application of the named stereotype, or nil.
type Extension ¶
type Extension struct {
// Extender is the tool named by the block's extender attribute.
Extender string
// Owner is the element the block sits in; nil at the document root.
Owner *Element
// Elements are the xmi:type and name of every typed element inside, e.g. "uml:Diagram Vehicle BDD".
Elements []ExtensionElement
}
Extension records one skipped xmi:Extension: who wrote it and what it held.
type ExtensionElement ¶
type ExtensionElement struct {
ID, Type, Name string
}
ExtensionElement is one typed element inside a skipped extension.
type Model ¶
type Model struct {
// Roots are the top-level UML elements, in document order.
Roots []*Element
// Stereotypes are every stereotype application, in document order.
Stereotypes []*Stereotype
// Exporter records the xmi:Documentation exporter, when the document names one.
Exporter string
// Extensions are the tool-private xmi:Extension blocks that were skipped.
Extensions []Extension
// contains filtered or unexported fields
}
Model is one document, or one archive's documents read as one.
func Parse ¶
Parse reads an XMI document, or a zip archive (such as a MagicDraw .mdzip) holding one or more, into a Model.
func (*Model) Lookup ¶
Lookup resolves an xmi:id, or an href of an element another document holds, to its element; nil when the document defines neither.
func (*Model) Refs ¶
Refs returns the elements a role of e refers to: the ids in the attribute of that name (space-separated, as XMI writes multi-valued references) and the child elements of that name carrying xmi:idref or href. Unresolvable ids are dropped (Unresolved lists them); an href yields a proxy element.
type Stereotype ¶
type Stereotype struct {
ID string
// Name is the stereotype's local name, such as "Block" or "Requirement".
Name string
// Namespace is the XML namespace the profile was serialized under.
Namespace string
// BaseID is the value of the base_* attribute; Base resolves it.
BaseID string
Base *Element
// Tags holds the tagged values: attributes other than xmi:* and base_*, and
// child elements as their text or idref, keyed by tag name. A multi-valued
// tag lists each value.
Tags map[string][]string
}
Stereotype is one stereotype application: an element outside the UML model whose base_* attribute names the element it extends.
func (*Stereotype) IDs ¶ added in v0.8.1
func (s *Stereotype) IDs(name string) []string
IDs returns the ids a reference-valued tag lists, one per value when the tool wrote child elements and split on whitespace when it wrote an IDREFS attribute.
func (*Stereotype) Tag ¶
func (s *Stereotype) Tag(name string) string
Tag returns the first value of a tag, or "".