www.sdmetrics.com

sdmetrics.model
Class MetaModel

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--sdmetrics.model.MetaModel
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class MetaModel
extends org.xml.sax.helpers.DefaultHandler

Class to read the SDMetrics UML metamodel from the metamodel definition file, and store the model for retrieval.

The class manages a set of metamodel elements, and provides access to them. Each metamodel element has a name, an ID, and a list of attributes.


Field Summary
static java.lang.String CONTEXT
          The name of the attribute that stores the owner of the model element.
static java.lang.String TL_ELEMENT
          The name of the top level XML element in the metamodel definition file.
 
Constructor Summary
MetaModel()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          SAX parser handler for XML PCDATA in metamodel definition file.
 void endDocument()
          SAX parser handler: at the end of the document, calculate the set of inherited attributes of each metamodel element.
 int getAttributeCount(int id)
          Retrieve the number of attributes for a metamodel element.
 java.lang.String getAttributeDescription(int id, int num)
          Retrieve the description of an attribute for a metamodel element.
 int getAttributeIndex(int id, java.lang.String s)
          Find the index of an attributes for a metamodel element.
 java.lang.String getAttributeName(int id, int num)
          Retrieve the name of an attribute for a metamodel element.
 int getNumberOfTypes()
          Retrieve the number of elements in the metamodel.
 int getTypeId(java.lang.String type)
          Retrieve the ID of a metamodel element from its name.
 java.lang.String getTypeName(int id)
          Retrieve the name of a metamodel element from its ID.
 boolean isRefAttribute(int id, int num)
          Test if an attribute of a metamodel element is a cross-reference attribute.
 boolean isSetAttribute(int id, int num)
          Test if an attribute of a metamodel element is multi-valued.
 void startDocument()
          SAX parser handler: empty the metamodel at the beginning of the XML document.
 void startElement(java.lang.String uri, java.lang.String local, java.lang.String raw, org.xml.sax.Attributes attrs)
          SAX parser handler to read an XML element in the metamodel definition file.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TL_ELEMENT

public static final java.lang.String TL_ELEMENT
The name of the top level XML element in the metamodel definition file.

See Also:
Constant Field Values

CONTEXT

public static final java.lang.String CONTEXT
The name of the attribute that stores the owner of the model element.

See Also:
Constant Field Values
Constructor Detail

MetaModel

public MetaModel()
Method Detail

startDocument

public void startDocument()
SAX parser handler: empty the metamodel at the beginning of the XML document.

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler

startElement

public void startElement(java.lang.String uri,
                         java.lang.String local,
                         java.lang.String raw,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
SAX parser handler to read an XML element in the metamodel definition file. Extracts and stores the metamodel element or attribute information.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
org.xml.sax.SAXException - The XML file contains something other than model element and attribute definitions.

characters

public void characters(char[] ch,
                       int start,
                       int length)
SAX parser handler for XML PCDATA in metamodel definition file. These contain informal brief descriptions for the attributes. Adds the text to the description of the current attribute of the current metamodel element entry.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

endDocument

public void endDocument()
SAX parser handler: at the end of the document, calculate the set of inherited attributes of each metamodel element.

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler

getTypeId

public int getTypeId(java.lang.String type)
Retrieve the ID of a metamodel element from its name.

Parameters:
type - The name of the metamodel element.
Returns:
The ID of the metamodel element, or -1 if type is null or the metamodel element was not found.

getNumberOfTypes

public int getNumberOfTypes()
Retrieve the number of elements in the metamodel.

Returns:
The number of types in this metamodel.

getTypeName

public java.lang.String getTypeName(int id)
Retrieve the name of a metamodel element from its ID.

Parameters:
id - The ID of the metamodel element.
Returns:
The name of the metamodel element.

getAttributeCount

public int getAttributeCount(int id)
Retrieve the number of attributes for a metamodel element.

Parameters:
id - The ID of the metamodel element.
Returns:
The number of attributes of that metamodel element.

getAttributeName

public java.lang.String getAttributeName(int id,
                                         int num)
Retrieve the name of an attribute for a metamodel element.

Parameters:
id - The ID of the metamodel element.
num - The index of the attribute.
Returns:
The name of the indexed attribute.

getAttributeDescription

public java.lang.String getAttributeDescription(int id,
                                                int num)
Retrieve the description of an attribute for a metamodel element.

Parameters:
id - The ID of the metamodel element.
num - The index of the attribute.
Returns:
A string describing the purpose of the indexed attribute.

isRefAttribute

public boolean isRefAttribute(int id,
                              int num)
Test if an attribute of a metamodel element is a cross-reference attribute.

Parameters:
id - The id of the metamodel element.
num - The index of the attribute.
Returns:
true if the attribute is a cross-reference attribute, false if it is a data attribute.

isSetAttribute

public boolean isSetAttribute(int id,
                              int num)
Test if an attribute of a metamodel element is multi-valued.

Parameters:
id - The id of the metamodel element.
num - The index of the attribute.
Returns:
true if the attribute is multi-valued, else false.

getAttributeIndex

public int getAttributeIndex(int id,
                             java.lang.String s)
Find the index of an attributes for a metamodel element.

Parameters:
id - The ID of the metamodel element.
s - The name of the attribute.
Returns:
The index of the attribute, or -1 of the metamodel element has no such attribute.

www.sdmetrics.com