Creating and configuring component-based applications using a text-based descriptive attribute grammar6083276Abstract A method for creating and configuring a component-based application through text-based descriptive attribute grammar includes creating a parse tree from an application description file, transforming the parse tree into a plurality of components corresponding to instances of classes in an application framework, and initializing and further processing the components to launch the component-based application. Additionally, a system for creating and configuring a component-based application includes a parser, a plurality of element processors, an element mapper, an attribute mapper, and a parameter converter. Claims We claim: Description BACKGROUND OF THE INVENTION
______________________________________
<Body>
<Rect Xpos=50 Ypos=50 Width=200 Height=100 BGColor=Red>
</Body>
______________________________________
Character Data and Markup Like standard XML documents, BML documents consist of markup data and content character data within specific elements' closures. Valid markup structures allowed by BML include start-tags, end-tags, empty elements, character references, comments and CDATA sections. The current preferred embodiment of BML does not support processing instructions 304, document type declarations or entities though these could be easily added if appropriate in other embodiments. Comments 302 in BML are marked and processed identically to XML documents and are, therefore, ignored by parser 116. As with XML, BML comments 302 may not appear within declarations or tags. Element and Attribute Declarations Like XML, BML documents contain one or more elements 306. Elements 306 are declared and delimited by a start-tag and end-tag. Like XML, the name 314 in an element's end-tag matches the name in its start-tag. Empty elements 306 in BML may be specified using the standard XML "empty element" tag. Unlike XML, BML does not require the special "empty element" tag. The following are allowable as valid empty BML elements 306:
______________________________________
<Foo Att1=Value1 Att2=Value2>
<Bar Att2=Value2 />
______________________________________
As with XML, the first character data inside an BML start tag is a valid element name or tag 314 which defines the element's type. Each element may have one or more attributes 310 which are declared in precisely the same name-value syntax as standard XML attributes. For example, in the "foo" empty element tag 314 above, the attribute 310 name "Att1" is set to the value "Value1," and the attribute 310 "Att2" set to the value "Value2". BML attribute 310 names correspond to the constraints of XML attribute names. Unlike XML, BML does not require quote characters for attribute 310 values with no embedded white space characters. For example, the following are valid BML elements 306:
______________________________________
<Foo Att1=Value1>
<Foo Att1="Value1">
<Foo Att1="A Value With Spaces">
______________________________________
Unlike XML, BML does not disallow duplicate attributes 310. In other words, attributes 310 may appear more than once in the same start-tag. For example, the following is a valid BML element: <Foo Att=1 Att=2 Att=3> Only certain BML elements 306 may have child elements 306. Whether or not a given element type can contain children is not a property of the BML syntax itself but is determined solely by the properties of the underlying component class 132 to which the element name 314 is mapped. In general, only component classes 132 that implement a specific "container" interface may have children element tags 314 as will become apparent hereafter. The following is valid as an element tag 314 with children if "Fizz" is mapped to a "container" component 212 interface:
______________________________________
<Fizz Att1=Value1>
<Foo Att1=Value3>
<Foo Att1=Value4>
</Fizz>
______________________________________
All BML attribute 310 values are input and parsed as string data. The parser 116, however, allows these string-based values to be parsed into primitive and object data types according to the parameter specifications of the attribute's corresponding mutator. Allowable basic parameter types include: string, double, boolean, date, integer, and arrays. Parameter types may be extended at runtime by individual components and element processors. In addition, BML allows a special string-based parameter type called a "named object reference," which will be discussed in greater detail hereafter. As with XML, BML element 306 and attribute 310 names are case insensitive. Attribute 310 values, however, may be case sensitive depending on the parameter type specified by the underlying component 212 method. Before attribute 310 values are passed to the underlying component 212, trailing and leading white space is removed unless explicitly declared within a pair of quotations. Event Declarations One object of the present invention is to provide a mechanism for defining complex component-based interactions within the limits of a descriptive attribute grammar. Thus, BML provides a special attribute 310 declaration, OnEvent, for specifying both user and application-generated "events". The OnEvent attribute 310 is used to define how a component 212 should "react" to specified event types as well as how event "messages" may be posted among the components 212 themselves. The syntax for the OnEvent attribute 310 declaration requires a single string value with comma-separated fields as follows: OnEvent=[Event Tag], [Action], [Target], {Parameter} In one embodiment, the Event Tag field is required and may correspond to either a component-specific event tag (e.g. "MOUSEUP", "MOUSEENTER", etc) or to a custom event tag used among components in the application (e.g. "IMPORTANTEVENT", "aCustomEventTag", etc). The Action field is also required and should correspond to a valid, publicly accessible method on the target component 212. Preferably, Event tags and Action fields are both case insensitive. Similarly, the Target field is required and should be a scoped name reference to a component 212 accessible from the base component 212. The Parameter field is optional. Any text data after the Target field is treated as a single string and part of the Parameter field. The raw parameter string is not converted to any appropriate data type until the associated action message is executed. Validation of the BML File Unlike typical XML or SGML files, a BML file cannot be validated by reference to a pre-existing DTD. Instead, the validity of an BML file can only be determined in a specific application context and in reference to the component object model specified by the BML file. In a valid BML file, the resulting object model should have the following characteristics: (1) each element 306 declaration in the BML file should be capable of being mapped to a corresponding application component class 132; (2) each element 306 with children should result in a corresponding "container" component 212 with analogous children components 212; (3) each attribute 310 declaration should be mapped to a corresponding property 320 value in the corresponding component 212 unless special processing for that attribute name has been specified; and (4) all "Event Declarations" should be mapped to equivalent event-based "triggers" in the underlying components 212. While transforming the elements of parse tree 204 into components 212, the element processors 118 are able to detect whether the four requirements above are met. Specifically, it can be determined whether a corresponding component class 132 exists for the specified element 306 and whether the attribute 310 declarations have a corresponding property 320 value. Thus, in a preferred embodiment, the element processors 118, in combination with the parser 116, may validate an BML file. 2. ADML ADML has a more restricted syntax than BML, which allows a document to be validated against a document type definition (DTD). The main difference between ADML and BML is that the names of tags 314 and associated attributes 310 in ADML are fixed and cannot be added to. Thus, by allowing only certain tags 314 and certain attributes 310 for those tags, a DTD may be defined, and ADML is XML in the strictest sense, being both "well formed" and "validating" XML. A DTD for ADML is attached as Appendix A and is described in detail below. The ADML DTD A DTD is a special document that describes the syntax of a markup language. The XML specification requires that the processor of a dialect of XML have a DTD and enforce the syntax in order to be considered "validating" XML. ADML's syntax is enforced by the ADML runtime. Appropriate error messages are generated when a ADML fails to conform to the DTD's rules. To fully understand the document type definition of ADML in Appendix A, the following should be noted:
______________________________________
an ELEMENT declaration declares the syntax for a specific element 306.
It declares the name of a tag 314 in the syntax, and what child tags 314,
if
any, it may have, and in what order.
If the word EMPTY is placed at the end of an ELEMENT
declaration instead of a list of child tags 314, that means that the
tag can have no attributes 310. An example is the CONSTANT tag
in ADML.
A #PCDATA child means that the tag 314 may contain child text.
An example is the P tag 314.
Lists of child tags 314 may contain "entities" or macros that
contain a predefined list of child tags 314. These entities may in
turn contain other entities. An example is the EVENT tag 314 whose
children are defined in the actions entity.
If there is a list of child tags 314 separated by commas, the child
tags 314 should occur in that order. An example is the ADML tag
314 at the beginning of the document, under which the BODY tag
should follow the HEAD tag 314.
If there is a list of child tags 314 separated by a vertical bar
".vertline." ,
any one of the tags 314 in that list may be used in that position. An
example of this is in the HEAD tag. Note that in this case, the list
is followed by a *, which modifies the rule as described hereafter.
A ? after a child tag 314 means that it is optional. Examples are
found in the CALL tag 314, for which the ON and ARGUMENTS
child tags 314 are optional.
A + after a child tag 314 means that there must be at least one of
that tag 314 there, but there may be more than one. An example is
the TEXT tag 314, has one or more child P tags 314.
A * after a child tag 314 means that it is optional, and there may be
more than one. An example is the PARAMS tag 314, which may
have 0 or more child PARAM tags 314.
Several marks can be used in combination to express more complex
rules, for example,
(A?, B?, C?) means that child tags 314 A, B, and C are all
optional, but they if they exist, there may only be at most one
of each, and they should appear in that order.
(A*, B*) means that all A tags 314, if any, should appear
before all B tags, if any.
(A.vertline.B)* means that there may be a sequence of 0 or more A's
and B's, in any order.
There may or may not be a corresponding ATTLIST 312
declaration for the same tag 314. When the ATTLIST 312 does not
exist, the tag 314 may not have attributes 310. When it does exist,
it defines exactly what attributes 310 there may be, what their format
is, and which must be there. It can also specify a default value for
the attribute 310. An example of an ELEMENT 306 with an
ATTLIST 312 is REQUEST. An example of an ELEMENT 306
without one is HEAD. There is no concept of ordering in attributes
310. A given attribute 310 may only be used once in a tag 314.
The attribute list 312 may contain an entity macro specifying a list
of attributes 310 declared elsewhere. An example is the STYLE tag
314 whose attributes 310 are defined by the styleattr entity.
An attribute 310 may be required. An error will be generated
if the attribute 310 is missing. An example is the Type
attribute 310 of EVENT.
An attribute 310 may be optional. An example is the
ARGUMENTS tag 314, for which the Classes attribute 310 is
optional.
DTDs have difficulty expressing certain rules. For
example, they cannot express the rule that "either attribute a
or attribute b must be present." When that is the case, all that
the DTD can say is that both are optional. An example is the
CONSTANT tag 314, where either a Value attribute 310 or an
IDRef attribute 310 must be present. In cases such as this, the
runtime will generate an error. The error message will show
the location in the source where the error occurred. Another
rule that the DTD cannot express is "attribute a and child tag
A cannot both be present". An example is the TYPE tag 314
and the <COMPONENT>, <CONTAINER>, <BEAN> family
of tags 314 that can optionally specify a value through either
the Value attribute 310 or the VALUE child tag 314, but not
both. Because of limitations such as these, the runtime is
more strict than the DTD.
______________________________________
Types In BML, the tag 314 name is used to identify the type of the component or "bean" 212. For instance, the <BUTTON> tag 314 is used to declare a button. Creation of new tags 314 is not permitted in ADML. Thus, the BML expression <BUTTON> is replaced by the ADML expression <COMPONENT Type="BUTTON">. COMPONENT is one standard tags 314 for declaring a bean 212, as described below. Although there are several different tags 314 in ADML for creating a bean 212, all are told what kind of bean 212 to create with a Type attribute 310, whose value should be the ID of a TYPE tag declared in the HEAD of the document. The standard types that are provided with the runtime can be found in a StandardHeader.ent file. These standard types do not have to be used, and can be replaced with custom designed types, but care must be taken that there is a TYPE for each bean's 212 Type attribute 310 or default type. If the Type attribute 310 is missing in a bean tag 314, the runtime will look for a TYPE whose ID is the name of the bean's tag 314. For example, if a bean is declared using a CONTAINER tag 314, but no Type is specified, the runtime will look for a TYPE in the HEAD section called "CONTAINER". An example of the differences in syntax between BML and ADML is illustrated below. For instance, a BML document might take the form:
______________________________________
<FRAME background="white" >
<BUTTON font="timesroman-plain-14"
background="blue" />
</FRAME>
______________________________________
whereas the same document in ADML would have the form:
______________________________________
<CONTAINER>
<INIT>
<SET Name="background" Value="white" />
</INIT>
<COMPONENT Type="BUTTON">
<INIT>
<SET Name="font" Value ="timesroman-plain-14" />
<SET Name="label" Value="Press Me" />
</INIT>
</COMPONENT>
</CONTAINER>
______________________________________
Inheriting Types In some situations, an existing type may be almost the desired type, but not quite. A user may be satisfied with the BUTTON type in the StandardHeader.ent file, but want to change the Tag, Class, Value, or Processor attributes. For example, a BUTTON type can normally only be used in a COMPONENT tag 314, because the Tag attribute 310 of the BUTTON type says "COMPONENT". Recognizing that the StandardHeader.ent file specifies a Swing JButton as the Class for the BUTTON type, if the user wants to take advantage of the fact that Swing buttons are actually containers, the user could create a type identical to BUTTON but usable in a CONTAINER tag 314. The user would create a new tag 314 derived from BUTTON and name it something new, such as:
______________________________________
<TYPE ID="CONTAINERBUTTON" Type="BUTTON"
Tag="CONTAINER"/>
______________________________________
INIT Macros An INIT section can be associated with a TYPE. All beans 212 declared with that type will have all of the contents of that INIT section executed when the bean 214 is created. This can be used to set up default bean property 320 values for a type. For example, the BUTTON type in the StandardHeader.ent file might have an INIT section that sets the opaque property on the JButton to "true," because the user did not want all the buttons to be transparent. Thus, any component 212 whose type is BUTTON will be opaque. When a type is inherited, it inherits all of the inits from above, but the derived type will execute its inits last, allowing it to override the inits of a parent type. The bean's own INIT section is likewise executed after all inits inherited from the TYPE. EVENT Macros Similar to INIT macros, event-handling macros can be specified to create default behavior for an object 212 of the given type. For example, one could create a button type that responds to "mouseEntered" and "mouseExited" event tags to create buttons that become brighter when the mouse passes over them. Like INIT macros, derived types' event handlers execute after parent type's event handlers, and event handlers attached to the bean tag are executed last of all. START and STOP Sections There may also be default START and STOP sections for a type. These are used to specify start and stop behavior for all beans 212 of that type. For example, the animation in an Animator bean 212 could be started and stopped so that whenever the bean 212 becomes invisible, the animation automatically stops, thus saving CPU time. Tags for Bean Creation and Declaration There are several tags 314 which create and declare bean components 212 in the ADML language. While, for the most part, they share a similar syntax, each tag has different semantics. In one embodiment, the tags include BEAN, COMPONENT, CONTAINER, BODY, TEXT, STYLE, P, LAYOUT, and POSITION.
______________________________________
BEAN - creates a bean 212 object, allows it to be named, and specifies
event handling for that bean. A BEAN 212 will not be laid out inside of
its
parent, even if its bean 212 is derived from java.awt.Component.
COMPONENT - like BEAN, but the bean 212 should be an instance of
java.awt.Component, and it will be laid out inside of a parent
CONTAINER or BODY and may specify a POSITION to specify a layout
constraint. Inside a P or STYLE, it is treated as a character, and
the layout constraint is ignored.
CONTAINER - like the COMPONENT in most respects, but the bean 212
should be an instance of java.awt.Container. It can also contain child
components. It can also use a LAYOUT tag to create a layout manager to
layout its children. Child tags 314 can refer to their container with
the
".sub.-- PARENT" ID.
BODY - creates a container to hold all of the contents of a BML file.
Similar to CONTAINER but it cannot have a POSITION. The body's
container object can be referred to elsewhere using the
".sub.-- BODY" ID.
TEXT - creates a text component 212.
STYLE - creates a text style within a paragraph object. It can be used
to
create hypertext links. It can contain text. Child components 212 will
be
treated as characters. It has attributes that apply to the text inside
the style.
Methods on the style can be used to change the text inside of it.
P - creates a paragraph object within a text component 212. It can
contain
STYLE tags and text. Child components 212 are treated as characters. It
has attributes that apply to paragraphs, such as justification.
LAYOUT - creates a LayoutManager (as described in the next section).
POSITION - creates a constraint object for the specified LayoutManager
(as described in the next section).
______________________________________
Most of the foregoing tags share the following common features:
______________________________________
They may have a Type attribute 310.
They may have an ID attribute 310 (called "Name" in BML) used to refer
to that bean in expressions elsewhere. Any time it needs to refer to
itself, it
may use the ".sub.-- SELF" ID.
They may have a Value attribute 310 which specifies a literal value for
the
bean 212. When this is present, the Class attribute 310 of its TYPE is
used to convert the Value to the actual bean 212 for that tag 314 using
ADML's built-in conversion mechanism 126. This attribute is not
permitted when there is a VALUE child tag 314.
They may have a VALUE child tag 314 which contains an expression for
creating the bean 212, if the default constructor for the bean 212 is
not
sufficient. This is described in more detail below. No forward
references
are allowed here (i.e. objects below the closing tag 314 of the parent of
the
VALUE tag are not visible yet. Because children of the parent are
processed before the parent, ID's of the VALUE's preceding sibling tags
are visible). This tag 314 is not permitted when there is a Value
attribute
310 for the bean 212.
They may have an INIT section, which is used to perform initialization
such as setting bean properties 320. Unlike BML, forward references are
possible here (i.e. all tag ID's are visible).
They may have START and STOP sections. These are used when the
parent frame gets a start and stop message. Typically, if the ADML page
were inside an Applet, they would be connected to its start() and stop()
methods. Inside an application, START is invoked whenever the frame
becomes visible, and STOP is invoked whenever the frame becomes
invisible.
They may have EVENT sections. An EVENT section has a Type attribute
310 which specifies the desired listener method to which the ADML
runtime should respond. ADML has built-in listeners for all AWT event
types as well as all JFC events. New ones can be registered with the
LISTENER tag in the HEAD section. The event types are the names of
the listener methods a listener. For example, "mousePressed" and
"mouseReleased" are two event types in ADML, as are all of the other
method names from the java.awt.event.MouseListener interface.
______________________________________
Using the <LAYOUT> Tag In general, a LayoutManager is a helper object that is associated with a Container that tells the container how to arrange its children within its area. Because they are objects, ADML allows them to be created and initialized using the same constructs as other beans 212. They are declared using the LAYOUT tag. The Type attribute 310 is used to identify which layout manager is being created. Like other beans 212, they can be configured using VALUE and INIT tags 314. If no LAYOUT is specified for a CONTAINER, the Container's default layout manager will be used (this will usually be FlowLayout). If LAYOUT is used, a Type should be specified, because it has no default type. Layout Types, like any other types, are specified in the HEAD section of the document. Some examples of the foregoing include:
______________________________________
<TYPE ID="FlowLayout" Tag="LAYOUT"
Class="java.awt.FlowLayout"/>
<TYPE ID="BorderLayout" Tag="LAYOUT"
Class="java.awt.BorderLayout"/>
<TYPE ID="CardLayout" Tag="LAYOUT"
Class="java.awt.CardLayout"/>
<TYPE ID="GridLayout" Tag="LAYOUT"
Class="java.awt.GridLayout"/>
<TYPE ID="GridBagLayout" Tag="LAYOUT"
Class="java.awt.GridBagLayout"/>
______________________________________
To use a declared layout type, its ID should be specified in the LAYOUT tag's Type attribute. For example, to use ADML's layout manager, the RLayout type declared in StandardHeader.ent should be used thus:
______________________________________
<CONTAINER>
<LAYOUT Type="RLayout" />
</CONTAINER>
______________________________________
Using the <POSITION> Tag A POSITION specifies the information, called "constraints", that constraints-based LayoutManagers need for a child of the container in order to know how the child is to be laid out. For example, ADML's built-in layout manager calls for one of three kinds of objects. The most useful one is used to specify relative positioning. Its Type, declared in StandardHeader.ent, is "RPosition". BorderLayout, on the other hand, requires a String. The RPosition type currently only supports the relative positioning portion of BML's built-in layout manager. It implements all of the BML layout attributes except x, y, width and height. RAbsolute and RPreferred are two other less common constraints types accepted by RLayout. If no POSITION tag is specified for a child, it is up to the LayoutManager to determine how to deal with the child. For example, if the RLayout type is used, and no POSITION is given for a child, the child will be stretched to fill the entire container. Because some LayoutManagers use Strings as constraints, String has been set up as the default type for a POSITION (if StandardHeader.ent is used). Therefore, if a POSITION tag with no Type is specified, the parent's LAYOUT should accept Strings for its constraints. Bean Creation Expressions Like Sun's beanbox, BML is limited to using the default constructor for a bean 212. ADML, on the other hand, allows a user to specify an expression for creating the bean 212. This expression can be a call to a non-default constructor (i.e. a constructor with arguments), a "factory" method that produces objects, or a CONSTANT value such as a String or a Color, an ARRAY, or the like. The following example uses a constructor for a JButton that takes a single Icon argument:
__________________________________________________________________________
<COMPONENT Type="BUTTON" ID="HANKBUTTON">
<VALUE>
<REQUEST METHOD="new" OnClass="com.sun.java.swing.JButton">
<ARGUMENTS>
<REQUEST Method="new"OnClass="com.sun.java.swing.ImageIcon">
<ARGUMENTS>
<REQUEST Method="new" OnClass="java.net.URL">
<ARGUMENTS>
<CONSTANT
value="http://users.itsnet.com/.about.hank/images/hank.gif"/>
</ARGUMENTS>
</REQUEST>
</ARGUMENTS>
</REQUEST>
</ARGUMENTS>
</REQUEST>
</VALUE>
</COMPONENT>
__________________________________________________________________________
The Method="new" tells the runtime to call a constructor. A Bean creation expression can be specified as part of a TYPE. The following example creates a type called SpecialButton. Components 212 of that type will be buttons that contain the text, "Click Me!". It calls the constructor for JButton that takes a single String argument.
______________________________________
<TYPE ID="SpecialButton" Tag="COMPONENT" Class=
"com.sun.java.swing.JButton">
<VALUE>
<REQUEST Method="new" OnClass="com.sun.java.swing.JButton">
<ARGUMENTS Classes="java.lang.String">
<CONSTANT Value="Click Me!"/>
</ARGUMENTS>
</REQUEST>
</VALUE>
</TYPE>
______________________________________
Expression Handling Tags in BML and ADML Table 1 provides a summary of expression handling tags in both BML and ADML.
TABLE 1
__________________________________________________________________________
PURPOSE In BML In ADML
__________________________________________________________________________
Calling a function on an object
<FUNCTION <REQUEST
when a value is called for, and
Selector="methodName"
Method="methodName"
passing in a single literal value
Target="SomeObject"
On="SomeObject">
Param="someValue"/>
<ARGUMENTS>
<CONSTANT Value=
"someValue"/>
</ARGUMENTS>
</REQUEST>
Calling a function on an object
<FUNCTION <REQUEST
when a value is called for, and
Selector="methodName"
Method="methodName"
passing in multiple arguments
Target="SomeObject">
On="SomeObject">
- parameter <ARGUMENTS>
expression goes
- parameter <!
here --> expression goes
- parameter here -->
expression goes
- parameter <!
here --> expression goes
- parameter here -->
expression goes
- parameter <!
here --> expression goes
</FUNCTION> here -->
</ARGUMENTS>
</REQUEST>
Calling a function on an object
<FUNCTION <REQUEST
when a value is called for, and
Selector="methodName"
Method="methodName"
passing in a reference to another
Target="SomeObject"
On="SomeObject">
object Param= ".sub.-- SOMEOBJECTNAME"
<ARGUMENTS>
/> <CONSTANT IDRef=
"SOMEOBJECTNAME"
/>
</ARGUMENTS>
</REQUEST>
Calling a static function on a class
<FUNCTION Selector=
<REQUEST Method=
when a value is called for
"staticMethodName"
"staticMethodName"
Target= OnClass="some.package.So
"some.package.SomeClass"
meClass" />
/>
Calling a constructor on a class
<FUNCTION Selector=
<REQUEST Method="new"
when a value is called for
"SomeClass" Target=
OnClass="some.package.So
"some.package.SomeClass"
meClass" />
/>
Getting a bean property when a
<FUNCTION Selector=
<GET Name="property"
value is called for
"property" Target=
On="SomeBean" />
"SomeBean" />
Getting a field when a value is
<FUNCTION <GET Name="field"
called for Selector="field"
On="SomeObject" />
Target="SomeObject" />
Getting a static field, such as a
<FUNCTION <GET Name="ACONSTANT"
constant, when a value is called for
Selector="ACONSTANT"
OnClass="some.package.So
Target= meClass" />
"some.package.SomeClass"
/>
Calling a function on an object
<FUNCTION Selector=
<REQUEST Method=
returned by another expression
"methodOnResultObject">
"methodOnResultObject">
when a value is called for
<TARGET Selector=
<ON>
"methodThatReturns
<REQUEST Method=
Object" "methodThatReturns
Target="SomeObject
Object"
" /> On="SomeObject" />
</FUNCTION> </ON>
</REQUEST>
Specifying a simple literal value
<PARAM Value= "AValue"/>
<CONSTANT Value=
when a value is called for "AValue" />
Specifying a simple reference to
<PARAM Value= <CONSTANT IDRef=
another object when a value is
".sub.-- SomeObject"/>
"SomeObject"/>
called for
Calling a function on an object
(same as FUNCTION but with an
(same as REQUEST but with a
when an action is called for
ACTION tag) CALL tag)
Setting a bean property with a
<ACTION <SET Name="property"
simple value when an action is
Selector="property"
Value= "someValue"
called for Target="SomeBean"
On="SomeBean"/>
param="someValue" />
Setting a bean property with an
<ACTION <SET Name="property"
expression when an action is called
Selector="property"
On="SomeBean">
for Target="SomeBean">
<VALUE>
- some expression<!
- some expression<!
goes here --> goes here -->
</ACTION> </VALUE>
</SET>
Setting a field value when an action
<ACTION Selector="field"
<SET Name="field" Value=
is called for Target="SomeObject"
"someValue"
param="someValue" />
On="SomeObject"/>
__________________________________________________________________________
Text Constructs in ADML Part of the ADML design is to allow text to be embedded within beans 212 and beans 212 within text and to allow both to interact with each other through ADML events. The text features center around three tags defined in the ADML DTD: TEXT, P, and STYLE. The TEXT tag is a tag 314 from the <COMPONENT>, <CONTAINNER> <BEAN> family of components 212. It resembles them in most respects in that it can generate events, be laid out within its parent with POSITION constraints, etc. The ADML event types available for the TEXT component 212 are the names of all the methods of all the listeners capable of being registered with a JTextComponent. A TEXT tag should not be empty because it contains at least one paragraph. A Paragraph is defined by the P tag 314. The paragraph can contain text, beans 212, and STYLE tags 314 that in turn contain more text and beans 212. It has certain bean 212 properties that correspond to paragraph attributes. In one embodiment, paragraphs do not have an INIT section, so these properties 320 should be set inside of the INIT section for the paragraph's type. Examples of text properties 320 are shown below in Table 2.
TABLE 2
______________________________________
property name values
______________________________________
alignment LEFT
CENTER
RIGHT
JUSTIFIED
lineSpacing float (points)
spaceAbove float (points)
spaceBelow float (points)
leftIndent float (points)
rightIndent float (points)
firstLineIndent float (points)
______________________________________
Additionally, any properties from STYLE are available to paragraphs. For example, to make a paragraph that contains red, centered text, with 1/2 inch left and right indents, a paragraph type is initially made that declares these properties as shown below:
______________________________________
<TYPE ID="CENTEREDRED" Type="P">
<INIT>
<SET Name="alignment" Value="CENTER"/>
<SET Name="leftIndent" Value="36.0"/>
<SET Name="rightIndent" Value="36.0"/>
</INIT>
</TYPE>
______________________________________
Thereafter, the paragraph of that type is declared:
______________________________________
<P Type="CENTEREDRED">
This is centered text!
</P>
______________________________________
Styles A Style is defined by the STYLE tag. The paragraph can contain text and beans 212. It has certain bean properties 320 that correspond to text attributes 310. In one embodiment, since styles cannot have an INIT section, these properties should be set inside of the INIT section for the style's type. An exemplary list of the style properties 320 is provided below in Table 3.
TABLE 3
______________________________________
property name
values
______________________________________
text the text inside that style block. Can be used to change
the text within that block dynamically.
font a font string of the form accepted by Font.decode().
fontFamily
string of the type returned by Font.getFamily().
fontSize int (points)
bold true or false
italic true or false
underline true or false
foreground
a color string of the form #rrggbb
______________________________________
For example, to make a style for large, green text, a style type that declares these properties 320 is shown below:
______________________________________
<TYPE ID="BIGGREEN" Type="Normal">
<INIT>
<SET Name="foreground" Value="&LeafGreen;"/>
<SET Name="font" Value="TimesRoman-bold-72"/>
</INIT>
</TYPE>
______________________________________
Thereafter, a style may be declared of that type:
______________________________________
<STYLE Type="BIGGREEN">
This is big, green and ugly text!
</STYLE>
______________________________________
Hypertext Events There are three special event types defined for styles related to hypertext. These event types include: hyperlinkActivated--called when text within that style block is clicked, hyperlinkEntered--called when mouse enters that style block, and hyperlinkexited--called when mouse exits that style block. Such event types can be used to create hypertext links. To create a hypertext link that is normally blue and underlined, but turns red when the mouse is over it, a style is first declared that is underlined and blue:
______________________________________
<TYPE ID="LINK" Type="Normal">
<INIT>
<SET Name="foreground" Value="#0000FF"/>
<SET Name="underline" Value="true"/>
</INIT>
</TYPE>
______________________________________
Thereafter, a text block is created with a style of that type, along with some EVENT tags:
______________________________________
<STYLE Type="LINK">
<EVENT Type="hyperlinkActivated">
<SET Name="text" Value="Hey, you clicked me!"/>
</EVENT>
<EVENT Type="hyperlinkEntered">
<SET Name="foreground" Value="#FF0000"/>
</EVENT>
<EVENT Type="hyperlinkExited">
<SET Name="foreground" Value="#0000FF"/>
</EVENT>
Click me!
</STYLE>
______________________________________
Although the foregoing provides a number of specific embodiments of an application description language (ADL), one skilled in the art will recognize that a variety of ADLs may be used within the scope of the present invention. Thus, the specific syntax of the ADL is not crucial and may vary without departing from the spirit of the invention. Method of Operation Referring now to FIG. 4A there is shown a high-level flow diagram for a method of creating and configuring a component-based application in accordance with a preferred embodiment of the present invention. The method begins by creating 402 the XML parse tree 204. Preferably, a conventional parser 116 is used to parse the ADF 202, as illustrated in FIG. 3A. Thereafter, the method continues by transforming 404 the parse tree 204 into uninitialized components 212. This step will be described in greater detail below with reference to FIG. 4B. Nevertheless, as noted above, each element 306 in the parse tree 204 is mapped to a corresponding target class 132, after which an uninitialized component 212 is instantiated. In addition, each attribute 310 of the element 306 is mapped to a corresponding property 320 of the component 212 by the attribute mapper 124. The method continues by processing 406 the components 212 to launch the component-based application 214. This step will be described in greater detail with respect to FIG. 4D. Nevertheless, in one embodiment, this is accomplished by initializing each of the components 212 and adding each child component 212 to its parent component 212. Referring now to FIG. 4B, there is shown a method of transforming the elements 204 of the parse tree 204 into uninitialized components 212 in accordance with a preferred embodiment of the present invention. As noted above, this is accomplished by recursively descending the parse tree 204 and creating an element processor 118 for each elements 306. Preferably, the parse tree 204 is traversed using a post-order recursive traversal algorithm, such that each child component 212 is created before its parent component 212. In one embodiment, the nodes of the parse tree 204 other than elements 306 are either ignored (in the case of comments 302 and processing instructions 304) or are processed appropriately (in the case of data 308). Starting with the root element 306 of the parse tree 204, the method begins by mapping 408 the element 306 to a target class 132. Preferably, an element mapper 112 is provided, which is an object used to map the string tag 314 of an element 314 with the corresponding element processor 118 and Java component class 132. In one embodiment, the element mapper 122 is implemented by an ElementTagManagerIntf instance, the public interface of which is provided below in Java pseudo-code:
______________________________________
public interface ElementTagManagerIntf {
// tells the manager to map theElementTag to the
// processor with the class name, theProcessorClassName
public void addProcessorTag(String theElementTag,
String theProcessorClassName);
// tells the manager to map theElementTag to the same
// element processor as used by theDefaultElementTag but
// to instantiate an instance of theJavaClassName instead
public void addComponentClassTag(String theElementTag,
String theDefaultElementTag,
String theJavaClassName);
// creates and returns the correct element processor
// instance for the given element tag. Sets up this
// processor to create a java instance of the correct
// class
public ElementProcessorIntf
createComponentProcessorForTag(String theElementTag);
______________________________________
The mapping information is preferably provided to the ElementTagManagerIntf instance 122 at runtime through the call, addProcessorTag(String theElementTag,String theProcessorClassName). This call dynamically associates the given element string tag 314 with the specific element processor class 132 name. In one embodiment, a single global instance 122 of ElementTagManagerIntf is used. However, one skilled in the art will recognize that several such ElementTagManagerIntf instances 122 could be used, depending on the requirements of a particular application 214. Following step 408, a determination 410 is made whether the element 306 was successfully mapped to a class 132. If not, an error message is generated 412, and the method is complete. Otherwise, the method continues by creating 414 the element processor 118 for the particular class 132. In one embodiment, the element processor 118 implements the Java interface, ElementProcessorIntf, an example of which provided below in Java pseudo-code:
______________________________________
public interface ElementProcessorIntf {
// instructs the given processor to handle the parse tree rooted at
// theElement and add the resulting component to
theContainerComponent
public void processElement(ElementIntf theElement,
Object theContainerComponent,
ElementTagManagerIntf theElementTagManager);
// instructs the given processor to construct an instance of the given
// java class and not its default class
public void setComponentClass(String theJavaClassName);
______________________________________
In one embodiment, a different element processor 118 is used for each distinct element tag 314. Alternatively, only a few "core" element processors 118 are used. In that case, instead of registering separate element processors 118 for every element tag 314, only the basic core element tags 314 have distinct element processors 118. Other element tags 314 simply reuse one of the core processors 118, but override the default component class 132 with their particular target class 132. In one embodiment, the target class 132 for a given element tag 314 can be specified in one of three ways: 1. Each element processor 118 has a "default" target class 132 associated with it. Unless otherwise overridden, an element tag 314 which makes use of this element processor 118 will create an instance of the given target class 132. 2. The target class 132 associated with a given element tag 314 may be "globally" overridden through the ElementTagManagerIntf method, addComponentClassTag(String theElementTag, String theDefaultElementTag, String theJavaClassName). This call specifies that the element processor 118 already registered with theDefaultElementTag should also be used with theElementTag but that instead of creating an instance of the default target class 132 for that processor 118, an instance is of theJavaClassName should be created instead. 3. In one embodiment, it is also possible to locally "override" a processor's target class 132 through a special markup attribute 310, Class. The value of the Class attribute 310 is expected to be the fully qualified name of a target class 132 which can be created and used by the given element processor 118 for a specific element 306 instance. In one embodiment built upon the Java programming language, the element processor 118 expects the value of the Class attribute 310 to be the fully qualified name of an accessible Java class 132 (what constitutes a valid, accessible Java class 132 will depend on the end-user's system and network environment as well as the other resources provided by the application 214). When the element processor 118 finds the Class attribute 310 declaration in a particular element 306 declaration, it is instructed to create and use the specified Java class 132 instead of the Java class 132 normally registered for that element 306. For example, in one embodiment, the following element 306 declaration instantiates an instance of the class 132, "my.SpecialClass", rather than the default class 132 specified for the given element processor 118: <Foo Class=my.SpecialClass Att1=Value1Att2=Value2> For the root element 306 of the parse tree 204, a top-level element processor 118 is preferably created. As explained in greater detail below, the top-level processor 118 is used to create a root component 212. In one embodiment, the root component 212 manages the "event loop" of application 214 and thus receives update and user event messages generated by the platform-specific operating system 128. One skilled in the art will recognize that the above-mentioned process is only one embodiment of the present invention, other variations are possible and may be advantageous under certain circumstances. For example, instead of using intermediary element processors 118, a variation could create Java components 212 directly and expect each component 212 to implement its own "processing" logic. After the element processor 118 is created, it instantiates 416 an uninitialized component 212, which is preferably a default instance of the associated Java class 132. Alternatively, the component 212 may be created in a non-default way, if so specified in special attributes 310 or child elements 306 dedicated to that purpose. After the component 212 has been instantiated, the element processor 118 maps 418 each attribute 310 in the attribute list 312 to a corresponding property 320 in the component 212. In one embodiment, the element processor 118 uses an attribute mapper 124 for this purpose. A detailed explanation of this process is provided below. Preferably, each element processor 118 is free to treat attribute 310 declarations in its own manner. A given element processor 118, for example, may choose to ignore certain attributes 310 or use specified attribute values in non-conventional ways. However, the default, "core" element processors 118 used in one embodiment of the invention treat the attribute lists 310 in a simple, canonical manner as defined hereafter. The element processors 118 expect the target component 212 to provide an exact description of its publicly accessible methods and properties 320 such that string-based attribute keys can be mapped to executable "mutator" and "accessor" methods on the target component 212. In one embodiment, this information is obtained through an attribute mapper 124, such as the BeanInfo instance as defined by Sun's JavaBeans specifications. The BeanInfo object 124 is used to map attribute 310 names to corresponding properties 320 in the underlying component 212. If the present invention is implemented in a different object-oriented languages such as Smalltalk or C++, analogous metadata frameworks could be used. As defined by the JavaBeans specification, each BeanInfo instance 124 may describe all its publicly accessible properties through an array of PropertyDescriptor instances 502, which are illustrated in FIG. 5. Each PropertyDescriptor instance 502 supplies a method, getDisplayName(), which returns the localized, display name for the given property 320, as well as a set of accessor and mutator methods (referred to herein as "write methods" 504) to be used in obtaining and setting the value of the property 320 in the component 212. Referring now to FIG. 4C, there is shown a flow diagram for a method of mapping element attributes 310 to component properties 320. The method begins by selecting 420 the next attribute 310 in the attribute list 312. Thereafter, the element processor 118 searches 422 the given BeanInfo instance 124 for a PropertyDescriptor instance 502 whose display name matches the given attribute 310 name on a case-insensitive basis. A determination 424 is then made whether a match was found. If a match is found, the write method 504 of the property 320 is obtained 428 through a getWriteMethod() call, and the method continues at step 430. If a match is not found, or if the property is hidden (i.e. PropertyDescriptor's isHidden() message returns a "true" value), an exception is generated 426 and the attribute 310 is ignored. If a valid write method 504 is obtained, the element processor 118 continues by checking 430 the expected parameters of the write method 504 against the string value of the attribute 310. A determination 432 then is made whether the attribute 230 value needs to be converted. If conversion is necessary, the method proceeds to step 434; otherwise, the method continues with step 436. In one embodiment, the element processors 118 use a parameter converter 126 for converting string values into a variety of basic data types, such as integers, doubles, dates, booleans, and the like. Methods for such type conversions are well known to those skilled in the art. Additionally, the parameter converter 126 may convert string-based component references into the corresponding component 212 instances. For example, in one embodiment, a set of canonical object names may be used anywhere within a scoped name path. These canonical object names include:
______________________________________
.sub.-- SELF which resolves to the current base target component 212;
.sub.-- PARENT which resolves to the parent container of the current
base
target component 212;
.sub.-- TOP which resolves to the top-level visual parent of the current
base
target component 212 (i.e. the visual container parent which itself has
no
visible parent);
.sub.-- PREV which resolves to the previous child component 212 in the
same
parent container as the current base target component 212;
.sub.-- NEXT which resolves to the next child component 212 in the same
parent container as the current base target component 212;
.sub.-- PAGE which resolves to the root component 212 corresponding to
the
root element 306 in which the caller is embedded;
.sub.-- APP which resolves to the current application 214
______________________________________
instance.
A number of other naming conventions may be provided within the scope of the present invention. If conversion is necessary, the attribute 320 string values are converted 434 by means of the parameter converter 126. A determination 438 is then made whether the conversion was successful. If so, the method proceeds to step 436; otherwise, control passes to step 426, wherein an exception is generated 426 and the attribute 310 is ignored. After the attribute is converted, or if no conversion is necessary, the write method 504 is executed 436 with the attribute 310 value being passed as a parameter. Thereafter, a determination 440 is made whether more attributes 310 in the element 306 remain to be mapped to the component 212. If more attributes 310 remain, the method returns to step 420 to select the next attribute; otherwise, the method is complete. As will be apparent from the foregoing discussion, for each attribute 310 in a given element 306, the element processor 118 set the properties 320 of the target component 212. An example of this process in Java pseudo-code is provided below:
______________________________________
public void handleAttributes(ElementIntf theElement,
Object theComponent) {
BeanInfo aBeanInfo = getBeanInfo(theComponent);
For each attribute in element {
// find property, if any, that matches attribute name
PropertyDescriptor aProperty =getProperty(anAttributeName,
aBeanInfo);
// if writable, set component attribute
if (aProperty.hasWriteMethod()) {
setProperty(theComponent, aProperty, anAttributeValue);
}
}
______________________________________
The setProperty() pseudo-method identified above takes a component object 212, a property 320, and a value, and attempts to call the property's write method 504, converting the value(s) to the correct data type(s), as follows:
______________________________________
protected void setProperty(Object theComponent,
PropertyDescriptor theProperty,
Object theValue) {
// get write method itself
Method aWriteMethod = theProperty.getWriteMethod();
// get parameter types
Class[] aTypes = aWriteMethod.getParameterTypes();
// convert string value to correct class object
Object[] aParameters = convertParameters (theValue, aTypes);
// invoke method
aWriteMethod(theComponent, aParameters);
______________________________________
In one embodiment, execution of the method is performed using the standard reflection functionality built into Java as of version 1.1 as specified by Sun Microsystems. Preferably, the element processors 118 expect all information about the underlying component 212 to be provided explicitly by the BeanInfo instance 124. Alternatively, runtime introspection could be used. One skilled in the art will recognize, however, that a variety of other element mappers 124 may be used within the scope of the present invention, and a Beaninfo instance 124 may be optional or unnecessary. Referring again to FIG. 4B, after all of the attributes 310 in the attribute list 312 are mapped, a determination 416 is made whether an exception was signaled as a result of extraneous attributes 310, or whether any required attributes 310 were missing from the element 306. If either case is true, an error message is generated 412 and the method is complete. Referring now to FIG. 4D, there is shown a method of processing 406 the components 212 to launch the component-based application 214 in accordance with a preferred embodiment of the present invention. Preferably, an object graph 318 including a plurality of components 212 was created in step 404. Starting with the root component 212, the associated element processor 118 is invoked, which applies 450 any specified initial properties 320 to the component 212. In one embodiment, such properties 320 may be specified in an <INIT> section of the corresponding element 306. Thereafter, the element processor 118 calls 452 any initialization method for the current component 212. In one embodiment, the initialization method may be specified in an <INIT> section of the corresponding element 306. Alternatively, a default method, such as init(), may be used, as in the standard Java Applet class. After the component 212 is initialized, the method continues by invoking the element processors 118 associated with any child elements, and instructing the element processors 118 to recursively perform each of the steps 450-460 of the current method. Because the initialization step 452 is performed using pre-order recursion, parent components 212 are initialized before their child components 212. When a component 212 without children (a leaf component 212) is encountered, the method continues by determining 456 whether the parent component 212 is of the appropriate type to have child components 212 (i.e., it is a "container element"). This will depend on the underlying specification of the component 212 within the framework 130. If the component cannot have children, an error is generated 458. If, however, the component is a container element, the method continues by adding 460 the child component 212 to the parent component 212. After either step 460 or 458, control is returned to the parent element processor 118. When complete, all child components 212 are added to their parents 212, from the bottom of the object graph 318, upwards. In one embodiment of the invention, after all of the components 212 have been processed, the init() and start() methods of the root component 212 are invoked in order to begin actual execution of the application 214. Preferably, the root component 212 implements the interface, MinAppIntf which is the minimal interface that is expected for any root-level component 212 to implement in order to be correctly instantiated and launched. In one embodiment, the MinAppIntf's interface is patterned after Java's standard Applet class. An example of the interface is provided below in Java pseudo-code:
______________________________________
public interface MinAppIntf {
// sets this application's top-level main window instance
public void setWindow(MainWindowIntf theWindow);
// gives application chance to setup any initial state
public void init();
// tells application to start execution. This method should not
// block. Event loop will be controlled externally by main window
public void start();
______________________________________
The MinAppIntf also specifies a setWindow(MainWindowIntf theWindow) method which is used to set the underlying window instance. In one embodiment, each application has one and only one top-level main window. The top-level main window may be platform-specific (i.e. Windows 95, Macintosh, etc.). It manages the application's "event loop" and thus receives update and user event messages generated by the platform-specific operating system. A given application may have an unlimited number of "child" windows. The application's main window is set prior to the init() sequence described above. The application's main window is responsible for communicating user and "paint" events to the application through its handleEvent(Event e) call. Finally, the window should be capable of supplying a graphics context on which the application's visible surface may be painted. The root component 212 class uses the start() method within the current processor 104 thread to launch the application 214 itself. After the start() call is made and finishes, the control passes to the created application 214. The above description is included to illustrate the operation of the preferred embodiments and is not meant to limit the scope of the invention. The scope of the invention is to be limited only by the following claims. From the above discussion, many variations will be apparent to one skilled in the art that would yet be encompassed by the spirit and scope of the present invention. ##SPC1##
|
Same subclass Same class Consider this |
||||||||||
