Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package org.xbmc.android.jsonrpc.api.model;
00022
00023 import android.os.Parcel;
00024 import android.os.Parcelable;
00025 import java.util.ArrayList;
00026 import java.util.Arrays;
00027 import java.util.HashSet;
00028 import java.util.List;
00029 import java.util.Set;
00030 import org.codehaus.jackson.JsonNode;
00031 import org.codehaus.jackson.node.ArrayNode;
00032 import org.codehaus.jackson.node.ObjectNode;
00033 import org.xbmc.android.jsonrpc.api.AbstractModel;
00034
00035 public final class SystemModel {
00036
00043 public static class PropertyValue extends AbstractModel {
00044 public final static String API_TYPE = "System.Property.Value";
00045
00046
00047 public static final String CANHIBERNATE = "canhibernate";
00048 public static final String CANREBOOT = "canreboot";
00049 public static final String CANSHUTDOWN = "canshutdown";
00050 public static final String CANSUSPEND = "cansuspend";
00051
00052
00053 public final Boolean canhibernate;
00054 public final Boolean canreboot;
00055 public final Boolean canshutdown;
00056 public final Boolean cansuspend;
00057
00064 public PropertyValue(Boolean canhibernate, Boolean canreboot, Boolean canshutdown, Boolean cansuspend) {
00065 this.canhibernate = canhibernate;
00066 this.canreboot = canreboot;
00067 this.canshutdown = canshutdown;
00068 this.cansuspend = cansuspend;
00069 }
00070
00075 public PropertyValue(JsonNode node) {
00076 canhibernate = parseBoolean(node, CANHIBERNATE);
00077 canreboot = parseBoolean(node, CANREBOOT);
00078 canshutdown = parseBoolean(node, CANSHUTDOWN);
00079 cansuspend = parseBoolean(node, CANSUSPEND);
00080 }
00081
00082 @Override
00083 public JsonNode toJsonNode() {
00084 final ObjectNode node = OM.createObjectNode();
00085 node.put(CANHIBERNATE, canhibernate);
00086 node.put(CANREBOOT, canreboot);
00087 node.put(CANSHUTDOWN, canshutdown);
00088 node.put(CANSUSPEND, cansuspend);
00089 return node;
00090 }
00091
00097 static List<PropertyValue> getSystemModelPropertyValueList(JsonNode node, String key) {
00098 if (node.has(key)) {
00099 final ArrayNode a = (ArrayNode)node.get(key);
00100 final List<PropertyValue> l = new ArrayList<PropertyValue>(a.size());
00101 for (int i = 0; i < a.size(); i++) {
00102 l.add(new PropertyValue((JsonNode)a.get(i)));
00103 }
00104 return l;
00105 }
00106 return new ArrayList<PropertyValue>(0);
00107 }
00108
00114 @Override
00115 public void writeToParcel(Parcel parcel, int flags) {
00116 parcel.writeInt(canhibernate ? 1 : 0);
00117 parcel.writeInt(canreboot ? 1 : 0);
00118 parcel.writeInt(canshutdown ? 1 : 0);
00119 parcel.writeInt(cansuspend ? 1 : 0);
00120 }
00121
00125 protected PropertyValue(Parcel parcel) {
00126 canhibernate = parcel.readInt() == 1;
00127 canreboot = parcel.readInt() == 1;
00128 canshutdown = parcel.readInt() == 1;
00129 cansuspend = parcel.readInt() == 1;
00130 }
00131
00135 public static final Parcelable.Creator<PropertyValue> CREATOR = new Parcelable.Creator<PropertyValue>() {
00136 @Override
00137 public PropertyValue createFromParcel(Parcel parcel) {
00138 return new PropertyValue(parcel);
00139 }
00140 @Override
00141 public PropertyValue[] newArray(int n) {
00142 return new PropertyValue[n];
00143 }
00144 };
00145
00146 @Override
00147 public int describeContents() {
00148 return 0;
00149 }
00150 }
00151
00155 public interface PropertyName {
00156
00157 public final String CANSHUTDOWN = "canshutdown";
00158 public final String CANSUSPEND = "cansuspend";
00159 public final String CANHIBERNATE = "canhibernate";
00160 public final String CANREBOOT = "canreboot";
00161
00162 public final static Set<String> values = new HashSet<String>(Arrays.asList(CANSHUTDOWN, CANSUSPEND, CANHIBERNATE, CANREBOOT));
00163 }
00164 }