Dresden OCL Toolkit

tudresden.ocl.check.types.xmifacade
Class XmiParser

java.lang.Object
  extended bytudresden.ocl.check.types.xmifacade.XmiParser

public final class XmiParser
extends Object


Field Summary
private  Adapter adapter
           
private  HashMap associations
           
private  HashMap classElements
          Maps model classes to the elements in xmi file.
private  LinkedList generalizations
           
private  HashMap ids
          Maps for all Class elements the XMI.id attribute to a XmiClass instance.
private  Model model
           
private static HashMap models
           
private  LinkedList packagePath
           
private  boolean qualifiersOnTarget
          This variable triggers, whether the qualifiers of an association are expected on the on the target end of the qualified association path, or on its source end.
private  boolean roughMode
          Flag for distinction of work modes.
private  String url
           
 
Constructor Summary
XmiParser(URL url, String description, boolean qualifiersOnTarget)
          The classic constructor.
XmiParser(URL url, String description, boolean qualifiersOnTarget, boolean roughMode)
          A constructor that supports the creations of rough models.
 
Method Summary
 String adapt(String x)
           
static Model createModel(URL url, String description)
           
static Model createModel(URL url, String description, boolean qualifiersOnTarget)
           
static Model createRoughModel(URL url, String description)
           
(package private) static String demandAttribute(Element e, String attrname)
          Returns the attribute of the element with given the name.
(package private) static Element demandChildElement(Element e, String tagname)
          Returns the first direct subelement with the given name.
(package private)  String demandSubElRef(Element element, String subelement)
          Given the element <element><subelement><XMI.reference target="somewhere"></></>, demandSubElRef(element, "subelement") will return "somewhere".
private  void elaborate(ModelClass modelclass)
           
(package private) static Element getChildElement(Element e, String tagname)
          Returns the first direct subelement with the given name.
(package private) static String getContent(Element e)
          Returns the content of the element.
private  Element getFirstChildElement(Element e)
           
static Model getModel(URL url, String description)
          Does caching, so that there is only one instance for each xmi file.
static Model getModel(URL url, String description, boolean qualifiersOnTarget)
           
private  Element getNextSiblingElement(Element e)
           
private  void handlePackage(Element packageElement)
           
private  void handlePackageElement(Element element)
           
static void main(String[] args)
           
private  void parse(URL url, String description, boolean qualifiersOnTarget)
          Note: Core method to create a model from a XMI file.
private  void parseAssociation(Element e, ModelClass associationclass)
           
private  ModelAssociationEnd parseAssociationEnd(Element e)
           
private  ModelAttribute parseAttribute(Element element)
           
private  Any parseClass(Element element, boolean basictype)
           
private  void parseGeneralization(Element element)
           
private  ModelOperation parseOperation(Element element)
           
private  void parsePackage(Element packageElement)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

qualifiersOnTarget

private boolean qualifiersOnTarget
This variable triggers, whether the qualifiers of an association are expected on the on the target end of the qualified association path, or on its source end. This trigger is evaluated in ModelAssociation.dissolve. The author believes, that the default value of false is compliant with the UML spec. However, the value true must be used for Rose 2000 with the Unisys XMI Plugin.

See Also:
ModelAssociation.dissolve(Model)

url

private String url

roughMode

private boolean roughMode
Flag for distinction of work modes.


models

private static HashMap models

model

private Model model

adapter

private Adapter adapter

ids

private HashMap ids
Maps for all Class elements the XMI.id attribute to a XmiClass instance. Maps for all DataType elements XMI.id attribute to a Basic/XmiVoid instance.


generalizations

private LinkedList generalizations

associations

private HashMap associations

packagePath

private LinkedList packagePath

classElements

private HashMap classElements
Maps model classes to the elements in xmi file. Used to cross the gap beetween first and second pass of class parsing.

Constructor Detail

XmiParser

