Design-time Meta-data Framework
Overview
The purpose of the JSF design-time meta-data framework is to provide a mechanism by which Eclipse plugin developers can attach the required meta-data to support improved tooling. In the JSF Tools 1.0 Release, this is mostly to support improved tooling for tag libraries.
XML Content models (DTD, Schema, Taglibs), do not contain all of the information that is required to provide high-quality tooling support. The information that they contain simply does not have all of the information to provide semantic validation, content assistance, graphical tooling support, etc. This framework is the foundation for providing meta-data driven features used with the JSF JSP source editor in this release.
A content model can have any number of meta-data files associated with it. The public id of the content model is the key. eg. "https://java.sun.com/jsf/core"
This framework is built using the Eclipse Modeling Framework (EMF). By leveraging this framework,the meta-data framework allows for a high degree of extensibility, generalization of the meta-data model, and improvements in queryability over the previous, and now deprecated, Content Model Annotations framework.
Extension Point
The extension-point
org.eclipse.jst.jsf.common.standardMetaDataFiles
to used to associate a meta-data file with the uri identifier of a tag library. A "standard" meta-data file is an xml file of entities, which represent things like tags and tag attributes, and traits, which represent properties of the entities.
Through the extension-point:
- The meta-data file is bound to the tag library using the public uri as the key
- An extender can specify a meta-data file locator. If not specified, a plugin-relative file locator is used.
Entities
An
entity
identifies the object for which meta-data is being provided. Entities can have 0-N child entities and can have 0-N traits. They also can reference entityGroups from any model for inclusion.
An entity
has a required id
attribute, and a optional type
.
Traits
A
trait
is a property of an entity
. The value of a trait
is the meta-data that is being applied to the entity
. The value of a trait
is an instance of a TraitType and is modeled as an EMF EObject.
A TraitType can be any EMF EClass. This effectively means that it is a "blob" allowing for an arbitrary structure to be stored as the value of that trait
giving the ToolsProvider a great deal of flexibility on how meta-data can be provided.
A trait
has a required id
attribute, and an optional type
which specifies it's EMF EClass type. If the type
is not specified, the EMF resource loader usually treats it as an EMF XML SimpleAnyType.
Model
The metadata
model
element is the root element, and extends entity
. It is a collection of entities and traits representing the objects and properties respectively of some identifiable model. In this release, only the tag library domain of entities is supported, and it is identified by the tag library uri. The id for the model element must match the uri supplied by the extension.
EntityGroup
An
entityGroup
is a special entity
whose collection of traits and child entities get copied to an entity
that references it. Entity groups are owned by the Model entity
and can be referenced by any entity
except another entityGroup
. The intention of an entityGroup
is to reduce the amount of duplicate meta-data.
To reference an entityGroup
from an entity
, use the include-entity-group
element. An entity
can have 0-N includes and are processed in the order provided. To reference an entity
group in a different model, the optional uri attribute can be used to identify the model that the entityGroup
comes from. If the uri is not specified, the current model is assumed.
A Single Merged Model
The framework allows any number of standard meta-data files to be registered for a given tag library uri. The framework will do the work of merging the meta-data into a single in-memory model so that any tool can access any item of meta-data for that tag library in a uniform manner.
Although it is currently an internal notion, meta-data sources are not limited to the "standard" meta-data files. The tag library itself is a source. It may be possible for other sources of meta-data to also be included in the single merged model of meta-data in the future.
The model loader will locate all sources of meta-data, prioritize according to a loading strategy, and build up the model by comparing id's for duplicates. If an entity
or trait
with a given id is already present in the merged model, it will not be included. However, the merge will recursively check for the presence of child entities and traits and merge those.
entitygroup
s are handled in a special manner during the merge. They are collected during the processing of all the meta-data sources, and only after all sources of meta-data have been merged, will the include-entity-group
's be processed. That processing is handled similarly to the processing of entities and traits during the first pass.
eg. A Section of one of the supplied JSF HTML Taglibrary Meta-data Files
<?xml version="1.0" encoding="UTF-8"?>
<md:metadatamodel
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="https://www.eclipse.org/emf/2002/Ecore"
xmlns:md="https://org.eclipse.jst.jsf.common.meta-data/metadata.ecore"
xmlns:mdt="https://org.eclipse.jst.jsf.common.metadata/metadataTraitTypes.ecore"
xmlns:cnst="https://org.eclipse.jst.jsf.core/constraints.ecore"
id="https://java.sun.com/jsf/html"
type="tagFile">
<entity id="commandButton" type="tag">
<include-entity-group id="common-attributes"/>
<trait id="containment-constraint">
<value xsi:type="cnst:ContainsTagConstraint">
<set-generator>
<algorithm>xpath</algorithm>
<expression>ancestor::*</expression>
</set-generator>
<satisfies-set>
<tagId>
<uri>https://java.sun.com/jsf/core</uri>
<name>view</name>
</tagId>
<tagId>
<uri>https://java.sun.com/jsf/html</uri>
<name>form</name>
</tagId>
</satisfies-set>
</value>
</trait>
<entity id="type">
<trait id="attribute-value-runtime-type">
<value>org.eclipse.jst.jsf.core.attributevalues.StringType</value>
</trait>
<trait id="valid-values">
<value xsi:type="mdt:ListOfValues">
<item>button</item>
<item>reset</item>
<item>submit</item>
</value>
</trait>
<trait id="default-value">
<value>submit</value>
</trait>
</entity>
etc....
Querying for Meta-data
Meta-data should only be accessed thru static calls to the
TaglibDomainMetaDataQueryHelper
class. This class has many convenience methods for locating models, entities and traits.
To locate meta-data, first one creates an initial context called the
ITaglibDomainMetaDataModelContext
using the above helper class. This identifies which meta-data model to load.
Since tag library meta-data comes not only from the standard files, but also the tag libraries themselves,
this domain of meta-data is dependent on the classpath and the reason why an IProject
,
along with the tag library uri, is required for the context.
eg. Typical Example of Looking up Meta-data
ITaglibDomainMetaDataModelContext modelContext =
TaglibDomainMetaDataQueryHelper.createMetaDataModelContext(project, uri);
Model model = TaglibDomainMetaDataQueryHelper.getModel(modelContext);
if (model != null){
Entity aTag = TaglibDomainMetaDataQueryHelper.getEntity(model, "ATag");
if (aTag != null){
Trait displayNameTrait = TaglibDomainMetaDataQueryHelper.getTrait(aTag, "display-name");
String displayName = TraitValueHelper.getValueAsString(displayNameTrait) ;
...
}
}
...