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.BooleanNode;
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 AddonModel {
00038
00045 public static class Detail extends ItemModel.BaseDetail {
00046 public final static String API_TYPE = "Addon.Details";
00047
00048
00049 public static final String ADDONID = "addonid";
00050 public static final String AUTHOR = "author";
00051 public static final String BROKEN = "broken";
00052 public static final String DEPENDENCIES = "dependencies";
00053 public static final String DESCRIPTION = "description";
00054 public static final String DISCLAIMER = "disclaimer";
00055 public static final String ENABLED = "enabled";
00056 public static final String EXTRAINFO = "extrainfo";
00057 public static final String FANART = "fanart";
00058 public static final String NAME = "name";
00059 public static final String PATH = "path";
00060 public static final String RATING = "rating";
00061 public static final String SUMMARY = "summary";
00062 public static final String THUMBNAIL = "thumbnail";
00063 public static final String TYPE = "type";
00064 public static final String VERSION = "version";
00065
00066
00067 public final String addonid;
00068 public final String author;
00069 public final Broken broken;
00070 public final List<Dependency> dependencies;
00071 public final String description;
00072 public final String disclaimer;
00073 public final Boolean enabled;
00074 public final List<Extrainfo> extrainfo;
00075 public final String fanart;
00076 public final String name;
00077 public final String path;
00078 public final Integer rating;
00079 public final String summary;
00080 public final String thumbnail;
00081 public final String type;
00082 public final String version;
00083
00088 public Detail(JsonNode node) {
00089 super(node);
00090 addonid = node.get(ADDONID).getTextValue();
00091 author = parseString(node, AUTHOR);
00092 broken = node.has(BROKEN) ? new Broken(node.get(BROKEN)) : null;
00093 dependencies = Dependency.getAddonModelDependencyList(node, DEPENDENCIES);
00094 description = parseString(node, DESCRIPTION);
00095 disclaimer = parseString(node, DISCLAIMER);
00096 enabled = parseBoolean(node, ENABLED);
00097 extrainfo = Extrainfo.getAddonModelExtrainfoList(node, EXTRAINFO);
00098 fanart = parseString(node, FANART);
00099 name = parseString(node, NAME);
00100 path = parseString(node, PATH);
00101 rating = parseInt(node, RATING);
00102 summary = parseString(node, SUMMARY);
00103 thumbnail = parseString(node, THUMBNAIL);
00104 type = parseString(node, TYPE);
00105 version = parseString(node, VERSION);
00106 }
00107
00108 @Override
00109 public JsonNode toJsonNode() {
00110 final ObjectNode node = (ObjectNode)super.toJsonNode();
00111 node.put(ADDONID, addonid);
00112 node.put(AUTHOR, author);
00113 node.put(BROKEN, broken.toJsonNode());
00114 final ArrayNode dependenciesArray = OM.createArrayNode();
00115 for (Dependency item : dependencies) {
00116 dependenciesArray.add(item.toJsonNode());
00117 }
00118 node.put(DEPENDENCIES, dependenciesArray);
00119 node.put(DESCRIPTION, description);
00120 node.put(DISCLAIMER, disclaimer);
00121 node.put(ENABLED, enabled);
00122 final ArrayNode extrainfoArray = OM.createArrayNode();
00123 for (Extrainfo item : extrainfo) {
00124 extrainfoArray.add(item.toJsonNode());
00125 }
00126 node.put(EXTRAINFO, extrainfoArray);
00127 node.put(FANART, fanart);
00128 node.put(NAME, name);
00129 node.put(PATH, path);
00130 node.put(RATING, rating);
00131 node.put(SUMMARY, summary);
00132 node.put(THUMBNAIL, thumbnail);
00133 node.put(TYPE, type);
00134 node.put(VERSION, version);
00135 return node;
00136 }
00137
00143 static List<Detail> getAddonModelDetailList(JsonNode node, String key) {
00144 if (node.has(key)) {
00145 final ArrayNode a = (ArrayNode)node.get(key);
00146 final List<Detail> l = new ArrayList<Detail>(a.size());
00147 for (int i = 0; i < a.size(); i++) {
00148 l.add(new Detail((JsonNode)a.get(i)));
00149 }
00150 return l;
00151 }
00152 return new ArrayList<Detail>(0);
00153 }
00154
00160 @Override
00161 public void writeToParcel(Parcel parcel, int flags) {
00162 super.writeToParcel(parcel, flags);
00163 parcel.writeValue(addonid);
00164 parcel.writeValue(author);
00165 parcel.writeValue(broken);
00166 parcel.writeInt(dependencies.size());
00167 for (Dependency item : dependencies) {
00168 parcel.writeParcelable(item, flags);
00169 }
00170 parcel.writeValue(description);
00171 parcel.writeValue(disclaimer);
00172 parcel.writeInt(enabled ? 1 : 0);
00173 parcel.writeInt(extrainfo.size());
00174 for (Extrainfo item : extrainfo) {
00175 parcel.writeParcelable(item, flags);
00176 }
00177 parcel.writeValue(fanart);
00178 parcel.writeValue(name);
00179 parcel.writeValue(path);
00180 parcel.writeValue(rating);
00181 parcel.writeValue(summary);
00182 parcel.writeValue(thumbnail);
00183 parcel.writeValue(type);
00184 parcel.writeValue(version);
00185 }
00186
00190 protected Detail(Parcel parcel) {
00191 super(parcel);
00192 addonid = parcel.readString();
00193 author = parcel.readString();
00194 broken = parcel.<Broken>readParcelable(Broken.class.getClassLoader());
00195 final int dependenciesSize = parcel.readInt();
00196 dependencies = new ArrayList<Dependency>(dependenciesSize);
00197 for (int i = 0; i < dependenciesSize; i++) {
00198 dependencies.add(parcel.<Dependency>readParcelable(Dependency.class.getClassLoader()));
00199 }
00200 description = parcel.readString();
00201 disclaimer = parcel.readString();
00202 enabled = parcel.readInt() == 1;
00203 final int extrainfoSize = parcel.readInt();
00204 extrainfo = new ArrayList<Extrainfo>(extrainfoSize);
00205 for (int i = 0; i < extrainfoSize; i++) {
00206 extrainfo.add(parcel.<Extrainfo>readParcelable(Extrainfo.class.getClassLoader()));
00207 }
00208 fanart = parcel.readString();
00209 name = parcel.readString();
00210 path = parcel.readString();
00211 rating = parcel.readInt();
00212 summary = parcel.readString();
00213 thumbnail = parcel.readString();
00214 type = parcel.readString();
00215 version = parcel.readString();
00216 }
00217
00221 public static final Parcelable.Creator<Detail> CREATOR = new Parcelable.Creator<Detail>() {
00222 @Override
00223 public Detail createFromParcel(Parcel parcel) {
00224 return new Detail(parcel);
00225 }
00226 @Override
00227 public Detail[] newArray(int n) {
00228 return new Detail[n];
00229 }
00230 };
00231
00232 @Override
00233 public int describeContents() {
00234 return 0;
00235 }
00236
00241 public static class Broken extends AbstractModel {
00242
00243
00244 public final Boolean booleanArg;
00245 public final String stringArg;
00246
00250 public Broken(Boolean booleanArg) {
00251 this.booleanArg = booleanArg;
00252 this.stringArg = null;
00253 }
00254
00258 public Broken(String stringArg) {
00259 this.stringArg = stringArg;
00260 this.booleanArg = null;
00261 }
00262
00267 public Broken(JsonNode node) {
00268 if (node.isBoolean()) {
00269 booleanArg = node.getBooleanValue();
00270 stringArg = null;
00271 }
00272 else if (node.isTextual()) {
00273 stringArg = node.getTextValue();
00274 booleanArg = null;
00275 }
00276 else {
00277 throw new RuntimeException("Weird type for \"broken\", I'm confused!");
00278 }
00279 }
00280
00281 @Override
00282 public JsonNode toJsonNode() {
00283 if (booleanArg != null) {
00284 return booleanArg ? BooleanNode.TRUE : BooleanNode.FALSE;
00285 }
00286 if (stringArg != null) {
00287 return new TextNode(stringArg);
00288 }
00289 return null;
00290 }
00291
00297 static List<Broken> getAddonModelBrokenList(JsonNode node, String key) {
00298 if (node.has(key)) {
00299 final ArrayNode a = (ArrayNode)node.get(key);
00300 final List<Broken> l = new ArrayList<Broken>(a.size());
00301 for (int i = 0; i < a.size(); i++) {
00302 l.add(new Broken((JsonNode)a.get(i)));
00303 }
00304 return l;
00305 }
00306 return new ArrayList<Broken>(0);
00307 }
00308
00314 @Override
00315 public void writeToParcel(Parcel parcel, int flags) {
00316 parcel.writeInt(booleanArg ? 1 : 0);
00317 parcel.writeValue(stringArg);
00318 }
00319
00323 protected Broken(Parcel parcel) {
00324 booleanArg = parcel.readInt() == 1;
00325 stringArg = parcel.readString();
00326 }
00327
00331 public static final Parcelable.Creator<Broken> CREATOR = new Parcelable.Creator<Broken>() {
00332 @Override
00333 public Broken createFromParcel(Parcel parcel) {
00334 return new Broken(parcel);
00335 }
00336 @Override
00337 public Broken[] newArray(int n) {
00338 return new Broken[n];
00339 }
00340 };
00341
00342 @Override
00343 public int describeContents() {
00344 return 0;
00345 }
00346 }
00347
00352 public static class Dependency extends AbstractModel {
00353
00354
00355 public static final String ADDONID = "addonid";
00356 public static final String OPTIONAL = "optional";
00357 public static final String VERSION = "version";
00358
00359
00360 public final String addonid;
00361 public final Boolean optional;
00362 public final String version;
00363
00369 public Dependency(String addonid, Boolean optional, String version) {
00370 this.addonid = addonid;
00371 this.optional = optional;
00372 this.version = version;
00373 }
00374
00379 public Dependency(JsonNode node) {
00380 addonid = node.get(ADDONID).getTextValue();
00381 optional = node.get(OPTIONAL).getBooleanValue();
00382 version = node.get(VERSION).getTextValue();
00383 }
00384
00385 @Override
00386 public JsonNode toJsonNode() {
00387 final ObjectNode node = OM.createObjectNode();
00388 node.put(ADDONID, addonid);
00389 node.put(OPTIONAL, optional);
00390 node.put(VERSION, version);
00391 return node;
00392 }
00393
00399 static List<Dependency> getAddonModelDependencyList(JsonNode node, String key) {
00400 if (node.has(key)) {
00401 final ArrayNode a = (ArrayNode)node.get(key);
00402 final List<Dependency> l = new ArrayList<Dependency>(a.size());
00403 for (int i = 0; i < a.size(); i++) {
00404 l.add(new Dependency((JsonNode)a.get(i)));
00405 }
00406 return l;
00407 }
00408 return new ArrayList<Dependency>(0);
00409 }
00410
00416 @Override
00417 public void writeToParcel(Parcel parcel, int flags) {
00418 parcel.writeValue(addonid);
00419 parcel.writeInt(optional ? 1 : 0);
00420 parcel.writeValue(version);
00421 }
00422
00426 protected Dependency(Parcel parcel) {
00427 addonid = parcel.readString();
00428 optional = parcel.readInt() == 1;
00429 version = parcel.readString();
00430 }
00431
00435 public static final Parcelable.Creator<Dependency> CREATOR = new Parcelable.Creator<Dependency>() {
00436 @Override
00437 public Dependency createFromParcel(Parcel parcel) {
00438 return new Dependency(parcel);
00439 }
00440 @Override
00441 public Dependency[] newArray(int n) {
00442 return new Dependency[n];
00443 }
00444 };
00445
00446 @Override
00447 public int describeContents() {
00448 return 0;
00449 }
00450 }
00451
00456 public static class Extrainfo extends AbstractModel {
00457
00458
00459 public static final String KEY = "key";
00460 public static final String VALUE = "value";
00461
00462
00463 public final String key;
00464 public final String value;
00465
00470 public Extrainfo(String key, String value) {
00471 this.key = key;
00472 this.value = value;
00473 }
00474
00479 public Extrainfo(JsonNode node) {
00480 key = node.get(KEY).getTextValue();
00481 value = node.get(VALUE).getTextValue();
00482 }
00483
00484 @Override
00485 public JsonNode toJsonNode() {
00486 final ObjectNode node = OM.createObjectNode();
00487 node.put(KEY, key);
00488 node.put(VALUE, value);
00489 return node;
00490 }
00491
00497 static List<Extrainfo> getAddonModelExtrainfoList(JsonNode node, String key) {
00498 if (node.has(key)) {
00499 final ArrayNode a = (ArrayNode)node.get(key);
00500 final List<Extrainfo> l = new ArrayList<Extrainfo>(a.size());
00501 for (int i = 0; i < a.size(); i++) {
00502 l.add(new Extrainfo((JsonNode)a.get(i)));
00503 }
00504 return l;
00505 }
00506 return new ArrayList<Extrainfo>(0);
00507 }
00508
00514 @Override
00515 public void writeToParcel(Parcel parcel, int flags) {
00516 parcel.writeValue(key);
00517 parcel.writeValue(value);
00518 }
00519
00523 protected Extrainfo(Parcel parcel) {
00524 key = parcel.readString();
00525 value = parcel.readString();
00526 }
00527
00531 public static final Parcelable.Creator<Extrainfo> CREATOR = new Parcelable.Creator<Extrainfo>() {
00532 @Override
00533 public Extrainfo createFromParcel(Parcel parcel) {
00534 return new Extrainfo(parcel);
00535 }
00536 @Override
00537 public Extrainfo[] newArray(int n) {
00538 return new Extrainfo[n];
00539 }
00540 };
00541
00542 @Override
00543 public int describeContents() {
00544 return 0;
00545 }
00546 }
00547
00551 public interface Type {
00552
00553 public final String UNKNOWN = "unknown";
00554 public final String XBMC_METADATA_SCRAPER_ALBUMS = "xbmc.metadata.scraper.albums";
00555 public final String XBMC_METADATA_SCRAPER_ARTISTS = "xbmc.metadata.scraper.artists";
00556 public final String XBMC_METADATA_SCRAPER_MOVIES = "xbmc.metadata.scraper.movies";
00557 public final String XBMC_METADATA_SCRAPER_MUSICVIDEOS = "xbmc.metadata.scraper.musicvideos";
00558 public final String XBMC_METADATA_SCRAPER_TVSHOWS = "xbmc.metadata.scraper.tvshows";
00559 public final String XBMC_UI_SCREENSAVER = "xbmc.ui.screensaver";
00560 public final String XBMC_PLAYER_MUSICVIZ = "xbmc.player.musicviz";
00561 public final String XBMC_PYTHON_PLUGINSOURCE = "xbmc.python.pluginsource";
00562 public final String XBMC_PYTHON_SCRIPT = "xbmc.python.script";
00563 public final String XBMC_PYTHON_WEATHER = "xbmc.python.weather";
00564 public final String XBMC_PYTHON_SUBTITLES = "xbmc.python.subtitles";
00565 public final String XBMC_PYTHON_LYRICS = "xbmc.python.lyrics";
00566 public final String XBMC_GUI_SKIN = "xbmc.gui.skin";
00567 public final String XBMC_GUI_WEBINTERFACE = "xbmc.gui.webinterface";
00568 public final String XBMC_PVRCLIENT = "xbmc.pvrclient";
00569 public final String XBMC_ADDON_VIDEO = "xbmc.addon.video";
00570 public final String XBMC_ADDON_AUDIO = "xbmc.addon.audio";
00571 public final String XBMC_ADDON_IMAGE = "xbmc.addon.image";
00572 public final String XBMC_ADDON_EXECUTABLE = "xbmc.addon.executable";
00573 public final String XBMC_SERVICE = "xbmc.service";
00574
00575 public final static Set<String> values = new HashSet<String>(Arrays.asList(UNKNOWN, XBMC_METADATA_SCRAPER_ALBUMS, XBMC_METADATA_SCRAPER_ARTISTS, XBMC_METADATA_SCRAPER_MOVIES, XBMC_METADATA_SCRAPER_MUSICVIDEOS, XBMC_METADATA_SCRAPER_TVSHOWS, XBMC_UI_SCREENSAVER, XBMC_PLAYER_MUSICVIZ, XBMC_PYTHON_PLUGINSOURCE, XBMC_PYTHON_SCRIPT, XBMC_PYTHON_WEATHER, XBMC_PYTHON_SUBTITLES, XBMC_PYTHON_LYRICS, XBMC_GUI_SKIN, XBMC_GUI_WEBINTERFACE, XBMC_PVRCLIENT, XBMC_ADDON_VIDEO, XBMC_ADDON_AUDIO, XBMC_ADDON_IMAGE, XBMC_ADDON_EXECUTABLE, XBMC_SERVICE));
00576 }
00577 }
00578
00582 public interface Content {
00583
00584 public final String UNKNOWN = "unknown";
00585 public final String VIDEO = "video";
00586 public final String AUDIO = "audio";
00587 public final String IMAGE = "image";
00588 public final String EXECUTABLE = "executable";
00589
00590 public final static Set<String> values = new HashSet<String>(Arrays.asList(UNKNOWN, VIDEO, AUDIO, IMAGE, EXECUTABLE));
00591 }
00592
00596 public interface Fields {
00597
00598 public final String NAME = "name";
00599 public final String VERSION = "version";
00600 public final String SUMMARY = "summary";
00601 public final String DESCRIPTION = "description";
00602 public final String PATH = "path";
00603 public final String AUTHOR = "author";
00604 public final String THUMBNAIL = "thumbnail";
00605 public final String DISCLAIMER = "disclaimer";
00606 public final String FANART = "fanart";
00607 public final String DEPENDENCIES = "dependencies";
00608 public final String BROKEN = "broken";
00609 public final String EXTRAINFO = "extrainfo";
00610 public final String RATING = "rating";
00611 public final String ENABLED = "enabled";
00612
00613 public final static Set<String> values = new HashSet<String>(Arrays.asList(NAME, VERSION, SUMMARY, DESCRIPTION, PATH, AUTHOR, THUMBNAIL, DISCLAIMER, FANART, DEPENDENCIES, BROKEN, EXTRAINFO, RATING, ENABLED));
00614 }
00615
00619 public interface Types {
00620
00621 public final String UNKNOWN = "unknown";
00622 public final String XBMC_METADATA_SCRAPER_ALBUMS = "xbmc.metadata.scraper.albums";
00623 public final String XBMC_METADATA_SCRAPER_ARTISTS = "xbmc.metadata.scraper.artists";
00624 public final String XBMC_METADATA_SCRAPER_MOVIES = "xbmc.metadata.scraper.movies";
00625 public final String XBMC_METADATA_SCRAPER_MUSICVIDEOS = "xbmc.metadata.scraper.musicvideos";
00626 public final String XBMC_METADATA_SCRAPER_TVSHOWS = "xbmc.metadata.scraper.tvshows";
00627 public final String XBMC_UI_SCREENSAVER = "xbmc.ui.screensaver";
00628 public final String XBMC_PLAYER_MUSICVIZ = "xbmc.player.musicviz";
00629 public final String XBMC_PYTHON_PLUGINSOURCE = "xbmc.python.pluginsource";
00630 public final String XBMC_PYTHON_SCRIPT = "xbmc.python.script";
00631 public final String XBMC_PYTHON_WEATHER = "xbmc.python.weather";
00632 public final String XBMC_PYTHON_SUBTITLES = "xbmc.python.subtitles";
00633 public final String XBMC_PYTHON_LYRICS = "xbmc.python.lyrics";
00634 public final String XBMC_GUI_SKIN = "xbmc.gui.skin";
00635 public final String XBMC_GUI_WEBINTERFACE = "xbmc.gui.webinterface";
00636 public final String XBMC_PVRCLIENT = "xbmc.pvrclient";
00637 public final String XBMC_ADDON_VIDEO = "xbmc.addon.video";
00638 public final String XBMC_ADDON_AUDIO = "xbmc.addon.audio";
00639 public final String XBMC_ADDON_IMAGE = "xbmc.addon.image";
00640 public final String XBMC_ADDON_EXECUTABLE = "xbmc.addon.executable";
00641 public final String XBMC_SERVICE = "xbmc.service";
00642
00643 public final static Set<String> values = new HashSet<String>(Arrays.asList(UNKNOWN, XBMC_METADATA_SCRAPER_ALBUMS, XBMC_METADATA_SCRAPER_ARTISTS, XBMC_METADATA_SCRAPER_MOVIES, XBMC_METADATA_SCRAPER_MUSICVIDEOS, XBMC_METADATA_SCRAPER_TVSHOWS, XBMC_UI_SCREENSAVER, XBMC_PLAYER_MUSICVIZ, XBMC_PYTHON_PLUGINSOURCE, XBMC_PYTHON_SCRIPT, XBMC_PYTHON_WEATHER, XBMC_PYTHON_SUBTITLES, XBMC_PYTHON_LYRICS, XBMC_GUI_SKIN, XBMC_GUI_WEBINTERFACE, XBMC_PVRCLIENT, XBMC_ADDON_VIDEO, XBMC_ADDON_AUDIO, XBMC_ADDON_IMAGE, XBMC_ADDON_EXECUTABLE, XBMC_SERVICE));
00644 }
00645 }