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.IntNode;
00033 import org.codehaus.jackson.node.ObjectNode;
00034 import org.codehaus.jackson.node.TextNode;
00035 import org.xbmc.android.jsonrpc.api.AbstractModel;
00036
00037 public final class ApplicationModel {
00038
00045 public static class PropertyValue extends AbstractModel {
00046 public final static String API_TYPE = "Application.Property.Value";
00047
00048
00049 public static final String MUTED = "muted";
00050 public static final String NAME = "name";
00051 public static final String VERSION = "version";
00052 public static final String VOLUME = "volume";
00053
00054
00055 public final Boolean muted;
00056 public final String name;
00057 public final Version version;
00058 public final Integer volume;
00059
00066 public PropertyValue(Boolean muted, String name, Version version, Integer volume) {
00067 this.muted = muted;
00068 this.name = name;
00069 this.version = version;
00070 this.volume = volume;
00071 }
00072
00077 public PropertyValue(JsonNode node) {
00078 muted = parseBoolean(node, MUTED);
00079 name = parseString(node, NAME);
00080 version = node.has(VERSION) ? new Version(node.get(VERSION)) : null;
00081 volume = parseInt(node, VOLUME);
00082 }
00083
00084 @Override
00085 public JsonNode toJsonNode() {
00086 final ObjectNode node = OM.createObjectNode();
00087 node.put(MUTED, muted);
00088 node.put(NAME, name);
00089 node.put(VERSION, version.toJsonNode());
00090 node.put(VOLUME, volume);
00091 return node;
00092 }
00093
00099 static List<PropertyValue> getApplicationModelPropertyValueList(JsonNode node, String key) {
00100 if (node.has(key)) {
00101 final ArrayNode a = (ArrayNode)node.get(key);
00102 final List<PropertyValue> l = new ArrayList<PropertyValue>(a.size());
00103 for (int i = 0; i < a.size(); i++) {
00104 l.add(new PropertyValue((JsonNode)a.get(i)));
00105 }
00106 return l;
00107 }
00108 return new ArrayList<PropertyValue>(0);
00109 }
00110
00116 @Override
00117 public void writeToParcel(Parcel parcel, int flags) {
00118 parcel.writeInt(muted ? 1 : 0);
00119 parcel.writeValue(name);
00120 parcel.writeValue(version);
00121 parcel.writeValue(volume);
00122 }
00123
00127 protected PropertyValue(Parcel parcel) {
00128 muted = parcel.readInt() == 1;
00129 name = parcel.readString();
00130 version = parcel.<Version>readParcelable(Version.class.getClassLoader());
00131 volume = parcel.readInt();
00132 }
00133
00137 public static final Parcelable.Creator<PropertyValue> CREATOR = new Parcelable.Creator<PropertyValue>() {
00138 @Override
00139 public PropertyValue createFromParcel(Parcel parcel) {
00140 return new PropertyValue(parcel);
00141 }
00142 @Override
00143 public PropertyValue[] newArray(int n) {
00144 return new PropertyValue[n];
00145 }
00146 };
00147
00148 @Override
00149 public int describeContents() {
00150 return 0;
00151 }
00152
00157 public static class Version extends AbstractModel {
00158
00159
00160 public static final String MAJOR = "major";
00161 public static final String MINOR = "minor";
00162 public static final String REVISION = "revision";
00163 public static final String TAG = "tag";
00164
00165
00166 public final Integer major;
00167 public final Integer minor;
00168 public final Revision revision;
00169 public final String tag;
00170
00177 public Version(Integer major, Integer minor, Revision revision, String tag) {
00178 this.major = major;
00179 this.minor = minor;
00180 this.revision = revision;
00181 this.tag = tag;
00182 }
00183
00188 public Version(JsonNode node) {
00189 major = node.get(MAJOR).getIntValue();
00190 minor = node.get(MINOR).getIntValue();
00191 revision = node.has(REVISION) ? new Revision(node.get(REVISION)) : null;
00192 tag = parseString(node, TAG);
00193 }
00194
00195 @Override
00196 public JsonNode toJsonNode() {
00197 final ObjectNode node = OM.createObjectNode();
00198 node.put(MAJOR, major);
00199 node.put(MINOR, minor);
00200 node.put(REVISION, revision.toJsonNode());
00201 node.put(TAG, tag);
00202 return node;
00203 }
00204
00210 static List<Version> getApplicationModelVersionList(JsonNode node, String key) {
00211 if (node.has(key)) {
00212 final ArrayNode a = (ArrayNode)node.get(key);
00213 final List<Version> l = new ArrayList<Version>(a.size());
00214 for (int i = 0; i < a.size(); i++) {
00215 l.add(new Version((JsonNode)a.get(i)));
00216 }
00217 return l;
00218 }
00219 return new ArrayList<Version>(0);
00220 }
00221
00227 @Override
00228 public void writeToParcel(Parcel parcel, int flags) {
00229 parcel.writeValue(major);
00230 parcel.writeValue(minor);
00231 parcel.writeValue(revision);
00232 parcel.writeValue(tag);
00233 }
00234
00238 protected Version(Parcel parcel) {
00239 major = parcel.readInt();
00240 minor = parcel.readInt();
00241 revision = parcel.<Revision>readParcelable(Revision.class.getClassLoader());
00242 tag = parcel.readString();
00243 }
00244
00248 public static final Parcelable.Creator<Version> CREATOR = new Parcelable.Creator<Version>() {
00249 @Override
00250 public Version createFromParcel(Parcel parcel) {
00251 return new Version(parcel);
00252 }
00253 @Override
00254 public Version[] newArray(int n) {
00255 return new Version[n];
00256 }
00257 };
00258
00259 @Override
00260 public int describeContents() {
00261 return 0;
00262 }
00263
00268 public static class Revision extends AbstractModel {
00269
00270
00271 public final Integer integerArg;
00272 public final String stringArg;
00273
00277 public Revision(Integer integerArg) {
00278 this.integerArg = integerArg;
00279 this.stringArg = null;
00280 }
00281
00285 public Revision(String stringArg) {
00286 this.stringArg = stringArg;
00287 this.integerArg = null;
00288 }
00289
00294 public Revision(JsonNode node) {
00295 if (node.isInt()) {
00296 integerArg = node.getIntValue();
00297 stringArg = null;
00298 }
00299 else if (node.isTextual()) {
00300 stringArg = node.getTextValue();
00301 integerArg = null;
00302 }
00303 else {
00304 throw new RuntimeException("Weird type for \"revision\", I'm confused!");
00305 }
00306 }
00307
00308 @Override
00309 public JsonNode toJsonNode() {
00310 if (integerArg != null) {
00311 return new IntNode(integerArg);
00312 }
00313 if (stringArg != null) {
00314 return new TextNode(stringArg);
00315 }
00316 return null;
00317 }
00318
00324 static List<Revision> getApplicationModelRevisionList(JsonNode node, String key) {
00325 if (node.has(key)) {
00326 final ArrayNode a = (ArrayNode)node.get(key);
00327 final List<Revision> l = new ArrayList<Revision>(a.size());
00328 for (int i = 0; i < a.size(); i++) {
00329 l.add(new Revision((JsonNode)a.get(i)));
00330 }
00331 return l;
00332 }
00333 return new ArrayList<Revision>(0);
00334 }
00335
00341 @Override
00342 public void writeToParcel(Parcel parcel, int flags) {
00343 parcel.writeValue(integerArg);
00344 parcel.writeValue(stringArg);
00345 }
00346
00350 protected Revision(Parcel parcel) {
00351 integerArg = parcel.readInt();
00352 stringArg = parcel.readString();
00353 }
00354
00358 public static final Parcelable.Creator<Revision> CREATOR = new Parcelable.Creator<Revision>() {
00359 @Override
00360 public Revision createFromParcel(Parcel parcel) {
00361 return new Revision(parcel);
00362 }
00363 @Override
00364 public Revision[] newArray(int n) {
00365 return new Revision[n];
00366 }
00367 };
00368
00369 @Override
00370 public int describeContents() {
00371 return 0;
00372 }
00373 }
00374
00378 public interface Tag {
00379
00380 public final String PREALPHA = "prealpha";
00381 public final String ALPHA = "alpha";
00382 public final String BETA = "beta";
00383 public final String RELEASECANDIDATE = "releasecandidate";
00384 public final String STABLE = "stable";
00385
00386 public final static Set<String> values = new HashSet<String>(Arrays.asList(PREALPHA, ALPHA, BETA, RELEASECANDIDATE, STABLE));
00387 }
00388 }
00389 }
00390
00394 public interface PropertyName {
00395
00396 public final String VOLUME = "volume";
00397 public final String MUTED = "muted";
00398 public final String NAME = "name";
00399 public final String VERSION = "version";
00400
00401 public final static Set<String> values = new HashSet<String>(Arrays.asList(VOLUME, MUTED, NAME, VERSION));
00402 }
00403 }