Event
and
Alarm
in XML format. These classes will be created when the XML file is
loaded.
Event
class has the
ID
attribute of type
string
. The
Alarm
class is a subclass of the
Event
class that has two attributes,
PerceivedSeverity
, of type
String
, and
Acknowledged
, a Boolean attribute that defaults to
false
. The
Alarm
class inherits the
ID
attribute from the
Event
class. For details, see Inheritance.
<classes xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation = "ilog/cpl/schema/model.xsd"> <classes> <class> <name>Event</name> <attribute> <name>ID</name> <javaClass>java.lang.String</javaClass> </attribute> </class> <class> <name>Alarm</name> <superClass>Event</superClass> <attribute> <name>PerceivedSeverity</name> <javaClass>java.lang.String</javaClass> </attribute> <attribute> <name>Acknowledged</name> <javaClass>java.lang.Boolean</javaClass> <defaultValue>false</defaultValue> </attribute> </class> </classes>
XML
element |
Attributes
|
Default
|
Description
|
---|---|---|---|
<classes>
|
None |
Delimits classes definition. This element is required. The
file containing classes should necessarily start and end with
this element. This element can be used inside data (see Elements in an XML data file ). This
element contains <class> elements.
|
|
<class>
|
None |
Contains
a class definition. The class definition contains a name and
possibly a <superClass> element and some
<attribute> elements. |
|
<superClass>
|
None |
Contains
the name of the superclass. |
|
<name>
|
None |
Contains
the name of the class or of the attribute being defined. |
|
<attribute>
|
None |
Defines
an attribute in the current <class>. The attribute
contains a <name>, a <javaClass>, and optionally
a <defaultValue>. |
|
<javaClass>
|
None |
Contains the name of the Java™ class of the attribute (for
example
java.lang.String
).
|
|
<defaultValue>
|
Contains
the default value of an attribute. |
||
javaClass
|
The
Java class of the attribute. |
Sometimes
the Java class of the default value is not the Java class of
the attribute (for example, if the Java class of the
attribute is abstract). This attribute allows you to specify
the Java class of the default value. |
|
null
|
false
|
If the default value is to be null, you can set this optional
attribute to
true
.
|
GetIlpClass()
method.
<classes>
has no impact when loading classes that have inheritance
relationships. In other words, you can define a class before a
superclass within the same
<classes>
element.
<javaClass>
element that lets you assign an abstract class or interface type
to an attribute (for example
java.lang.Number
) and provide a default value.
<attribute> <name>number</name> <javaClass>java.lang.Number</javaClass> <defaultValue javaClass="java.lang.Integer">100</defaultValue> </attribute>
String
, its default value will be "".
<attribute> <name>emptyString</name> <javaClass>java.lang.String</javaClass> <defaultValue /> </attribute>
<attribute> <name>nullString</name> <javaClass>java.lang.String</javaClass> <defaultValue null="true" /> </attribute>
createJavaInstance
and
createStringValue
. These methods support all the types defined in
java.lang
, plus extra ones such as:
java.util.Date
). The following format is supported:
"yyyy'-'MM'-'dd'T'HH':'mm':'ss"
java.awt.Color
). Regular HTML formats are supported; for example:
"RED" or "#NNNNNN"
java.awt.Font
). To know the formats that are supported, see the
java.awt.Font.decode
method.
ilog.util.IlEnum
).
XmlReader
and write it as a SAX event to a SAX
ContentHandler
. To be recognized, this interface should be implemented by a
class named
<className>SAXInfo
; or, if you are using the default type converter
implementation ( IlpDefaultTypeConverter), you can
register the value handler so that it is automatically taken
into account by the XML parser, using the method IlpDefaultTypeConverter. setAttributeValueHandler.
SAXInfo
class. For example, the IlpPoint class in the
ilog.cpl.graphic
package comes with the
IlpPointSAXInfo
class. When an IlpPoint is to be read, the default type
converter checks whether there is a corresponding IlpSAXSerializable instance. If not, it
will try to load the IlpPointSAXInfo class. If it succeeds,
this class will be returned as the
IlpSAXSerializable
interface of the
IlpPoint
class.
IlpPointSAXInfo
.
/** * Returns a SAX handler capable of reading the attribute. * To avoid an instance of a SAX handler being used simultaneously * by two concurrent threads, this method should either return a new * instance of a SAX handler each time it is called or take advantage of * the java.lang.ThreadLocal class to return a different * instance for each thread. * @return A SAX event handler. */ public IlpSAXAttributeValueHandler getSAXHandler() { return new IlpSAXPointHandler(); } public static class IlpSAXPointHandler extends IlpSAXAttributeValueHandler { protected float x; protected float y; /** * Indicates the beginning of an element. * By default, this method only clears the content of the element. */ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (localName.equals(finalTag)) { x = y = 0.0f; } super.startElement(namespaceURI,localName,qName,atts); } /** * Notifies the end of an element. * When this method is called for the "attribute" element, * the <CODE>getAttributeValue</CODE> method is called, the object * is modified accordingly, and parsing continues. */ public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (localName.equals("x")) { x = Float.parseFloat(getContent()); } if (localName.equals("y")) { y = Float.parseFloat(getContent()); } super.endElement(namespaceURI,localName,qName); } /** * Is called at the end of the "attribute" element. */ protected Object getAttributeValue() { Object value = new IlpPoint(x,y); return value; } } /** * Writes the <CODE>value</CODE> to a SAX ContentHandler. * The method translates the object as SAX ContentHandler method calls. * @param value The object to write. * @param typeConverter The type converter that may be needed to translate * values to strings. * @param outputHandler The SAX ContentHandler used by this method. * @see ilog.cpl.util.IlpTypeConverter#createStringValue(Object,IlpKey) */ public void output(Object value, IlpTypeConverter typeConverter, ContentHandler outputHandler) throws SAXException { IlpPoint point = (IlpPoint)value; String valueStr = String.valueOf(point.x); outputHandler.startElement("","x","x",IlpSAXSerializable.EMPTY_ATTRS); outputHandler.characters(valueStr.toCharArray(),0,valueStr.length()); outputHandler.endElement("","x","x"); valueStr = String.valueOf(point.y); outputHandler.startElement("","y","y",IlpSAXSerializable.EMPTY_ATTRS); outputHandler.characters(valueStr.toCharArray(),0,valueStr.length()); outputHandler.endElement("","y","y"); } }