Red Hat Web Application Framework 6.1 用户手册

下载
页码 230
146
Chapter 11. Services Tutorials
String[1..1] name
= frobs.frob_name VARCHARA;
}
In the above example, the versioning system will ignore changes to the
type
attribute of the
Frob object type
.
5. The current versioning service provides the ability to compute a diff between any two points in
history of a versioned data object. The old service did not provide a similar capability.
11.6. Search Tutorial
This section provides useful tutorials for the search service.
11.6.1. Making a domain object searchable
Making a domain object in an application searchable requires implementing and registering a meta-
data provider class. This adapter pattern enables the search service to extract the metadata it requires
from domain objects without requiring any specific knowledge of the application domain. The APIs
required to achieve this task are provided by a handful of classes from the
com.arsdigita.search
package:
MetadataProvider.java
MetadataProviderRegistry.java
ContentProvider.java
ContentType.java
11.6.1.1. Core search metadata
The first task is to implement the
MetadataProvider.java
interface, providing the core search
metadata - the object’s locale, title and summary blurb. All the methods in this interface have a
Do-
mainObject
as the first argument. The object supplied as the value for this argument will be an
instance (or subtype) of the object type specified when registering the provider with the
Metadat-
aProviderRegistry
.
package com.example.binder;
import com.arsdigita.search.MetadataProvider;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.util.StringUtils;
import java.util.Locale;
public class NoteMetadataProvider implements MetadataProvider {
public Locale getLocale(DomainObject dobj) {
Note note = (Note)dobj;
// Note doesn’t store the locale yet, so we just return null
return null;
}
public String getTitle(DomainObject dobj) {
Note note = (Note)dobj;
return note.getTitle();
}