Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create XQCommonHandler interface #1

Open
cfoster opened this issue Sep 26, 2012 · 0 comments
Open

Create XQCommonHandler interface #1

cfoster opened this issue Sep 26, 2012 · 0 comments
Assignees

Comments

@cfoster
Copy link
Owner

cfoster commented Sep 26, 2012

Create XQCommonHandler interface, along the lines of:

import javax.xml.xquery.XQItemAccessor;
import javax.xml.xquery.XQItem;
import javax.xml.xquery.XQException;

public interface XQCommonHandler
{
  public XQItem fromObject(Object obj) throws XQException;
  public Object toObject(XQItemAccessor item) throws XQException;
}

Add methods to XQConnection2 to enable the user to specify their own XQCommonHandler implementation in such a way that they can also simply override certain scenarios (e.g. certain Objects) and allow the rest of the XQJ driver to cater for everything else, as it would do normally.

So essentially, the user could create an implementation, something along the lines of:

public class CustomXQCommonHandler implements XQCommonHandler
{
  XQCommonHandler subordinateHandler; // e.g. the XQJ Driver's DEFAULT handler.
  XQDataFactory dataFactory;

  public CustomXQCommonHandler(
    XQCommonHandler handler,
    XQDataFactory factory)
  {
    subordinateHandler = handler;
    dataFactory = factory;
  }

  public XQItem fromObject(Object obj) throws XQException
  {
    if(obj instanceof MyFavouritePOJO)
    {
      /**
        create and return XQItem via dataFactory
      **/
    }
    else
    {
      return subordinateHandler.fromObject(obj);
    }
  }

  public Object toObject(XQItemAccessor item) throws XQException
  {
    if(item --- has certain characteristics we are interested in)
    {
      return createMyFavouritePOJO();
    }
    else
    {
      return subordinateHandler.toObject(item);
    }
}

When a user is using a custom XQCommonHandler, methods such as

  • XQItemAccessor.getObject()
  • XQDynamicContext.bindObject(QName varName, Object value, XQItemType type)
  • XQDataFactory.createItemFromObject(Object value, XQItemType type)

will be affected.

This must be well documented.

@ghost ghost assigned cfoster Sep 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant