com.novell.sentinel.client.bean
Class BeanTransporterBase<B extends SentinelBean,P>

java.lang.Object
  extended by com.novell.sentinel.client.bean.BeanTransporterBase<B,P>
Type Parameters:
B - Bean type (e.g., IdentityBean)
P - HTTP content parser type (e.g., JSONParser or org.xml.sax.Parser)
All Implemented Interfaces:
BeanTransporter<B>
Direct Known Subclasses:
BeanTransporterJSON, BeanTransporterSyncBase

public abstract class BeanTransporterBase<B extends SentinelBean,P>
extends Object
implements BeanTransporter<B>

Base class for GWT and asynchronous Java BeanTransporter implementations.


Nested Class Summary
static class BeanTransporterBase.ParseException
          Generic carrier exception to allow derived classes to report errors in parsing HTTP results.
 
Field Summary
 
Fields inherited from interface com.novell.sentinel.client.bean.BeanTransporter
NO_FIELDS, UNLIMITED_PAGE_SIZE
 
Constructor Summary
protected BeanTransporterBase(BeanMetaData<? extends B> _beanMD, HttpRequestor<P> _requestor, UriConstructorFactory _urlFactory)
          Constructor for derived classes.
 
Method Summary
 void cleanup(String url, OnBeanDelete handler)
          Issues a cleanup request to the server for the passed URL.
 void count(OnBeanCount handler)
          Get a count of the data instances available.
 void count(String query, OnBeanCount handler)
          Get a count of the data instances available, optionally filtered by the passed query.
protected abstract  B createBean(P parser)
          Derived classes must create a single instance of class B from the HTTP GET result content obtained from the parser parameter.
protected abstract  PagedBeanCollection<B> createPage(P parser)
          Derived classes must create a PagedBeanCollection instance based on the HTTP GET result content obtained from the parser parameter.
protected abstract  P createParser(B bean)
          Derived classes must create a data source from which can be obtained the content data for an HTTP PUT or POST request.
 void delete(B bean, OnBeanDelete handler)
          Delete the data instance represented by the passed bean.
 void delete(String url, OnBeanDelete handler)
          Delete the data instance at the specified URL.
 void get(String url, Iterable<String> fields, OnBeanLoad<B> handler)
          Get the data at the passed URL in a bean.
 void get(String url, OnOctetStreamLoad handler)
          Get the octet stream value of an object attribute referenced by the passed URL.
protected  BeanMetaData<? extends B> getBeanMD()
          Return the metadata for the bean-type handled by this instance.
 String getLocaleName()
          Get the locale name currently set in the implementing instance.
 HttpRequestor<P> getRequestor()
          Get the HttpRequestor used by this instance.
 List<String> getSortFields()
          Get the sort field names currently set in the implementing instance.
 UriConstructorFactory getUrlFactory()
          Get the URL creator factory used by this instance.
 void list(OnBeanPageLoad<B> handler)
          Get a collection of the beans available.
 void list(String query, int pageSize, Iterable<String> fields, boolean getChangeCounts, OnBeanPageLoad<B> handler)
          Get a collection of the data instances available, optionally filtered by the passed query.
 void list(String query, int pageSize, Iterable<String> fields, OnBeanPageLoad<B> handler)
          Get a collection of the data instances available, optionally filtered by the passed query.
 void listFromURL(String url, int pageSize, Iterable<String> fields, boolean getChangeCounts, OnBeanPageLoad<B> handler)
          Get a collection of the data instances available at the passed URL.
 void listFromURL(String url, int pageSize, Iterable<String> fields, OnBeanPageLoad<B> handler)
          Get a collection of the data instances available at the passed URL.
 void listFromURL(String url, OnBeanPageLoad<B> handler)
          Get a collection of the beans available at the passed URL.
protected abstract  long parseCount(P parser)
          Derived classes must parse the item count returned as a result of an HTTP GET request.
protected abstract  String parseURL(P parser)
          Derived classes must parse the URL returned as a result of an HTTP POST request.
 void post(B bean, OnBeanPost handler)
          Create a new data instance.
 void put(B bean, OnBeanPut handler)
          Update the underlying Sentinel data from the passed bean.
 void put(String url, byte[] data, OnBeanPut handler)
          Put the octet stream value of an object attribute referenced by the passed URL.
 void setLocaleName(String localeName)
          Set the name of the locale to use to sort list results if an order is used.
 void setSortFields(List<String> sortFields)
          Set list of field names on which to sort list results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanTransporterBase

protected BeanTransporterBase(BeanMetaData<? extends B> _beanMD,
                              HttpRequestor<P> _requestor,
                              UriConstructorFactory _urlFactory)
Constructor for derived classes.

Parameters:
_beanMD - The metadata of the SentinelBean implementation.
_requestor - The interface through which HTTP requests will be made.
_urlFactory - The factory instance from which request URLs will be constructed. The factory must return UriConstructor instances which are pre-loaded with the base URL of the Sentinel DataObject REST API.
Method Detail

getLocaleName

public String getLocaleName()
Description copied from interface: BeanTransporter
Get the locale name currently set in the implementing instance.

