Package ca.carleton.gcrc.couch.onUpload.conversion

Source Code of ca.carleton.gcrc.couch.onUpload.conversion.AbstractDescriptor

package ca.carleton.gcrc.couch.onUpload.conversion;

import net.sf.json.JSONObject;

public abstract class AbstractDescriptor {

  protected abstract JSONObject getJson();

  protected abstract void setSavingRequired(boolean flag);
 
  protected String getStringAttribute(String key) {
    String value = null;

    JSONObject json = getJson();
    if( json.containsKey(key) ) {
      value = json.getString(key);
    }
   
    return value;
  }
 
  protected void setStringAttribute(String key, String value) {
    JSONObject json = getJson();
    json.put(key,value);
    setSavingRequired(true);
  }

  protected boolean getBooleanAttribute(String key) {
    boolean value = false;

    JSONObject json = getJson();
    if( json.containsKey(key) ) {
      value = json.getBoolean(key);
    }
   
    return value;
  }
 
  protected void setBooleanAttribute(String key, boolean value) {
    JSONObject json = getJson();
    json.put(key, value);
    setSavingRequired(true);
  }

  protected long getLongAttribute(String key) {
    long value = -1;

    JSONObject json = getJson();
    if( json.containsKey(key) ) {
      value = json.getLong(key);
    }
   
    return value;
  }
 
  protected void setLongAttribute(String key, long value) {
    if( value >= 0 ) {
      JSONObject json = getJson();
      json.put(key, value);
      setSavingRequired(true);
    }
  }

  protected int getIntAttribute(String key) {
    int value = -1;

    JSONObject json = getJson();
    if( json.containsKey(key) ) {
      value = json.getInt(key);
    }
   
    return value;
  }
 
  protected void setIntAttribute(String key, int value) {
    if( value >= 0 ) {
      JSONObject json = getJson();
      json.put(key, value);
      setSavingRequired(true);
    }
  }
}
TOP

Related Classes of ca.carleton.gcrc.couch.onUpload.conversion.AbstractDescriptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.