Author: rob.stryker(a)jboss.com
Date: 2011-03-01 19:08:54 -0500 (Tue, 01 Mar 2011)
New Revision: 29430
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientBundle.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/API.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Action.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ActionAware.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/AddressList.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusCode.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusRange.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/IdAware.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Image.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Instance.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Key.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Property.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Realm.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ResourceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/StateAware.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractDeltaCloudRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractListObjectsRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateInstanceRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/DeltaCloudRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfileRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfilesRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImageRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImagesRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstanceRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstancesRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmsRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/PerformActionRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/TypeRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/APIUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractActionAwareUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDOMUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ActionUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfileUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfilesUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/IDeltaCloudObjectUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImageUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImagesUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstanceUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstancesUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeyUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeysUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/StringUtils.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/UrlBuilder.java
Log:
JBIDE-7589 cursecursecurse
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientBundle.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientBundle.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientBundle.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,50 @@
+package org.jboss.tools.deltacloud.client;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class DeltaCloudClientBundle extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.jboss.tools.deltacloud.client";
//$NON-NLS-1$
+
+ // The shared instance
+ private static DeltaCloudClientBundle plugin;
+
+ /**
+ * The constructor
+ */
+ public DeltaCloudClientBundle() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static DeltaCloudClientBundle getDefault() {
+ return plugin;
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudException.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.client;
+
+public class DeltaCloudException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudException(String message)
+ {
+ super(message);
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/API.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/API.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/API.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class API extends IdAware {
+
+ private static final long serialVersionUID = 1L;
+
+ public static enum Driver {
+ UNKNOWN, MOCK, EC2;
+
+ public static Driver checkedValueOf(String name) {
+ for (Driver driver : values()) {
+ if (driver.name().equals(name)) {
+ return driver;
+ }
+ }
+ return UNKNOWN;
+ }
+
+ }
+
+ private Driver driver;
+
+ public API() {
+ }
+
+ public void setDriver(Driver driver) {
+ this.driver = driver;
+ }
+
+ public void setDriver(String driver) {
+ setDriver(Driver.checkedValueOf(driver.toUpperCase()));
+ }
+
+ public Driver getDriver() {
+ return driver;
+ }
+
+ @Override
+ public String toString() {
+ return "API [driver=" + driver.name() + super.toString() + "]";
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Action.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Action.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Action.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * An action that may be performed on a resource
+ *
+ * @author André Dietisheim
+ */
+public class Action<OWNER> {
+
+ public static final String START_NAME = "start";
+ public static final String STOP_NAME = "stop";
+ public static final String REBOOT_NAME = "reboot";
+ public static final String DESTROY_NAME = "destroy";
+
+ private String name;
+ private String url;
+ private HttpMethod method;
+ private OWNER owner;
+
+ public HttpMethod getMethod() {
+ return method;
+ }
+
+ public void setMethodString(String method) {
+ this.method = HttpMethod.valueOf(method.toUpperCase());
+ }
+
+ public void setMethod(HttpMethod method) {
+ this.method = method;
+ }
+
+ public void setMethod(String method) {
+ this.method = HttpMethod.valueOf(method.toUpperCase());
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setOwner(OWNER owner) {
+ this.owner = owner;
+ }
+
+ public OWNER getOwner() {
+ return owner;
+ }
+
+ public boolean isStart() {
+ return START_NAME.equals(getName());
+ }
+
+ public boolean isStop() {
+ return STOP_NAME.equals(getName());
+ }
+
+ public boolean isReboot() {
+ return REBOOT_NAME.equals(getName());
+ }
+
+ public boolean isDestroy() {
+ return DESTROY_NAME.equals(getName());
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ActionAware.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ActionAware.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ActionAware.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Martyn Taylor
+ * @author André Dietisheim
+ */
+public abstract class ActionAware<OWNER> extends IdAware {
+
+ private List<Action<OWNER>> actions;
+
+ public Action<OWNER> getAction(String name) {
+ if (name == null) {
+ return null;
+ }
+
+ for (Action<OWNER> action : getActions()) {
+ if (name.equals(action.getName())) {
+ return action;
+ }
+ }
+ return null;
+ }
+
+ public List<String> getActionNames() {
+ ArrayList<String> names = new ArrayList<String>();
+ for (Action<OWNER> action : getActions()) {
+ names.add(action.getName());
+ }
+ return names;
+ }
+
+ public boolean start(DeltaCloudClient client) throws DeltaCloudClientException {
+ return client.performAction(getAction(Action.START_NAME));
+ }
+
+ public boolean stop(DeltaCloudClient client) throws DeltaCloudClientException {
+ return client.performAction(getAction(Action.STOP_NAME));
+ }
+
+ public boolean destroy(DeltaCloudClient client) throws DeltaCloudClientException {
+ return client.performAction(getAction(Action.DESTROY_NAME));
+ }
+
+ public boolean reboot(DeltaCloudClient client) throws DeltaCloudClientException {
+ return client.performAction(getAction(Action.REBOOT_NAME));
+ }
+
+ public boolean canStart() {
+ return getAction(Action.START_NAME) != null;
+ }
+
+ public boolean canStop() {
+ return getAction(Action.STOP_NAME) != null;
+ }
+
+ public boolean canReboot() {
+ return getAction(Action.REBOOT_NAME) != null;
+ }
+
+ public boolean canDestroy() {
+ return getAction(Action.DESTROY_NAME) != null;
+ }
+
+ public void setActions(List<Action<OWNER>> actions) {
+ this.actions = actions;
+ }
+
+ public List<Action<OWNER>> getActions() {
+ return actions;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/AddressList.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/AddressList.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/AddressList.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.List;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlList;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * @author Martyn Taylor
+ * @author André Dietisheim
+ */
+@XmlType
+public class AddressList
+{
+ private static final long serialVersionUID = 1L;
+
+ @XmlElement
+ @XmlList
+ private List<String> addresses;
+
+ public AddressList()
+ {
+ }
+
+ public AddressList(List<String> addresses)
+ {
+ setAddress(addresses);
+ }
+
+ protected void setAddress(List<String> addresses)
+ {
+ this.addresses = addresses;
+ }
+
+ public List<String> getAddress()
+ {
+ return addresses;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudAuthClientException.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class DeltaCloudAuthClientException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudAuthClientException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DeltaCloudAuthClientException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public DeltaCloudAuthClientException(String message)
+ {
+ super(message);
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.List;
+
+import org.jboss.tools.deltacloud.core.client.API.Driver;
+
+/**
+ * @author Martyn Taylor
+ * @author Andre Dietisheim
+ */
+public interface DeltaCloudClient {
+
+ /**
+ * Returns the server type this client is connected to.
+ *
+ * @return the server type
+ *
+ * @see DeltaCloudServerType
+ */
+ public Driver getServerType();
+
+ /**
+ * Returns a list of Delta Cloud Realms
+ *
+ * @return List of Delta Cloud Realms
+ * @throws DeltaCloudClientException
+ */
+ public List<Realm> listRealms() throws DeltaCloudClientException;
+
+ /**
+ * Returns a single Delta Cloud Realm given its ID
+ *
+ * @param realmId
+ * @return Delta Cloud Realm
+ * @throws DeltaCloudClientException
+ */
+ public Realm listRealms(String realmId) throws DeltaCloudClientException;
+
+ public List<HardwareProfile> listProfiles() throws DeltaCloudClientException;
+
+ /**
+ * Returns a Delta Cloud Flavors
+ *
+ * @param flavorId
+ * @return Delta Cloud Flavor
+ * @throws DeltaCloudClientException
+ */
+ public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException;
+
+ /**
+ * Returns a List of Delta Cloud Images
+ *
+ * @return List of Delta Cloud Images
+ * @throws DeltaCloudClientException
+ */
+ public List<Image> listImages() throws DeltaCloudClientException;
+
+ /**
+ * Returns a Delta Cloud Image given its ID
+ *
+ * @param imageId
+ * @return
+ * @throws DeltaCloudClientException
+ */
+ public Image listImages(String imageId) throws DeltaCloudClientException;
+
+ /**
+ * Returns a list of all Instances from the Delta Cloud Provider
+ *
+ * @return
+ * @throws DeltaCloudClientException
+ */
+ public List<Instance> listInstances() throws DeltaCloudClientException;
+
+ /**
+ * Returns an Instance from the Delta Cloud Provider given on the Instances
+ * ID
+ *
+ * @param instanceId
+ * @return
+ * @throws DeltaCloudClientException
+ */
+ public Instance listInstances(String instanceId) throws DeltaCloudClientException;
+
+ /**
+ * Creates a new Delta Cloud Instance based on the Image specified by the
+ * Image ID. Default parameters are used for the Flavor, Realm and Name.
+ * These are specified by the Delta Cloud Provider
+ *
+ * @param imageId
+ * @return The newly created Delta Cloud Instance
+ * @throws DeltaCloudClientException
+ */
+ public Instance createInstance(String imageId) throws DeltaCloudClientException;
+
+ /**
+ * Creates a new Delta Cloud Instance, the instance will be based on the
+ * Image specified by the instance ID. It will be of type flavor and in the
+ * location realm
+ *
+ * @param imageId
+ * @param flavor
+ * @param realm
+ * @param name
+ * @return
+ * @throws DeltaCloudClientException
+ */
+ public Instance createInstance(String name, String imageId, String profileId, String
realmId, String memory, String storage)
+ throws DeltaCloudClientException;
+
+ public Instance createInstance(String name, String imageId, String profileId, String
realmId, String keyname, String memory,
+ String storage) throws DeltaCloudClientException;
+
+ /**
+ * Creates a key for a given name on the deltacloud server.
+ *
+ * @param keyname
+ * the name of the key to retrieve from the server
+ * @param keyStoreLocation
+ * the path to the file to store the key in
+ * @throws DeltaCloudClientException
+ * the delta cloud client exception
+ */
+ public Key createKey(String keyname) throws DeltaCloudClientException;
+
+ /**
+ * Lists all keys available on the deltacloud server this client is
+ * connected to.
+ *
+ * @return the keys that are available
+ * @throws DeltaCloudClientException
+ *
+ */
+ public List<Key> listKeys() throws DeltaCloudClientException;
+
+ /**
+ * Returns a key with the given name if it is available on the server.
+ * Throws a DeltaCloudException if it is not available.
+ */
+ public Key listKey(String id) throws DeltaCloudClientException;
+
+ /**
+ * Performs the given action.
+ *
+ * @param action the action to execute
+ * @return true, if successful
+ *
+ * @see Action
+ */
+ public boolean performAction(Action<?> action) throws DeltaCloudClientException;
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientException.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Martyn Taylor
+ */
+public class DeltaCloudClientException extends Exception
+{
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudClientException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudClientException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudClientException(String message)
+ {
+ super(message);
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,348 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.jboss.tools.deltacloud.core.client.API.Driver;
+import org.jboss.tools.deltacloud.core.client.request.CreateInstanceRequest;
+import org.jboss.tools.deltacloud.core.client.request.CreateKeyRequest;
+import org.jboss.tools.deltacloud.core.client.request.DeltaCloudRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListHardwareProfileRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListHardwareProfilesRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListImageRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListImagesRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListInstanceRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListInstancesRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListKeyRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListKeysRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListRealmRequest;
+import org.jboss.tools.deltacloud.core.client.request.ListRealmsRequest;
+import org.jboss.tools.deltacloud.core.client.request.PerformActionRequest;
+import org.jboss.tools.deltacloud.core.client.request.TypeRequest;
+import org.jboss.tools.deltacloud.core.client.unmarshal.APIUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.HardwareProfileUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.HardwareProfilesUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.ImageUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.ImagesUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.InstanceUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.InstancesUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.KeyUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.KeysUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.RealmUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.RealmsUnmarshaller;
+
+/**
+ * @author Andre Dietisheim (based on prior implementation by Martyn Taylor)
+ */
+public class DeltaCloudClientImpl implements DeltaCloudClient {
+
+ private String baseUrl;
+ private String username;
+ private String password;
+
+ public DeltaCloudClientImpl(String url) throws MalformedURLException,
+ DeltaCloudClientException {
+ this(url, null, null);
+ }
+
+ public DeltaCloudClientImpl(String url, String username, String password) throws
DeltaCloudClientException {
+ this.baseUrl = url;
+ this.username = username;
+ this.password = password;
+ }
+
+ protected InputStream request(DeltaCloudRequest deltaCloudRequest)
+ throws DeltaCloudClientException {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ try {
+ URL url = deltaCloudRequest.getUrl();
+ addCredentials(url, httpClient, username, password);
+ HttpUriRequest request = createRequest(deltaCloudRequest);
+ HttpResponse httpResponse = httpClient.execute(request);
+ throwOnHttpErrors(deltaCloudRequest.getUrl(), httpResponse);
+ if (httpResponse.getEntity() == null) {
+ return null;
+ }
+ return httpResponse.getEntity().getContent();
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (MalformedURLException e) {
+ throw new DeltaCloudClientException(MessageFormat.format(
+ "Could not connect to \"{0}\". The url is invalid.",
deltaCloudRequest.toString()), e);
+ } catch (IOException e) {
+ throw new DeltaCloudClientException(e);
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ private void throwOnHttpErrors(URL requestUrl, HttpResponse httpResponse)
+ throws DeltaCloudClientException {
+ int statusCode = httpResponse.getStatusLine().getStatusCode();
+ if (HttpStatusCode.OK.isStatus(statusCode)) {
+ return;
+ } else if (HttpStatusCode.UNAUTHORIZED.isStatus(statusCode)) {
+ throw new DeltaCloudAuthClientException(
+ MessageFormat
+ .format("The server reported an authorization error \"{0}\" on
requesting \"{1}\"",
+ httpResponse.getStatusLine()
+ .getReasonPhrase(), requestUrl));
+ } else if (HttpStatusCode.NOT_FOUND.isStatus(statusCode)) {
+ throw new DeltaCloudNotFoundClientException(MessageFormat.format(
+ "The server could not find the resource \"{0}\"",
+ requestUrl));
+ } else if (HttpStatusRange.CLIENT_ERROR.isInRange(statusCode)
+ || HttpStatusRange.SERVER_ERROR.isInRange(statusCode)) {
+ throw new DeltaCloudClientException(
+ MessageFormat
+ .format("The server reported an error \"{0}\" on requesting
\"{1}\"",
+ httpResponse.getStatusLine()
+ .getReasonPhrase(), requestUrl));
+ }
+ }
+
+ /**
+ * Returns a request instance for the given request type and url.
+ *
+ * @param httpMethod
+ * the request type to use
+ * @param requestUrl
+ * the requested url
+ * @return the request instance
+ * @throws MalformedURLException
+ */
+ protected HttpUriRequest createRequest(DeltaCloudRequest deltaCloudRequest)
+ throws MalformedURLException {
+ HttpUriRequest request = null;
+ String url = deltaCloudRequest.getUrl().toString();
+ HttpMethod httpMethod = deltaCloudRequest.getHttpMethod();
+ switch (httpMethod) {
+ case POST:
+ request = new HttpPost(url);
+ break;
+ case DELETE:
+ request = new HttpDelete(url);
+ break;
+ case GET:
+ default:
+ request = new HttpGet(url);
+ }
+ request.setHeader("Accept", "application/xml;q=1");
+ return request;
+ }
+
+ /**
+ * Adds the credentials to the given http client.
+ *
+ * @param httpClient
+ * the http client
+ * @return the default http client
+ * @throws UnknownHostException
+ */
+ private DefaultHttpClient addCredentials(URL url,
+ DefaultHttpClient httpClient, String username, String password)
+ throws UnknownHostException {
+ if (username != null && password != null) {
+ httpClient.getCredentialsProvider().setCredentials(
+ new AuthScope(url.getHost(), url.getPort()),
+ new UsernamePasswordCredentials(username, password));
+ }
+ return httpClient;
+ }
+
+ public Driver getServerType() {
+ try {
+ InputStream response = request(new TypeRequest(baseUrl));
+ API api = new APIUnmarshaller().unmarshall(response, new API());
+ return api.getDriver();
+ } catch (DeltaCloudClientException e) {
+ return Driver.UNKNOWN;
+ }
+ }
+
+ @Override
+ public Instance createInstance(String imageId) throws DeltaCloudClientException {
+ try {
+ InputStream response = request(new CreateInstanceRequest(baseUrl, imageId));
+ return new InstanceUnmarshaller().unmarshall(response, new Instance());
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+
+ }
+
+ public Instance createInstance(String name, String imageId, String profileId, String
realmId, String memory,
+ String storage) throws DeltaCloudClientException {
+ return createInstance(name, imageId, profileId, realmId, null, memory, storage);
+ }
+
+ public Instance createInstance(String name, String imageId, String profileId, String
realmId, String keyId,
+ String memory, String storage) throws DeltaCloudClientException {
+ try {
+ InputStream response = request(
+ new CreateInstanceRequest(baseUrl, name, imageId, profileId, realmId, keyId, memory,
storage));
+ Instance instance = new InstanceUnmarshaller().unmarshall(response, new Instance());
+ // TODO: WORKAROUND for
+ //
https://issues.jboss.org/browse/JBIDE-8005
+ if (keyId != null) {
+ instance.setKeyId(keyId);
+ }
+ // TODO: WORKAROUND for
+ //
https://issues.jboss.org/browse/JBIDE-8005
+ return instance;
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ @Override
+ public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
+ try {
+ InputStream response = request(new ListHardwareProfileRequest(baseUrl, profileId));
+ return new HardwareProfileUnmarshaller().unmarshall(response, new HardwareProfile());
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ @Override
+ public List<HardwareProfile> listProfiles() throws DeltaCloudClientException {
+ try {
+ InputStream response = request(new ListHardwareProfilesRequest(baseUrl));
+ List<HardwareProfile> profiles = new ArrayList<HardwareProfile>();
+ new HardwareProfilesUnmarshaller().unmarshall(response, profiles);
+ return profiles;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(MessageFormat.format("could not get realms on
cloud at \"{0}\"",
+ baseUrl), e);
+ }
+ }
+
+ @Override
+ public List<Image> listImages() throws DeltaCloudClientException {
+ InputStream response = request(new ListImagesRequest(baseUrl));
+ List<Image> images = new ArrayList<Image>();
+ new ImagesUnmarshaller().unmarshall(response, images);
+ return images;
+ }
+
+ @Override
+ public Image listImages(String imageId) throws DeltaCloudClientException {
+ InputStream response = request(new ListImageRequest(baseUrl, imageId));
+ return new ImageUnmarshaller().unmarshall(response, new Image());
+ }
+
+ @Override
+ public List<Instance> listInstances() throws DeltaCloudClientException {
+ InputStream inputStream = request(new ListInstancesRequest(baseUrl));
+ List<Instance> instances = new ArrayList<Instance>();
+ new InstancesUnmarshaller().unmarshall(inputStream, instances);
+ return instances;
+ }
+
+ @Override
+ public Instance listInstances(String instanceId) throws DeltaCloudClientException {
+ try {
+ InputStream response = request(new ListInstanceRequest(baseUrl, instanceId));
+ return new InstanceUnmarshaller().unmarshall(response, new Instance());
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ @Override
+ public List<Realm> listRealms() throws DeltaCloudClientException {
+ try {
+ InputStream inputStream = request(new ListRealmsRequest(baseUrl));
+ List<Realm> realms = new ArrayList<Realm>();
+ new RealmsUnmarshaller().unmarshall(inputStream, realms);
+ return realms;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(
+ MessageFormat.format("could not get realms on cloud at \"{0}\"",
baseUrl), e);
+ }
+ }
+
+ @Override
+ public Realm listRealms(String realmId) throws DeltaCloudClientException {
+ try {
+ InputStream response = request(new ListRealmRequest(baseUrl, realmId));
+ return new RealmUnmarshaller().unmarshall(response, new Realm());
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(
+ MessageFormat.format("could not get realms on cloud at \"{0}\"",
baseUrl), e);
+ }
+ }
+
+ public Key createKey(String keyname) throws DeltaCloudClientException {
+ try {
+ CreateKeyRequest keyRequest = new CreateKeyRequest(baseUrl, keyname);
+ InputStream inputStream = request(keyRequest);
+ Key key = new KeyUnmarshaller().unmarshall(inputStream, new Key());
+ return key;
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ public List<Key> listKeys() throws DeltaCloudClientException {
+ InputStream inputStream = request(new ListKeysRequest(baseUrl));
+ List<Key> keys = new ArrayList<Key>();
+ new KeysUnmarshaller().unmarshall(inputStream, keys);
+ return keys;
+ }
+
+ public Key listKey(String id) throws DeltaCloudClientException {
+ InputStream inputStream = request(new ListKeyRequest(baseUrl, id));
+ Key key = new KeyUnmarshaller().unmarshall(inputStream, new Key());
+ return key;
+ }
+
+ public boolean performAction(Action<?> action) throws DeltaCloudClientException {
+ if (action != null) {
+ try {
+ request(new PerformActionRequest(action.getUrl(), action.getMethod()));
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ return true;
+ }
+ return false;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class DeltaCloudNotFoundClientException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudNotFoundClientException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudNotFoundClientException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudNotFoundClientException(String message)
+ {
+ super(message);
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.core.client.Property.Names;
+
+/**
+ * @author Martyn Taylor
+ * @author André Dietisheim
+ */
+public class HardwareProfile extends IdAware {
+ private static final long serialVersionUID = 1L;
+
+ private List<Property> properties;
+
+ public HardwareProfile() {
+ }
+
+ public void setProperties(List<Property> properties) {
+ this.properties = properties;
+ }
+
+ public List<Property> getProperties() {
+ if (properties == null)
+ properties = new ArrayList<Property>();
+ return properties;
+ }
+
+ public Property getNamedProperty(Names nameEnum) {
+ if (nameEnum == null) {
+ return null;
+ }
+ return getNamedProperty(nameEnum.name().toLowerCase());
+ }
+
+ public Property getNamedProperty(String name) {
+ if (properties != null) {
+ for (Property p : properties) {
+ if (p.getName().equals(name))
+ return p;
+ }
+ }
+ return null;
+ }
+
+ public String getArchitecture() {
+ Property p = getNamedProperty(Property.Names.ARCHITECTURE);
+ if (p != null)
+ return p.getValue();
+ return null;
+ }
+
+ public String getMemory() {
+ Property p = getNamedProperty("memory");
+ if (p != null)
+ return p.toString();
+ return null;
+ }
+
+ public String getStorage() {
+ Property p = getNamedProperty("storage");
+ if (p != null)
+ return p.toString();
+ return null;
+ }
+
+ public String getCPU() {
+ Property p = getNamedProperty("cpu");
+ if (p != null)
+ return p.getValue();
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ String s = "";
+ s += "Hardware-profile:\t\t" + getId() + "\n";
+ for (Property p : properties) {
+ s += p.getName() + ":\t\t" + p.getValue() + "\n";
+ }
+ return s;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpMethod.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+public enum HttpMethod {
+ GET, POST, PUT, DELETE, HEAD;
+}
\ No newline at end of file
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusCode.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusCode.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusCode.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Andre Dietisheim
+ */
+public enum HttpStatusCode {
+
+ OK(200), NOT_FOUND(404), FORBIDDEN(403), UNAUTHORIZED(401);
+
+ private int code;
+
+ private HttpStatusCode(int code) {
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public boolean isStatus(int statusCode) {
+ return code == statusCode;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusRange.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusRange.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/HttpStatusRange.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Andre Dietisheim
+ */
+public enum HttpStatusRange {
+
+ CLIENT_ERROR(400, 499), SERVER_ERROR(500, 599);
+
+ private int start;
+ private int stop;
+
+ HttpStatusRange(int start, int stop) {
+ this.start = start;
+ this.stop = stop;
+ }
+
+ public boolean isInRange(int statusCode) {
+ return statusCode >= start
+ && statusCode <= stop;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/IdAware.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/IdAware.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/IdAware.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * @author Martyn Taylor
+ * @author André Dietisheim
+ */
+public abstract class IdAware {
+
+ protected String id;
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @XmlAttribute
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return "IdAware [id=" + id + "]";
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Image.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Image.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Image.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+
+/**
+ * @author Martyn Taylor
+ */
+public class Image extends IdAware
+{
+ private static final long serialVersionUID = 1L;
+
+ private String ownerId;
+
+ private String name;
+
+ private String description;
+
+ private String architecture;
+
+ public Image()
+ {
+ }
+
+ public void setOwnerId(String ownerId)
+ {
+ this.ownerId = ownerId;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ }
+
+ public void setArchitecture(String architecture)
+ {
+ this.architecture = architecture;
+ }
+
+ public String getOwnerId()
+ {
+ return ownerId;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getArchitecture()
+ {
+ return architecture;
+ }
+
+ @Override
+ public String toString()
+ {
+ String s = "";
+ s += "Image:\t\t" + getId() + "\n";
+ s += "Owner:\t\t" + getOwnerId() + "\n";
+ s += "Name:\t\t" + getName() + "\n";
+ s += "Desc:\t\t" + getDescription() + "\n";
+ s += "Arch:\t\t" + getArchitecture() + "\n";
+ return s;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Instance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Instance.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Instance.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.List;
+
+/**
+ * @author Martyn Taylor
+ * @author Andre Dietisheim
+ */
+public class Instance extends StateAware<Instance> {
+
+ private static final long serialVersionUID = 1L;
+
+ private String ownerId;
+
+ private String name;
+
+ private String imageId;
+
+ private String profileId;
+
+ private String memory;
+
+ private String storage;
+
+ private String cpu;
+
+ private String realmId;
+
+ private String keyId;
+
+ private AddressList publicAddresses;
+
+ private AddressList privateAddresses;
+
+ public Instance() {
+ }
+
+ public void setOwnerId(String ownerId) {
+ this.ownerId = ownerId;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setImageId(String imageId) {
+ this.imageId = imageId;
+ }
+
+ public void setProfileId(String profileId) {
+ this.profileId = profileId;
+ }
+
+ protected void setMemory(String memory) {
+ this.memory = memory;
+ }
+
+ protected void setStorage(String storage) {
+ this.storage = storage;
+ }
+
+ protected void setCPU(String cpu) {
+ this.cpu = cpu;
+ }
+
+ public void setRealmId(String realmId) {
+ this.realmId = realmId;
+ }
+
+ public void setKeyId(String keyId) {
+ this.keyId = keyId;
+ }
+
+ public String getKeyId() {
+ return keyId;
+ }
+
+ public void setPrivateAddresses(AddressList privateAddresses) {
+ this.privateAddresses = privateAddresses;
+ }
+
+ public void setPublicAddresses(AddressList publicAddresses) {
+ this.publicAddresses = publicAddresses;
+ }
+
+ public String getOwnerId() {
+ return ownerId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getImageId() {
+ return imageId;
+ }
+
+ public String getProfileId() {
+ return profileId;
+ }
+
+ public String getMemory() {
+ return memory;
+ }
+
+ public String getStorage() {
+ return storage;
+ }
+
+ public String getCPU() {
+ return cpu;
+ }
+
+ public String getRealmId() {
+ return realmId;
+ }
+
+ public List<String> getPublicAddresses() {
+ return publicAddresses.getAddress();
+ }
+
+ public List<String> getPrivateAddresses() {
+ return privateAddresses.getAddress();
+ }
+
+ @Override
+ public String toString() {
+ String s = "";
+ s += "Instance:\t" + getId() + "\n";
+ s += "Owner:\t\t" + getOwnerId() + "\n";
+ s += "Image:\t\t" + getImageId() + "\n";
+ s += "Realm:\t\t" + getRealmId() + "\n";
+ s += "Profile:\t\t" + getProfileId() + "\n";
+ if (getMemory() != null)
+ s += "Memory:\t\t" + getMemory() + "\n";
+ if (getStorage() != null) {
+ s += "Storage:\t\t" + getStorage() + "\n";
+ }
+ if (getCPU() != null) {
+ s += "CPU:\t\t" + getCPU() + "\n";
+ }
+ s += "State:\t\t" + getState() + "\n";
+
+ List<Action<Instance>> actions = getActions();
+ if (actions != null) {
+ for (int i = 0; i < actions.size(); i++) {
+ if (i == 0) {
+ s += "Actions:\t" + actions.get(i) + "\n";
+ } else {
+ s += "\t\t" + actions.get(i) + "\n";
+ }
+ }
+ }
+
+ for (int i = 0; i < publicAddresses.getAddress().size(); i++) {
+ if (i == 0) {
+ s += "Public Addr:\t" + publicAddresses.getAddress().get(i) +
"\n";
+ } else {
+ s += "\t\t" + publicAddresses.getAddress().get(i) + "\n";
+ }
+ }
+
+ for (int i = 0; i < publicAddresses.getAddress().size(); i++) {
+ if (i == 0) {
+ s += "Private Addr:\t" + publicAddresses.getAddress().get(i) +
"\n";
+ } else {
+ s += "\t\t" + privateAddresses.getAddress().get(i) + "\n";
+ }
+ }
+
+ return s;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Key.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Key.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Key.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class Key extends StateAware<Key> {
+
+ private static final long serialVersionUID = 1L;
+
+ private URL url;
+ private String pem;
+ private String fingerprint;
+ private String state;
+
+ public Key() {
+ }
+
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+
+ public void setUrl(String url) throws MalformedURLException {
+ this.url = new URL(url);
+ }
+
+ public void setPem(String pem) {
+ this.pem = pem;
+ }
+
+ public void setFingerprint(String fingerprint) {
+ this.fingerprint = fingerprint;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public String getFingerprint() {
+ return fingerprint;
+ }
+
+ public String getPem() {
+ return pem;
+ }
+
+ @Override
+ public String toString() {
+ return "Key [url=" + url + ", pem=" + pem + ",
fingerprint=" + fingerprint + ", state=" + state + ", actions="
+ + getActions() + ", toString()=" + super.toString() + "]";
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Property.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Property.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Property.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.List;
+
+/**
+ * @author Martyn Taylor
+ */
+public class Property extends IdAware {
+
+ private static final long serialVersionUID = 1L;
+
+ public static enum Kind {
+ FIXED, RANGE, ENUM
+ };
+
+ public static enum Names {
+ MEMORY, STORAGE, CPU, ARCHITECTURE
+ }
+
+ public static enum UNIT {
+ MB {
+ public boolean matches(String value) {
+ return name().equals(value);
+ }},
+ GB{
+ public boolean matches(String value) {
+ return name().equals(value);
+ }},
+ LABEL{
+ public boolean matches(String value) {
+ return name().toLowerCase().equals(value);
+ }},
+ COUNT{
+ public boolean matches(String value) {
+ return name().toLowerCase().equals(value);
+ }};
+
+ public abstract boolean matches(String value);
+ }
+
+ public class Range {
+ private String first;
+ private String last;
+
+ public Range(String first, String last) {
+ this.first = first;
+ this.last = last;
+ }
+
+ public String getFirst() {
+ return first;
+ }
+
+ public String getLast() {
+ return last;
+ }
+ }
+
+ public Property() {
+ }
+
+ private String kind;
+
+ private String unit;
+
+ private String name;
+
+ private String value;
+
+ // For range
+ private String first;
+ private String last;
+
+ // For enum
+ private List<String> enums;
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public Range getRange() {
+ return new Range(first, last);
+ }
+
+ public List<String> getEnums() {
+ return enums;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public void setUnit(String unit) {
+ this.unit = unit;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public void setRange(String first, String last) {
+ this.first = first;
+ this.last = last;
+ }
+
+ public void setEnums(List<String> enums) {
+ this.enums = enums;
+ }
+
+ public String toString() {
+ if (kind.equals("range")) {
+ // return first += "-" + last + "(default:" + value +
")";
+ return new StringBuilder()
+ .append(first)
+ .append('-').append(last)
+ .append("(default: ").append(value).append(")")
+ .toString();
+ } else if (kind.equals("enum")) {
+ String s = enums.get(0);
+ for (int i = 1; i < enums.size(); ++i) {
+ s += ", " + enums.get(i);
+ }
+ s += " (default:" + value + ")";
+ return s;
+ } else {
+ // return value += " " + (unit.equals("label") ? "" :
unit);
+ StringBuilder builder = new StringBuilder();
+ builder.append(value);
+ if (!UNIT.LABEL.matches(unit)) {
+ builder.append(' ').append(unit);
+ }
+ return builder.toString();
+ }
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Realm.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Realm.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/Realm.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+/**
+ * @author Martyn Taylor
+ * @author André Dietisheim
+ */
+public class Realm extends IdAware {
+ private static final long serialVersionUID = 1L;
+
+ public static final int LIMIT_DEFAULT = -1;
+
+ private String name;
+ private RealmState state;
+ private int limit;
+
+ public static enum RealmState {
+ AVAILABLE, UNAVAILABLE, UNKNOWN
+ }
+
+ public Realm() {
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public void setLimit(int limit) {
+ this.limit = limit;
+ }
+
+ public void setLimit(String limit) {
+ try {
+ this.limit = Integer.parseInt(limit);
+ } catch (Exception e) {
+ this.limit = LIMIT_DEFAULT;
+ }
+ }
+
+ public int getLimit() {
+ return limit;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setState(String state) {
+ try {
+ this.state = RealmState.valueOf(state.toUpperCase());
+ } catch (Exception e) {
+ this.state = RealmState.UNKNOWN;
+ }
+ }
+
+ public RealmState getState() {
+ return state;
+ }
+
+ @Override
+ public String toString() {
+ String s = "";
+ s += "Realm:\t\t" + getId() + "\n";
+ s += "Name\t\t" + getName() + "\n";
+ s += "State:\t\t" + getState() + "\n";
+ s += "Limit:\t\t" + getLimit() + "\n";
+ return s;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ResourceAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ResourceAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/ResourceAction.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+
+/**
+ * @author André Dietisheim
+ */
+public interface ResourceAction<OWNER> {
+
+ public static final String DESTROY = "destroy";
+
+ public String getName();
+
+ public String getUrl();
+
+ public HttpMethod getMethod();
+
+ public OWNER getOwner();
+
+ public boolean isDestroy();
+}
\ No newline at end of file
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/StateAware.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/StateAware.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/StateAware.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+
+/**
+ * @author André Dietisheim
+ *
+ * @param <OWNER>
+ */
+public class StateAware<OWNER> extends ActionAware<OWNER> {
+
+ public static enum State {
+ RUNNING, STOPPED, PENDING, TERMINATED, BOGUS
+ };
+
+ private State state;
+
+ public void setState(String state) {
+ try {
+ this.state = State.valueOf(state);
+ } catch (Exception e) {
+ this.state = State.BOGUS;
+ }
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ public boolean isRunning() {
+ return getState() == State.RUNNING;
+ }
+
+ public boolean isStopped() {
+ return getState() == State.STOPPED;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractDeltaCloudRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractDeltaCloudRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractDeltaCloudRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * @author André Dietisheim
+ */
+public abstract class AbstractDeltaCloudRequest implements DeltaCloudRequest {
+
+ private String urlString;
+ private URL url;
+ private HttpMethod httpMethod;
+ private UrlBuilder urlBuilder;
+
+ protected AbstractDeltaCloudRequest(String baseURL, HttpMethod httpMethod) {
+ this.httpMethod = httpMethod;
+ this.urlBuilder = createUrlBuilder(baseURL);
+ }
+
+ protected abstract String doCreateUrl(UrlBuilder urlBuilder);
+
+ protected UrlBuilder createUrlBuilder(String baseUrl) {
+ return new UrlBuilder(baseUrl).path(API_PATH_SEGMENT);
+ }
+
+ public URL getUrl() throws MalformedURLException {
+ if (url == null) {
+ this.url = new URL(getUrlString());
+ }
+ return url;
+ }
+
+ protected String getUrlString() {
+ if (urlString == null) {
+ this.urlString = doCreateUrl(urlBuilder);
+ }
+ return urlString;
+ }
+
+ public String toString() {
+ return getUrlString();
+ }
+
+ public HttpMethod getHttpMethod() {
+ return httpMethod;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractListObjectsRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractListObjectsRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/AbstractListObjectsRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Lists images, instances, realms or profiles on the deltacloud server.
+ *
+ * @see ListRealmRequest
+ * @see ListHardwareProfilesRequest
+ * @see ListHardwareProfilesRequest
+ * @see ListInstancesRequest
+ *
+ * @author André Dietisheim
+ */
+public abstract class AbstractListObjectsRequest extends AbstractDeltaCloudRequest {
+
+ private String objectType;
+
+ public AbstractListObjectsRequest(String baseUrl, String objectType) {
+ super(baseUrl, HttpMethod.GET);
+ this.objectType = objectType;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path(objectType).toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateInstanceRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateInstanceRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateInstanceRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Creates a new instance
+ *
+ * @author André Dietisheim
+ */
+public class CreateInstanceRequest extends AbstractDeltaCloudRequest {
+
+ private String name;
+ private String imageId;
+ private String profileId;
+ private String realmId;
+ private String keyname;
+ private String memory;
+ private String storage;
+
+ public CreateInstanceRequest(String baseUrl, String imageId) {
+ this(baseUrl, null, imageId, null, null, null, null, null);
+ }
+
+ public CreateInstanceRequest(String baseUrl, String name, String imageId, String
profileId, String realmId,
+ String keyId, String memory, String storage) {
+ super(baseUrl, HttpMethod.POST);
+ this.name = name;
+ this.imageId = imageId;
+ this.profileId = profileId;
+ this.realmId = realmId;
+ this.keyname = keyId;
+ this.memory = memory;
+ this.storage = storage;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("instances")
+ .parameter("keyname", keyname)
+ // WORKAROUND for JBIDE-8005, STEAM-303
+ .parameter("key_name", keyname)
+ // WORKAROUND for JBIDE-8005, STEAM-303
+ .parameter("name", name)
+ .parameter("image_id", imageId)
+ .parameter("hwp_id", profileId)
+ .parameter("realm_id", realmId)
+ .parameter("hwp_memory", memory)
+ .parameter("hwp_storage", storage)
+ .parameter("commit", "create")
+ .toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/CreateKeyRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Creates a key on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class CreateKeyRequest extends AbstractDeltaCloudRequest {
+
+ private String keyName;
+
+ public CreateKeyRequest(String baseUrl, String keyName) {
+ super(baseUrl, HttpMethod.POST);
+ this.keyName = keyName;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("keys")
+ .parameter("name", keyName)
+ .parameter("commit", "create")
+ .toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/DeltaCloudRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/DeltaCloudRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/DeltaCloudRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+
+/**
+ * @author André Dietisheim
+ */
+public interface DeltaCloudRequest {
+
+ public static final char PATH_SEPARATOR = '/';
+ public static final char PARAMETER_SEPARATOR = '?';
+ public static final String API_PATH_SEGMENT = "api";
+
+ public URL getUrl() throws MalformedURLException;
+
+ public HttpMethod getHttpMethod();
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfileRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfileRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfileRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * A request for a hardware profile on a deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class ListHardwareProfileRequest extends AbstractDeltaCloudRequest {
+
+ private String profileId;
+
+ /**
+ * Instantiates a new type request.
+ *
+ * @param baseUrl the base url
+ * @param imageId
+ */
+ public ListHardwareProfileRequest(String baseUrl, String profileId) {
+ super(baseUrl, HttpMethod.GET);
+ this.profileId = profileId;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("hardware_profiles").path(profileId).toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfilesRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfilesRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListHardwareProfilesRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+/**
+ * Lists profiles on the deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class ListHardwareProfilesRequest extends AbstractListObjectsRequest {
+
+ public ListHardwareProfilesRequest(String baseUrl) {
+ super(baseUrl, "hardware_profiles");
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImageRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImageRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImageRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+
+/**
+ * A request for an image on a deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class ListImageRequest extends AbstractDeltaCloudRequest {
+
+ private String imageId;
+
+ public ListImageRequest(String baseUrl, String imageId) {
+ super(baseUrl, HttpMethod.GET);
+ this.imageId = imageId;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("images").path(imageId).toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImagesRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImagesRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListImagesRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+/**
+ * Lists images on the deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class ListImagesRequest extends AbstractListObjectsRequest {
+
+ public ListImagesRequest(String baseUrl) {
+ super(baseUrl, "images");
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstanceRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstanceRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstanceRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Lists an instance on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class ListInstanceRequest extends AbstractDeltaCloudRequest {
+
+ private String instanceId;
+
+ public ListInstanceRequest(String baseUrl, String instanceId) {
+ super(baseUrl, HttpMethod.GET);
+ this.instanceId = instanceId;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("instances").path(instanceId).toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstancesRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstancesRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListInstancesRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+/**
+ * Lists instances on the deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class ListInstancesRequest extends AbstractListObjectsRequest {
+
+ public ListInstancesRequest(String baseUrl) {
+ super(baseUrl, "instances");
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeyRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * List a key with a given name that is available on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class ListKeyRequest extends AbstractDeltaCloudRequest {
+
+ private String name;
+
+ public ListKeyRequest(String baseUrl, String name) {
+ super(baseUrl, HttpMethod.GET);
+ this.name = name;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("keys").path(name).toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListKeysRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Lists keys available on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class ListKeysRequest extends AbstractDeltaCloudRequest {
+
+ public ListKeysRequest(String baseUrl) {
+ super(baseUrl, HttpMethod.GET);
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("keys").toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Lists a realm on the deltacloud server
+ *
+ * @author André Dietisheim
+ */
+public class ListRealmRequest extends AbstractDeltaCloudRequest {
+
+ private String realmId;
+
+ public ListRealmRequest(String baseUrl, String realmId) {
+ super(baseUrl, HttpMethod.GET);
+ this.realmId = realmId;
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.path("realms").path(realmId).toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmsRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmsRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/ListRealmsRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+/**
+ * Lists realms on the deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class ListRealmsRequest extends AbstractListObjectsRequest {
+
+ public ListRealmsRequest(String baseUrl) {
+ super(baseUrl, "realms");
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/PerformActionRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/PerformActionRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/PerformActionRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.Action;
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * Performs an action on a resource of the deltacloud server. The typical
+ * actions are
+ * <ul>
+ * <li>START</li>
+ * <li>STOP</li>
+ * <li>DESTROY</li>
+ * <li>REBOOT</li>
+ * </ul>
+ *
+ * @author André Dietisheim
+ *
+ * @see Action
+ */
+public class PerformActionRequest extends AbstractDeltaCloudRequest {
+
+ public PerformActionRequest(String url, HttpMethod httpMethod) {
+ super(url, httpMethod);
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.toString();
+ }
+
+ @Override
+ protected UrlBuilder createUrlBuilder(String baseURL) {
+ return new UrlBuilder(baseURL);
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/TypeRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/TypeRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/request/TypeRequest.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.request;
+
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
+import org.jboss.tools.deltacloud.core.client.utils.UrlBuilder;
+
+/**
+ * A request for the type of deltacloud server.
+ *
+ * @author André Dietisheim
+ */
+public class TypeRequest extends AbstractDeltaCloudRequest {
+
+ public TypeRequest(String baseUrl) {
+ super(baseUrl, HttpMethod.GET);
+ }
+
+ @Override
+ protected String doCreateUrl(UrlBuilder urlBuilder) {
+ return urlBuilder.parameter("format", "xml").toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/APIUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/APIUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/APIUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.API;
+import org.w3c.dom.Element;
+
+/**
+ * @author André Dietisheim
+ */
+public class APIUnmarshaller extends AbstractDOMUnmarshaller<API> {
+
+ public APIUnmarshaller() {
+ super("api", API.class);
+ }
+
+ protected API doUnmarshall(Element element, API server) throws Exception {
+ if (element != null) {
+ server.setDriver(getAttributeText("driver", element));
+ }
+ return server;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractActionAwareUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractActionAwareUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractActionAwareUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.core.client.Action;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author André Dietisheim
+ *
+ * @param <DELTACLOUDOBJECT>
+ */
+public abstract class AbstractActionAwareUnmarshaller<DELTACLOUDOBJECT> extends
AbstractDOMUnmarshaller<DELTACLOUDOBJECT>{
+
+ private String actionElementName;
+ public AbstractActionAwareUnmarshaller(String tagName, Class<DELTACLOUDOBJECT>
type, String actionElementName) {
+ super(tagName, type);
+ this.actionElementName = actionElementName;
+ }
+
+ protected List<Action<DELTACLOUDOBJECT>> getActions(Element element,
DELTACLOUDOBJECT owner) throws DeltaCloudClientException {
+ if (element == null) {
+ return null;
+ }
+ List<Action<DELTACLOUDOBJECT>> actions = new
ArrayList<Action<DELTACLOUDOBJECT>>();
+ NodeList nodeList = element.getElementsByTagName(actionElementName);
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node linkNode = nodeList.item(i);
+ Action<DELTACLOUDOBJECT> action = createAction(linkNode);
+ if (action != null) {
+ action.setOwner(owner);
+ actions.add(action);
+ }
+ }
+ return actions;
+ }
+
+ protected Action<DELTACLOUDOBJECT> createAction(Node node) throws
DeltaCloudClientException {
+ if (!(node instanceof Element)) {
+ return null;
+ }
+ return unmarshallAction((Element) node);
+ }
+
+ protected abstract Action<DELTACLOUDOBJECT> unmarshallAction(Element element)
throws DeltaCloudClientException;
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDOMUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDOMUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDOMUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.MessageFormat;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.tools.deltacloud.core.client.Action;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * @author André Dietisheim
+ *
+ * @param <DELTACLOUDOBJECT>
+ */
+public abstract class AbstractDOMUnmarshaller<DELTACLOUDOBJECT> {
+
+ private Class<DELTACLOUDOBJECT> type;
+ private String tagName;
+
+ public AbstractDOMUnmarshaller(String tagName, Class<DELTACLOUDOBJECT> type) {
+ this.type = type;
+ this.tagName = tagName;
+ }
+
+ public DELTACLOUDOBJECT unmarshall(InputStream inputStream, DELTACLOUDOBJECT
deltacloudObject) throws DeltaCloudClientException {
+ try {
+ Element element = getFirstElement(tagName, getDocument(inputStream));
+ if (element == null) {
+ return null;
+ }
+ return unmarshall(element, deltacloudObject);
+ } catch (Exception e) {
+ // TODO: internationalize strings
+ throw new DeltaCloudClientException(
+ MessageFormat.format("Could not unmarshall type \"{0}\"", type),
e);
+ }
+
+ }
+
+ protected Document getDocument(InputStream inputStream) throws
ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder = factory.newDocumentBuilder();
+ return documentBuilder.parse(inputStream);
+ }
+
+ public DELTACLOUDOBJECT unmarshall(Element element, DELTACLOUDOBJECT resource) throws
DeltaCloudClientException {
+ try {
+ return doUnmarshall(element, resource);
+ } catch (Exception e) {
+ // TODO: internationalize strings
+ throw new DeltaCloudClientException(
+ MessageFormat.format("Could not unmarshall type \"{0}\"", type),
e);
+ }
+ }
+
+ protected abstract DELTACLOUDOBJECT doUnmarshall(Element element, DELTACLOUDOBJECT
resource) throws Exception;
+
+ protected String getFirstElementAttributeText(String elementName, String attributeId,
Element element) {
+ Element firstElement = getFirstElement(elementName, element);
+ if (firstElement == null) {
+ return null;
+ }
+ return firstElement.getAttribute(attributeId);
+ }
+
+ protected String getFirstElementText(String elementName, Element element) {
+ Element firstElement = getFirstElement(elementName, element);
+ if (firstElement == null) {
+ return null;
+ }
+ return firstElement.getTextContent();
+ }
+
+ protected Element getFirstElement(String elementName, Element element) {
+ NodeList elements = element.getElementsByTagName(elementName);
+ if (elements != null
+ && elements.getLength() > 0) {
+ return (Element) elements.item(0);
+ }
+ return null;
+ }
+
+ protected Element getFirstElement(String elementName, Document document) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ if (elements != null
+ && elements.getLength() > 0) {
+ return (Element) elements.item(0);
+ }
+ return null;
+ }
+
+ protected String getAttributeText(String attributeName, Element element) {
+ Node attribute = element.getAttributeNode(attributeName);
+ if (attribute != null) {
+ return attribute.getTextContent();
+ }
+ return null;
+ }
+
+ protected String stripText(String textContent) {
+ if (textContent == null || textContent.length() == 0) {
+ return textContent;
+ }
+ return textContent.trim();
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+* Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.io.InputStream;
+import java.text.MessageFormat;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudException;
+
+/**
+ * @author André Dietisheim
+ *
+ * @param <RESOURCE>
+ */
+public abstract class AbstractDeltaCloudObjectUnmarshaller<RESOURCE> implements
IDeltaCloudObjectUnmarshaller<RESOURCE> {
+
+ private Class<RESOURCE> type;
+
+ public AbstractDeltaCloudObjectUnmarshaller(Class<RESOURCE> type) {
+ this.type = type;
+ }
+
+ public RESOURCE create(InputStream inputStream) throws DeltaCloudException {
+
+ try {
+ return doCreate(inputStream);
+ } catch (Exception e) {
+ // TODO: internationalize strings
+ throw new DeltaCloudException(
+ MessageFormat.format("Could not unmarshall resource of type
\"{0}\"", type), e);
+ }
+ }
+
+ protected abstract RESOURCE doCreate(InputStream inputStream) throws Exception;
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.util.List;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author André Dietisheim
+ */
+@SuppressWarnings("rawtypes")
+public abstract class AbstractDeltaCloudObjectsUnmarshaller<CHILD> extends
AbstractDOMUnmarshaller<List> {
+
+ private String childTag;
+
+ public AbstractDeltaCloudObjectsUnmarshaller(String parentTag, String childTag) {
+ super(parentTag, List.class);
+ this.childTag = childTag;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected List doUnmarshall(Element element, List children) throws Exception {
+ if (element != null) {
+ NodeList nodeList = element.getElementsByTagName(childTag);
+ if (nodeList != null
+ && nodeList.getLength() > 0) {
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element) {
+ CHILD child = unmarshallChild(node);
+ children.add(child);
+ }
+ }
+ }
+ }
+ return children;
+ }
+
+ protected abstract CHILD unmarshallChild(Node node) throws DeltaCloudClientException;
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ActionUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ActionUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ActionUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.Action;
+import org.w3c.dom.Element;
+
+/**
+ * @author André Dietisheim
+ */
+public class ActionUnmarshaller<OWNER> extends
AbstractDOMUnmarshaller<Action<OWNER>> {
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public ActionUnmarshaller() {
+ super("link", (Class) Action.class);
+ }
+
+ @Override
+ protected Action<OWNER> doUnmarshall(Element element, Action<OWNER> action)
throws Exception {
+ if (element != null) {
+ action.setMethod(getAttributeText("method", element));
+ action.setName(getAttributeText("rel", element));
+ action.setUrl(getAttributeText("href", element));
+ }
+ return action;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfileUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfileUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfileUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.jboss.tools.deltacloud.core.client.HardwareProfile;
+import org.jboss.tools.deltacloud.core.client.Property;
+import org.jboss.tools.deltacloud.core.client.Property.Kind;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author André Dietisheim
+ */
+public class HardwareProfileUnmarshaller extends
AbstractDOMUnmarshaller<HardwareProfile> {
+
+ public HardwareProfileUnmarshaller() {
+ super("hardware_profile", HardwareProfile.class);
+ }
+
+ @Override
+ protected HardwareProfile doUnmarshall(Element element, HardwareProfile profile) throws
Exception {
+ profile.setId(getAttributeText("id", element));
+ profile.setProperties(createProperties(element.getElementsByTagName("property")));
+ return profile;
+ }
+
+ private List<Property> createProperties(NodeList propertiesList) {
+ List<Property> properties = new ArrayList<Property>();
+ for (int i = 0; i < propertiesList.getLength(); i++) {
+ Property property = createProperty(propertiesList.item(i));
+ properties.add(property);
+ }
+ return properties;
+ }
+
+ private Property createProperty(Node node) {
+ Assert.isTrue(node instanceof Element);
+ Element element = (Element) node;
+ Property property = new Property();
+ property.setName(element.getAttribute("name"));
+ property.setId(element.getAttribute("id"));
+ property.setUnit(element.getAttribute("unit"));
+ property.setValue(element.getAttribute("value"));
+ String kind = element.getAttribute("kind");
+ Assert.isTrue(kind != null);
+ kind = kind.toUpperCase();
+ property.setKind(kind);
+ if (Kind.RANGE.toString().equals(property.getKind())) {
+ setRange(element, property);
+ } else if (Kind.ENUM.toString().equals(property.getKind())) {
+ setEnum(element, property);
+ } else if (Kind.FIXED.toString().equals(property.getKind())) {
+ // no special treatement
+ }
+ return property;
+ }
+
+ private void setRange(Element propertyElement, Property property) {
+ Node node = propertyElement.getElementsByTagName("range").item(0);
+ Assert.isLegal(node instanceof Element);
+ Element rangeElement = (Element) node;
+ property.setRange(rangeElement.getAttribute("first"),
rangeElement.getAttribute("last"));
+ }
+
+ private void setEnum(Element propertyElement, Property property) {
+ Node node = propertyElement.getElementsByTagName("enum").item(0);
+ Assert.isLegal(node instanceof Element);
+ Element enumElement = (Element) node;
+ NodeList nodeList = enumElement.getElementsByTagName("entry");
+ ArrayList<String> enumValues = new ArrayList<String>();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node entryNode = nodeList.item(i);
+ Assert.isTrue(entryNode instanceof Element);
+ Element entryElement = (Element) entryNode;
+ enumValues.add(entryElement.getAttribute("value"));
+ }
+ property.setEnums(enumValues);
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfilesUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfilesUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/HardwareProfilesUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.HardwareProfile;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author André Dietisheim
+ */
+public class HardwareProfilesUnmarshaller extends
AbstractDeltaCloudObjectsUnmarshaller<HardwareProfile> {
+
+ public HardwareProfilesUnmarshaller() {
+ super("hardware_profiles", "hardware_profile");
+ }
+
+ @Override
+ protected HardwareProfile unmarshallChild(Node node) throws DeltaCloudClientException {
+ return new HardwareProfileUnmarshaller().unmarshall((Element) node, new
HardwareProfile());
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/IDeltaCloudObjectUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/IDeltaCloudObjectUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/IDeltaCloudObjectUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.io.InputStream;
+
+/**
+ * @author André Dietisheim
+ */
+public interface IDeltaCloudObjectUnmarshaller<DELTACLOUDOBJECT> {
+
+ public DELTACLOUDOBJECT unmarshall(InputStream inputStream);
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImageUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImageUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImageUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.Image;
+import org.w3c.dom.Element;
+
+/**
+ * @author André Dietisheim
+ */
+public class ImageUnmarshaller extends AbstractDOMUnmarshaller<Image> {
+
+ public ImageUnmarshaller() {
+ super("image", Image.class);
+ }
+
+ protected Image doUnmarshall(Element element, Image image) throws Exception {
+ image.setId(getAttributeText("id", element));
+ image.setName(getFirstElementText("name", element));
+ image.setOwnerId(getFirstElementText("owner_id", element));
+ image.setDescription(getFirstElementText("description", element));
+ image.setArchitecture(getFirstElementText("architecture", element));
+ return image;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImagesUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImagesUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/ImagesUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Image;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author André Dietisheim
+ */
+public class ImagesUnmarshaller extends
AbstractDeltaCloudObjectsUnmarshaller<Image> {
+
+ public ImagesUnmarshaller() {
+ super("images", "image");
+ }
+
+ @Override
+ protected Image unmarshallChild(Node node) throws DeltaCloudClientException {
+ Image image = new ImageUnmarshaller().unmarshall((Element) node, new Image());
+ return image;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstanceUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstanceUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstanceUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.core.client.Action;
+import org.jboss.tools.deltacloud.core.client.AddressList;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Instance;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author André Dietisheim
+ */
+public class InstanceUnmarshaller extends AbstractActionAwareUnmarshaller<Instance>
{
+
+ public InstanceUnmarshaller() {
+ super("instance", Instance.class, "link");
+ }
+
+ protected Instance doUnmarshall(Element element, Instance instance) throws Exception {
+ instance.setId(getAttributeText("id", element));
+ instance.setName(getFirstElementText("name", element));
+ instance.setOwnerId(getFirstElementText("owner_id", element));
+ instance.setOwnerId(getFirstElementText("owner_id", element));
+ instance.setImageId(getFirstElementAttributeText("image", "id",
element));
+ instance.setProfileId(getFirstElementAttributeText("hardware_profile",
"id", element));
+ instance.setRealmId(getFirstElementAttributeText("realm", "id",
element));
+ instance.setState(getFirstElementText("state", element));
+ setKeyname(instance, element);
+ instance.setActions(getActions(element, instance));
+ instance.setPublicAddresses(getAddressList("public_addresses", element));
+ instance.setPrivateAddresses(getAddressList("private_addresses", element));
+ return instance;
+ }
+
+ private AddressList getAddressList(String elementName, Element element) {
+ Element addressElement = getFirstElement(elementName, element);
+ if (addressElement != null) {
+ NodeList addressList = addressElement.getChildNodes();
+ if (addressList != null) {
+ List<String> addresses = new ArrayList<String>();
+ for (int i = 0; i < addressList.getLength(); i++) {
+ Node addressNode = addressList.item(i);
+ if (addressNode != null) {
+ String address = stripText(addressNode.getTextContent());
+ if (address != null && address.length() > 0) {
+ addresses.add(address);
+ }
+ }
+ }
+ return new AddressList(addresses);
+ }
+ }
+ return new AddressList();
+ }
+
+ private void setKeyname(Instance instance, Element element) {
+ Element authenticationElement = getFirstElement("authentication", element);
+ if (authenticationElement != null) {
+ Element loginElement = getFirstElement("login", authenticationElement);
+ if (loginElement != null) {
+ String keyname = getFirstElementText("keyname", loginElement);
+ instance.setKeyId(keyname);
+ }
+ }
+ }
+
+ @Override
+ protected Action<Instance> unmarshallAction(Element element) throws
DeltaCloudClientException {
+ Action<Instance> action = new Action<Instance>();
+ new ActionUnmarshaller<Instance>().unmarshall(element, action);
+ return action;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstancesUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstancesUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/InstancesUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Instance;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author André Dietisheim
+ */
+public class InstancesUnmarshaller extends
AbstractDeltaCloudObjectsUnmarshaller<Instance> {
+
+ public InstancesUnmarshaller() {
+ super("instances", "instance");
+ }
+
+ @Override
+ protected Instance unmarshallChild(Node node) throws DeltaCloudClientException {
+ Instance instance = new InstanceUnmarshaller().unmarshall((Element) node, new
Instance());
+ return instance;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeyUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeyUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeyUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.jboss.tools.deltacloud.core.client.Action;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Key;
+import org.w3c.dom.Element;
+
+/**
+ * @author André Dietisheim
+ */
+public class KeyUnmarshaller extends AbstractActionAwareUnmarshaller<Key> {
+
+ public KeyUnmarshaller() {
+ super("key", Key.class, "link");
+ }
+
+ protected Key doUnmarshall(Element element, Key key) throws Exception {
+ if (element != null) {
+ key.setId(getAttributeText("id", element));
+ key.setUrl(getAttributeText("href", element));
+ key.setState(getFirstElementText("state", element));
+ key.setFingerprint(getFirstElementText("fingerprint", element));
+ key.setPem(trimPem(getPem(element))); //$NON-NLS-1$
+ key.setActions(getActions(element, key));
+ }
+ return key;
+ }
+
+ private String getPem(Element element) {
+ Element pemElement = getFirstElement("pem", element);
+ if (pemElement != null) {
+ return getFirstElementText("pem", pemElement);
+ }
+ return null;
+ }
+
+ private String trimPem(String pem) throws IOException {
+ if (pem == null
+ || pem.length() <= 0) {
+ return null;
+ }
+ StringBuffer sb = new StringBuffer();
+ String line = null;
+ BufferedReader reader = new BufferedReader(new StringReader(pem));
+ while ((line = reader.readLine()) != null) {
+ // We must trim off the white-space from the xml
+ // Complete white-space lines are to be ignored.
+ String trimmedLine = line.trim();
+ if (trimmedLine.length() > 0) {
+ sb.append(trimmedLine).append('\n');
+ }
+ }
+ return sb.toString();
+ }
+
+ @Override
+ protected Action<Key> unmarshallAction(Element element) throws
DeltaCloudClientException {
+ Action<Key> keyAction = new Action<Key>();
+ new ActionUnmarshaller<Key>().unmarshall(element, keyAction);
+ return keyAction;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeysUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeysUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/KeysUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Key;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author André Dietisheim
+ */
+public class KeysUnmarshaller extends AbstractDeltaCloudObjectsUnmarshaller<Key> {
+
+ public KeysUnmarshaller() {
+ super("keys", "key");
+ }
+
+ @Override
+ protected Key unmarshallChild(Node node) throws DeltaCloudClientException {
+ Key key = new KeyUnmarshaller().unmarshall((Element) node, new Key());
+ return key;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.Realm;
+import org.w3c.dom.Element;
+
+/**
+ * @author André Dietisheim
+ */
+public class RealmUnmarshaller extends AbstractDOMUnmarshaller<Realm> {
+
+ public RealmUnmarshaller() {
+ super("realm", Realm.class);
+ }
+
+ protected Realm doUnmarshall(Element element, Realm realm) throws Exception {
+ realm.setId(getAttributeText("id", element));
+ realm.setName(getFirstElementText("name", element));
+ realm.setLimit(getFirstElementText("limit", element));
+ realm.setState(getFirstElementText("state", element));
+ return realm;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Realm;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author André Dietisheim
+ */
+public class RealmsUnmarshaller extends
AbstractDeltaCloudObjectsUnmarshaller<Realm> {
+
+ public RealmsUnmarshaller() {
+ super("realms", "realm");
+ }
+
+ @Override
+ protected Realm unmarshallChild(Node node) throws DeltaCloudClientException {
+ return new RealmUnmarshaller().unmarshall((Element) node, new Realm());
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/StringUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/StringUtils.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/StringUtils.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class StringUtils {
+
+ /**
+ * Returns a formatted string for a collection of elements that get
+ * formatted by a user supplied element formatter.
+ *
+ * @param elements
+ * the elements to be processed
+ * @param elements
+ * the elements
+ * @param elementFormatter
+ * the formatter to apply on each element to be processed
+ * @return the formatted string
+ */
+ public static <E> String getFormattedString(Collection<E> elements,
IElementFormatter<E> elementFormatter) {
+ StringBuilder builder = new StringBuilder();
+ for (E element : elements) {
+ String formattedElement = elementFormatter.format(element);
+ if (formattedElement != null && formattedElement.length() > 0) {
+ builder.append(formattedElement);
+ }
+ }
+ if (builder.length() > 0) {
+ return builder.toString();
+ } else {
+ return "";
+ }
+ }
+
+ public interface IElementFormatter<E> {
+ public String format(E element);
+ }
+
+ /**
+ * Returns a collection of formatted strings for the given collection of
+ * elements and given formatter
+ *
+ * @param <E>
+ * the type of elements that shall be processed
+ * @param elements
+ * the elements to be processed
+ * @param elementFormatter
+ * the formatter to apply on each element to be processed
+ * @return the formatted strings
+ */
+ public static <E> Collection<String> getFormattedStrings(Collection<E>
elements,
+ IElementFormatter<E> elementFormatter) {
+ List<String> strings = new ArrayList<String>();
+ for (E element : elements) {
+ String formattedElement = elementFormatter.format(element);
+ if (formattedElement != null && formattedElement.length() > 0) {
+ strings.add(formattedElement);
+ }
+ }
+ return strings;
+ }
+
+ public static String null2EmptyString(String stringValue) {
+ if (stringValue == null) {
+ return "";
+ }
+ return stringValue;
+ }
+
+ public static String emptyString2Null(String stringValue) {
+ if (stringValue != null
+ && stringValue.length() == 0) {
+ return null;
+ }
+ return stringValue;
+ }
+
+ public static boolean isEmpty(String stringValue) {
+ return stringValue == null || stringValue.isEmpty();
+ }
+
+
+ public static String toString(InputStream inputStream) throws IOException {
+ StringBuilder builder = new StringBuilder();
+ for(int character = -1; (character = inputStream.read()) != -1; ) {
+ builder.append((char) character);
+ }
+ return builder.toString();
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/UrlBuilder.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/UrlBuilder.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/core/client/utils/UrlBuilder.java 2011-03-02
00:08:54 UTC (rev 29430)
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.deltacloud.core.client.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Collection;
+
+/**
+ * A builder for an url. Currently no state checking is done, the user is
+ * responsible to build something that makes sense.
+ *
+ * @author André Dietisheim
+ */
+public class UrlBuilder {
+ private static final String URL_ENCODING = "UTF-8";
+ private static final String HOST_PROTOCOL_DELIMITER = ":";
+ private static final String HTTP_PROTOCOL_PREFIX = "http://";
+ private static final char PARAMETER_URL_DELIMITER = '?';
+ private static final char PARAMETER_DELIMITER = '&';
+ private static final char PARAMETER_NAME_VALUE_DELIMITER = '=';
+ private static final char PATH_SEPARATOR = '/';
+
+ private StringBuilder urlStringBuilder = new StringBuilder();
+
+ private boolean parametersAdded = false;
+
+ public UrlBuilder() {
+ }
+
+ public UrlBuilder(String baseUrl) {
+ urlStringBuilder.append(baseUrl);
+ }
+
+ public UrlBuilder(URL baseUrl) {
+ urlStringBuilder.append(baseUrl.toString());
+ }
+
+ /**
+ * adds a host to .
+ *
+ * @param host
+ * the host
+ *
+ * @return the url builder
+ */
+ public UrlBuilder host(String host) {
+ urlStringBuilder.append(HTTP_PROTOCOL_PREFIX);
+ urlStringBuilder.append(host);
+ return this;
+ }
+
+ /**
+ * Adds a port.
+ *
+ * @param port
+ * the port
+ *
+ * @return the url builder
+ */
+ public UrlBuilder port(Object port) {
+ urlStringBuilder.append(HOST_PROTOCOL_DELIMITER);
+ urlStringBuilder.append(port);
+ return this;
+ }
+
+ /**
+ * adds a path to the url.
+ *
+ * @param path
+ * the path
+ *
+ * @return the url builder
+ */
+ public UrlBuilder path(String path) {
+ urlStringBuilder.append(PATH_SEPARATOR);
+ urlStringBuilder.append(path);
+ return this;
+ }
+
+ public UrlBuilder path(Collection<String> paths) {
+ for (String path : paths) {
+ path(path);
+ }
+ return this;
+ }
+
+ public UrlBuilder parameter(String name, String value) {
+ if (value != null) {
+ appendParameterDelimiter();
+ urlStringBuilder.append(name).append(PARAMETER_NAME_VALUE_DELIMITER).append(urlEncode(value));
+ }
+ return this;
+ }
+
+ private void appendParameterDelimiter() {
+ if (!parametersAdded) {
+ urlStringBuilder.append(PARAMETER_URL_DELIMITER);
+ parametersAdded = true;
+ } else {
+ urlStringBuilder.append(PARAMETER_DELIMITER);
+ }
+ }
+
+ public UrlBuilder parameters(String... parameters) {
+ for (String parameter : parameters) {
+ parameter(parameter);
+ }
+ return this;
+ }
+
+ public UrlBuilder parameter(String parameter) {
+ appendParameterDelimiter();
+ urlStringBuilder.append(urlEncode(parameter));
+ return this;
+ }
+
+ private String urlEncode(String value) {
+ try {
+ return URLEncoder.encode(value, URL_ENCODING);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public URL toUrl() throws MalformedURLException {
+ return new URL(urlStringBuilder.toString());
+ }
+
+ public String toString() {
+ return urlStringBuilder.toString();
+ }
+}