Author: adietish
Date: 2011-05-21 10:23:46 -0400 (Sat, 21 May 2011)
New Revision: 31411
Added:
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/API.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Action.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/ActionAware.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/AddressList.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudAuthClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClient.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientImpl.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudNotFoundClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HardwareProfile.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpMethod.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpStatusCode.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpStatusRange.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/IdAware.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Image.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Instance.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Key.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Property.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Realm.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/ResourceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/StateAware.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/AbstractDeltaCloudRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/AbstractListObjectsRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/CreateInstanceRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/CreateKeyRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/DeltaCloudRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfileRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfilesRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListImageRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListImagesRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListInstanceRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListInstancesRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListKeyRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListKeysRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListRealmRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListRealmsRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/PerformActionRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/TypeRequest.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/AbstractHttpTransport.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/Base64Coder.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/IHttpTransport.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/APIUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractActionAwareUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDOMUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ActionUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfilesUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/IDeltaCloudObjectUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ImageUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ImagesUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/InstanceUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/InstancesUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/KeyUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/KeysUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/RealmUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/RealmsUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/StringUtils.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/UrlBuilder.java
Log:
[JBIDE-8975] corrected package structure in Deltacloud client, removed bundle activator
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/API.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/API.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/API.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/Action.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Action.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Action.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,94 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/ActionAware.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/ActionAware.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/ActionAware.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+import java.io.InputStream;
+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 {
+ InputStream in = client.performAction(getAction(Action.START_NAME));
+ update(in);
+ return in != null;
+ }
+
+ public boolean stop(DeltaCloudClient client) throws DeltaCloudClientException {
+ InputStream in = client.performAction(getAction(Action.STOP_NAME));
+ update(in);
+ return in != null;
+ }
+
+ public boolean destroy(DeltaCloudClient client) throws DeltaCloudClientException {
+ InputStream in = client.performAction(getAction(Action.DESTROY_NAME));
+ return in != null;
+ }
+
+ public boolean reboot(DeltaCloudClient client) throws DeltaCloudClientException {
+ InputStream in = client.performAction(getAction(Action.REBOOT_NAME));
+ update(in);
+ return in != null;
+ }
+
+ protected void update(InputStream in) throws DeltaCloudClientException {
+ if (in == null) {
+ return;
+ }
+
+ doUpdate(in);
+ }
+
+ protected abstract void doUpdate(InputStream in) throws DeltaCloudClientException;
+
+ 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/client/AddressList.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/AddressList.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/AddressList.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,58 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/DeltaCloudAuthClientException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudAuthClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudAuthClientException.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/DeltaCloudClient.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClient.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClient.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,171 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.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
+ * @throws DeltaCloudClientException the delta cloud client exception
+ * @see Action
+ */
+ public InputStream performAction(Action<?> action) throws
DeltaCloudClientException;
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientException.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/DeltaCloudClientImpl.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientImpl.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudClientImpl.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,255 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.API.Driver;
+import org.jboss.tools.deltacloud.client.request.CreateInstanceRequest;
+import org.jboss.tools.deltacloud.client.request.CreateKeyRequest;
+import org.jboss.tools.deltacloud.client.request.DeltaCloudRequest;
+import org.jboss.tools.deltacloud.client.request.ListHardwareProfileRequest;
+import org.jboss.tools.deltacloud.client.request.ListHardwareProfilesRequest;
+import org.jboss.tools.deltacloud.client.request.ListImageRequest;
+import org.jboss.tools.deltacloud.client.request.ListImagesRequest;
+import org.jboss.tools.deltacloud.client.request.ListInstanceRequest;
+import org.jboss.tools.deltacloud.client.request.ListInstancesRequest;
+import org.jboss.tools.deltacloud.client.request.ListKeyRequest;
+import org.jboss.tools.deltacloud.client.request.ListKeysRequest;
+import org.jboss.tools.deltacloud.client.request.ListRealmRequest;
+import org.jboss.tools.deltacloud.client.request.ListRealmsRequest;
+import org.jboss.tools.deltacloud.client.request.PerformActionRequest;
+import org.jboss.tools.deltacloud.client.request.TypeRequest;
+import org.jboss.tools.deltacloud.client.transport.IHttpTransport;
+import org.jboss.tools.deltacloud.client.transport.URLConnectionTransport;
+import org.jboss.tools.deltacloud.client.unmarshal.APIUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.HardwareProfileUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.HardwareProfilesUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.ImageUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.ImagesUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.InstanceUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.InstancesUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.KeyUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.KeysUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.RealmUnmarshaller;
+import org.jboss.tools.deltacloud.client.unmarshal.RealmsUnmarshaller;
+
+/**
+ * @author Andre Dietisheim (based on prior implementation by Martyn Taylor)
+ */
+public class DeltaCloudClientImpl implements DeltaCloudClient {
+
+ private String baseUrl;
+ private IHttpTransport transport;
+
+ public DeltaCloudClientImpl(String url) throws MalformedURLException,
DeltaCloudClientException {
+ this(url, null, null);
+ }
+
+ public DeltaCloudClientImpl(String url, String username, String password) throws
MalformedURLException,
+ DeltaCloudClientException {
+ this(url, new URLConnectionTransport(username, password));
+ }
+
+ public DeltaCloudClientImpl(String url, IHttpTransport transport) throws
DeltaCloudClientException {
+ this.baseUrl = url;
+ this.transport = transport;
+ }
+
+ protected InputStream request(DeltaCloudRequest deltaCloudRequest) throws
DeltaCloudClientException {
+ return transport.request(deltaCloudRequest);
+ }
+
+ 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 InputStream performAction(Action<?> action) throws
DeltaCloudClientException {
+ InputStream in = null;
+ if (action != null) {
+ try {
+ in = request(new PerformActionRequest(action.getUrl(), action.getMethod()));
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+ return in;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudNotFoundClientException.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudNotFoundClientException.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/DeltaCloudNotFoundClientException.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/HardwareProfile.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HardwareProfile.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HardwareProfile.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,103 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.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/client/HttpMethod.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpMethod.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpMethod.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,24 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/HttpStatusCode.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpStatusCode.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpStatusCode.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,42 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/HttpStatusRange.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpStatusRange.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/HttpStatusRange.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/IdAware.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/IdAware.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/IdAware.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,46 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/Image.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Image.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Image.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,92 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/Instance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Instance.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Instance.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,201 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.unmarshal.InstanceUnmarshaller;
+
+/**
+ * @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
+ protected void doUpdate(InputStream in) throws DeltaCloudClientException {
+ new InstanceUnmarshaller().unmarshall(in, this);
+ }
+
+
+ @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/client/Key.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Key.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Key.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,81 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.client.unmarshal.KeyUnmarshaller;
+
+/**
+ * @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
+ protected void doUpdate(InputStream in) throws DeltaCloudClientException {
+ new KeyUnmarshaller().unmarshall(in, this);
+ }
+
+ @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/client/Property.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Property.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Property.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,171 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/Realm.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Realm.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/Realm.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,88 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/ResourceAction.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/ResourceAction.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/ResourceAction.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,39 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/StateAware.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/StateAware.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/StateAware.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,55 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client;
+
+
+/**
+ * @author André Dietisheim
+ *
+ * @param <OWNER>
+ */
+public abstract 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/client/request/AbstractDeltaCloudRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/AbstractDeltaCloudRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/AbstractDeltaCloudRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,70 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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;
+ }
+
+ public 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/client/request/AbstractListObjectsRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/AbstractListObjectsRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/AbstractListObjectsRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,48 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/CreateInstanceRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/CreateInstanceRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/CreateInstanceRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,72 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/CreateKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/CreateKeyRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/CreateKeyRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,46 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/DeltaCloudRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/DeltaCloudRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/DeltaCloudRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.jboss.tools.deltacloud.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 String getUrlString();
+
+ public HttpMethod getHttpMethod();
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfileRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfileRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfileRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,49 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/ListHardwareProfilesRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfilesRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListHardwareProfilesRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,32 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/request/ListImageRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListImageRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListImageRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/ListImagesRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListImagesRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListImagesRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,32 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/request/ListInstanceRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListInstanceRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListInstanceRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/ListInstancesRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListInstancesRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListInstancesRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,32 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/request/ListKeyRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListKeyRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListKeyRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/ListKeysRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListKeysRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListKeysRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/ListRealmRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListRealmRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListRealmRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/ListRealmsRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListRealmsRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/ListRealmsRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,32 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/request/PerformActionRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/PerformActionRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/PerformActionRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,56 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/request/TypeRequest.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/TypeRequest.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/request/TypeRequest.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.request;
+
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.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/client/transport/AbstractHttpTransport.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/AbstractHttpTransport.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/AbstractHttpTransport.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,91 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.transport;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudAuthClientException;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.client.HttpStatusCode;
+import org.jboss.tools.deltacloud.client.HttpStatusRange;
+import org.jboss.tools.deltacloud.client.request.DeltaCloudRequest;
+
+/**
+ * @author André Dietisheim
+ */
+public abstract class AbstractHttpTransport implements IHttpTransport {
+
+ private String username;
+ private String password;
+
+ public AbstractHttpTransport(String username, String password) {
+ this.username = username;
+ this.password = password;
+ }
+
+ @Override
+ public final InputStream request(DeltaCloudRequest request) throws
DeltaCloudClientException {
+ try {
+ return doRequest(request);
+ } catch (MalformedURLException e) {
+ throw new DeltaCloudClientException(MessageFormat.format(
+ "Could not connect to \"{0}\". The url is invalid.",
request.getUrlString()), e);
+ } catch(DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ protected abstract InputStream doRequest(DeltaCloudRequest request) throws Exception;
+
+ protected void throwOnHttpErrors(int statusCode, String statusMessage, URL requestUrl)
+ throws DeltaCloudClientException {
+ 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}\"",
+ statusMessage, 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}\"",
+ statusMessage, requestUrl));
+ }
+ }
+
+ protected String getUsername() {
+ return username;
+ }
+
+ protected String getPassword() {
+ return password;
+ }
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/Base64Coder.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/Base64Coder.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/Base64Coder.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,226 @@
+// Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich,
Switzerland
+//
www.source-code.biz,
www.inventec.ch/chdh
+//
+// This module is multi-licensed and may be used under the terms
+// of any of the following licenses:
+//
+// EPL, Eclipse Public License, V1.0 or later,
http://www.eclipse.org/legal
+// LGPL, GNU Lesser General Public License, V2.1 or later,
http://www.gnu.org/licenses/lgpl.html
+// GPL, GNU General Public License, V2 or later,
http://www.gnu.org/licenses/gpl.html
+// AL, Apache License, V2.0 or later,
http://www.apache.org/licenses
+// BSD, BSD License,
http://www.opensource.org/licenses/bsd-license.php
+//
+// Please contact the author if you need another license.
+// This module is provided "as is", without warranties of any kind.
+
+package org.jboss.tools.deltacloud.client.transport;
+
+/**
+* A Base64 encoder/decoder.
+*
+* <p>
+* This class is used to encode and decode data in Base64 format as described in RFC
1521.
+*
+* <p>
+* Project home page: <a
href="http://www.source-code.biz/base64coder/java/">www.source-code.biz/base64coder/java</a><br>
+* Author: Christian d'Heureuse, Inventec Informatik AG, Zurich,
Switzerland<br>
+* Multi-licensed: EPL / LGPL / GPL / AL / BSD.
+*/
+public class Base64Coder {
+
+// The line separator string of the operating system.
+private static final String systemLineSeparator =
System.getProperty("line.separator");
+
+// Mapping table from 6-bit nibbles to Base64 characters.
+private static char[] map1 = new char[64];
+ static {
+ int i=0;
+ for (char c='A'; c<='Z'; c++) map1[i++] = c;
+ for (char c='a'; c<='z'; c++) map1[i++] = c;
+ for (char c='0'; c<='9'; c++) map1[i++] = c;
+ map1[i++] = '+'; map1[i++] = '/'; }
+
+// Mapping table from Base64 characters to 6-bit nibbles.
+private static byte[] map2 = new byte[128];
+ static {
+ for (int i=0; i<map2.length; i++) map2[i] = -1;
+ for (int i=0; i<64; i++) map2[map1[i]] = (byte)i; }
+
+/**
+* Encodes a string into Base64 format.
+* No blanks or line breaks are inserted.
+* @param s A String to be encoded.
+* @return A String containing the Base64 encoded data.
+*/
+public static String encodeString (String s) {
+ return new String(encode(s.getBytes())); }
+
+/**
+* Encodes a byte array into Base 64 format and breaks the output into lines of 76
characters.
+* This method is compatible with
<code>sun.misc.BASE64Encoder.encodeBuffer(byte[])</code>.
+* @param in An array containing the data bytes to be encoded.
+* @return A String containing the Base64 encoded data, broken into lines.
+*/
+public static String encodeLines (byte[] in) {
+ return encodeLines(in, 0, in.length, 76, systemLineSeparator); }
+
+/**
+* Encodes a byte array into Base 64 format and breaks the output into lines.
+* @param in An array containing the data bytes to be encoded.
+* @param iOff Offset of the first byte in <code>in</code> to be
processed.
+* @param iLen Number of bytes to be processed in <code>in</code>,
starting at <code>iOff</code>.
+* @param lineLen Line length for the output data. Should be a multiple of 4.
+* @param lineSeparator The line separator to be used to separate the output lines.
+* @return A String containing the Base64 encoded data, broken into lines.
+*/
+public static String encodeLines (byte[] in, int iOff, int iLen, int lineLen, String
lineSeparator) {
+ int blockLen = (lineLen*3) / 4;
+ if (blockLen <= 0) throw new IllegalArgumentException();
+ int lines = (iLen+blockLen-1) / blockLen;
+ int bufLen = ((iLen+2)/3)*4 + lines*lineSeparator.length();
+ StringBuilder buf = new StringBuilder(bufLen);
+ int ip = 0;
+ while (ip < iLen) {
+ int l = Math.min(iLen-ip, blockLen);
+ buf.append (encode(in, iOff+ip, l));
+ buf.append (lineSeparator);
+ ip += l; }
+ return buf.toString(); }
+
+/**
+* Encodes a byte array into Base64 format.
+* No blanks or line breaks are inserted in the output.
+* @param in An array containing the data bytes to be encoded.
+* @return A character array containing the Base64 encoded data.
+*/
+public static char[] encode (byte[] in) {
+ return encode(in, 0, in.length); }
+
+/**
+* Encodes a byte array into Base64 format.
+* No blanks or line breaks are inserted in the output.
+* @param in An array containing the data bytes to be encoded.
+* @param iLen Number of bytes to process in <code>in</code>.
+* @return A character array containing the Base64 encoded data.
+*/
+public static char[] encode (byte[] in, int iLen) {
+ return encode(in, 0, iLen); }
+
+/**
+* Encodes a byte array into Base64 format.
+* No blanks or line breaks are inserted in the output.
+* @param in An array containing the data bytes to be encoded.
+* @param iOff Offset of the first byte in <code>in</code> to be processed.
+* @param iLen Number of bytes to process in <code>in</code>, starting at
<code>iOff</code>.
+* @return A character array containing the Base64 encoded data.
+*/
+public static char[] encode (byte[] in, int iOff, int iLen) {
+ int oDataLen = (iLen*4+2)/3; // output length without padding
+ int oLen = ((iLen+2)/3)*4; // output length including padding
+ char[] out = new char[oLen];
+ int ip = iOff;
+ int iEnd = iOff + iLen;
+ int op = 0;
+ while (ip < iEnd) {
+ int i0 = in[ip++] & 0xff;
+ int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
+ int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
+ int o0 = i0 >>> 2;
+ int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
+ int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
+ int o3 = i2 & 0x3F;
+ out[op++] = map1[o0];
+ out[op++] = map1[o1];
+ out[op] = op < oDataLen ? map1[o2] : '='; op++;
+ out[op] = op < oDataLen ? map1[o3] : '='; op++; }
+ return out; }
+
+/**
+* Decodes a string from Base64 format.
+* No blanks or line breaks are allowed within the Base64 encoded input data.
+* @param s A Base64 String to be decoded.
+* @return A String containing the decoded data.
+* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
+*/
+public static String decodeString (String s) {
+ return new String(decode(s)); }
+
+/**
+* Decodes a byte array from Base64 format and ignores line separators, tabs and blanks.
+* CR, LF, Tab and Space characters are ignored in the input data.
+* This method is compatible with
<code>sun.misc.BASE64Decoder.decodeBuffer(String)</code>.
+* @param s A Base64 String to be decoded.
+* @return An array containing the decoded data bytes.
+* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
+*/
+public static byte[] decodeLines (String s) {
+ char[] buf = new char[s.length()];
+ int p = 0;
+ for (int ip = 0; ip < s.length(); ip++) {
+ char c = s.charAt(ip);
+ if (c != ' ' && c != '\r' && c != '\n'
&& c != '\t')
+ buf[p++] = c; }
+ return decode(buf, 0, p); }
+
+/**
+* Decodes a byte array from Base64 format.
+* No blanks or line breaks are allowed within the Base64 encoded input data.
+* @param s A Base64 String to be decoded.
+* @return An array containing the decoded data bytes.
+* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
+*/
+public static byte[] decode (String s) {
+ return decode(s.toCharArray()); }
+
+/**
+* Decodes a byte array from Base64 format.
+* No blanks or line breaks are allowed within the Base64 encoded input data.
+* @param in A character array containing the Base64 encoded data.
+* @return An array containing the decoded data bytes.
+* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
+*/
+public static byte[] decode (char[] in) {
+ return decode(in, 0, in.length); }
+
+/**
+* Decodes a byte array from Base64 format.
+* No blanks or line breaks are allowed within the Base64 encoded input data.
+* @param in A character array containing the Base64 encoded data.
+* @param iOff Offset of the first character in <code>in</code> to be
processed.
+* @param iLen Number of characters to process in <code>in</code>, starting
at <code>iOff</code>.
+* @return An array containing the decoded data bytes.
+* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
+*/
+public static byte[] decode (char[] in, int iOff, int iLen) {
+ if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded
input string is not a multiple of 4.");
+ while (iLen > 0 && in[iOff+iLen-1] == '=') iLen--;
+ int oLen = (iLen*3) / 4;
+ byte[] out = new byte[oLen];
+ int ip = iOff;
+ int iEnd = iOff + iLen;
+ int op = 0;
+ while (ip < iEnd) {
+ int i0 = in[ip++];
+ int i1 = in[ip++];
+ int i2 = ip < iEnd ? in[ip++] : 'A';
+ int i3 = ip < iEnd ? in[ip++] : 'A';
+ if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
+ throw new IllegalArgumentException ("Illegal character in Base64 encoded
data.");
+ int b0 = map2[i0];
+ int b1 = map2[i1];
+ int b2 = map2[i2];
+ int b3 = map2[i3];
+ if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
+ throw new IllegalArgumentException ("Illegal character in Base64 encoded
data.");
+ int o0 = ( b0 <<2) | (b1>>>4);
+ int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
+ int o2 = ((b2 & 3)<<6) | b3;
+ out[op++] = (byte)o0;
+ if (op<oLen) out[op++] = (byte)o1;
+ if (op<oLen) out[op++] = (byte)o2; }
+ return out; }
+
+// Dummy constructor.
+private Base64Coder() {}
+
+} // end class Base64Coder
\ No newline at end of file
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/IHttpTransport.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/IHttpTransport.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/IHttpTransport.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,38 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.transport;
+
+import java.io.InputStream;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.client.request.DeltaCloudRequest;
+
+/**
+ * An interface for http transport implementation to be used by the
+ * DeltaCloudClient.
+ *
+ * @author André Dietisheim
+ * @see URLConnectionTransport
+ */
+public interface IHttpTransport {
+
+ public InputStream request(DeltaCloudRequest request) throws DeltaCloudClientException;
+
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/transport/URLConnectionTransport.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,127 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+package org.jboss.tools.deltacloud.client.transport;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Authenticator;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.MessageFormat;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.client.HttpMethod;
+import org.jboss.tools.deltacloud.client.request.DeltaCloudRequest;
+
+public class URLConnectionTransport extends AbstractHttpTransport {
+
+ private static final char USERNAME_PASSWORD_DELIMITER = ':';
+ private static final String PROPERTY_AUTHORIZATION = "Authorization";
+ private static final String PROPERTY_ACCEPT = "Accept";
+ private static final String PREFIX_BASIC_AUTHENTICATION = "Basic ";
+ private static final int TIMEOUT = 10 * 1024;
+ private static final String RESPONSE_CODE_PREFIX = "HTTP response code: ";
+ private static final int RESPONSE_CODE_LENGTH = 3;
+
+ public URLConnectionTransport(String username, String password) {
+ super(username, password);
+ }
+
+ @Override
+ protected InputStream doRequest(DeltaCloudRequest request) throws Exception {
+ try {
+ URL url = request.getUrl();
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setUseCaches(false);
+ connection.setDoInput(true);
+ connection.setAllowUserInteraction(false);
+ connection.setConnectTimeout(TIMEOUT);
+ connection.setRequestProperty(PROPERTY_ACCEPT, "application/xml;q=1");
+ connection.setInstanceFollowRedirects(true);
+ addCredentials(connection);
+ setRequestMethod(request, connection);
+ BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
+ throwOnHttpErrors(
+ connection.getResponseCode(), connection.getResponseMessage(), request.getUrl());
+ return in;
+ } catch (FileNotFoundException e) {
+ /*
+ * thrown by #connect when server resonds with 404
+ */
+ throw new DeltaCloudNotFoundClientException(
+ MessageFormat.format("Could not find resource {0}",
request.getUrlString()));
+ }
+ }
+
+ private void setRequestMethod(DeltaCloudRequest request, HttpURLConnection connection)
throws IOException {
+ HttpMethod httpMethod = request.getHttpMethod();
+ connection.setRequestMethod(httpMethod.name());
+ switch (httpMethod) {
+ case PUT:
+ case POST:
+ connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
+ connection.setRequestProperty("Content-Length", "0");//
String.valueOf(request.getParametersLength()));
+ connection.setDoOutput(true);
+ connection.getOutputStream().flush();
+ break;
+ case GET:
+ connection.setDoOutput(false);
+ break;
+ }
+
+ }
+
+ /**
+ * Adds the credentials to the given http url connection.
+ *
+ * The current implementation uses low level API. Alternatively
+ * {@link Authenticator#setDefault(Authenticator)} could be used which would
+ * then rule all url connections in the same jvm.
+ *
+ * @param httpClient
+ * the http client
+ * @return the default http client
+ * @throws IOException
+ */
+ private void addCredentials(URLConnection urlConnection) throws IOException {
+ String username = getUsername();
+ String password = getPassword();
+ if (username != null && password != null) {
+ String credentials = new StringBuilder()
+ .append(PREFIX_BASIC_AUTHENTICATION)
+ .append(getAuthenticationValue(username, password))
+ .toString();
+ urlConnection.setRequestProperty(PROPERTY_AUTHORIZATION, credentials);
+ }
+
+ }
+
+ private String getAuthenticationValue(String username, String password) throws
IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ out.write(username.getBytes());
+ out.write(USERNAME_PASSWORD_DELIMITER);
+ out.write(password.getBytes());
+ char[] encoded = Base64Coder.encode(out.toByteArray());
+ return new String(encoded);
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/APIUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/APIUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/APIUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.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/client/unmarshal/AbstractActionAwareUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractActionAwareUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractActionAwareUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.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/client/unmarshal/AbstractDOMUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDOMUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDOMUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,135 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+
+package org.jboss.tools.deltacloud.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.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/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDeltaCloudObjectUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,53 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import java.io.InputStream;
+import java.text.MessageFormat;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+
+/**
+ * @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 DeltaCloudClientException {
+
+ try {
+ return doCreate(inputStream);
+ } catch (Exception e) {
+ // TODO: internationalize strings
+ throw new DeltaCloudClientException(
+ 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/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/AbstractDeltaCloudObjectsUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,61 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import java.util.List;
+
+import org.jboss.tools.deltacloud.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/client/unmarshal/ActionUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ActionUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ActionUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,44 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.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/client/unmarshal/HardwareProfileUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfileUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,102 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.jboss.tools.deltacloud.client.HardwareProfile;
+import org.jboss.tools.deltacloud.client.Property;
+import org.jboss.tools.deltacloud.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/client/unmarshal/HardwareProfilesUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfilesUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/HardwareProfilesUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/unmarshal/IDeltaCloudObjectUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/IDeltaCloudObjectUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/IDeltaCloudObjectUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,31 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/unmarshal/ImageUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ImageUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ImageUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,42 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.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/client/unmarshal/ImagesUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ImagesUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/ImagesUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/unmarshal/InstanceUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/InstanceUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/InstanceUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,96 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.client.AddressList;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/unmarshal/InstancesUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/InstancesUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/InstancesUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/unmarshal/KeyUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/KeyUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/KeyUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,85 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.jboss.tools.deltacloud.client.Action;
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/unmarshal/KeysUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/KeysUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/KeysUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/unmarshal/RealmUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/RealmUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/RealmUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,41 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.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/client/unmarshal/RealmsUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/RealmsUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/unmarshal/RealmsUnmarshaller.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.client.unmarshal;
+
+import org.jboss.tools.deltacloud.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.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/client/utils/StringUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/StringUtils.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/StringUtils.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,115 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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/client/utils/UrlBuilder.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/UrlBuilder.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.client/src/org/jboss/tools/deltacloud/client/utils/UrlBuilder.java 2011-05-21
14:23:46 UTC (rev 31411)
@@ -0,0 +1,152 @@
+/*************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************************/
+
+package org.jboss.tools.deltacloud.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();
+ }
+}