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.7, 13/04/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()
           
 Hashtable getElementMap()
           
 XMIElementAttributesReader getElementReader()
           
 XMIModelLinkReader getLinkReader()
           
 Model getModel()
           
 Namespace getNamespace()
           
 Relationship getRelationship()
           
 XMIElementTypeSwitch getTypeSwitch()
           
 XMLReader getXmlParser()
           
 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)
          Prepares for read().
 void processingInstruction(String target, String data)
          Processing instruction.
 Model read(InputStream input, 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)
           
protected  void setElementMap(Hashtable elementMap)
           
protected  void setElementReader(XMIElementAttributesReader elementReader)
           
protected  void setLinkReader(XMIModelLinkReader linkReader)
           
protected  void setModel(Model model)
           
protected  void setNamespace(Namespace namespace)
           
protected  void setRelationship(Relationship relationship)
           
protected  void setTypeSwitch(XMIElementTypeSwitch typeSwitch)
           
protected  void setXmlParser(XMLReader xmlParser)
           
 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 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,
                  ModelFactory factory)
           throws IOException,
                  ModelElementException
Reads the model from its uri.

Specified by:
read in interface ModelReader
Parameters:
input - - the stream 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.

preRead

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

Parameters:
factory - - the factory to create the model and the elements.
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

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)

getElement

public ModelElement getElement()

setElementMap

protected void setElementMap(Hashtable elementMap)

getElementMap

public Hashtable getElementMap()

setElementReader

protected void setElementReader(XMIElementAttributesReader elementReader)

getElementReader

public XMIElementAttributesReader getElementReader()

setLinkReader

protected void setLinkReader(XMIModelLinkReader linkReader)

getLinkReader

public XMIModelLinkReader getLinkReader()

setModel

protected void setModel(Model model)

getModel

public Model getModel()

setNamespace

protected void setNamespace(Namespace namespace)

getNamespace

public Namespace getNamespace()

setRelationship

protected void setRelationship(Relationship relationship)

getRelationship

public Relationship getRelationship()

setTypeSwitch

protected void setTypeSwitch(XMIElementTypeSwitch typeSwitch)

getTypeSwitch

public XMIElementTypeSwitch getTypeSwitch()

setXmlParser

protected void setXmlParser(XMLReader xmlParser)

getXmlParser

public XMLReader getXmlParser()