public class DocManager extends HandlerBase
The documentation is constructed by a multi-tiered method. The first level of information is provided by an attribute named DOC_ATTRIBUTE_NAME contained by the object. The second level of information is provided by an XML file in the same package as the class of the associated object. The name of the XML file is "xDoc.xml", where x is the name of the class of the object. The third level of information is provided by an XML file associated with the base class of the associated object. The remaining levels are provided by searching up the inheritance hierarchy. When a method of the DocManager class is invoked to get documentation information, this class looks first in the first tier for the information. If the information is not present in the first tier, then it looks in the second tier, etc. If the information is not present in any tier, then it returns a string indicating that there is no information. Except for the first tier, the documentation information is constructed lazily, only when the methods to access the information are invoked, and only if the first tier has not provided the information.
If the information is found but is malformed, then all information methods return a description of the error.
At all tiers, the documentation information is given in XML with a specified DTD.
A doc file should be an XML file beginning with
<?xml version="1.0" standalone="yes"?> <!DOCTYPE doc PUBLIC "-//UC Berkeley//DTD DocML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/DocML_1.dtd">and should then have a top-level element of the form
<doc name="actorName" class="actorClass">The main description is text included within the description element, as in
<description> description here </description>The description can include HTML formatting, although any < and > should be escaped and represented as < and >.
Additional information can be provided in the author, version, since, Pt.ProposedRating, and Pt.AcceptedRating elements. These are, like the description, simple text that gets rendered (and HTML formatted) in the documentation.
Documentation for ports and parameters is given using the following forms:
<port name="portName" documentation </port> <property name="parameterName" documentation </property>The use of the "property" keyword matches MoML.
Red (cxh) |
Red (eal) |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DocML_DTD_1
The standard DocML DTD, represented as a string.
|
Constructor and Description |
---|
DocManager(Configuration configuration,
java.lang.Class targetClass)
Construct a manager to handle documentation for the specified target
class.
|
DocManager(Configuration configuration,
NamedObj target)
Construct a manager to handle documentation for the specified target.
|
DocManager(Configuration configuration,
java.net.URL url)
Construct a manager for documentation at the specified URL.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_checkForNull(java.lang.Object object,
java.lang.String message)
If the argument is null, throw an exception with the given message.
|
protected java.lang.String |
_currentExternalEntity()
Get the the URI for the current external entity.
|
void |
attribute(java.lang.String name,
java.lang.String value,
boolean specified)
Handle an attribute assignment that is part of an XML element.
|
void |
charData(char[] chars,
int offset,
int length)
Handle character data.
|
static java.net.URL |
docClassNameToURL(Configuration configuration,
java.lang.String className,
boolean lookForPtDoc,
boolean lookForJavadoc,
boolean lookForSource,
boolean lookForActorIndex)
Given a dot separated class name, return the URL of the
documentation.
|
void |
endDocument()
End the document.
|
void |
endElement(java.lang.String elementName)
End an element.
|
void |
error(java.lang.String message,
java.lang.String systemID,
int line,
int column)
Indicate a fatal XML parsing error.
|
java.lang.String |
getAcceptedRating()
Return the Pt.AcceptedRating field, or null
if none has been given.
|
java.lang.String |
getAuthor()
Return the author field, or the string "No author given"
if none has been given.
|
java.lang.String |
getClassName()
Return the class name, or null if none has been given.
|
java.lang.String |
getDescription()
Return the description, or null if none has been given.
|
DocManager |
getNextTier()
Return next tier, if there is one.
|
java.lang.String |
getPortDoc(java.lang.String name)
Return the documentation for the specified port, or null
if there is none.
|
java.lang.String |
getPropertyDoc(java.lang.String name)
Return the documentation for the specified property
(parameter or attribute), or null if there is none.
|
java.lang.String |
getProposedRating()
Return the Pt.ProposedRating field, or null
if none has been given.
|
static java.lang.String |
getRemoteDocumentationURLBase()
Get the location of the website documentation.
|
java.lang.String |
getSeeAlso()
Return "see also" information.
|
java.lang.String |
getSince()
Return the since field, or null
if none has been given.
|
java.lang.Class |
getTargetClass()
Return the class of the target.
|
java.lang.String |
getVersion()
Return the version field, or null
if none has been given.
|
boolean |
hadException()
Return true if an exception was encountered parsing
the DocML data.
|
boolean |
isInstanceDoc()
Return true if the primary source of documentation is
the instance.
|
boolean |
isTargetInstantiableAttribute()
Return true if the target class is a subclass of Attribute
that has a two-argument constructor compatible where the
first argument is a CompositeEntity and the second is a
String.
|
boolean |
isTargetInstantiableEntity()
Return true if the target class is a subclass of Entity
that has a two-argument constructor compatible where the
first argument is a CompositeEntity and the second is a
String.
|
boolean |
isTargetInstantiablePort()
Return true if the target class is a subclass of Port
that has a two-argument constructor compatible where the
first argument is a CompositeEntity and the second is a
String.
|
void |
parse(java.lang.String text)
Parse the given text as DocML.
|
void |
parse(java.net.URL base,
java.io.InputStream input)
Parse the given stream as a DocML file.
|
void |
parse(java.net.URL base,
java.io.Reader reader)
Parse the given stream as a DocML file.
|
java.lang.Object |
resolveEntity(java.lang.String publicID,
java.lang.String systemID)
Resolve an external entity.
|
static void |
setRemoteDocumentationURLBase(java.lang.String remoteDocumentationURLBase)
Set the location of the remote documentation.
|
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.
|
doctypeDecl, endExternalEntity, ignorableWhitespace, processingInstruction
public static final java.lang.String DocML_DTD_1
public DocManager(Configuration configuration, NamedObj target)
configuration
- The configuration in which to look up the
_docApplicationSpecializer and _applicationName parameterstarget
- The object to be documented.public DocManager(Configuration configuration, java.lang.Class targetClass)
configuration
- The configuration in which to look up the
_docApplicationSpecializer and _applicationName parameterstargetClass
- The class to be documented.public DocManager(Configuration configuration, java.net.URL url)
configuration
- The configuration in which to look up the
_docApplicationSpecializer and _applicationName parametersurl
- The URL.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 static java.net.URL docClassNameToURL(Configuration configuration, java.lang.String className, boolean lookForPtDoc, boolean lookForJavadoc, boolean lookForSource, boolean lookForActorIndex)
If the configuration has a parameter
_docApplicationSpecializer and that parameter names a class
that that implements the DocApplicationSpecializer
interface, then we pass the class name to
DocApplicationSpecializer.docClassNameToURL(String, String, boolean, boolean, boolean, boolean)
and if a non-null is returned from docClassNameToURL(), we
return that value.
If the configuration has a parameter _applicationName, then
we search in doc/codeDocapplicationName
for
the PtDoc, Javadoc and Actor Index files. Otherwise, we search
in doc/codeDoc
. Source files are searched for
in the classpath by using getResource().
The lookForPtDoc, lookForJavadoc, lookForSource and lookForActorIndex parameters control which documents are searched for. The documents are searched in the same order as the parameters that have true values, that is if the parameters are true, true, false, false, then if the the PtDoc .xml file is searched for locally, then the Javadoc .html file is search for locally and then if the _remoteDocumentation base attribute is set the PtDoc .xml file is searched for on the remote host and then the Javadoc .html file is search for on the remote host.
configuration
- The configuration in which to look up the
_docApplicationSpecializer and _applicationName parametersclassName
- The dot separated class name.lookForPtDoc
- True if we should look for ptdoc .xml files.lookForJavadoc
- True if we should look for javadoc files.lookForSource
- True if we should look for source files.
Note that lookForPtDoc and lookForJavadoc must both be false for
the source code to be found.lookForActorIndex
- True if we should look for the actor index.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 endDocument() throws java.lang.Exception
endDocument
in interface XmlHandler
endDocument
in class HandlerBase
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
- Not thrown in this base class.XmlHandler.endElement(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.lang.String getAcceptedRating()
public java.lang.String getAuthor()
public java.lang.String getClassName()
public java.lang.String getDescription()
public DocManager getNextTier()
public java.lang.String getPortDoc(java.lang.String name)
name
- The name of the port.public java.lang.String getPropertyDoc(java.lang.String name)
name
- The name of the property.public java.lang.String getProposedRating()
public java.lang.String getSince()
public static java.lang.String getRemoteDocumentationURLBase()
http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII/Major.Version
,
where Major.Version
is the value returned by
VersionAttribute.majorCurrentVersion()
.setRemoteDocumentationURLBase(String)
public java.lang.Class getTargetClass()
public java.lang.String getVersion()
public java.lang.String getSeeAlso()
public boolean hadException()
public boolean isInstanceDoc()
public boolean isTargetInstantiableAttribute()
public boolean isTargetInstantiableEntity()
public boolean isTargetInstantiablePort()
public void parse(java.net.URL base, java.io.InputStream input) throws java.lang.Exception
DocManager parser = new DocManager(); URL xmlFile = new URL(null, docURL); parser.parse(xmlFile.openStream());A variety of exceptions might be thrown if the parsed data does not represent a valid DocML file.
base
- The base URL from which the XML is read.input
- The stream from which to read XML.java.lang.Exception
- If the parser fails.public void parse(java.net.URL base, java.io.Reader reader) throws java.lang.Exception
base
- The base URL from which the XML is read.reader
- The stream from which to read XML.java.lang.Exception
- If the parser fails.public void parse(java.lang.String text) throws java.lang.Exception
text
- The DocML data.java.lang.Exception
- If the parser fails.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 static void setRemoteDocumentationURLBase(java.lang.String remoteDocumentationURLBase)
remoteDocumentationURLBase
- The remote location of the class
documentation.getRemoteDocumentationURLBase()
public void startDocument()
startDocument
in interface XmlHandler
startDocument
in class HandlerBase
XmlHandler.startDocument()
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)
protected void _checkForNull(java.lang.Object object, java.lang.String message) throws XmlException
object
- The reference to check for null.message
- The message to issue if the reference is null.XmlException
- If the object parameter is null.protected java.lang.String _currentExternalEntity()