diff --git a/src/oca/java/src/org/opennebula/client/Pool.java b/src/oca/java/src/org/opennebula/client/Pool.java
index 69d694bcfd..6afc200198 100644
--- a/src/oca/java/src/org/opennebula/client/Pool.java
+++ b/src/oca/java/src/org/opennebula/client/Pool.java
@@ -108,7 +108,7 @@ public abstract class Pool{
return xmlrpcInfo(client, infoMethod, MINE_GROUP, -1, -1);
}
- private static OneResponse xmlrpcInfo(Client client, String infoMethod, Object...args)
+ protected static OneResponse xmlrpcInfo(Client client, String infoMethod, Object...args)
{
return client.call(infoMethod, args);
}
@@ -153,7 +153,7 @@ public abstract class Pool{
* representation of the pool.
* @param info The XML-RPC *pool.info response
*/
- public void processInfo(OneResponse info)
+ protected void processInfo(OneResponse info)
{
if (info.isError())
{
diff --git a/src/oca/java/src/org/opennebula/client/document/Document.java b/src/oca/java/src/org/opennebula/client/document/Document.java
new file mode 100644
index 0000000000..0b92c1a051
--- /dev/null
+++ b/src/oca/java/src/org/opennebula/client/document/Document.java
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.opennebula.client.document;
+
+import org.opennebula.client.Client;
+import org.opennebula.client.OneResponse;
+import org.opennebula.client.PoolElement;
+import org.w3c.dom.Node;
+
+/**
+ * This class represents an OpenNebula document.
+ * Documents are generic objects. You can dynamically create new Pools in
+ * OpenNebula, creating subclasses with different TYPE values.
+ *
+ * TYPE must be the same for the corresponding pool, see {@link DocumentPool}
+ *
+ * For example:
+ *
+ *
+ * public class GenericObjA extends Document
+ * {
+ * private static final int TYPE = 200;
+ *
+ * protected int type()
+ * {
+ * return TYPE;
+ * }
+ *
+ * public GenericObjA(int id, Client client)
+ * {
+ * super(id, client);
+ * }
+ *
+ * public GenericObjA(Node xmlElement, Client client)
+ * {
+ * super(xmlElement, client);
+ * }
+ *
+ * public static OneResponse allocate(Client client, String description)
+ * {
+ * return Document.allocate(client, description, TYPE);
+ * }
+ * }
+ *
+ *
+ *
+ */
+public abstract class Document extends PoolElement
+{
+
+ private static final String METHOD_PREFIX = "document.";
+ private static final String ALLOCATE = METHOD_PREFIX + "allocate";
+ private static final String DELETE = METHOD_PREFIX + "delete";
+ private static final String INFO = METHOD_PREFIX + "info";
+
+ private static final String UPDATE = METHOD_PREFIX + "update";
+ private static final String CHOWN = METHOD_PREFIX + "chown";
+ private static final String CHMOD = METHOD_PREFIX + "chmod";
+ private static final String CLONE = METHOD_PREFIX + "clone";
+
+ /**
+ * Creates a new Document representation.
+ * @param id The document id.
+ * @param client XML-RPC Client.
+ */
+ public Document(int id, Client client)
+ {
+ super(id, client);
+ }
+
+ /**
+ * @see PoolElement
+ */
+ public Document(Node xmlElement, Client client)
+ {
+ super(xmlElement, client);
+ }
+
+ protected abstract int type();
+
+ // =================================
+ // Static XML-RPC methods
+ // =================================
+
+ /**
+ * Allocates a new Document in OpenNebula.
+ *
+ * @param client XML-RPC Client.
+ * @param description A string containing the template of the document.
+ * @return If successful the message contains the associated
+ * id generated for this Document.
+ */
+ protected static OneResponse allocate(Client client, String description, int type)
+ {
+ return client.call(ALLOCATE, description, type);
+ }
+
+ /**
+ * Retrieves the information of the given Document.
+ *
+ * @return If successful the message contains the string
+ * with the information returned by OpenNebula.
+ */
+ public OneResponse info()
+ {
+ return client.call(INFO, id, type());
+ }
+
+ /**
+ * Deletes a document from OpenNebula.
+ *
+ * @return A encapsulated response.
+ */
+ public OneResponse delete()
+ {
+ return client.call(DELETE, id, type());
+ }
+
+ /**
+ * Replaces the document template contents.
+ *
+ * @param new_document New template contents.
+ * @return If successful the message contains the document id.
+ */
+ public OneResponse update(String new_document)
+ {
+ return client.call(UPDATE, id, new_document, type());
+ }
+
+ /**
+ * Publishes or unpublishes a document.
+ *
+ * @param publish True for publishing, false for unpublishing.
+ * @return If successful the message contains the document id.
+ */
+ public OneResponse publish(boolean publish)
+ {
+ int group_u = publish ? 1 : 0;
+
+ return chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1);
+ }
+
+ /**
+ * Changes the owner/group
+ *
+ * @param uid The new owner user ID. Set it to -1 to leave the current one.
+ * @param gid The new group ID. Set it to -1 to leave the current one.
+ * @return If an error occurs the error message contains the reason.
+ */
+ public OneResponse chown(int uid, int gid)
+ {
+ return client.call(CHOWN, id, uid, gid, type());
+ }
+
+ /**
+ * Changes the document permissions
+ *
+ * @param owner_u 1 to allow, 0 deny, -1 do not change
+ * @param owner_m 1 to allow, 0 deny, -1 do not change
+ * @param owner_a 1 to allow, 0 deny, -1 do not change
+ * @param group_u 1 to allow, 0 deny, -1 do not change
+ * @param group_m 1 to allow, 0 deny, -1 do not change
+ * @param group_a 1 to allow, 0 deny, -1 do not change
+ * @param other_u 1 to allow, 0 deny, -1 do not change
+ * @param other_m 1 to allow, 0 deny, -1 do not change
+ * @param other_a 1 to allow, 0 deny, -1 do not change
+ * @return If an error occurs the error message contains the reason.
+ */
+ public OneResponse chmod( int owner_u, int owner_m, int owner_a,
+ int group_u, int group_m, int group_a,
+ int other_u, int other_m, int other_a)
+ {
+ return chmod(client, CHMOD, id,
+ owner_u, owner_m, owner_a,
+ group_u, group_m, group_a,
+ other_u, other_m, other_a);
+ }
+
+ /**
+ * Changes the permissions
+ *
+ * @param octet Permissions octed , e.g. 640
+ * @return If an error occurs the error message contains the reason.
+ */
+ public OneResponse chmod(String octet)
+ {
+ return chmod(client, CHMOD, id, octet);
+ }
+
+ /**
+ * Changes the permissions
+ *
+ * @param octet Permissions octed , e.g. 640
+ * @return If an error occurs the error message contains the reason.
+ */
+ public OneResponse chmod(int octet)
+ {
+ return chmod(client, CHMOD, id, octet);
+ }
+
+ /**
+ * Clones this document into a new one
+ *
+ * @param name Name for the new document.
+ * @return If successful the message contains the new document ID.
+ */
+ public OneResponse clone(String name)
+ {
+ return client.call(CLONE, id, name, type());
+ }
+
+ // =================================
+ // Helpers
+ // =================================
+
+ /**
+ * Publishes the document.
+ *
+ * @return If successful the message contains the document id.
+ */
+ public OneResponse publish()
+ {
+ return publish(true);
+ }
+
+ /**
+ * Unpublishes the document.
+ *
+ * @return If successful the message contains the document id.
+ */
+ public OneResponse unpublish()
+ {
+ return publish(false);
+ }
+
+ /**
+ * Changes the owner
+ *
+ * @param uid The new owner user ID.
+ * @return If an error occurs the error message contains the reason.
+ */
+ public OneResponse chown(int uid)
+ {
+ return chown(uid, -1);
+ }
+
+ /**
+ * Changes the group
+ *
+ * @param gid The new group ID.
+ * @return If an error occurs the error message contains the reason.
+ */
+ public OneResponse chgrp(int gid)
+ {
+ return chown(-1, gid);
+ }
+}
diff --git a/src/oca/java/src/org/opennebula/client/document/DocumentPool.java b/src/oca/java/src/org/opennebula/client/document/DocumentPool.java
new file mode 100644
index 0000000000..80e588627f
--- /dev/null
+++ b/src/oca/java/src/org/opennebula/client/document/DocumentPool.java
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.opennebula.client.document;
+
+import org.opennebula.client.Client;
+import org.opennebula.client.OneResponse;
+import org.opennebula.client.Pool;
+
+/**
+ * + * This class represents an OpenNebula Document pool. + *
+ * Documents are generic objects. You can dynamically create new Pools in + * OpenNebula, creating subclasses with different TYPE values. + *
+ *
+ * public class GenericObjAPool extends DocumentPool implements Iterable{@code }
+ * {
+ * private static final int TYPE = 200;
+ *
+ * protected int type()
+ * {
+ * return TYPE;
+ * }
+ *
+ * public GenericObjAPool(Client client)
+ * {
+ * super(client);
+ * }
+ *
+ * public GenericObjAPool(Client client, int filter)
+ * {
+ * super(client, filter);
+ * }
+ *
+ * public GenericObjA factory(Node node)
+ * {
+ * return new GenericObjA(node, client);
+ * }
+ *
+ * {@code public Iterator iterator()}
+ * {
+ * {@code AbstractList ab = new AbstractList()}
+ * {
+ * public int size()
+ * {
+ * return getLength();
+ * }
+ *
+ * public GenericObjA get(int index)
+ * {
+ * return (GenericObjA) item(index);
+ * }
+ * };
+ *
+ * return ab.iterator();
+ * }
+ * }
+ *
+ *
+ */
+public abstract class DocumentPool extends Pool
+{
+ private static final String ELEMENT_NAME = "DOCUMENT";
+ private static final String INFO_METHOD = "documentpool.info";
+
+ private final int filter;
+
+ protected abstract int type();
+
+ /**
+ * Creates a new Document pool with the default filter flag value
+ * set to {@link Pool#MINE_GROUP} (Document belonging to the connected user,
+ * and the ones in his group)
+ *
+ * @param client XML-RPC Client.
+ *
+ * @see DocumentPool#DocumentPool(Client, int)
+ */
+ public DocumentPool(Client client)
+ {
+ super(ELEMENT_NAME, client, INFO_METHOD);
+ this.filter = MINE_GROUP;
+ }
+
+ /**
+ * Creates a new Document pool.
+ *
+ * @param client XML-RPC Client.
+ * @param filter Filter flag to use by default in the method
+ * {@link DocumentPool#info()}. Possible values:
+ *