|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
XQCommonHandler defines the interface for all handlers for
object models such as DOM4J, JDOM, JAXB, etc.
This interface provides the default behaviour for handling known objects,
that is to return the corresponding Java object for each XML type
as defined by Java to XML type mapping. The default object model is DOM.
For example, XQCommonHandler returns Integer
object for integer type, String for string type, Double
for double type, DOM node for Node, and so forth.
The application must provide a subclass implementation for the specific
object model to be supported.
A usage example with a JAXB handler :
...
XQDataSource dataSource = ...
XQConnection con = dataSource.getConnection("myUID", "myPWD");
// Find all Employees belong to the SW department
// from the EMPS collection
String qs = "for $e in collection('EMPS.xml')
where $e/Dept='SW'
return $e";
XQPreparedExpression = con.preparedExpression(qs);
XQResultSequence rs = expression.executeQuery();
// JAXBHandler class is provided by the application
// or by a service provider
// Creates a JAXB handler for com.acme.xml package
JAXBContext jaxbContext = JAXBContext.newInstance("com.acme.xml");
XQCommonHandler jaxbHandler = new JAXBHandler(jaxbContext);
while(rs.next()) {
// Employee is a JAXB object
// defined in com.acme.xml package
// Note that we could have set the jaxbHandler at the connection
// level, before preparing the expression, in which case,
// we need not supply the handler to the getObject.
Employee emp = (Employee) rs.getObject(jaxbHandler);
// use the Employee object
// assuming Employee implements toString()
System.out.println(emp);
}
...
Usage :getObject() method. For example,
Employee emp = (Employee) rs.getObject(jaxbHandler);
connection.setCommonHandler(jaxbHandler); XQPreparedExpression pe = connection.prepareExpression(expression); XQSequence rs = pe.executeQuery(); ... Employee emp = (Employee) rs.getObject();
getObject method can be invoked without a
parameter. For example,
XQDataSource datasource = ... datasource.setCommonHandler(jaxbHandler); XQConnection conn = datasource.getConnection(); XQPreparedExpression pe = connection.prepareExpression(expression); XQSequence rs = pe.executeQuery(); ... Employee emp = (Employee) rs.getObject();
XQSequence,
XQResultSequence,
XQItem| Method Summary | |
XQItem |
fromObject(Object obj)
Converts an object from a specific object model to a standard XQItem
object containable in a sequence, thus compatible with other operations
involving items and sequences.
|
Object |
toObject(XQItemAccessor item)
Converts an item into its corresponding object in the current object model supported. |
| Method Detail |
public Object toObject(XQItemAccessor item)
throws XQException
XQItemAccessor interface and
hence the item object passed in could reside in a sequence or
exist independently.
This method is called by XQSequence.getObject(),
XQSequence.getObject(XQCommonHandler ch),
XQItem.getObject(), and XQItem.getObject(XQCommonHandler ch)
to convert an item representation into an object of the appropriate
object model.
getObject(XQCommondHandler ch) above is:
public Object getObject(XQCommonHandler ch) {
return ch.toObject(this);
}
The following is using the default handler,
public Object getObject() {
return defaultHandler.toObject(this);
}
The defaultHandler is a private variable of the XQSequence
implementation that is initially set to the default XQCommonHandler class.
This can be overriden with a more specific handler using the method
setCommonHandler(XQCommonHandler ch).
item - the item to be converted accessible
via an item accessor interface
XQException - if the current item can not be converted to
the specified object model
public XQItem fromObject(Object obj)
throws XQException
XQItem
object containable in a sequence, thus compatible with other operations
involving items and sequences.
obj - an object from a specific object model,
e.g. DOM4J, JDOM, JAXB, etc
XQItem item
XQException - if conversion failed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||