Android Open Source - colibri Cursor Def






From Project

Back to project page colibri.

License

The source code is released under:

Apache License

If you think the Android project colibri listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package labrom.colibri.xml;
// w  ww . j  a  v a2  s  .  c o  m
import java.io.InputStream;
import java.io.Reader;

import org.xmlpull.v1.XmlPullParserException;
/**
 * A cursor definition represents a mapping from XML structures to Java objects.
 * An instance of CursorDef can be (re)used to create one or multiple {@linkplain Cursor cursors} on an actual XML stream.
 * 
 * To obtain a CursorDef, use {@link RootContext} and {@link ElementContext}.
 * 
 * @author Romain Laboisse labrom@gmail.com
 * 
 * @see RootContext
 * @see ElementContext
 *
 * @param <T> The type of objects that Pulloid will create. This class must be written by developers.
 */
public class CursorDef<T> {
  
  Class<T> cursorType;
  ElementContext<T> ctx;
  
  protected CursorDef(ElementContext<T> ctx) {
    this(null, ctx);
  }
  
  protected CursorDef(Class<T> cursorType, ElementContext<T> ctx) {
    this.cursorType = cursorType;
    this.ctx = ctx;
  }
  
  public ElementContext<T> getContext() {
    return ctx;
  }
  
  /**
   * Creates a new cursor. Many cursors can be created from a single CursorDef.
   * @param input The XML input stream.
   * @return A cursor.
   */
  public Cursor<T> pull(InputStream input) {
    try {
      return new Cursor<T>(new Reflector<T>(cursorType), ctx, ParserFactory.newParser(), input);
    } catch (XmlPullParserException e) {
      throw new CursorException(e);
    }
  }

  /**
   * Creates a new cursor. Many cursors can be created from a single CursorDef.
   * @param reader The XML reader.
   * @return A cursor.
   */
  public Cursor<T> pull(Reader reader) {
    try {
      return new Cursor<T>(new Reflector<T>(cursorType), ctx, ParserFactory.newParser(), reader);
    } catch (XmlPullParserException e) {
      throw new CursorException(e);
    }
  }

  /**
   * Creates a new cursor. Many cursors can be created from a single CursorDef.
   * @param input The XML input stream.
   * @param objectFactory An object factory that allows the application to provide its own objects instantiation mechanism.
   * @return A cursor.
   */
  public Cursor<T> pull(InputStream input, ObjectFactory<T> objectFactory) {
    try {
      return new Cursor<T>(new Reflector<T>(objectFactory), ctx, ParserFactory.newParser(), input);
    } catch (XmlPullParserException e) {
      throw new CursorException(e);
    }
  }

  /**
   * Creates a new cursor. Many cursors can be created from a single CursorDef.
   * @param reader The XML reader.
   * @param objectFactory An object factory that allows the application to provide its own objects instantiation mechanism.
   * @return A cursor.
   */
  public Cursor<T> pull(Reader reader, ObjectFactory<T> objectFactory) {
    try {
      return new Cursor<T>(new Reflector<T>(objectFactory), ctx, ParserFactory.newParser(), reader);
    } catch (XmlPullParserException e) {
      throw new CursorException(e);
    }
  }
}




Java Source Code List

labrom.colibri.Util.java
labrom.colibri.cache.CacheEntry.java
labrom.colibri.cache.Cache.java
labrom.colibri.cache.Entries.java
labrom.colibri.data.ActiveContentProvider.java
labrom.colibri.data.ActiveRecordList.java
labrom.colibri.data.ActiveRecord.java
labrom.colibri.data.Database.java
labrom.colibri.data.SelectionArgs.java
labrom.colibri.xml.AttributeContext.java
labrom.colibri.xml.CursorDef.java
labrom.colibri.xml.CursorException.java
labrom.colibri.xml.Cursor.java
labrom.colibri.xml.CustomMap.java
labrom.colibri.xml.ElementContext.java
labrom.colibri.xml.FieldSetter.java
labrom.colibri.xml.Item.java
labrom.colibri.xml.NodeContext.java
labrom.colibri.xml.ObjectFactory.java
labrom.colibri.xml.ParserFactory.java
labrom.colibri.xml.ParserUtil.java
labrom.colibri.xml.PullTest.java
labrom.colibri.xml.ReflectorTest.java
labrom.colibri.xml.Reflector.java
labrom.colibri.xml.RootContext.java
labrom.colibri.xml.SetterTest.java
labrom.colibri.xml.StringToDateTransformer.java
labrom.colibri.xml.StringTransformer.java
labrom.colibri.xml.maps.Cursor4Maps.java
labrom.colibri.xml.maps.CursorDef4Maps.java
labrom.colibri.xml.maps.ElementContext4Maps.java
labrom.colibri.xml.maps.RootContext4Maps.java
labrom.colibri.xml.maps.package-info.java
labrom.colibri.xml.package-info.java