Android Open Source - colibri Node Context






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;
/*from  w w  w  .  ja v a 2 s  . c om*/
import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/**
 * Base abstract class for all XML nodes contexts.
 * 
 * Use {@linkplain RootContext} to start defining XML contexts.
 * 
 * @author Romain Laboisse labrom@gmail.com
 *
 * @param <T> The type of objects that Pulloid will create. This class must be written by developers.
 */
public abstract class NodeContext<T> {
  
  ElementContext<T> parent;
  NodeContext<T> nextSibling;
  String name;
  StringTransformer<?> transformer;
  FieldSetter<T> setter;


  
  protected NodeContext(ElementContext<T> parent, String name) {
    this.parent = parent;
    this.name = name;
  }
  

  public void setStringTransformer(StringTransformer<?> tr) {
    this.transformer = tr;
  }
  
  void registerField(String name) {
    registerField(name, null, null);
  }
  
  void registerField(String name, Class<?> type) {
    registerField(name, type, null);
  }
  
  /**
   * Registers a field with a {@link StringTransformer}.
   * @param <TT>
   * @param name
   * @param type The type of the field to set. If the {@link StringTransformer} is not null then the type must be specified too
   * and type parameters must be the same.
   * @param tr A string transformer. If not null, the {@code type} parameter must be non-null too.
   */
  protected <TT> void registerField(String name, Class<TT> type, StringTransformer<TT> tr) {
    CursorDef<T> cursorDef = findCursorDef();
    if(cursorDef == null)
      throw new CursorException("Operation not allowed in this context, a cursor must be defined before fields are registered");
    if(tr != null && type == null)
      throw new CursorException("A string transformer was passed but no associated target type");
    this.setter = new FieldSetter<T>(cursorDef.cursorType, name, type);
    this.transformer = tr;
  }
  
  protected void registerField(String name, Class<?> type, StringTransformer<?> tr, FieldSetter<T> setter) {
    CursorDef<T> cursorDef = findCursorDef();
    if(cursorDef == null)
      throw new CursorException("Operation not allowed in this context, a cursor must be defined before fields are registered");
    this.setter = setter;
    this.transformer = tr;
  }

  CursorDef<T> findCursorDef() {
    if(parent != null)
      return parent.findCursorDef();
    return null;
  }


  abstract void hydrate(XmlPullParser p, Reflector<T> record) throws XmlPullParserException, IOException;

  
}




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