public XmiParser(URL url,
                 String description,
                 boolean qualifiersOnTarget,
                 boolean roughMode)
          throws SAXException,
                 IOException
A constructor that supports the creations of rough models. That is, no flattening of generalization relationships and dissolving of associations will be done. One can determine the quality of the model with the method isRough() in class Model.

Parameters:
url - xmi source file url
description - a description of the model
qualifiersOnTarget - see field description of qualifiersOnTarget
roughMode - true if the model should be created without flattening and dissolving, false otherwise

XmiParser

public XmiParser(URL url,
                 String description,
                 boolean qualifiersOnTarget)
          throws SAXException,
                 IOException
The classic constructor. Calling this constructor creates a model with flattend generalization relationships and dissolved associations.

Parameters:
url - xmi source file url
description - a description of the model
qualifiersOnTarget - see field description of qualifiersOnTarget
Method Detail

createModel

public static Model createModel(URL url,
                                String description)
                         throws SAXException,
                                IOException
Throws:
SAXException
IOException

createModel

public static Model createModel(URL url,
                                String description,
                                boolean qualifiersOnTarget)
                         throws SAXException,
                                IOException
Throws:
SAXException
IOException

getModel

public static Model getModel(URL url,
                             String description)
                      throws SAXException,
                             IOException
Does caching, so that there is only one instance for each xmi file.

Throws:
SAXException
IOException

getModel

public static Model getModel(URL url,
                             String description,
                             boolean qualifiersOnTarget)
                      throws SAXException,
                             IOException
Throws:
SAXException
IOException

adapt

public String adapt(String x)

parseGeneralization

private void parseGeneralization(Element element)

parseAssociationEnd

private ModelAssociationEnd parseAssociationEnd(Element e)

parseAssociation

private void parseAssociation(Element e,
                              ModelClass associationclass)

parse

private void parse(URL url,
                   String description,
                   boolean qualifiersOnTarget)
            throws SAXException,
                   IOException
Note: Core method to create a model from a XMI file. That work was formerly done by the only constructor of XmiParser.

Throws:
SAXException
IOException

handlePackage

private void handlePackage(Element packageElement)

parsePackage

private void parsePackage(Element packageElement)

handlePackageElement

private void handlePackageElement(Element element)

parseClass

private Any parseClass(Element element,
                       boolean basictype)

elaborate

private void elaborate(ModelClass modelclass)

parseAttribute

private ModelAttribute parseAttribute(Element element)

parseOperation

private ModelOperation parseOperation(Element element)

getChildElement

static Element getChildElement(Element e,
                               String tagname)
Returns the first direct subelement with the given name. Returns null if no such subelement exists.


demandChildElement

static Element demandChildElement(Element e,
                                  String tagname)
Returns the first direct subelement with the given name. Throws XmiException if no such subelement exists.

See Also:
XmiException

demandAttribute

static String demandAttribute(Element e,
                              String attrname)
Returns the attribute of the element with given the name. Throws XmiException if no such attribute exists.

See Also:
XmiException

getContent

static String getContent(Element e)
Returns the content of the element. The element should contain untagged text only.

See Also:
XmiException

getFirstChildElement

private Element getFirstChildElement(Element e)

getNextSiblingElement

private Element getNextSiblingElement(Element e)

demandSubElRef

String demandSubElRef(Element element,
                      String subelement)
Given the element <element><subelement><XMI.reference target="somewhere"></></>, demandSubElRef(element, "subelement") will return "somewhere". Vastly needed in XMI. Throws XmiException if subelements or attribute does not exist.

See Also:
XmiException

main

public static void main(String[] args)

createRoughModel

public static Model createRoughModel(URL url,
                                     String description)
                              throws SAXException,
                                     IOException
Parameters:
url - xmi source file url
description - a description of the model
Returns:
a model with unflattened model classes and undissolved associations
Throws:
SAXException
IOException

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.