be.ac.vub.cocompose.io.xmi
Class XMIModelReader

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bybe.ac.vub.cocompose.io.xmi.XMIModelReader
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, ModelReader

public class XMIModelReader
extends DefaultHandler
implements ModelReader

Reads a CoCompose model from an XMI file (requires second pass by XMIModelLinkReader).

Since:
0.2.0
Version:
0.2.10, 10/05/2004
Author:
Dennis Wagelaar

Constructor Summary
XMIModelReader()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
          Characters.
 void endCoComposeElement(String local)
          Start CoCompose element.
 void endElement(String uri, String local, String raw)
          End element.
 void endOwnedElement()
          Finalises an ownedElement tag
 void endXMIElement(String local)
          End XMI element.
 ModelElement getElement()
          Gets the last parsed element.
 Map getElementMap()
          Gets the mapping of ids to elements.
 XMIElementAttributesReader getElementReader()
          Gets the element attributes reader.
 XMIModelLinkReader getLinkReader()
          Gets the element link reader for non-containment references.
 Model getModel()
          Gets the model that is read.
 Namespace getNamespace()
          Gets the last parsed namespace.
 Relationship getRelationship()
          Gets the last parsed relationship.
 XMIElementTypeSwitch getTypeSwitch()
          Gets the type switch for creating the right element.
 XMLReader getXmlParser()
          Gets the XML parser.
 void ignorableWhitespace(char[] ch, int start, int length)
          Ignorable whitespace.
 void notationDecl(String name, String publicId, String systemId)
          DTD declaration.
protected  void preRead(ModelFactory factory, String uri)
          Prepares for read().
 void processingInstruction(String target, String data)
          Processing instruction.
 Model read(InputStream input, String uri, ModelFactory factory)
          Reads the model from its uri.
 Model read(String uri, ModelFactory factory)
          Reads the model from its uri.
protected  void setElement(ModelElement element)
          Sets the last parsed element.
protected  void setElementMap(Map elementMap)
          Sets the mapping of ids to elements.
protected  void setElementReader(XMIElementAttributesReader elementReader)
          Sets the element attributes reader.
protected  void setLinkReader(XMIModelLinkReader linkReader)
          Sets the element link reader for non-containment references.
protected  void setModel(Model model)
          Sets the model that is read.
protected  void setNamespace(Namespace namespace)
          Sets the last parsed namespace.
protected  void setRelationship(Relationship relationship)
          Sets the last parsed relationship.
protected  void setTypeSwitch(XMIElementTypeSwitch typeSwitch)
          Sets the type switch for creating the right element.
protected  void setXmlParser(XMLReader xmlParser)
          Sets the XML parser.
 void startCoComposeElement(String local, Attributes attrs)
          Start CoCompose element.
 void startColor(Attributes attrs)
          Parses a color tag
 void startDocument()
          Start document.
 void startElement(String uri, String local, String raw, Attributes attrs)
          Start element.
 void startMultiplicity(Attributes attrs)
          Parses a multiplicity tag
 void startOwnedElement(Attributes attrs)
          Parses an ownedElement tag
 void startPosition(Attributes attrs)
          Parses a position tag
 void startXMIElement(String local, Attributes attrs)
          Start XMI element.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMIModelReader

public XMIModelReader()
Method Detail

read

public Model read(String uri,
                  ModelFactory factory)
           throws IOException,
                  ModelElementException
Reads the model from its uri.

Specified by:
read in interface ModelReader
Parameters:
uri - the uri to read from.
factory - the model factory used to create the elements.
Returns:
the model
Throws:
IOException - if the model could not be read.
ModelElementException - if a model element could not be read.

read

public Model read(InputStream input,
                  String uri,
                  ModelFactory factory)
           throws IOException,
                  ModelElementException
Reads the model from its uri.

Specified by:
read in interface ModelReader
Parameters:
input - the stream to read from.
uri - the uri of the model.
factory - the model factory used to create the elements.
Returns:
the model
Throws:
IOException - if the model could not be read.
ModelElementException - if a model element could not be read.

preRead

protected void preRead(ModelFactory factory,
                       String uri)
                throws Exception
Prepares for read().

Parameters:
factory - the factory to create the model and the elements.
uri - the uri of the model.
Throws:
Exception - if pre-read setup failed.

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Processing instruction.

Specified by:
processingInstruction in interface ContentHandler
Parameters:
target - Processing instruction element name.
data - Processing instruction element data.
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Start document.

Specified by:
startDocument in interface ContentHandler
Throws:
SAXException

startElement

public void startElement(String uri,
                         String local,
                         String raw,
                         Attributes attrs)
                  throws SAXException
Start element.

Specified by:
startElement in interface ContentHandler
Parameters:
uri - XML namespace URI.
local - local element name.
raw - raw (qualified) element name.
attrs - element attributes.
Throws:
SAXException

startXMIElement

