From 04c0abd8443c2a2e8834a7bfab49803daeeb70a0 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 16 Nov 2012 11:29:20 +0100 Subject: [PATCH] feature #1617: Datastore types for JAVA OCA --- .../client/datastore/Datastore.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java index 7665af9853..f2bca4788c 100644 --- a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java +++ b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java @@ -36,6 +36,10 @@ public class Datastore extends PoolElement private static final String CHOWN = METHOD_PREFIX + "chown"; private static final String CHMOD = METHOD_PREFIX + "chmod"; + private static final String[] DATASTORE_TYPES = {"IMAGE", "SYSTEM", "FILE"}; + + private static final String[] SHORT_DATASTORE_TYPES = {"img", "sys", "fil"}; + /** * Creates a new Datastore representation. * @param id The datastore id. @@ -358,6 +362,38 @@ public class Datastore extends PoolElement // ================================= // Helpers // ================================= + /** + * Returns the type of the Datastore. + * + * @return The type of the Datastore. + */ + public int type() + { + String state = xpath("TYPE"); + return state != null ? Integer.parseInt( state ) : -1; + } + + /** + * Returns the type of the Datastore as a String. + * + * @return The type of the Datastore as a String. + */ + public String typeStr() + { + int type = type(); + return type != -1 ? DATASTORE_TYPES[type] : null; + } + + /** + * Returns the type of the Datastore as a short String. + * + * @return The type of the Datastore as a short String. + */ + public String shortTypeStr() + { + int type = type(); + return type != -1 ? SHORT_DATASTORE_TYPES[type] : null; + } /** * Returns whether or not the image is part of this datastore