Specified by:
getLocaleName in interface BeanTransporter<B extends SentinelBean>
Returns:
The locale name (may be null).

setLocaleName

public void setLocaleName(String localeName)
Description copied from interface: BeanTransporter
Set the name of the locale to use to sort list results if an order is used.

Specified by:
setLocaleName in interface BeanTransporter<B extends SentinelBean>
Parameters:
localeName - The _ string representing a locale. Supported locales are those available in Java.

setSortFields

public void setSortFields(List<String> sortFields)
Description copied from interface: BeanTransporter
Set list of field names on which to sort list results. Setting this to null (the default) will return the objects unsorted, or if there is a default order defined for the object type, sorted by the default order. To eliminate any default sort order, set this to an empty list.

Specified by:
setSortFields in interface BeanTransporter<B extends SentinelBean>
Parameters:
sortFields - The list of field names on which to sort list results.

getSortFields

public List<String> getSortFields()
Description copied from interface: BeanTransporter
Get the sort field names currently set in the implementing instance.

Specified by:
getSortFields in interface BeanTransporter<B extends SentinelBean>
Returns:
The sort fields names (may be null).

count

public void count(OnBeanCount handler)
Description copied from interface: BeanTransporter
Get a count of the data instances available.

Specified by:
count in interface BeanTransporter<B extends SentinelBean>
Parameters:
handler - The handler to which the result of the HTTP request will be reported.

count

public void count(String query,
                  OnBeanCount handler)
Description copied from interface: BeanTransporter
Get a count of the data instances available, optionally filtered by the passed query.

Specified by:
count in interface BeanTransporter<B extends SentinelBean>
Parameters:
query - Optional filter for the results (may be null).
handler - The handler to which the result of the HTTP request will be reported.

listFromURL

public void listFromURL(String url,
                        OnBeanPageLoad<B> handler)
Description copied from interface: BeanTransporter
Get a collection of the beans available at the passed URL. The URL supplied must be appropriate for the bean type <B>.

Specified by:
listFromURL in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The URL specifying the beans.
handler - The handler to which the result of the HTTP request will be reported.

listFromURL

public void listFromURL(String url,
                        int pageSize,
                        Iterable<String> fields,
                        OnBeanPageLoad<B> handler)
Description copied from interface: BeanTransporter
Get a collection of the data instances available at the passed URL. The URL supplied must be appropriate for the bean type <B>.

Specified by:
listFromURL in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The URL specifying the beans.
pageSize - The maximum number of beans to return as a result of this call.
fields - Optional collection of the names of fields to return in each bean (may be null, if a single value of "none" is specified then no fields are retrieved).
handler - The handler to which the result of the HTTP request will be reported.

listFromURL

public void listFromURL(String url,
                        int pageSize,
                        Iterable<String> fields,
                        boolean getChangeCounts,
                        OnBeanPageLoad<B> handler)
Description copied from interface: BeanTransporter
Get a collection of the data instances available at the passed URL. The URL supplied must be appropriate for the bean type <B>.

Specified by:
listFromURL in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The URL specifying the beans.
pageSize - The maximum number of beans to return as a result of this call.
fields - Optional collection of the names of fields to return in each bean (may be null, if a single value of "none" is specified then no fields are retrieved).
getChangeCounts - if true, get the "delta counts" of the object.
handler - The handler to which the result of the HTTP request will be reported.

list

public void list(String query,
                 int pageSize,
                 Iterable<String> fields,
                 OnBeanPageLoad<B> handler)
Description copied from interface: BeanTransporter
Get a collection of the data instances available, optionally filtered by the passed query.

Specified by:
list in interface BeanTransporter<B extends SentinelBean>
Parameters:
query - Optional filter for the results (may be null).
pageSize - The maximum number of beans to return as a result of this call.
fields - Optional collection of the names of fields to return in each bean (may be null, if a single value of "none" is specified then no fields are retrieved).
handler - The handler to which the result of the HTTP request will be reported.

list

public void list(String query,
                 int pageSize,
                 Iterable<String> fields,
                 boolean getChangeCounts,
                 OnBeanPageLoad<B> handler)
Description copied from interface: BeanTransporter
Get a collection of the data instances available, optionally filtered by the passed query.

Specified by:
list in interface BeanTransporter<B extends SentinelBean>
Parameters:
query - Optional filter for the results (may be null).
pageSize - The maximum number of beans to return as a result of this call.
fields - Optional collection of the names of fields to return in each bean (may be null, if a single value of "none" is specified then no fields are retrieved).
getChangeCounts - if true, get the "delta counts" of the object.
handler - The handler to which the result of the HTTP request will be reported.

list

public void list(OnBeanPageLoad<B> handler)
Description copied from interface: BeanTransporter
Get a collection of the beans available.

Specified by:
list in interface BeanTransporter<B extends SentinelBean>
Parameters:
handler - The handler to which the result of the HTTP request will be reported.

get

public void get(String url,
                Iterable<String> fields,
                OnBeanLoad<B> handler)
Description copied from interface: BeanTransporter
Get the data at the passed URL in a bean.

