Author: adietish
Date: 2011-01-11 08:44:39 -0500 (Tue, 11 Jan 2011)
New Revision: 28093
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Realm.java
Log:
[JBIDE-7935] moved realms unmarshalling to separate classes (and added tests).
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2011-01-11 11:51:14
UTC (rev 28092)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2011-01-11 13:44:39
UTC (rev 28093)
@@ -1,5 +1,8 @@
2011-01-11 André Dietisheim <André Dietisheim@adietisheim-thinkpad>
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
+ (listRealms):
+ [JBIDE-7935] moved realms unmarshalling to separate classes (and added tests).
* src/org/jboss/tools/deltacloud/core/client/request/TypeRequest.java:
* src/org/jboss/tools/deltacloud/core/client/request/PerformInstanceActionRequest.java:
* src/org/jboss/tools/deltacloud/core/client/request/ListRealmsRequest.java:
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2011-01-11
11:51:14 UTC (rev 28092)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2011-01-11
13:44:39 UTC (rev 28093)
@@ -34,7 +34,6 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
-import org.eclipse.core.runtime.Assert;
import org.jboss.tools.deltacloud.core.client.request.CreateInstanceRequest;
import org.jboss.tools.deltacloud.core.client.request.CreateKeyRequest;
import org.jboss.tools.deltacloud.core.client.request.DeleteKeyRequest;
@@ -59,8 +58,9 @@
import org.jboss.tools.deltacloud.core.client.unmarshal.InstancesUnmarshaller;
import org.jboss.tools.deltacloud.core.client.unmarshal.KeyUnmarshaller;
import org.jboss.tools.deltacloud.core.client.unmarshal.KeysUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.RealmUnmarshaller;
+import org.jboss.tools.deltacloud.core.client.unmarshal.RealmsUnmarshaller;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
@@ -111,7 +111,8 @@
} catch (DeltaCloudClientException e) {
throw e;
} catch (MalformedURLException e) {
- throw new DeltaCloudClientException(MessageFormat.format("Could not connect to
\"{0}\". The url is invalid.", deltaCloudRequest.toString()), e);
+ throw new DeltaCloudClientException(MessageFormat.format(
+ "Could not connect to \"{0}\". The url is invalid.",
deltaCloudRequest.toString()), e);
} catch (IOException e) {
throw new DeltaCloudClientException(e);
} catch (Exception e) {
@@ -360,46 +361,21 @@
@Override
public List<Realm> listRealms() throws DeltaCloudClientException {
try {
- return buildRealms(request(new ListRealmsRequest(baseUrl)));
+ 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);
+ throw new DeltaCloudClientException(
+ MessageFormat.format("could not get realms on cloud at \"{0}\"",
baseUrl), e);
}
}
- private List<Realm> buildRealms(InputStream inputStream)
- throws ParserConfigurationException, SAXException, IOException,
DeltaCloudClientException {
- Document document = getDocument(getResponse(inputStream));
- List<Realm> realms = new ArrayList<Realm>();
- NodeList elements = document.getElementsByTagName("realm");
- for (int i = 0; i < elements.getLength(); i++) {
- Realm realm = createRealm((Element) elements.item(i));
- realms.add(realm);
- }
- return realms;
- }
-
- private Realm createRealm(Node node) {
- Assert.isLegal(node instanceof Element);
- Realm realm = new Realm();
- updateRealm(realm, (Element) node);
- return realm;
- }
-
- private Realm updateRealm(Realm realm, Element element) {
- realm.setId(element.getAttribute("id"));
- realm.setName(element.getElementsByTagName("name").item(0).getTextContent());
- realm.setLimit(element.getElementsByTagName("limit").item(0).getTextContent());
- realm.setState(element.getElementsByTagName("state").item(0).getTextContent());
-
- return realm;
- }
-
@Override
public Realm listRealms(String realmId) throws DeltaCloudClientException {
try {
- Document document = getDocument(getResponse(request(new ListRealmRequest(baseUrl,
realmId))));
- return createRealm((Element)
document.getElementsByTagName("realm").item(0));
+ 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);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Realm.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Realm.java 2011-01-11
11:51:14 UTC (rev 28092)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Realm.java 2011-01-11
13:44:39 UTC (rev 28093)
@@ -10,70 +10,63 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.core.client;
-import javax.xml.bind.annotation.XmlElement;
-
/**
* @author Martyn Taylor
+ * @author André Dietisheim
*/
public class Realm extends AbstractDeltaCloudObject {
private static final long serialVersionUID = 1L;
- public static enum RealmState {
- AVAILABLE, UNAVAILABLE, UNKNOWN
- }
+ public static final int LIMIT_DEFAULT = -1;
- @XmlElement
private String name;
-
- @XmlElement
private RealmState state;
-
- @XmlElement
private int limit;
- protected Realm() {
+ public static enum RealmState {
+ AVAILABLE, UNAVAILABLE, UNKNOWN
}
- protected void setName(String name) {
- this.name = name;
+ public Realm() {
}
- protected void setState(String state) {
- try {
- this.state = RealmState.valueOf(state);
- } catch (Exception e) {
- this.state = RealmState.UNKNOWN;
- }
+ public void setName(String name) {
+ this.name = name;
}
- protected void setLimit(int limit) {
+
+ public void setLimit(int limit) {
this.limit = limit;
}
- protected void setLimit(String limit) {
+ public void setLimit(String limit) {
try {
this.limit = Integer.parseInt(limit);
} catch (Exception e) {
- this.limit = -1;
+ this.limit = LIMIT_DEFAULT;
}
}
-
- public static long getSerialversionuid() {
- return serialVersionUID;
+
+ 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;
}
- public int getLimit() {
- return limit;
- }
-
@Override
public String toString() {
String s = "";
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java 2011-01-11
13:44:39 UTC (rev 28093)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.Realm;
+import org.w3c.dom.Element;
+
+/**
+ * @author André Dietisheim
+ */
+public class RealmUnmarshaller extends AbstractDOMUnmarshaller<Realm> {
+
+ public RealmUnmarshaller() {
+ super("realm", Realm.class);
+ }
+
+ protected Realm doUnmarshall(Element element, Realm realm) throws Exception {
+ realm.setId(getAttributeText("id", element));
+ realm.setName(getFirstElementText("name", element));
+ realm.setLimit(getFirstElementText("limit", element));
+ realm.setState(getFirstElementText("state", element));
+ return realm;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmUnmarshaller.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java 2011-01-11
13:44:39 UTC (rev 28093)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client.unmarshal;
+
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.Realm;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @author André Dietisheim
+ */
+public class RealmsUnmarshaller extends
AbstractDeltaCloudObjectsUnmarshaller<Realm> {
+
+ public RealmsUnmarshaller() {
+ super("realms", "realm");
+ }
+
+ @Override
+ protected Realm unmarshallChild(Node node) throws DeltaCloudClientException {
+ return new RealmUnmarshaller().unmarshall((Element) node, new Realm());
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/unmarshal/RealmsUnmarshaller.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain