# Meta-Data Processing Framework

### Overview

This framework makes use of the meta-data contributed by the Design-time Meta-data Framework. It's intention in this release is to simplify how services like Content Assist and Validation can be provided in source editors for tag library based attributes values.

The goal for this framework is to allow developers to assign "runtime type" information to an attibute's value using meta-data and then, because based on that type, "features" can naturally be exposed.

To make this more concrete, let's consider the example of the JSF Core `actionListener` tag and its `type` attribute. The value should resolve to a Java class type that implements the interface `javax.faces.event.ActionListener`. Having this knowledge is enough to provide:

- Validation - ensure that the specified class can be found and implements the correct interface
- Content Assist - provide a list of all of the classes that can be found that implement the interface
- Quick Fix/Quick Assist - open the new Java class wizard with the required interface preset in the dialog

### Types and Features

In the above example, the "Type" is a Java class type and we have identified three "Feature" that the type implements.

We have created an interface called `ITypeDescriptor` that represents the runtime type of the attribute value of a tag. An implementor needs to return a list of feature adapters that this type supports. The features must implement the `IMetaDataEnabledFeature` interface.

A default implementation, `AbstractRootTypeDescriptor` has been provided as a convenient starting point for implementing types, and it itself implements `AbstractMetaDataEnabledFeature`. This allows the type descriptor to implement features itself which should simplify development.

### Attribute Value Runtime Type Extension Point

We bind a type identifier in meta-data to a class through an extension point. `org.eclipse.jst.jsf.core.AttributeValueRuntimeTypes`. Please see Design-time Meta-Data Framework to see how the meta-data files are created.

The JSF Tools project has implemented a type descriptor class `org.eclipse.jst.jsf.core.attributevalues.JavaClassType`. In order to use this type, it must first be declared as an `AttributeValueRuntimeType` and then referenced in a meta-data file.

Below comes from the `org.eclipse.jst.jsf.core` plugin that declares this type:

          <attributeValueRuntimeType
                class="org.eclipse.jst.jsf.core.attributevalues.JavaClassType"
                id="attributevalues.JavaClassType"/>

Below is the section of the jsf_core.xml meta-data file from the core plugin that supplies meta-data for the `actionListener` tag:

    	<entity id="actionListener">
    		<entity id="type">
    			<trait id="attribute-value-runtime-type">
    				<value>
    					org.eclipse.jst.jsf.core.attributevalues.JavaClassType
    				</value>
    			</trait>
    			<trait id="valid-interfaces">
    				<value>javax.faces.event.ActionListener</value>
    			</trait>
    		</entity>
    	</entity>

Notice that the value of the `attribute-value-runtime-type` trait uses the plugin qualified id of the AttributeValueRuntimeType extension.

For a complete list of implemented types and features, please see the API reference

The `JavaClassType` implements two Features:

- IValidValues - an interface used by a WTP Validation framework validator class to check and provide validation error messages if invalid when being used in a non-EL context
- IPossibleValues - an interface used by an extension to the WTP SSE editor for content assistance

Although not applicable to the `JavaClassType`, the following round out the Features defined by this release:

- IValidELValues - an interface used by a WTP Validation framework validator class to check and provide validation error messages if invalid when being used in an EL context
- IDefaultValue - an interface for providing a default value
- ICreateValues - an unimplemented experimental interface with intentoin of being used for providing Quick Fix/Quick Assist services

The Feature implementer can require additional information from meta-data. Notice that the `JavaClassType` calls back to the meta-data to get the list of `valid-interface` values. For a complete list of the property names used by the Types and Features from the core plugin see the constant values reference page

### How are these used?

A client interested in requesting a set of all the Feature implementers for a given tag attribute will use the `MetaDataEnabledProcessingFactory` and the `getAttributeValueRuntimeTypeFeatureProcessors method`. This method will lookup the runtime type from the meta-data file that it will identify from the passed context. This method is currently being called by the `JSPSemanticValidator` with `IValidValues.class` and `IValidELValues.class` passed as the feature class along with the context. For content assist, `IPossibleValues.class` is being passed by the content assist processor.

### Creating New Behaviors

Hopefully by now you know enough knowledge to create your own types, or reuse existing types in your meta-data files. But what if you wanted to associate a completely new behaviour(Feature) with a runtime type? This is handled by implementing a new `IMetaDataEnabledFeature` and registering it against a type identifier. To register, use the `org.eclipse.jst.jsf.metadataprocessing.MetaDataEnabledFeatures` extension-point.

### Other Resources

- Tutorial