Specified by:
get in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The URL specifying the data to retrieve.
fields - Optional collection of the names of fields to return in each bean (may be null, if a single value of "none" is specified then no fields are retrieved).
handler - The handler to which the result of the HTTP request will be reported.

get

public void get(String url,
                OnOctetStreamLoad handler)
Description copied from interface: BeanTransporter
Get the octet stream value of an object attribute referenced by the passed URL.

Specified by:
get in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The reference to the attribute value.
handler - The handler to which the result of the HTTP request will be reported.

put

public void put(B bean,
                OnBeanPut handler)
         throws BeanSerializationException
Description copied from interface: BeanTransporter
Update the underlying Sentinel data from the passed bean.

Specified by:
put in interface BeanTransporter<B extends SentinelBean>
Parameters:
bean - The bean containing the updated data (must have been obtained from a list or get call.
handler - The handler to which the status of the HTTP request will be reported.
Throws:
BeanSerializationException

put

public void put(String url,
                byte[] data,
                OnBeanPut handler)
Description copied from interface: BeanTransporter
Put the octet stream value of an object attribute referenced by the passed URL.

Specified by:
put in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The reference to the attribute value.
data - The octet stream data for the attribute value.
handler - The handler to which the status of the HTTP request will be reported.

post

public void post(B bean,
                 OnBeanPost handler)
          throws BeanSerializationException
Description copied from interface: BeanTransporter
Create a new data instance.

Specified by:
post in interface BeanTransporter<B extends SentinelBean>
Parameters:
bean - The bean containing the data for the new instance.
handler - The handler to which the result of the HTTP request will be reported.
Throws:
BeanSerializationException - If an error occurs transforming the bean data into HTTP request data.

delete

public void delete(String url,
                   OnBeanDelete handler)
Description copied from interface: BeanTransporter
Delete the data instance at the specified URL.

Specified by:
delete in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The URL specifying the data instance to be deleted.
handler - The handler to which the result of the HTTP request will be reported.

delete

public void delete(B bean,
                   OnBeanDelete handler)
Description copied from interface: BeanTransporter
Delete the data instance represented by the passed bean.

Specified by:
delete in interface BeanTransporter<B extends SentinelBean>
Parameters:
bean - The representation of the data instance to be deleted (must have been obtained from a list or get call.
handler - The handler to which the result of the HTTP request will be reported.

cleanup

public void cleanup(String url,
                    OnBeanDelete handler)
Description copied from interface: BeanTransporter
Issues a cleanup request to the server for the passed URL. Cleanup requests are used for certain types of resources that implicitly create server-side resources that can be freed once the client is finished with them. An example is a search job created implicitly when events are searched for using the EventBean list operation, rather than the EventSearch post operation.

Specified by:
cleanup in interface BeanTransporter<B extends SentinelBean>
Parameters:
url - The URL representing the resource to clean up.
handler - The handler to which the result of the HTTP request will be reported.

getRequestor

public HttpRequestor<P> getRequestor()
Get the HttpRequestor used by this instance.


getUrlFactory

public UriConstructorFactory getUrlFactory()
Get the URL creator factory used by this instance.


createPage

protected abstract PagedBeanCollection<B> createPage(P parser)
                                                                   throws BeanSerializationException
Derived classes must create a PagedBeanCollection instance based on the HTTP GET result content obtained from the parser parameter.

Parameters:
parser - The source of the HTTP GET results.
Returns:
A page implementation.
Throws:
BeanSerializationException - if an error occurs during construction from the GET results.

createBean

protected abstract B createBean(P parser)
                                              throws BeanSerializationException
Derived classes must create a single instance of class B from the HTTP GET result content obtained from the parser parameter.

Parameters:
parser - The source of the HTTP GET results.
Returns:
The created bean.
Throws:
BeanSerializationException - if an error occurs during construction from the GET results.

createParser

protected abstract P createParser(B bean)
                           throws BeanSerializationException
Derived classes must create a data source from which can be obtained the content data for an HTTP PUT or POST request.

Parameters:
bean - The bean containing the Sentinel data item fields.
Returns:
A source for HTTP PUT or POST content.
Throws:
BeanSerializationException - if an error occurs during the construction of the data source.

parseURL

protected abstract String parseURL(P parser)
                            throws BeanTransporterBase.ParseException
Derived classes must parse the URL returned as a result of an HTTP POST request.

Parameters:
parser - The source for the result content of the HTTP POST request.
Returns:
The URL from the result content.
Throws:
BeanTransporterBase.ParseException - If an error occurs during the parsing of the POST result content.

parseCount

protected abstract long parseCount(P parser)
                            throws BeanTransporterBase.ParseException
Derived classes must parse the item count returned as a result of an HTTP GET request.

Parameters:
parser - The source for the result content of the HTTP GET request.
Returns:
The URL from the result content.
Throws:
BeanTransporterBase.ParseException - If an error occurs during the parsing of the GET result content.

getBeanMD

protected BeanMetaData<? extends B> getBeanMD()
Return the metadata for the bean-type handled by this instance.