|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microstar.xml.HandlerBase
ptolemy.moml.MoMLParser
public class MoMLParser
This class constructs Ptolemy II models from specifications in MoML (modeling markup language), which is based on XML. The class contains an instance of the Microstar Ælfred XML parser and implements callback methods to interpret the parsed XML. The way to use this class is to call its parse() method. The returned value is top-level composite entity of the model.
For convenience, there are several forms of the parse method. Most of these take two arguments, a base, and some specification of the MoML to parse (a stream or the text itself). The base is used to interpret relative URLs that might be present in the MoML. For example, the base might be the document base of an applet. An applet might use this class as follows:
MoMLParser parser = new MoMLParser(); URL docBase = getDocumentBase(); URL xmlFile = new URL(docBase, modelURL); NamedObj toplevel = parser.parse(docBase, xmlFile);If the first argument to parse() is null, then it is assumed that all URLs in the MoML file are absolute.
It can be difficult to create an appropriate URL to give as a base, particularly if what you have is a file or file name in the directory that you want to use as a base. The easiest technique is to use the toURL() method of the File class. Some of the URL constructors, for reasons we don't understand, create URLs that do not work.
The MoML code given to a parse() method may be a fragment, and does not need to include the "<?xml ... >" element nor the DOCTYPE specification. However, if the DOCTYPE specification is not given, then the DTD will not be read. The main consequence of this, given the parser we are using, is that default values for attributes will not be set. This could cause errors. The parser itself is not a validating parser, however, so it makes very limited use of the DTD. This may change in the future, so it is best to give the DOCTYPE element.
The parse() methods can be used for incremental parsing. After creating an initial model using a call to parse(), further MoML fragments without top-level entity or derived objects can be evaluated to modify the model. You can specify the context in which the MoML to be interpreted by calling setContext(). However, the XML parser limits each fragment to one element. So there always has to be one top-level element. If you wish to evaluate a group of MoML elements in some context, set the context and then place your MoML elements within a group element, as follows:
<group> ... sequence of MoML elements ... </group>The group element is ignored, and just serves to aggregate the MoML elements, unless it has a name attribute. If it has a name attribute, then the name becomes a prefix (separated by a colon) of all the names of items immediately in the group element. If the value of the name attribute is "auto", then the group is treated specially. Each item immediately contained by the group (i.e. not deeply contained) will be created with its specified name or a modified version of that name that does not match a pre-existing object already contained by the container. That is, when name="auto" is specified, each item is forced to be created with unique name, rather than possibly matching a pre-existing item.
The parse methods throw a variety of exceptions if the parsed data does not represent a valid MoML file or if the stream cannot be read for some reason.
This parser supports the way Ptolemy II handles hierarchical models, where components are instances cloned from reference models called "classes." A model (a composite entity) is a "class" in Ptolemy II if the elementName field of its MoMLInfo object is the string "class". If a component is cloned from a class, then when that component exports MoML, it references the class from which it was cloned and exports only differences from that class. I.e., if further changes are made to the component, it is important that when the component exports MoML, that those changes are represented in the exported MoML. This effectively implements an inheritance mechanism, where a component inherits all the features of the master from which it is cloned, but then extends the model with its own changes.
This class always processes MoML commands in the following order within a "class" or "entity" element, irrespective of the order in which they appear:
This class works closely with MoMLChangeRequest to implement another feature of Ptolemy II hierarchy. In particular, if an entity is cloned from another that identifies itself as a "class", then any changes that are made to the class via a MoMLChangeRequest are also made to the clone. This parser ensures that those changes are not exported when MoML is exported by the clone, because they will be exported when the master exports MoML.
MoMLChangeRequest
Red (johnr) |
Red (eal) |
Nested Class Summary | |
---|---|
private class |
MoMLParser.DeleteRequest
|
private class |
MoMLParser.LinkRequest
|
private class |
MoMLParser.UnlinkRequest
|
Field Summary | |
---|---|
private static java.util.Set |
_approvedRemoteXmlFiles
|
private java.util.List |
_attributeNameList
|
private java.util.Map |
_attributes
|
private static java.lang.String |
_AUTO_NAMESPACE
|
private java.net.URL |
_base
|
private java.lang.ClassLoader |
_classLoader
|
private int |
_configureNesting
|
private java.lang.String |
_configureSource
|
private java.util.Stack |
_containers
|
private NamedObj |
_current
|
private java.lang.StringBuffer |
_currentCharData
|
private java.lang.String |
_currentDocName
|
private static java.lang.String |
_DEFAULT_NAMESPACE
|
private static int |
_DELETE_ENTITY
|
private static int |
_DELETE_PORT
|
private static int |
_DELETE_PROPERTY
|
private static int |
_DELETE_RELATION
|
private java.util.List |
_deleteRequests
|
private java.util.Stack |
_deleteRequestStack
|
private int |
_docNesting
|
private java.util.Stack |
_externalEntities
|
private static java.util.List |
_filterList
|
private static ErrorHandler |
_handler
|
private static IconLoader |
_iconLoader
IconLoader used to load icons. |
private java.util.Stack |
_ifElementStack
|
private static java.util.Map |
_imports
|
private java.util.List |
_linkRequests
|
private java.util.Stack |
_linkRequestStack
|
private static boolean |
_modified
|
private java.lang.String |
_namespace
|
private java.util.Stack |
_namespaces
|
private boolean |
_namespacesPushed
|
private java.util.Stack |
_namespaceTranslations
|
private java.util.Map |
_namespaceTranslationTable
|
private NamedObj |
_originalContext
|
private java.util.Set |
_paramsToParse
|
private boolean |
_previousDeferStatus
|
private int |
_skipElement
|
private boolean |
_skipElementIsNew
|
private java.lang.String |
_skipElementName
|
private boolean |
_skipRendition
|
private NamedObj |
_toplevel
|
private java.util.List |
_topObjectsCreated
|
private UndoContext |
_undoContext
|
private java.util.Stack |
_undoContexts
|
private static boolean |
_undoDebug
|
private boolean |
_undoEnabled
|
private java.util.List<UndoAction> |
_undoForOverrides
|
private java.util.List |
_unrecognized
|
private Workspace |
_workspace
|
private java.net.URL |
_xmlFile
The XML file being read, if any. |
private java.lang.String |
_xmlFileName
The name of the XMLFile, which we cache for performance reasons. |
private XmlParser |
_xmlParser
The XmlParser. |
static java.util.List |
inputFileNamesToSkip
List of Strings that name files to be skipped. |
static java.lang.String |
MoML_DTD_1
The standard MoML DTD, represented as a string. |
static java.lang.String |
MoML_PUBLIC_ID_1
The public ID for version 1 MoML. |
Constructor Summary | |
---|---|
MoMLParser()
Construct a parser that creates a new workspace into which to put the entities created by the parse() method. |
|
MoMLParser(Workspace workspace)
Construct a parser that creates entities in the specified workspace. |
|
MoMLParser(Workspace workspace,
java.lang.ClassLoader loader)
Construct a parser that creates entities in the specified workspace. |
Method Summary | |
---|---|
private void |
_addParamsToParamsToParse(NamedObj object)
Add all (deeply) contained instances of Settable to the _paramsToParse list, which will ensure that they get validated. |
private ComponentEntity |
_attemptToFindMoMLClass(java.lang.String className,
java.lang.String source)
Attempt to find a MoML class from an external file. |
private void |
_checkClass(java.lang.Object object,
java.lang.Class correctClass,
java.lang.String msg)
|
private void |
_checkForNull(java.lang.Object object,
java.lang.String message)
|
private NamedObj |
_createEntity(java.lang.String className,
java.lang.String entityName,
java.lang.String source,
boolean isClass)
Create a new entity from the specified class name, give it the specified entity name, and specify that its container is the current container object. |
private NamedObj |
_createInstance(java.lang.Class newClass,
java.lang.Object[] arguments)
Create an instance of the specified class name by finding a constructor that matches the specified arguments. |
protected java.lang.String |
_currentExternalEntity()
Get the the URI for the current external entity. |
private NamedObj |
_deleteEntity(java.lang.String entityName)
Delete the entity after verifying that it is contained (deeply) by the current environment. |
private Port |
_deletePort(java.lang.String portName,
java.lang.String entityName)
Delete the port after verifying that it is contained (deeply) by the current environment. |
private Attribute |
_deleteProperty(java.lang.String attributeName)
Delete an attribute after verifying that it is contained (deeply) by the current environment. |
private Relation |
_deleteRelation(java.lang.String relationName)
Delete the relation after verifying that it is contained (deeply) by the current environment. |
private NamedObj |
_findOrParse(MoMLParser parser,
java.net.URL base,
java.lang.String file,
java.lang.String className,
java.lang.String source)
Use the specified parser to parse the file or URL, which contains MoML, using the specified base to find the URL. |
private int |
_getColumnNumber()
Return the column number from the XmlParser. |
private java.lang.String |
_getCurrentElement(java.lang.String elementName)
|
private int |
_getLineNumber()
Return the line number from the XmlParser. |
private ComponentPort |
_getPort(java.lang.String portspec,
CompositeEntity context)
Return the port corresponding to the specified port name in the specified composite entity. |
private java.lang.String |
_getUndoForDeleteAttribute(Attribute toDelete)
Return the MoML commands to undo deleting the specified attribute from the current context. |
private java.lang.String |
_getUndoForDeleteEntity(ComponentEntity toDelete)
Return the MoML commands to undo deleting the specified entity from the current context. |
private java.lang.String |
_getUndoForDeletePort(Port toDelete)
Return the MoML commands to undo deleting the specified port from the current context. |
private java.lang.String |
_getUndoForDeleteRelation(ComponentRelation toDelete)
Return the MoML commands to undo deleting the specified relation from the current context. |
private void |
_handlePropertyElement(java.lang.String className,
java.lang.String propertyName,
java.lang.String value)
Create a property and/or set its value. |
private boolean |
_isLinkInClass(NamedObj context,
Port port,
Relation relation)
Return true if the link between the specified port and relation is part of the class definition. |
private boolean |
_isLinkInClass(NamedObj context,
Relation relation1,
Relation relation2)
Return true if the link between the specified relations is part of the class definition. |
private boolean |
_isUndoableElement(java.lang.String elementName)
Return whether or not the given element name is undoable. |
private boolean |
_loadFileInContext(java.lang.String fileName,
NamedObj context)
If the file with the specified name exists, parse it in the context of the specified instance. |
private boolean |
_loadIconForClass(java.lang.String className,
NamedObj context)
Look for a MoML file associated with the specified class name, and if it exists, parse it in the context of the specified instance. |
private void |
_markContentsDerived(NamedObj object,
int depth)
Mark the contents as being derived objects at a depth one greater than the depth argument, and then recursively mark their contents derived. |
private void |
_markParametersToParse(NamedObj object)
Mark deeply contained parameters as needing validation. |
private NamedObj |
_parse(MoMLParser parser,
java.net.URL base,
java.lang.String source)
Use the specified parser to parse the file or URL, which contains MoML, using the specified base to find the URL. |
private void |
_processLink(java.lang.String relation1Name,
java.lang.String relation2Name)
Process a link command between two relations. |
private void |
_processLink(java.lang.String portName,
java.lang.String relationName,
java.lang.String insertAtSpec,
java.lang.String insertInsideAtSpec)
Process a link command between a port and a relation. |
private void |
_processPendingRequests()
Process pending link and delete requests, if any. |
private void |
_processUnlink(java.lang.String relation1Name,
java.lang.String relation2Name)
Process an unlink request between two relations. |
private void |
_processUnlink(java.lang.String portName,
java.lang.String relationName,
java.lang.String indexSpec,
java.lang.String insideIndexSpec)
Process an unlink request between a port and relation. |
private void |
_pushContext()
Push the current context. |
private void |
_resetUndo()
Reset the undo information to give a fresh setup for the next incremental change. |
private Attribute |
_searchForAttribute(java.lang.String name)
Given a name that is either absolute (with a leading period) or relative to _current, find an attribute with that name. |
private ComponentEntity |
_searchForClassInContext(java.lang.String name,
java.lang.String source)
Search for a class definition in the current context or anywhere above it in the hierarchy. |
private ComponentEntity |
_searchForEntity(java.lang.String name,
NamedObj context)
Given a name that is either absolute (with a leading period) or relative to the specified context, find a component entity with that name. |
private Port |
_searchForPort(java.lang.String name)
Given a name that is either absolute (with a leading period) or relative to _current, find a port with that name. |
private ComponentRelation |
_searchForRelation(java.lang.String name)
Given a name that is either absolute (with a leading period) or relative to _current, find a relation with that name. |
private void |
_setXmlFile(java.net.URL xmlFile)
Store the value of the file being read. |
static void |
addMoMLFilter(MoMLFilter filter)
Add a MoMLFilter to the end of the list of MoMLFilters used to translate names. |
static void |
addMoMLFilters(java.util.List filterList)
Add a List of MoMLFilters to the end of the list of MoMLFilters used to translate names. |
void |
attribute(java.lang.String name,
java.lang.String value,
boolean specified)
Handle an attribute assignment that is part of an XML element. |
void |
changeExecuted(ChangeRequest change)
React to a change request has been successfully executed. |
void |
changeFailed(ChangeRequest change,
java.lang.Exception exception)
React to a change request has resulted in an exception. |
void |
charData(char[] chars,
int offset,
int length)
Handle character data. |
void |
clearTopObjectsList()
Clear the top objects list. |
void |
doctypeDecl(java.lang.String name,
java.lang.String publicID,
java.lang.String systemID)
If a public ID is given, and is not that of MoML, then throw a CancelException, which causes the parse to abort and return null. |
void |
endDocument()
End the document. |
void |
endElement(java.lang.String elementName)
End an element. |
void |
endExternalEntity(java.lang.String systemID)
Handle the end of an external entity. |
void |
error(java.lang.String message,
java.lang.String systemID,
int line,
int column)
Indicate a fatal XML parsing error. |
java.net.URL |
fileNameToURL(java.lang.String source,
java.net.URL base)
Given a file name or URL description, find a URL on which openStream() will work. |
static ErrorHandler |
getErrorHandler()
Get the error handler to handle parsing errors. |
static IconLoader |
getIconLoader()
Get the icon loader for all MoMLParsers. |
static java.util.List |
getMoMLFilters()
Get the List of MoMLFilters used to translate names. |
NamedObj |
getToplevel()
Get the top-level entity associated with this parser, or null if none. |
static boolean |
isModified()
Return the value set by setModified(), or false if setModified() has yet not been called. |
NamedObj |
parse(java.lang.String text)
Parse the given string, which contains MoML. |
NamedObj |
parse(java.net.URL base,
java.io.InputStream input)
Deprecated. Use parse(URL base, String systemID, InputStream input)
for better error messages that include the name of the file being
read. |
NamedObj |
parse(java.net.URL base,
java.io.Reader reader)
Deprecated. Use parse(URL base, String systemID, Reader reader)
for better error messages that include the name of the file being
read. |
NamedObj |
parse(java.net.URL base,
java.lang.String text)
Parse the given string, which contains MoML, using the specified base to evaluate relative references. |
NamedObj |
parse(java.net.URL base,
java.lang.String systemID,
java.io.InputStream input)
Parse the given stream, using the specified url as the base to expand any external references within the MoML file. |
NamedObj |
parse(java.net.URL base,
java.lang.String systemID,
java.io.Reader reader)
Parse the given stream, using the specified url as the base The reader is wrapped in a BufferedReader before being used. |
NamedObj |
parse(java.net.URL base,
java.net.URL input)
Parse the MoML file at the given URL, which may be a file on the local file system, using the specified base to expand any relative references within the MoML file. |
NamedObj |
parseFile(java.lang.String filename)
Parse the file with the given name, which contains MoML. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Handle a processing instruction. |
static void |
purgeAllModelRecords()
Purge all records of models opened. |
static void |
purgeModelRecord(java.lang.String filename)
Purge any record of a model opened from the specified file name. |
static void |
purgeModelRecord(java.net.URL url)
Purge any record of a model opened from the specified URL. |
void |
reset()
Reset the MoML parser. |
void |
resetAll()
Reset the MoML parser, forgetting about any previously parsed models. |
java.lang.Object |
resolveEntity(java.lang.String publicID,
java.lang.String systemID)
Resolve an external entity. |
ComponentEntity |
searchForClass(java.lang.String name,
java.lang.String source)
Given the name of a MoML class and a source URL, check to see whether this class has already been instantiated, and if so, return the previous instance. |
void |
setContext(NamedObj context)
Set the context for parsing. |
static void |
setErrorHandler(ErrorHandler handler)
Set the error handler to handle parsing errors. |
static void |
setIconLoader(IconLoader loader)
Set the icon loader for all MoMLParsers. |
static void |
setModified(boolean modified)
Record whether the parsing of the moml modified the data. |
static void |
setMoMLFilters(java.util.List filterList)
Set the list of MoMLFilters used to translate names. |
void |
setToplevel(NamedObj toplevel)
Set the top-level entity. |
void |
setUndoable(boolean undoable)
Set the current context as undoable. |
void |
startDocument()
Start a document. |
void |
startElement(java.lang.String elementName)
Start an element. |
void |
startExternalEntity(java.lang.String systemID)
Handle the start of an external entity. |
java.util.List |
topObjectsCreated()
Get the top objects list. |
Methods inherited from class com.microstar.xml.HandlerBase |
---|
ignorableWhitespace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String MoML_DTD_1
public static java.lang.String MoML_PUBLIC_ID_1
public static java.util.List inputFileNamesToSkip
private static java.util.Set _approvedRemoteXmlFiles
private java.util.Map _attributes
private java.util.List _attributeNameList
private static java.lang.String _AUTO_NAMESPACE
private java.net.URL _base
private java.lang.ClassLoader _classLoader
private int _configureNesting
private java.lang.String _configureSource
private java.util.Stack _containers
private NamedObj _current
private java.lang.StringBuffer _currentCharData
private java.lang.String _currentDocName
private static java.lang.String _DEFAULT_NAMESPACE
private static int _DELETE_ENTITY
private static int _DELETE_PORT
private static int _DELETE_PROPERTY
private static int _DELETE_RELATION
private java.util.List _deleteRequests
private java.util.Stack _deleteRequestStack
private int _docNesting
private java.util.Stack _externalEntities
private static ErrorHandler _handler
private static java.util.List _filterList
private static IconLoader _iconLoader
private static java.util.Map _imports
private java.util.List _linkRequests
private java.util.Stack _linkRequestStack
private static boolean _modified
private java.lang.String _namespace
private java.util.Stack _namespaces
private boolean _namespacesPushed
private java.util.Map _namespaceTranslationTable
private java.util.Stack _namespaceTranslations
private NamedObj _originalContext
private java.util.Set _paramsToParse
private XmlParser _xmlParser
private boolean _previousDeferStatus
private java.util.Stack _ifElementStack
private int _skipElement
private boolean _skipElementIsNew
private java.lang.String _skipElementName
private boolean _skipRendition
private NamedObj _toplevel
private java.util.List _topObjectsCreated
private java.util.Stack _undoContexts
private UndoContext _undoContext
private static boolean _undoDebug
private boolean _undoEnabled
private java.util.List<UndoAction> _undoForOverrides
private java.util.List _unrecognized
private Workspace _workspace
private java.net.URL _xmlFile
private java.lang.String _xmlFileName
Constructor Detail |
---|
public MoMLParser()
public MoMLParser(Workspace workspace)
workspace
- The workspace into which to place entities.public MoMLParser(Workspace workspace, java.lang.ClassLoader loader)
workspace
- The workspace into which to place entities.loader
- The class loader that will be used to create classes,
or null if the the bootstrap class loader is to be used.Method Detail |
---|
public static void addMoMLFilter(MoMLFilter filter)
filter
- The MoMLFilter to add to the list of MoMLFilters.addMoMLFilters(List filterList)
,
getMoMLFilters()
,
setMoMLFilters(List filterList)
public static void addMoMLFilters(java.util.List filterList)
filterList
- The list of MoMLFilters to add to the
list of MoMLFilters to be used to translate names.addMoMLFilter(MoMLFilter filter)
,
getMoMLFilters()
,
setMoMLFilters(List filterList)
public void attribute(java.lang.String name, java.lang.String value, boolean specified) throws XmlException
attribute
in interface XmlHandler
attribute
in class HandlerBase
name
- The name of the attribute.value
- The value of the attribute, or null if the attribute
is #IMPLIED
and not specified.specified
- True if the value is specified, false if the
value comes from the default value in the DTD rather than from
the XML file.
XmlException
- If the name or value is null.XmlHandler.attribute(java.lang.String, java.lang.String, boolean)
public void changeExecuted(ChangeRequest change)
changeExecuted
in interface ChangeListener
change
- The change that has been executed, or null if
the change was not done via a ChangeRequest.public void changeFailed(ChangeRequest change, java.lang.Exception exception)
changeFailed
in interface ChangeListener
change
- The change that was attempted or null if
the change was not done via a ChangeRequest.exception
- The exception that resulted.public void charData(char[] chars, int offset, int length)
charData
in interface XmlHandler
charData
in class HandlerBase
chars
- The character data.offset
- The starting position in the array.length
- The number of characters available.XmlHandler.charData(char[], int, int)
public void clearTopObjectsList()
topObjectsCreated()
public void doctypeDecl(java.lang.String name, java.lang.String publicID, java.lang.String systemID) throws CancelException
doctypeDecl
in interface XmlHandler
doctypeDecl
in class HandlerBase
name
- The name of the document type.publicID
- The public ID of the document type.systemID
- The system ID of the document type.
CancelException
- If the public ID is not that of MoML.XmlHandler.doctypeDecl(java.lang.String, java.lang.String, java.lang.String)
public void endDocument() throws java.lang.Exception
endDocument
in interface XmlHandler
endDocument
in class HandlerBase
CancelException
- If an error occurs parsing one of the
parameter values, and the user clicks on "cancel" to cancel the
parse.
java.lang.Exception
- The handler may throw any exception.XmlHandler.endDocument()
public void endElement(java.lang.String elementName) throws java.lang.Exception
endElement
in interface XmlHandler
endElement
in class HandlerBase
elementName
- The element type name.
java.lang.Exception
- If thrown while adding properties.XmlHandler.endElement(java.lang.String)
public void endExternalEntity(java.lang.String systemID)
endExternalEntity
in interface XmlHandler
endExternalEntity
in class HandlerBase
systemID
- The URI for the external entity.XmlHandler.endExternalEntity(java.lang.String)
public void error(java.lang.String message, java.lang.String systemID, int line, int column) throws XmlException
error
in interface XmlHandler
error
in class HandlerBase
message
- The error message.systemID
- The URI of the entity that caused the error.line
- The approximate line number of the error.column
- The approximate column number of the error.
XmlException
- If called.XmlHandler.error(java.lang.String, java.lang.String, int, int)
public java.net.URL fileNameToURL(java.lang.String source, java.net.URL base) throws java.lang.Exception
NOTE: This may trigger a dialog with the user (about security concerns), and hence should be called in the event thread.
source
- A file name or URL description.base
- The base URL for relative references, or null if
there is none.
java.lang.Exception
- If the file or URL cannot be found or
if the user cancels on being warned of a security concern.public static ErrorHandler getErrorHandler()
setErrorHandler(ErrorHandler)
public static IconLoader getIconLoader()
setIconLoader(IconLoader)
public static java.util.List getMoMLFilters()
addMoMLFilter(MoMLFilter filter)
,
setMoMLFilters(List filterList)
public NamedObj getToplevel()
setToplevel(NamedObj)
public static boolean isModified()
setModified(boolean)
public NamedObj parse(java.net.URL base, java.net.URL input) throws java.lang.Exception
base
- The base URL for relative references, or null if
not known.input
- The stream from which to read XML.
java.lang.Exception
- If the parser fails.purgeModelRecord(URL)
,
purgeAllModelRecords()
public NamedObj parse(java.net.URL base, java.io.InputStream input) throws java.lang.Exception
parse(URL base, String systemID, InputStream input)
for better error messages that include the name of the file being
read.
base
- The base URL for relative references, or null if
not known.input
- The stream from which to read XML.
java.lang.Exception
- If the parser fails.public NamedObj parse(java.net.URL base, java.lang.String systemID, java.io.InputStream input) throws java.lang.Exception
base
- The base URL for relative references, or null if
not known.systemID
- The URI of the document.input
- The stream from which to read XML.
java.lang.Exception
- If the parser fails.public NamedObj parse(java.net.URL base, java.io.Reader reader) throws java.lang.Exception
parse(URL base, String systemID, Reader reader)
for better error messages that include the name of the file being
read.
base
- The base URL for relative references, or null if
not known.reader
- The reader from which to read XML.
java.lang.Exception
- If the parser fails.public NamedObj parse(java.net.URL base, java.lang.String systemID, java.io.Reader reader) throws java.lang.Exception
base
- The base URL for relative references, or null if
not known.systemID
- The URI of the document.reader
- The reader from which to read XML.
java.lang.Exception
- If the parser fails.public NamedObj parse(java.lang.String text) throws java.lang.Exception
text
- The string from which to read MoML.
java.lang.Exception
- If the parser fails.
java.lang.SecurityException
- If the user.dir system property is
not available.public NamedObj parse(java.net.URL base, java.lang.String text) throws java.lang.Exception
base
- The base URL for relative references, or null if
not known.text
- The string from which to read MoML.
java.lang.Exception
- If the parser fails.public NamedObj parseFile(java.lang.String filename) throws java.lang.Exception
If you have an absolute pathname, rather than calling this method, you may want to try:
CompositeActor toplevel = (CompositeActor) parser.parse(null, new File(xmlFilename).toURL());
Note that this method attempts to read the user.dir system property, which is not generally available in applets. Hence it is probably not a good idea to use this method in applet code, since it will probably fail outright.
If the file has already been parsed, then return the model that previously parsed. Note that this means that an application that opens and then closes a model and expects to re-parse the XML when re-opening should call purgeModelRecord() when closing it.
filename
- The file name from which to read MoML.
java.lang.Exception
- If the parser fails.
java.lang.SecurityException
- If the user.dir system property is
not available.purgeModelRecord(String)
,
purgeAllModelRecords()
public void processingInstruction(java.lang.String target, java.lang.String data)
processingInstruction
in interface XmlHandler
processingInstruction
in class HandlerBase
target
- The name of the processing instruction.data
- The body of the processing instruction.XmlHandler.processingInstruction(java.lang.String, java.lang.String)
public static void purgeAllModelRecords()
purgeModelRecord(URL)
,
resetAll()
public static void purgeModelRecord(java.net.URL url)
reset()
so
that the _toplevel is reset on any parser.
url
- The URL.parse(URL, URL)
,
purgeAllModelRecords()
public static void purgeModelRecord(java.lang.String filename) throws java.net.MalformedURLException
Note that this method attempts to read the user.dir system property, which is not generally available in applets. Hence it is probably not a good idea to use this method in applet code, since it will probably fail outright.
Note that you may also need to call reset()
so
that the _toplevel is reset.
filename
- The file name from which to read MoML.
java.net.MalformedURLException
- If the file name cannot be converted to a URL.
java.lang.SecurityException
- If the user.dir system property is
not available.parse(URL, String)
,
purgeAllModelRecords()
public void reset()
resetAll()
.
resetAll()
,
purgeModelRecord(String)
,
purgeAllModelRecords()
public void resetAll()
reset()
in that
this method does as complete a reset of the MoMLParser
as possible.
purgeModelRecord(String)
,
purgeAllModelRecords()
public java.lang.Object resolveEntity(java.lang.String publicID, java.lang.String systemID)
resolveEntity
in interface XmlHandler
resolveEntity
in class HandlerBase
publicID
- The public identifier, or null if none was supplied.systemID
- The system identifier.
XmlHandler.resolveEntity(java.lang.String, java.lang.String)
public ComponentEntity searchForClass(java.lang.String name, java.lang.String source) throws java.lang.Exception
name
- The name of the MoML class to search for.source
- The URL source
java.lang.Exception
- If thrown while searching for the classpublic void setContext(NamedObj context)
Callers should be careful about calling this method and resetting the modified flag to false when parsing moml that has been modified by the backward compatibility filter. It is safer to do something like:
boolean modified = isModified(); MoMLParser newParser = new MoMLParser(...); newParser.setContext(context); setModified(modified);
context
- The context for parsing.public static void setErrorHandler(ErrorHandler handler)
handler
- The ErrorHandler to call.getErrorHandler()
public static void setIconLoader(IconLoader loader)
loader
- The IconLoader for all MoMLParsers.getIconLoader()
public static void setMoMLFilters(java.util.List filterList)
filterList
- The List of MoMLFilters.addMoMLFilter(MoMLFilter filter)
,
getMoMLFilters()
public static void setModified(boolean modified)
modified
- True if the data was modified while parsing.isModified()
,
MoMLFilter
public void setToplevel(NamedObj toplevel)
toplevel
- The top-level to associate with this parser.getToplevel()
public void setUndoable(boolean undoable)
undoable
- The new Undoable valuepublic void startDocument()
startDocument
in interface XmlHandler
startDocument
in class HandlerBase
endDocument()
public void startElement(java.lang.String elementName) throws XmlException
startElement
in interface XmlHandler
startElement
in class HandlerBase
elementName
- The element type name.
XmlException
- If the element produces an error
in constructing the model.XmlHandler.startElement(java.lang.String)
public void startExternalEntity(java.lang.String systemID)
startExternalEntity
in interface XmlHandler
startExternalEntity
in class HandlerBase
systemID
- The URI for the external entity.XmlHandler.startExternalEntity(java.lang.String)
public java.util.List topObjectsCreated()
clearTopObjectsList()
protected java.lang.String _currentExternalEntity()
private void _addParamsToParamsToParse(NamedObj object)
object
- The object to be scanned for Settables.private ComponentEntity _attemptToFindMoMLClass(java.lang.String className, java.lang.String source) throws java.lang.Exception
className
- The class name.source
- The source as specified in the XML.
java.lang.Exception
private void _checkClass(java.lang.Object object, java.lang.Class correctClass, java.lang.String msg) throws XmlException
XmlException
private void _checkForNull(java.lang.Object object, java.lang.String message) throws XmlException
XmlException
private NamedObj _createEntity(java.lang.String className, java.lang.String entityName, java.lang.String source, boolean isClass) throws java.lang.Exception
className
- entityName
- source
- isClass
- True to create a class definition, false to create
an instance.
java.lang.Exception
- If anything goes wrong.private NamedObj _createInstance(java.lang.Class newClass, java.lang.Object[] arguments) throws java.lang.Exception
newClass
- The class.arguments
- The constructor arguments.
java.lang.Exception
- If no matching constructor is found, or if
invoking the constructor triggers an exception.private NamedObj _deleteEntity(java.lang.String entityName) throws java.lang.Exception
entityName
- The relative or absolute name of the
entity to delete.
java.lang.Exception
- If there is no such entity or if the entity
is defined in the class definition.private Port _deletePort(java.lang.String portName, java.lang.String entityName) throws java.lang.Exception
portName
- The relative or absolute name of the
port to delete.entityName
- Optional name of the entity that contains
the port (or null to use the current context).
java.lang.Exception
- If there is no such port or if the port
is defined in the class definition.private Attribute _deleteProperty(java.lang.String attributeName) throws java.lang.Exception
attributeName
- The relative or absolute name of the
attribute to delete.
java.lang.Exception
- If there is no such attribute or if the attribute
is defined in the class definition.private Relation _deleteRelation(java.lang.String relationName) throws java.lang.Exception
relationName
- The relative or absolute name of the
relation to delete.
java.lang.Exception
- If there is no such relation or if the relation
is defined in the class definition.private NamedObj _findOrParse(MoMLParser parser, java.net.URL base, java.lang.String file, java.lang.String className, java.lang.String source) throws java.lang.Exception
parser
- The parser to use.base
- The base URL for relative references, or null if
not known.file
- The file or URL from which to read MoML.className
- The class name to assign if the file is
parsed anew.source
- The source file to assign if the file is
parsed anew, or null to not assign one.
java.lang.Exception
- If the parser fails.private int _getColumnNumber()
private java.lang.String _getCurrentElement(java.lang.String elementName)
private int _getLineNumber()
private ComponentPort _getPort(java.lang.String portspec, CompositeEntity context) throws XmlException
portspec
- The relative port name.context
- The context in which to look for the port.
XmlException
- If no such port is found.private java.lang.String _getUndoForDeleteAttribute(Attribute toDelete) throws java.io.IOException
toDelete
- The component to delete.
java.io.IOException
private java.lang.String _getUndoForDeleteEntity(ComponentEntity toDelete) throws java.io.IOException
toDelete
- The component to delete.
java.io.IOException
private java.lang.String _getUndoForDeletePort(Port toDelete) throws java.io.IOException
toDelete
- The component to delete.
java.io.IOException
private java.lang.String _getUndoForDeleteRelation(ComponentRelation toDelete) throws java.io.IOException
toDelete
- The component to delete.
java.io.IOException
private void _handlePropertyElement(java.lang.String className, java.lang.String propertyName, java.lang.String value) throws java.lang.Exception
className
- The class name field, if present.propertyName
- The property name field.value
- The value, if present.
java.lang.Exception
- If something goes wrong.private boolean _isLinkInClass(NamedObj context, Port port, Relation relation)
context
- The context containing the link.port
- The port.relation
- The relation.
private boolean _isLinkInClass(NamedObj context, Relation relation1, Relation relation2)
context
- The context containing the link.relation1
- The first relation.relation2
- The second relation.
private boolean _isUndoableElement(java.lang.String elementName)
elementName
- Description of Parameter
private boolean _loadFileInContext(java.lang.String fileName, NamedObj context) throws java.lang.Exception
fileName
- The file name.context
- The context into which to load the file.
java.lang.Exception
- If the file exists but cannot be read
for some reason.private boolean _loadIconForClass(java.lang.String className, NamedObj context) throws java.lang.Exception
setIconLoader(IconLoader)
has been called with
a non-null argument, then invoke the
IconLoader.loadIconForClass(String, NamedObj)
method. If setIconLoader(IconLoader)
has not
been called, or was called with a null argument, then
The file name is constructed from
the class name by replacing periods with file separators
("/") and appending "Icon.xml". So, for example, for
the class name "ptolemy.actor.lib.Ramp", if there is a
file "ptolemy/actor/lib/RampIcon.xml" in the classpath
then that file be read.
className
- The class name.context
- The context into which to load the file.
java.lang.Exception
- If the file exists but cannot be read
for some reason or if there is some other problem loading
the icon.setIconLoader(IconLoader)
,
IconLoader
private void _markContentsDerived(NamedObj object, int depth)
object
- The instance that is defined by a class.depth
- The depth (normally 0).private void _markParametersToParse(NamedObj object)
object
- The instance to mark.private NamedObj _parse(MoMLParser parser, java.net.URL base, java.lang.String source) throws java.lang.Exception
parser
- The parser to use.base
- The base URL for relative references, or null if
not known.source
- The URL from which to read MoML.
java.lang.Exception
- If the parser fails.private void _processLink(java.lang.String relation1Name, java.lang.String relation2Name) throws XmlException, IllegalActionException
relation1Name
- The first relation name.relation2Name
- The second relation name.
XmlException
IllegalActionException
private void _processLink(java.lang.String portName, java.lang.String relationName, java.lang.String insertAtSpec, java.lang.String insertInsideAtSpec) throws XmlException, IllegalActionException
portName
- The port name.relationName
- The relation name.insertAtSpec
- The place to insert.insertInsideAtSpec
- The place to insert inside.
XmlException
IllegalActionException
private void _processPendingRequests() throws java.lang.Exception
java.lang.Exception
- If something goes wrong.private void _processUnlink(java.lang.String relation1Name, java.lang.String relation2Name) throws XmlException, IllegalActionException
relation1Name
- The first relation name.relation2Name
- The second relation name.
XmlException
- If something goes wrong.
IllegalActionException
- If the link is part of a class definition.private void _processUnlink(java.lang.String portName, java.lang.String relationName, java.lang.String indexSpec, java.lang.String insideIndexSpec) throws XmlException, IllegalActionException
portName
- The port name.relationName
- The relation name.indexSpec
- The index of the channel.insideIndexSpec
- The index of the inside channel.
XmlException
- If something goes wrong.
IllegalActionException
- If the link is part of a class definition.private void _pushContext()
private void _resetUndo()
private Attribute _searchForAttribute(java.lang.String name) throws XmlException
name
- The name of the attribute, relative or absolute.
XmlException
- If the attribute is not found.private ComponentEntity _searchForClassInContext(java.lang.String name, java.lang.String source) throws java.lang.Exception
name
- The name of the class.source
- The source for the class.
java.lang.Exception
- If a source is specified and it cannot
be opened.private ComponentEntity _searchForEntity(java.lang.String name, NamedObj context) throws XmlException, IllegalActionException
name
- The name of the entity.context
- The context in which to search.
XmlException
- If the name refers to an entity in an
innappropriate context or if the context is not an instance
of CompositeEntity.
IllegalActionException
- If the name is ambiguous in that
more than one entity in workspace matches. This will only occur
if the name is absolute and is not inside the current model.private Port _searchForPort(java.lang.String name) throws XmlException
name
- The name of the port.
XmlException
- If the port is not found.private ComponentRelation _searchForRelation(java.lang.String name) throws XmlException
name
- The name of the relation.
XmlException
- If the relation is not found.private void _setXmlFile(java.net.URL xmlFile)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |