JonFerraiolo 20090522
From MemberWiki
This wiki page holds a portion of the latest internal editorial draft for what ultimately will become the OpenAjax Metadata 1.0 Specification. The base wiki page for this (latest) version of the draft specification is at /member/wiki/OpenAjax_Metadata_Specification. Here are the IDE WG's rules for editing this specification:
- The current working text for the specification has normal text properties (i.e., black)
- Open issues that require WG discussion are highlighted with red text
- Notes to the editor about necessary minor editorial changes are highlighted with purple text
- Sections whose text has gone through final review and have been approved will show the word [Approved] in green
Contents |
Chapter 6: API Metadata
Introduction
This chapter defines the OpenAjax Metadata XML grammar for the runtime JavaScript APIs (e.g., classes and methods) that are available for a given Ajax library.
The following elements are defined in this chapter:
- <alias> (and <aliases>)
- <ancestor> (and <ancestors>)
- <class> (and <classes>)
- <constructor> (and <constructors>)
- <event> (and <events> and <handlerFunction>)
- <exception> (and <exceptions>)
- <globals>
- <interface> (and <interfaces>)
- <method> (and <methods>)
- <mix> (and <mixes>)
- <mixin> (and <mixins>)
- <namespace> (and <namespaces>)
- <parameter> (and <parameters>)
- <returnType> (and <returnTypes>)
- <singleton> (and <singletons>)
The following elements are defined in subsequent chapters:
- <property>
- <description>
- <title>
- <shortDescription>
- <example>
- <remarks>
- <reference>
- <author>
- <license>
- <available>
- <deprecated>
- <useragent>
- <config>
- <enum>
- <option>
Additional information about API Metadata can be found in:
- Localization chapter
- Variable Substitution chapter
<api>
The <api> element is the root element of an OpenAjax Metadata file that defines JavaScript APIs.
An Ajax library may define all of its APIs within a single OpenAjax Metadata file or split the API definitions across multiple OpenAjax Metadata files.
Schema
api_element = element api {
api_content & api_attributes & foreign_nodes
}
api_content = (
descriptive_elements &
class_element* & classes_element* & config_element* & configs_element* &
enum_element* & enums_element* & globals_element* &
interface_element* & interfaces_element* & license_element? & locale_element* &
mixin_element* & mixins_element* & namespace_element* & namespaces_element* &
singleton_element* & singletons_element*
)
api_attributes = (
lang? & language? & spec & version? &
pattern_attributes
)
Child content
The <api> element might contain any of the following sub-elements:
- descriptive_elements (various elements, such as <description> and <example>)
- <class>, <classes>
- <config>, <configs>
- <enum>, <enums>
- <globals>
- <interface>, <interfaces>
- <license>
- <locale>
- <mixin>, <mixins>
- <namespace>, <namespaces>
- <singleton>, <singletons>
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| getterPattern | Name pattern for property getter functions. | String (see below) | no | none |
| lang | Identifies the natural or formal language for the content. Defined in Localization chapter. | |||
| language | Programming language to which the API metadata applies | String (see below) | no | javascript |
| registerCallbackPattern | Name pattern for property setter functions. | String (see below) | no | none |
| setterPattern | Name pattern for property setter functions. | String (see below) | no | none |
| spec | Version number of the OpenAjax Metadata spec to which this metadata file conforms | Version string (see below) | yes | none |
| unregisterCallbackPattern | Name pattern for property setter functions. | String (see below) | no | none |
| version | Version number for the JavaScript APIs that are described by this metadata file | Version string (see below) | no | none |
Attribute details
'language' attribute
The language attribute specifies the programming language for which the API metadata applies. The default is "javascript", which indicates the various versions of the language whose standard is named "ECMAScript" (e.g., ECMA-262).
'getterPattern' attribute
The getterPattern attribute specifies the name or name pattern for property getter functions. This attribute are inheritable in that all descendant <property> elements that do not specify the attribute will inherit this attribute. For additional information, see the write-up on "Pattern attributes".
'registerCallbackPattern' attribute
The registerCallbackPattern and unregisterCallbackPattern attributes apply to the <event> element and specifies the name pattern for the event handler registration and unregistration functions for that event. For more about these attributes, see the write-up on "Pattern attributes".
'setterPattern' attribute
The setterPattern attribute specifies the name or name pattern for property setter functions. This attribute are inheritable in that all descendant <property> elements that do not specify the attribute will inherit this attribute. For additional information, see the write-up on "Pattern attributes".
'spec' attribute
The spec attribute specifies the version number of the OpenAjax Metadata spec to which this metadata file conforms. (See the write-up on Version number attributes for rules on version number attributes.)
'unregisterCallbackPattern' attribute
See 'registerCallbackPattern' attribute
'version' attribute
The version attribute specifies the version number for the JavaScript APIs that are described by this metadata file. (See the write-up on Version number attributes for rules on version number attributes.)
<alias>
The <alias> element can be used to specify an alternate name for an object that a tool might use during content assist. Typically, the alternate name is shorter and/or more understandable that the original name.
Schema
alias_element = element alias {
alias_content & alias_attributes & foreign_attributes
}
alias_content = (
empty
)
alias_attributes = (
name
)
Child content
<alias> must be an empty element (i.e., no child content).
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| name | Name of the alias | String | yes | none |
Attribute details
'name' attribute
The name attribute specifies the name of the alias.
Additional information
Example:
<class name="jQuery"> <alias name="$" /> </class>
<ancestor>
The <ancestor> element specifies (via the datatype attribute) a "superclass" for the current class or interface.
Schema
ancestor_element = element ancestor {
ancestor_content & ancestor_attributes & foreign_attributes
}
ancestor_content = (
empty
)
ancestor_attributes = (
datatype
)
Child content
<ancestor> must be an empty element (i.e., no child content).
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| datatype | Name of an ancestor <class>, <interface>, <mixin> or <singleton>. |
String (see below) | yes | none |
Attribute details
'datatype' attribute
The datatype attribute specifies the name of a <class>, <interface>, <mixin> or <singleton> whose <property>s, <method>s, <event>s, <alias>es, <ancestor>s, <config>s, <constructor>s, <event>s and <mix>es are included within the current class. For additional information, refer the detailed specification for the 'datatype' attribute.
<class>
The <class> element describes a JavaScript class.
Schema
class_element = element class {
class_content & class_attributes & foreign_nodes
}
class_content = (
descriptive_elements & compatibility_elements &
alias_element* & aliases_element* & ancestor_element* & ancestors_element* &
config_element* & configs_element* & constructor_element* & constructors_element* &
event_element* & events_element* & mix_element* & mixes_element* &
method_element* & methods_element* & property_element* & properties_element*
)
class_attributes = (
name & visibility? &
pattern_attributes & registerCallbackPattern? & unregisterCallbackPattern?
)
Child content
The <class> element might contain any of the following sub-elements:
- descriptive_elements (various elements, such as <description> and <example>)
- compatibility_elements (various elements, such as <available> and
<deprecated>) - <alias>, <aliases>
- <ancestor>, <ancestors>
- <config>, <configs>
- <constructor>, <constructors>
- <event>, <events>
- <mix>, <mixes>
- <method>, <methods>
- <property>, <properties>
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| getterPattern | Name pattern for property getter functions. | String (see below) | no | none |
| name | Absolute object name using JavaScript dot notation for the class. | String (see below) | yes | none |
| registerCallbackPattern | Specifies the name pattern for the event handler registration function. | String (see below) | no | none |
| setterPattern | Name pattern for property setter functions. | String (see below) | no | none |
| unregisterCallbackPattern | Specifies the name pattern for the event handler unregistration function. | String (see below) | no | none |
| visibility | Intended visibility of this class to other parts of the JavaScript application. | public|private|protected|internal|protected-internal | no | public |
Attribute details
'getterPattern' attribute
The getterPattern attribute specifies the name or name pattern for property getter functions. This attribute are inheritable in that all descendant <property> elements that do not specify the attribute will inherit this attribute. For additional information, see the write-up on "Pattern attributes".
'name' attribute
The name attribute specifies the absolute object name using JavaScript dot notation for the class, such as "FooToolkit.io.httpreq" (where the Foo toolkit has a main global object called "FooToolkit", a subobject "io", with subobject "httpreq" which is set up as a JavaScript class (i.e., has an appropriate constructor function).
'registerCallbackPattern' attribute
The registerCallbackPattern and unregisterCallbackPattern attributes apply to the <event> element and specifies the name pattern for the event handler registration and unregistration functions for that event. For more about these attributes, see the write-up on "Pattern attributes".
'setterPattern' attribute
The setterPattern attribute specifies the name or name pattern for property setter functions. This attribute are inheritable in that all descendant <property> elements that do not specify the attribute will inherit this attribute. For additional information, see the write-up on "Pattern attributes".
'unregisterCallbackPattern' attribute
See 'registerCallbackPattern' attribute
'visibility' attribute
The visibility attribute specifies the intended visibility of this class to other parts of the JavaScript application. Its value can be any of the following access modifiers:
-
publicindicates that the given feature is intended to be available to any code within the application. (This is the default.) -
privateindicates that the given feature is intended to be available only within the class or interface itself. Private features are not intended to be available to derived classes. -
protectedindicates that the given feature is intended to be available only within the class itself and to derived classes. -
internalindicates that the given feature is intended to be public within the class's top-level namespace, but private to JavaScript logic outside of the top-level namespace. (For the purposes of this attribute, if a class has the name "aaa.bbb.ccc", then "aaa" and "aaa.bbb" are considered namespaces, and "aaa" is the top-level namespace.) -
protected-internalindicates that access to the given feature is the union of the access granted byprotectedand the access granted byinternal.
<constructor>
The <constructor> element describes a constructor method. A constructor can be described by multiple<constructor> elements, in which case the different <constructor> elements can be used to specify different parameter and return value alternatives.
In most usage scenarios, constructors will return an Object that is an instance of the constructor's class. However, because of the possibility that a programmer might have leveraged JavaScript's flexibility to return a different value from the constructor, it is usually necessary that the <constructor> element specifies its return type explicitly. For example, suppose you have a class MyClass with a single constructor function that returns an Object of type MyClass. The metadata might look as follows (note the presence of the <returnType> element):
<class name="MyClass">
<constructor>
<!-- not shown: constructor parameters, description, etc. -->
<returnType datatype="MyClass"/>
</constructor>
</class>
Schema
constructor_element = element constructor {
constructor_content & constructor_attributes & foreign_nodes
}
constructor_content = (
descriptive_elements & compatibility_elements &
exception_element* & exceptions_element* & parameter_element* & parameters_element* &
returnType_element* & returnTypes_element*
)
constructor_attributes = (
visibility?
)
Child content
The <ancestor> might contain any of the following sub-elements:
- descriptive_elements (various elements, such as <description> and <example>)
- compatibility_elements (various elements, such as <available> and
<deprecated>) - <exception>, <exceptions>
- <parameter>, <parameters>
- <returnType>, <returnTypes>
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| visibility | Intended visibility of this constructor to other parts of the JavaScript application. | public|private|protected|internal|protected-internal | no | public |
'visibility' attribute
The visibility attribute specifies the intended visibility of this constructor
to other parts of the JavaScript application.
See visibility attribute for the <class> element.
Additional information
Example:
<class name="jQuery">
<constructor>
<shortDescription>This function accepts a string containing a CSS selector which is then used to match
a set of elements.</shortDescription>
<description>
The core functionality of jQuery centers around this function. Everything in jQuery is based
upon this, or uses this in some way. The most basic use of this function is to pass in an expression
(usually consisting of CSS), which then finds all matching elements.
By default, if no context is specified, $() looks for DOM elements within the context of the current HTML
document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched
against the contents of that context.
See <a href='Selectors'>Selectors</a> for the allowed CSS syntax for expressions.
</description>
<!-- parameters here -->
<returnType datatype="jQuery"/>
<!-- examples here -->
</constructor>
<!-- more constructors here -->
</class>
<event>
The <event> element is used to describe various aspects for library-specific events, such as the naming pattern used by the library for functions to register and unregister event handlers.
Schema
event_element = element event {
event_content & event_attributes & foreign_nodes
}
event_content = (
descriptive_elements & compatibility_elements &
handlerFunction_element?
)
event_attributes = (
name & registerCallbackPattern? & unregisterCallbackPattern? & visibility?
)
Child content
The <event> element might contain any of the following sub-elements:
- descriptive_elements (various elements, such as <description> and <example>)
- compatibility_elements (various elements, such as <available> and
<deprecated>) - <handlerFunction>
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| name | Name of the event. | String (see below) | yes | none |
| registerCallbackPattern | Specifies the name pattern for the event handler registration function. | String (see below) | no | none |
| unregisterCallbackPattern | Specifies the name pattern for the event handler unregistration function. | String (see below) | no | none |
'name' attribute
The name attribute specifies the name of the event.
'registerCallbackPattern' attribute
The registerCallbackPattern and unregisterCallbackPattern attributes apply to the <event> element and specifies the name pattern for the event handler registration and unregistration functions for that event. For more about these attributes, see the write-up on "Pattern attributes".
'unregisterCallbackPattern' attribute
See 'registerCallbackPattern' attribute
<exception>
The <exception> element describes an exception that a JavaScript function might throw.
Schema
exception_element = element exception {
exception_content & exception_attributes & foreign_nodes
}
exception_content = (
descriptive_elements & compatibility_elements &
parameter_element* & parameters_element* & property_element* & properties_element* &
returnType_element* & returnTypes_element*
)
exception_attributes = (
datatype?
)
Child content
The <exception> element might contain any of the following sub-elements:
- descriptive_elements (various elements, such as <description> and <example>)
- compatibility_elements (various elements, such as <available> and
<deprecated>) - <parameter>, <parameters>
- <property>, <properties>
- <returnType>, <returnTypes>
Attribute summary
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| datatype | Class name for the exception object | String (see below) | no | Error |
Attribute details
'datatype' attribute
The datatype attribute specifies the class name for the exception object. See the Datatypes chapter for the detailed definition of this attribute.
Additional information
2009-02-24: Make sure the spec is clear that child <parameter> elements only apply when datatype="Function" and that child <property> elements only apply when datatype="Object". 2009-05-21: Default to 'Error'?
<globals>
The <globals> element describes properties and methods that are global to the JavaScript runtime environment (i.e., available directly from the JavaScript window object) and therefore not contained inside of a particular namespace or class.
Schema
globals_element = element globals {
globals_content & globals_attributes & foreign_nodes
}
globals_content = (
property_element* & properties_element* & method_element* & methods_element*
)
globals_attributes = (
pattern_attributes
)
Child content
The <globals> element might contain any of the following sub-elements:
Attribute summary
| getterPattern | Name pattern for property getter functions. | String (see below) | no | none |
| registerCallbackPattern | Specifies the name pattern for the event handler registration function. | String (see below) | no | none |
| setterPattern | Name pattern for property setter functions. | String (see below) | no | none |
| unregisterCallbackPattern | Specifies the name pattern for the event handler unregistration function. | String (see below) | no | none |
Attribute details
'getterPattern' attribute
The getterPattern attribute specifies the name or name pattern for property getter functions. This attribute are inheritable in that all descendant <property> elements that do not specify the attribute will inherit this attribute. For additional information, see the write-up on "Pattern attributes".
'registerCallbackPattern' attribute
The registerCallbackPattern and unregisterCallbackPattern attributes apply to the <event> element and specifies the name pattern for the event handler registration and unregistration functions for that event. For more about these attributes, see the write-up on "Pattern attributes".
'setterPattern' attribute
The setterPattern attribute specifies the name or name pattern for property setter functions. This attribute are inheritable in that all descendant <property> elements that do not specify the attribute will inherit this attribute. For additional information, see the write-up on "Pattern attributes".
'unregisterCallbackPattern' attribute
See 'registerCallbackPattern' attribute
<handlerFunction>
The <handlerFunction> element is an optional child element to the <event> element that can be used to describe the naming pattern for the function that registers an event handler for this event and to describe the parameters to the event handler function. For example:
handlerFunction_element = element handlerFunction {
handlerFunction_content & handlerFunction_attributes & foreign_nodes
}
handlerFunction_content = (
descriptive_elements & compatibility_elements &
exception_element* & exceptions_element* & parameter_element* & parameters_element* &
returnType_element* & returnTypes_element*
)
handlerFunction_attributes = (
registerCallbackPattern? & unregisterCallbackPattern?
)
The <handlerFunction> might contain any of the following sub-elements:
- descriptive_elements (various elements, such as <description> and <example>)
- compatibility_elements (various elements, such as <available> and
<deprecated>) - <exception>, <exceptions>
- <parameter>, <parameters>
- <returnType>, <returnTypes>
The following table summarizes the attributes:
| Attribute | Description | Type | Required | Default |
|---|---|---|---|---|
| registerCallbackPattern | Naming pattern for the function that registers an event handler. | String (see below) | no | none |
| unregisterCallbackPattern | Naming pattern for the function that unregisters an event handler. | String (see below) | no | none |
Here is an example:
<event name="locationChange">
<handlerFunction registerCallbackPattern="{{event}}Handler({{callback}})">
<parameter name="lat" datatype="Number"/>
<parameter name="long" datatype="Number"/>
</handlerFunction>
</event>
In the above example, the function to register an event handler is named locationChangeHandler that takes a single parameter, which is the callback function. The event handler function will be passed two parameters, both of which are Number values.
<interface>
interface_element = element interface {
interface_content & interface_attributes & foreign_nodes
}
interface_content = (
descriptive_elements & compatibility_elements &
ancestor_element* & ancestors_element* & config_element* & configs_element* &
constructor_element* & constructors_element* & event_element* & events_element* &
mix_element* & mixes_element* & method_element* & methods_element* &
property_element* & properties_element*
)
interface_attributes = (
name & visibility? &
pattern_attributes & registerCallbackPattern? & unregisterCallbackPattern?
)
The <interface> element describes a logical group of JavaScript features (e.g., methods and properties) that are used as a superclass by other classes or interfaces. Typically, <interface> elements are referenced by <ancestor> elements.
As shown in the Compact RelaxNG schema snippet above, the <interface> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The name attribute specifies the absolute object name using JavaScript dot notation for the class, such as "FooToolkit.io.httpreq" (where the Foo toolkit has a main global object called "FooToolkit", a subobject "io", with subobject "httpreq" which is set up as a JavaScript class (i.e., has an appropriate constructor function).
The visibility attribute specifies the intended visibility of this interface to other parts of the JavaScript application. Its value can be any of the following access modifiers: public|private|protected|internal|protected-internal. For descriptions of these access modifiers, refer to the description of the visibility attribute for the <class> element.
The getterPattern and setterPattern attributes specify the name or name pattern for property getter and setter functions. Both attributes are inheritable in that all descendant <property> elements that do not specify the attribute will inherit these attributes. For more about these attributes, see the write-up on "Pattern attributes".
<method>
method_element = element method {
method_content & method_attributes & foreign_nodes
}
method_content = (
descriptive_elements & compatibility_elements &
exception_element* & exceptions_element* & parameter_element* & parameters_element* &
returnType_element* & returnTypes_element*
)
method_attributes = (
name & scope? & visibility?
)
The <method> element describes a JavaScript function that is not used as a constructor.
As shown in the Compact RelaxNG schema snippet above, the <method> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The name attribute specifies JavaScript name for this function.
The scope attribute can have values instance or static. A value of instance indicates that this class method is available only after an instance of this class has been created. A value of static indicates that this class method belongs to the class itself (i.e., does not require object instantiation).
The visibility attribute specifies the intended visibility of this method to other parts of the JavaScript application. Its value can be any of the following access modifiers: public|private|protected|internal|protected-internal. For descriptions of these access modifiers, refer to the description of the visibility attribute for the <class> element.
Example:
<method name="addClass" scope="instance">
<shortDescription>Adds the specified class(es) to each of the set of matched elements.</shortDescription>
<parameters>
<parameter name="class" datatype="String" usage="required">
<description>One or more classes to add to the elements, these are separated by spaces.</description>
</parameter>
</parameters>
<returnType datatype="jQuery"/>
<! -- examples here -->
</method>
<mix>
mix_element = element mix {
mix_content & mix_attributes & foreign_nodes
}
mix_content = (
descriptive_elements
)
mix_attributes = (
datatype & fromProperty? & toProperty? & fromScope? & toScope?
)
The <mix> element indicates that methods and properties (and other features) from another object are copied (i.e., mixed in) into this object. The datatype attribute specifies the name of a <class>, <interface>, <mixin> or <singleton> whose <property>s, <method>s, <event>s, <alias>es, <ancestor>s, <config>s, <constructor>s, <event>s and <mix>es are included within the current class. This element can be used to mix in either a set of methods and properties or (if the fromProperty attribute has a value) an individual method or property.
As shown in the Compact RelaxNG schema snippet above, the <mix> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The datatype attribute is a reference to the 'datatype' on the <mixin>, <interface> or <class> element whose features should be mixed in.
The fromScope attribute applies to properties and methods and can have values instance or static. If fromScope="instance", then all instance properties and methods are mixed in. If fromScope="static", then all static properties and methods are mixed in. (See the description of the scope attribute.)
The toScope attribute applies to properties and methods and can have values instance or static. If toScope="instance", then all properties and methods are mixed on an instance basis. If toScope="static", then all properties and methods are mixed on an static basis. (See the description of the scope attribute.)
If the fromProperty attribute has a value and is not the empty string, then only a single method or property will be mixed in. The fromProperty attribute provides the name of the property that is to be copied from the referenced <mixin>, <interface> or <class> element.
The toProperty attribute provides the name for the mixed-in property when placed on this <mixin>, <interface> or <class>. If not specified or if it is the empty string, then the mixed-in property's name has the same name as the fromProperty.
<mixin>
mixin_element = element mixin {
mixin_content & mixin_attributes & foreign_nodes
}
mixin_content = (
descriptive_elements &
config_element* & configs_element* & constructor_element* & constructors_element* &
event_element* & events_element* & mix_element* & mixes_element* &
method_element* & methods_element* & property_element* & properties_element*
)
mixin_attributes = (
name & scope? & visibility? &
pattern_attributes & registerCallbackPattern? & unregisterCallbackPattern?
)
The <mixin> element defines a collection of methods, properties, etc. that are available to be mixed into other classes (i.e., referred to by a <mix> element).
As shown in the Compact RelaxNG schema snippet above, the <mixin> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The name attribute specifies the absolute object name using JavaScript dot notation for the mixin, such as "FooToolkit.io.http" (where the Foo toolkit has a main global object called "FooToolkit", a subobject "io", with subobject "http" which is set up as a JavaScript mixin.
The scope attribute can have values instance or static. A value of instance indicates that this class method is available only after an instance of this class has been created. A value of static indicates that this class method belongs to the class itself (i.e., does not require object instantiation).
The visibility attribute specifies the intended visibility of this mixin to other parts of the JavaScript application. Its value can be any of the following access modifiers: public|private|protected|internal|protected-internal. For descriptions of these access modifiers, refer to the description of the visibility attribute for the <class> element.
<namespace>
namespace_element = element namespace {
namespace_content & namespace_attributes & foreign_nodes
}
namespace_content = (
descriptive_elements
)
namespace_attributes = (
name & visibility?
)
The <namespace> element can be used to describes a JavaScript object that is a base object for other JavaScript classes but which itself is not a class (i.e., there is no constructor which creates instances of this object). For example, suppose there is a class named "MyLibrary.io.xhr" where the "xhr" object has a constructor, but "MyLibrary" and "io" do not. In this case, "MyLibrary" and "MyLibrary.io" are candidates for the <namespace> element. One way to use the <namespace> element is to provide descriptive information (e.g., using the <description> element) about the base object.
As shown in the Compact RelaxNG schema snippet above, the <namespace> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The name attribute specifies the absolute object name using JavaScript dot notation for the class, such as "FooToolkit.io.httpreq" (where the Foo toolkit has a main global object called "FooToolkit", a subobject "io", with subobject "httpreq" which is set up as a JavaScript class (i.e., has an appropriate constructor function).
The visibility attribute specifies the intended visibility of this namespace to other parts of the JavaScript application. Its value can be any of the following access modifiers: public|private|protected|internal|protected-internal. For descriptions of these access modifiers, refer to the description of the visibility attribute for the <class> element.
<parameter>
parameter_element = element parameter {
parameter_content & parameter_attributes & foreign_nodes
}
parameter_content = (
descriptive_elements & compatibility_elements &
option_element* & options_element* &
parameter_element* & parameters_element* & property_element* & properties_element* &
returnType_element* & returnTypes_element*
)
parameter_attributes = (
datatype? & name & usage? &
datatype_supplemental_attributes
)
2009-02-10: Need to add discussion about nested property elements
2009-02-24: Make sure the spec is clear that child <parameter> and <returnType> elements only apply when datatype="Function" and that child <property> elements only apply when datatype="Object".
2009-04-09: Make sure the spec is clear that this is a feature mostly for the IDE case in that it provides a poor-man's JSON schema feature. It isn't possible to express everything in JSON schema, such as unions.
The <parameter> element describes a parameter to a JavaScript function.
As shown in the Compact RelaxNG schema snippet above, the <parameter> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The name attribute specifies the name of the corresponding parameter within the JavaScript function definition. For example, consider the following JavaScript function:
MyClass.Init = function(parm1, parm2) { ... }
The corresponding OpenAjax Metadata for this function might look like this:
<class name="MyClass">
<method name="Init">
<parameter name="parm1" .../>
<parameter name="parm2" .../>
</method>
</class>
The datatype attribute specifies the allowed datatype(s) for the parameter. See the Datatypes chapterfor the detailed definition of this attribute.
The usage attribute specifies whether the parameter is required or optional and whether a variable number of values may be provided (i.e., zero-or-more or one-or-more). Permissible values are:
-
required(the default value for this attribute) -
optional -
zero-or-more -
one-or-more
Example:
<method name="animate" scope="instance">
<shortDescription>A function for making custom animations.</shortDescription>
<description>
The key aspect of this function is the object of style properties that will be animated,
and to what end. Each key within the object represents a style property that will also be animated
(e.g. "height", "top", or "opacity").
Note that properties should be specified using camel case, e.g. "marginLeft" instead of "margin-left."
The value associated with the key represents to what end the property will be animated. If a number is
provided as the value, then the style property will be transitioned from its current state to that new
number. Otherwise if the string "hide", "show", or "toggle" is provided, a default animation will be
constructed for that property.
</description>
<parameters>
<parameter name="params" datatype="Options" usage="required">
<description>A set of style attributes that you wish to animate, and to what end.</description>
<properties>
<property name="duration" datatype="String, Number" defaultValue=""normal"">
<description>A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the
number of milliseconds to run the animation (e.g. 1000).</description>
</property>
<property name="easing" datatype="String" defaultValue=""swing"">
<description>The name of the easing effect that you want to use (plugin required). There are two built-in values,
"linear" and "swing".</description>
</property>
<property name="complete" datatype="Function" defaultValue="">
<description>A function to be executed whenever the animation completes, executes once for each element animated against.</description>
</property>
<property name="step" datatype="Callback" defaultValue="">
<description/>
</property>
<property name="queue" datatype="Boolean" defaultValue="true">
<description>Setting this to false will make the animation skip the queue and begin running immediately.
(Added in jQuery 1.2)</description>
</property>
</properties>
</parameter>
<parameter name="options" datatype="Options " usage="required">
<description>A set of options with which to configure the animation.</description>
<properties>
<property name="duration" datatype="String, Number" defaultValue=""normal"">
<description>A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number
of milliseconds to run the animation (e.g. 1000).</description>
</property>
<property name="easing" datatype="String" defaultValue=""swing"">
<description>The name of the easing effect that you want to use (plugin required). There are two built-in values,
"linear" and "swing".</description>
</property>
<property name="complete" datatype="Function" defaultValue="">
<description>A function to be executed whenever the animation completes, executes once for each element animated against.</description>
</property>
<property name="step" datatype="Callback" defaultValue="" />
<property name="queue" datatype="Boolean" defaultValue="true">
<description>Setting this to false will make the animation skip the queue and begin running immediately. (Added in jQuery 1.2)</description>
</property>
</properties>
</parameter>
</parameters>
<returnType datatype="jQuery"/>
<!-- examples here ->
</method>
2009-02-17 At today's telecon, we agreed there were some issues in the example above. Lori will investigate and see if there is a different and better example. One of the issues is datatype="Callback". Also, Jon needs to investigate what's going on with datatype="Options".
<returnType>
returnType_element = element returnType {
returnType_content & returnType_attributes & foreign_nodes
}
returnType_content = (
descriptive_elements &
parameter_element* & parameters_element* & property_element* & properties_element* &
returnType_element* & returnTypes_element*
)
returnType_attributes = (
datatype & paramName? & paramValue? &
datatype_supplemental_attributes
)
2009-02-24: Make sure the spec is clear that child <parameter> elements only apply when datatype="Function" and that child <property> elements only apply when datatype="Object".
The <returnType> element specifies the datatype of the value that the method returns and supplemental descriptive information about the return value.
As shown in the Compact RelaxNG schema snippet above, the <returnType> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The datatype attribute specifies the datatype for the value that the method returns. The detailed specification for the datatype attribute can be found in the Datatypes chapter of this specification. However, for the <returns> element, the datatype attribute includes one additional feature that targets factory methods, where the datatype attribute can reference one of the method's parameters. In this case, the string value of the datatype attribute must exactly match the string value of the name attribute on one of the <parameter> elements for this method. If such a match exists between the <returns> element's datatype and the <parameter> element's name, then the return value from the method is the value of that parameter, which can be either a String value (the name of the class) or a Function value (the class constructor). To illustrate, suppose you have the following method definition:
<method name="classFactory"> <parameter name="classToInstantiate" datatype="String"/> <returns datatype="classToInstantiate"/> </method>
The method definition indicates that the return value from the method is an object whose classname is passed as a String to the classFactory method. Now, let's furthermore suppose this method might be invoked at runtime by any of the following:
-
myShape = classFactory('acme.graphtools.circleClass') -
myShape = classFactory('acme.graphtools.rectClass')
In this hypothetical case, the method will return an object that is either an instance of acme.graphtools.circleClass or acme.graphtools.rectClass.
Here is the same example, except that a Function value is used to identify the class:
<method name="classFactory"> <parameter name="classToInstantiate" datatype="Function"/> <returns datatype="classToInstantiate"/> </method>
For this example, the factory method might be invoked as follows (note that the arguments are not quoted, whereas in the previous String example, the class names were in quotes):
-
myShape = classFactory(acme.graphtools.circleClass) -
myShape = classFactory(acme.graphtools.rectClass)
User agents must first look to see if the specified datatype matches one of the parameter names, and then determine if the specified datatype matches one of the ECMAScript core datatypes or the name of a JavaScript class.
The paramName and paramValue attributes are most useful for factory methods where the datatype of the return value is dependent on a parameter whose possible values consists of an enumeration. If paramName and paramValue are provided, then they indicate that when the <parameter> element whose name attribute exactly matches the value of the paramName attribute and where the value of the parameter exactly matches the paramValue attribute, then the method returns the datatype specified on this <returns> element. To illustrate, suppose you have the following method definition:
<method name="classFactory">
<parameter name="classToInstantiate" datatype="String">
<options>
<option value="rect"/>
<option value="circle"/>
</options>
</parameter>
<returns paramName="classToInstantiate" paramValue="rect" datatype="acme.graphtools.rectClass"/>
<returns paramName="classToInstantiate" paramValue="circle" datatype="acme.graphtools.circleClass"/>
</method>
and furthermore suppose at runtime this method can be invoked by either myShape = classFactory('rect'); or myShape = classFactory('circle');. The above method definition indicates that: (a) when 'rect' is passed as the parameter then the return datatype is 'acme.graphtools.rectClass', and (b) when 'circle' is passed as the parameter then the return datatype is 'acme.graphtools.circleClass'.
Note that paramName and paramValue do not require the use of an enumeration (i.e., <options> and <option> elements). These attributes can also be used on parameters whose datatype is String that do not specify a discrete list of available options.
The metadata file is incorrectly formulated (i.e., in error) for the following situations: (a) if only one of paramName and paramValue are specified; (b) when paramName does not match one of the method's parameters; and (c) when a discrete enumeration is specified and paramValue does not match one of the possible values for the parameter.
Note that attribute datatype is a required attribute in OpenAjax Metadata, whereas in some inline commenting systems such as JSDoc, the datatype might be optional.
When converting from these inline commenting systems into OpenAjax Metadata, if the datatype is not specified, a suggested approach is to set datatype to Object.
<singleton>
20081216: There are some details to work out on this element.
singleton_element = element singleton {
singleton_content & singleton_attributes & foreign_nodes
}
singleton_content = (
descriptive_elements & compatibility_elements &
alias_element* & aliases_element* & ancestor_element* & ancestors_element* &
config_element* & configs_element* &
event_element* & events_element* & mix_element* & mixes_element* &
method_element* & methods_element* & property_element* & properties_element*
)
singleton_attributes = (
name & visibility? &
pattern_attributes & registerCallbackPattern? & unregisterCallbackPattern?
)
The <singleton> element describes a global static JavaScript object that functions like a <class> in that it might include its own APIs, such as method and properties, but unlike <class>, does not include the ability to construct new instances of itself.
As shown in the Compact RelaxNG schema snippet above, the <singleton> element can contain various child elements. Descriptions of these child elements can be found elsewhere within this specification.
The name attribute specifies the absolute object name using JavaScript dot notation for the singleton, such as "FooToolkit.io.httpreq" (where the Foo toolkit has a main global object called "FooToolkit", a subobject "io", with subobject "httpreq" which is set up as a JavaScript singleton (i.e., has an appropriate constructor function).
The visibility attribute specifies the intended visibility of this singleton to other parts of the JavaScript application. Its value can be any of the following access modifiers: public|private|protected|internal|protected-internal. For descriptions of these access modifiers, refer to the description of the visibility attribute for the <class> element.
The getterPattern and setterPattern attributes specify the name or name pattern for property getter and setter functions. Both attributes are inheritable in that all descendant <property> elements that do not specify the attribute will inherit these attributes. For more about these attributes, see the write-up on "Pattern attributes".
EDITOR: Make sure that all 'datatype' attributes refer to datatypes chapter and make sure there is appropriate writeup on classname datatypes to talk about the use of JavaScript dot notation to identify classes.
