-
Notifications
You must be signed in to change notification settings - Fork 263
Role Playing with Adaptation
Adaptation is one of the most useful techniques in all of ATF and it abounds there.
In particular, DOM adapters employ adaptation to allow a single DomNode
to take on many roles. This is what a DOM adapter does: a DomNode
can be adapted to any DOM adapter defined for the DomNode
's type. The DOM adapter class provides the methods and properties useful to handle the object in that role. It is especially useful to define DOM adapters on the type of the root DomNode
so it can be adapted to many different types.
The main adaptation methods provided in the Adapters
class are:
-
As<T>()
: adapt an object to the given type, returningnull
if no adapter found. -
Cast<T>()
: adapt an object to the given type, raising an exception if no adapter found. -
Is<T>()
: test if an adapter is available for an object for the given type.
To use a DOM adapter in an editor or any other ATF application, do the following:
- Define DOM adapters for types, usually in the type schema loader. For details on doing this, see Defining DOM Adapters for Types.
- Design DOM adapter classes for the types, deriving from
DomNodeAdapter
. These can be very basic, simply containing a few properties, or quite comprehensive. For a description of various things DOM adapters can do, see:- DOM Adapters Adapt: general capabilities of DOM adapters.
- Wrapping Attributes and Elements in Properties: access attributes through C# properties.
-
DOM Adapters Listen: listen for events on
DomNode
s. -
DOM Adapters Validate: validate the data in a
DomNode
.
If you look for all the occurrences of the adaptation methods in the ATF Simple DOM Editor Sample, you find that all of them are used with DOM adapters! Consider the IDocumentClient.Show()
method in the Editor
class:
public void Show(IDocument document)
{
EventSequenceContext context = Adapters.As<EventSequenceContext>(document);
m_controlHostService.Show(context.ListView);
}
The document
parameter implements IDocument
. In SimpleDOMEditor, the IDocument
implementer is EventSequenceDocument
:
public class EventSequenceDocument : DomDocument, ISearchableContext
As noted in IDocument Interface Implementation, DomDocument
implements IDocument
. Because the EventSequenceDocument
class derives from DomDocument
, the IDocument document
parameter refers to an EventSequenceDocument
instance.
Show()
is attempting to adapt this IDocument
to the EventSequenceContext
DOM adapter. Here is a partial list of DOM adapters defined for types in SimpleDOMEditor (see Define DOM Extensions for the entire list):
Schema.eventSequenceType.Type.Define(new ExtensionInfo<EventSequenceDocument>());
Schema.eventSequenceType.Type.Define(new ExtensionInfo<EventSequenceContext>());
EventSequenceDocument
and EventSequenceContext
are defined on the type "eventSequenceType". A DomNode
can always be adapted to all DOM adapters defined for its type. For an explanation of why this is so, see Adapting to All Available Interfaces in Adaptation in ATF. In particular, this means that an EventSequenceDocument
instance can be adapted to EventSequenceContext
, just as Show()
does.
Other uses of As<T>()
, Cast<T>()
, and Is<T>()
in SimpleDOMEditor employ similar adaptations. These adaptations make it easier to access all the different kind of objects you need to implement an editor.
In summary, DOM adapters make it easier to implement the interfaces you need in an editor.
Creating an Editor Application
- Designing the Application Data Model with the DOM: Define an application data model that works with the ATF DOM in a data definition language, such as an XML Schema.
- Creating Documents for Application Data: Develop classes that work with documents, using the ATF document interfaces.
- Editing and Selecting Data with Contexts: Create contexts with services for editing and selecting data.
- Creating Data Instances: Create new data instances with the instancing framework.
- Editing Data Properties: Edit properties of data types using property editor components.
-
Role Playing with Adaptation: DOM adapters allow
DomNode
s to play many roles.
- Home
- Getting Started
- Features & Benefits
- Requirements & Dependencies
- Gallery
- Technology & Samples
- Adoption
- News
- Release Notes
- ATF Community
- Searching Documentation
- Using Documentation
- Videos
- Tutorials
- How To
- Programmer's Guide
- Reference
- Code Samples
- Documentation Files
© 2014-2015, Sony Computer Entertainment America LLC