Android Open Source - acs-android-sdk C C Object






From Project

Back to project page acs-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project acs-android-sdk 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 com.appcelerator.cloud.sdk;
/*from   ww w  .j  ava 2  s. co m*/
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.json.JSONException;
import org.json.JSONObject;

public class CCObject implements Externalizable {
  protected String objectId;
  protected java.util.Date createdDate;
  protected java.util.Date updatedDate;

  public String getObjectId() {
    return objectId;
  }

  public java.util.Date getCreatedDate() {
    return createdDate;
  }

  public java.util.Date getUpdatedDate() {
    return updatedDate;
  }

  public CCObject(JSONObject jObject) throws ACSClientError {
    try {
      objectId = jObject.getString(CCConstants.ID);
    } catch (JSONException e) {
      throw new ACSClientError("Invalid server response: " + this.getClass().getName() + ": Missing id");
    }

    SimpleDateFormat ccDateFormatter = new SimpleDateFormat(CCConstants.DATE_FORMAT);
    try {
      String dateString = jObject.getString(CCConstants.UPDATED_AT);
      updatedDate = ccDateFormatter.parse(dateString);
    } catch (JSONException e) {
      //        throw new ACSClientError("Invalid Server Response: " + this.getClass().getName() + ": Missing updatedDate");
    } catch (ParseException e) {
      throw new ACSClientError("Invalid Server Response: " + this.getClass().getName() + ": invalid date format for updatedDate");
    }  

    try {
      String dateString = jObject.getString(CCConstants.CREATED_AT);
      createdDate = ccDateFormatter.parse(dateString);
    } catch (JSONException e) {
      //        throw new ACSClientError("Invalid Server Response: " + this.getClass().getName() + ": Missing createdDate");
    } catch (ParseException e) {
      throw new ACSClientError("Invalid Server Response: " + this.getClass().getName() + ": invalid date format for createdDate");
    }

  }

  protected CCObject() {

  }

  public void readExternal(ObjectInput input) throws IOException,
  ClassNotFoundException {
    boolean hasObjectId = input.readBoolean();
    if (hasObjectId) {
      objectId = input.readUTF();
    }

    SimpleDateFormat ccDateFormatter = new SimpleDateFormat(CCConstants.DATE_FORMAT);
    boolean hasCreatedDate = input.readBoolean();
    if (hasCreatedDate) {
      String dateString = input.readUTF();
      try {
        createdDate = ccDateFormatter.parse(dateString);
      } catch (ParseException e) {
      }
    }

    boolean hasUpdatedDate = input.readBoolean();
    if (hasUpdatedDate) {
      String dateString = input.readUTF();
      try {
        updatedDate = ccDateFormatter.parse(dateString);
      } catch (ParseException e) {
      }
    }
  }

  public void writeExternal(ObjectOutput output) throws IOException {
    boolean hasObjectId = true;
    if (objectId == null || objectId.trim().length() == 0) {
      hasObjectId = false;
    } 
    output.writeBoolean(hasObjectId);

    if (hasObjectId) {
      output.writeUTF(objectId);
    }

    SimpleDateFormat ccDateFormatter = new SimpleDateFormat(CCConstants.DATE_FORMAT);

    if (createdDate != null) {
      output.writeBoolean(true);
      output.writeUTF(ccDateFormatter.format(createdDate));
    } else {
      output.writeBoolean(false);
    }

    if (updatedDate != null) {
      output.writeBoolean(true);
      output.writeUTF(ccDateFormatter.format(updatedDate));
    } else {
      output.writeBoolean(false);
    }

  }
}




Java Source Code List

com.appcelerator.cloud.demo.BaloonLayout.java
com.appcelerator.cloud.demo.CheckinAdapter.java
com.appcelerator.cloud.demo.DemoApplication.java
com.appcelerator.cloud.demo.DemoSession.java
com.appcelerator.cloud.demo.Explore.java
com.appcelerator.cloud.demo.MyDlgCustomizer.java
com.appcelerator.cloud.demo.PlaceAdapter.java
com.appcelerator.cloud.demo.PlaceView.java
com.appcelerator.cloud.demo.SignUp.java
com.appcelerator.cloud.demo.TabView.java
com.appcelerator.cloud.demo.UserView.java
com.appcelerator.cloud.pushdemo.ArrivalActivity.java
com.appcelerator.cloud.pushdemo.CustomReceiver.java
com.appcelerator.cloud.pushdemo.ExtendedReceiver.java
com.appcelerator.cloud.pushdemo.GCMUtility.java
com.appcelerator.cloud.pushdemo.PushActivity.java
com.appcelerator.cloud.pushdemo.PushNotificationsManager.java
com.appcelerator.cloud.sdk.ACSClientError.java
com.appcelerator.cloud.sdk.ACSClient.java
com.appcelerator.cloud.sdk.CCConstants.java
com.appcelerator.cloud.sdk.CCMeta.java
com.appcelerator.cloud.sdk.CCMultipartEntity.java
com.appcelerator.cloud.sdk.CCObject.java
com.appcelerator.cloud.sdk.CCPagination.java
com.appcelerator.cloud.sdk.CCRequestMethod.java
com.appcelerator.cloud.sdk.CCResponse.java
com.appcelerator.cloud.sdk.CCUser.java
com.appcelerator.cloud.sdk.SerializableCookie.java
com.appcelerator.cloud.sdk.oauth2.ACSClientDialog.java
com.appcelerator.cloud.sdk.oauth2.DialogError.java
com.appcelerator.cloud.sdk.oauth2.DialogListener.java
com.appcelerator.cloud.sdk.oauth2.DlgCustomizer.java
com.appcelerator.cloud.sdk.oauth2.Util.java
com.appcelerator.com.cloud.demotest.TestDriver.java