public void startXMIElement(String local,
                            Attributes attrs)
                     throws SAXException
Start XMI element.

Parameters:
local - local element name.
attrs - element attributes.
Throws:
SAXException

startCoComposeElement

public void startCoComposeElement(String local,
                                  Attributes attrs)
                           throws SAXException
Start CoCompose element.

Parameters:
local - local element name.
attrs - element attributes.
Throws:
SAXException

startOwnedElement

public void startOwnedElement(Attributes attrs)
                       throws ModelElementException
Parses an ownedElement tag

Parameters:
attrs - element attributes
Throws:
ModelElementException

startMultiplicity

public void startMultiplicity(Attributes attrs)
                       throws ModelElementException
Parses a multiplicity tag

Parameters:
attrs - element attributes
Throws:
ModelElementException

endOwnedElement

public void endOwnedElement()
                     throws ModelElementException
Finalises an ownedElement tag

Throws:
ModelElementException

startPosition

public void startPosition(Attributes attrs)
                   throws ModelElementException
Parses a position tag

Parameters:
attrs - element attributes
Throws:
ModelElementException

startColor

public void startColor(Attributes attrs)
                throws ModelElementException
Parses a color tag

Parameters:
attrs - element attributes
Throws:
ModelElementException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Characters.

Specified by:
characters in interface ContentHandler
Parameters:
ch - Characters to print.
start - Starting index of characters.
length - Length of characters.
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Ignorable whitespace.

Specified by:
ignorableWhitespace in interface ContentHandler
Parameters:
ch - Characters to print.
start - Starting index of characters.
length - Length of characters.
Throws:
SAXException

endElement

public void endElement(String uri,
                       String local,
                       String raw)
                throws SAXException
End element.

Specified by:
endElement in interface ContentHandler
Parameters:
uri - Ignored.
local - Ignored.
raw - Element name.
Throws:
SAXException

endXMIElement

public void endXMIElement(String local)
                   throws SAXException
End XMI element.

Parameters:
local - local element name.
Throws:
SAXException

endCoComposeElement

public void endCoComposeElement(String local)
                         throws SAXException
Start CoCompose element.

Parameters:
local - local element name.
Throws:
SAXException

notationDecl

public void notationDecl(String name,
                         String publicId,
                         String systemId)
                  throws SAXException
DTD declaration.

Specified by:
notationDecl in interface DTDHandler
Parameters:
name - DTD name.
publicId - DTD public ID.
systemId - DTD system ID.
Throws:
SAXException

setElement

protected void setElement(ModelElement element)
Sets the last parsed element.

Parameters:
element - the last parsed element.

getElement

public ModelElement getElement()
Gets the last parsed element.

Returns:
the last parsed element.

setElementMap

protected void setElementMap(Map elementMap)
Sets the mapping of ids to elements.

Parameters:
elementMap - the mapping of ids to elements.

getElementMap

public Map getElementMap()
Gets the mapping of ids to elements.

Returns:
the mapping of ids to elements.

setElementReader

protected void setElementReader(XMIElementAttributesReader elementReader)
Sets the element attributes reader.

Parameters:
elementReader - the element attributes reader.

getElementReader

public XMIElementAttributesReader getElementReader()
Gets the element attributes reader.

Returns:
the element attributes reader.

setLinkReader

protected void setLinkReader(XMIModelLinkReader linkReader)
Sets the element link reader for non-containment references.

Parameters:
linkReader - the element link reader for non-containment references.

getLinkReader

public XMIModelLinkReader getLinkReader()
Gets the element link reader for non-containment references.

Returns:
the element link reader for non-containment references.

setModel

protected void setModel(Model model)
Sets the model that is read.

Parameters:
model - the model that is read.

getModel

public Model getModel()
Gets the model that is read.

Returns:
the model that is read.

setNamespace

protected void setNamespace(Namespace namespace)
Sets the last parsed namespace.

Parameters:
namespace - the last parsed namespace.

getNamespace

public Namespace getNamespace()
Gets the last parsed namespace.

Returns:
the last parsed namespace.

setRelationship

protected void setRelationship(Relationship relationship)
Sets the last parsed relationship.

Parameters:
relationship - the last parsed relationship.

getRelationship

public Relationship getRelationship()
Gets the last parsed relationship.

Returns:
the last parsed relationship.

setTypeSwitch

protected void setTypeSwitch(XMIElementTypeSwitch typeSwitch)
Sets the type switch for creating the right element.

Parameters:
typeSwitch - the type switch for creating the right element.

getTypeSwitch

public XMIElementTypeSwitch getTypeSwitch()
Gets the type switch for creating the right element.

Returns:
the type switch for creating the right element.

setXmlParser

protected void setXmlParser(XMLReader xmlParser)
Sets the XML parser.

Parameters:
xmlParser - the XML parser.

getXmlParser

public XMLReader getXmlParser()
Gets the XML parser.

Returns:
the XML parser.