mirror of https://github.com/apache/jclouds.git
Issue 280: normalized cleansing of namespace from xml attributes
This commit is contained in:
parent
1cfd0b051b
commit
053351ba12
|
@ -28,42 +28,50 @@ import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
|
||||||
import org.jclouds.vcloud.domain.internal.TaskImpl.ErrorImpl;
|
import org.jclouds.vcloud.domain.internal.TaskImpl.ErrorImpl;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static ReferenceType newNamedResource(Attributes attributes, String defaultType) {
|
public static ReferenceType newReferenceType(Map<String, String> attributes, String defaultType) {
|
||||||
String uri = attributes.getValue(attributes.getIndex("href"));
|
String uri = attributes.get("href");
|
||||||
String type = attributes.getValue(attributes.getIndex("type"));
|
String type = attributes.get("type");
|
||||||
return new ReferenceTypeImpl(attributes.getValue(attributes.getIndex("name")), type != null ? type : defaultType,
|
return new ReferenceTypeImpl(attributes.get("name"), type != null ? type : defaultType, URI.create(uri));
|
||||||
URI.create(uri));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ReferenceType newNamedResource(Attributes attributes) {
|
public static Map<String, String> cleanseAttributes(Attributes in) {
|
||||||
return newNamedResource(attributes, null);
|
Map<String, String> attrs = Maps.newLinkedHashMap();
|
||||||
|
for (int i = 0; i < in.getLength(); i++) {
|
||||||
|
String name = in.getQName(i);
|
||||||
|
if (name.indexOf(':') != -1)
|
||||||
|
name = name.substring(name.indexOf(':') + 1);
|
||||||
|
attrs.put(name, in.getValue(i));
|
||||||
|
}
|
||||||
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task.Error newError(Attributes attributes) {
|
public static ReferenceType newReferenceType(Map<String, String> attributes) {
|
||||||
String minorErrorCode = attrOrNull(attributes, "minorErrorCode");
|
return newReferenceType(attributes, null);
|
||||||
String vendorSpecificErrorCode = attrOrNull(attributes, "vendorSpecificErrorCode");
|
}
|
||||||
|
|
||||||
|
public static Task.Error newError(Map<String, String> attributes) {
|
||||||
|
String minorErrorCode = attributes.get("minorErrorCode");
|
||||||
|
String vendorSpecificErrorCode = attributes.get("vendorSpecificErrorCode");
|
||||||
int errorCode;
|
int errorCode;
|
||||||
// remove this logic when vcloud 0.8 is gone
|
// remove this logic when vcloud 0.8 is gone
|
||||||
try {
|
try {
|
||||||
errorCode = Integer.parseInt(attrOrNull(attributes, "majorErrorCode"));
|
errorCode = Integer.parseInt(attributes.get("majorErrorCode"));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
errorCode = 500;
|
errorCode = 500;
|
||||||
vendorSpecificErrorCode = attrOrNull(attributes, "majorErrorCode");
|
vendorSpecificErrorCode = attributes.get("majorErrorCode");
|
||||||
}
|
}
|
||||||
return new ErrorImpl(attrOrNull(attributes, "message"), errorCode, minorErrorCode, vendorSpecificErrorCode,
|
return new ErrorImpl(attributes.get("message"), errorCode, minorErrorCode, vendorSpecificErrorCode, attributes
|
||||||
attrOrNull(attributes, "stackTrace"));
|
.get("stackTrace"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String attrOrNull(Attributes attributes, String attr) {
|
public static void putReferenceType(Map<String, ReferenceType> map, Map<String, String> attributes) {
|
||||||
return attributes.getIndex(attr) >= 0 ? attributes.getValue(attributes.getIndex(attr)) : null;
|
map.put(attributes.get("name"), newReferenceType(attributes));
|
||||||
}
|
|
||||||
|
|
||||||
public static void putNamedResource(Map<String, ReferenceType> map, Attributes attributes) {
|
|
||||||
map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,12 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.putReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -32,7 +35,6 @@ import org.jclouds.vcloud.domain.Catalog;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.internal.CatalogImpl;
|
import org.jclouds.vcloud.domain.internal.CatalogImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -62,20 +64,21 @@ public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
|
||||||
private boolean published = true;
|
private boolean published = true;
|
||||||
|
|
||||||
public Catalog getResult() {
|
public Catalog getResult() {
|
||||||
return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getHref(), org, description, contents, tasks,
|
return new CatalogImpl(catalog.getName(), catalog.getType(), catalog.getHref(), org, description, contents,
|
||||||
published);
|
tasks, published);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Catalog")) {
|
if (qName.equals("Catalog")) {
|
||||||
catalog = Utils.newNamedResource(attributes, VCloudMediaType.CATALOG_XML);
|
catalog = newReferenceType(attributes, VCloudMediaType.CATALOG_XML);
|
||||||
} else if (qName.equals("CatalogItem")) {
|
} else if (qName.equals("CatalogItem")) {
|
||||||
Utils.putNamedResource(contents, attributes);
|
putReferenceType(contents, attributes);
|
||||||
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
|
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
|
||||||
org = newNamedResource(attributes);
|
org = newReferenceType(attributes);
|
||||||
} else {
|
} else {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.vcloud.domain.CatalogItem;
|
import org.jclouds.vcloud.domain.CatalogItem;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
|
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -49,13 +52,14 @@ public class CatalogItemHandler extends ParseSax.HandlerWithResult<CatalogItem>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("CatalogItem")) {
|
if (qName.equals("CatalogItem")) {
|
||||||
catalogItem = Utils.newNamedResource(attributes);
|
catalogItem = newReferenceType(attributes);
|
||||||
} else if (qName.equals("Entity")) {
|
} else if (qName.equals("Entity")) {
|
||||||
entity = Utils.newNamedResource(attributes);
|
entity = newReferenceType(attributes);
|
||||||
} else if (qName.equals("Property")) {
|
} else if (qName.equals("Property")) {
|
||||||
key = attributes.getValue(attributes.getIndex("key"));
|
key = attributes.get("key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
import static org.jclouds.vcloud.util.Utils.putNamedResource;
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.putReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -28,8 +29,8 @@ import java.util.Map;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
|
||||||
import org.jclouds.vcloud.domain.Org;
|
import org.jclouds.vcloud.domain.Org;
|
||||||
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.internal.OrgImpl;
|
import org.jclouds.vcloud.domain.internal.OrgImpl;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
@ -68,24 +69,25 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Org> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Org")) {
|
if (qName.equals("Org")) {
|
||||||
org = newNamedResource(attributes);
|
org = newReferenceType(attributes);
|
||||||
} else if (qName.equals("Link")) {
|
} else if (qName.equals("Link")) {
|
||||||
int typeIndex = attributes.getIndex("type");
|
String type = attributes.get("type");
|
||||||
if (typeIndex != -1) {
|
if (type != null) {
|
||||||
if (attributes.getValue(typeIndex).indexOf("vdc+xml") != -1) {
|
if (type.indexOf("vdc+xml") != -1) {
|
||||||
putNamedResource(vdcs, attributes);
|
putReferenceType(vdcs, attributes);
|
||||||
} else if (attributes.getValue(typeIndex).indexOf("catalog+xml") != -1) {
|
} else if (type.indexOf("catalog+xml") != -1) {
|
||||||
putNamedResource(catalogs, attributes);
|
putReferenceType(catalogs, attributes);
|
||||||
} else if (attributes.getValue(typeIndex).indexOf("tasksList+xml") != -1) {
|
} else if (type.indexOf("tasksList+xml") != -1) {
|
||||||
tasksList = newNamedResource(attributes);
|
tasksList = newReferenceType(attributes);
|
||||||
} else if (attributes.getValue(typeIndex).indexOf("network+xml") != -1) {
|
} else if (type.indexOf("network+xml") != -1) {
|
||||||
putNamedResource(networks, attributes);
|
putReferenceType(networks, attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
import static org.jclouds.vcloud.util.Utils.putNamedResource;
|
import static org.jclouds.vcloud.util.Utils.putReferenceType;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -34,8 +34,7 @@ import com.google.common.collect.Maps;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class OrgListHandler extends
|
public class OrgListHandler extends ParseSax.HandlerWithResult<Map<String, ReferenceType>> {
|
||||||
ParseSax.HandlerWithResult<Map<String, ReferenceType>> {
|
|
||||||
|
|
||||||
private Map<String, ReferenceType> org = Maps.newHashMap();
|
private Map<String, ReferenceType> org = Maps.newHashMap();
|
||||||
|
|
||||||
|
@ -44,13 +43,13 @@ public class OrgListHandler extends
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName,
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
Attributes attributes) throws SAXException {
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Org")) {
|
if (qName.equals("Org")) {
|
||||||
int typeIndex = attributes.getIndex("type");
|
String type = attributes.get("type");
|
||||||
if (typeIndex != -1) {
|
if (type != null) {
|
||||||
if (attributes.getValue(typeIndex).equals(ORG_XML)) {
|
if (type.indexOf("org+xml") != -1) {
|
||||||
putNamedResource(org, attributes);
|
putReferenceType(org, attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -49,7 +51,6 @@ import org.jclouds.vcloud.domain.network.nat.NatType;
|
||||||
import org.jclouds.vcloud.domain.network.nat.rules.OneToOneVmRule;
|
import org.jclouds.vcloud.domain.network.nat.rules.OneToOneVmRule;
|
||||||
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
|
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
|
||||||
import org.jclouds.vcloud.domain.network.nat.rules.VmRule;
|
import org.jclouds.vcloud.domain.network.nat.rules.VmRule;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -142,22 +143,23 @@ public class OrgNetworkHandler extends ParseSax.HandlerWithResult<OrgNetwork> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("OrgNetwork")) {
|
if (qName.equals("OrgNetwork")) {
|
||||||
network = newNamedResource(attributes);
|
network = newReferenceType(attributes);
|
||||||
} else if (qName.equals("FirewallRule")) {
|
} else if (qName.equals("FirewallRule")) {
|
||||||
this.inFirewallRule = true;
|
this.inFirewallRule = true;
|
||||||
} else if (qName.equals("ParentNetwork")) {
|
} else if (qName.equals("ParentNetwork")) {
|
||||||
parentNetwork = newNamedResource(attributes);
|
parentNetwork = newReferenceType(attributes);
|
||||||
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
|
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
|
||||||
org = newNamedResource(attributes);
|
org = newReferenceType(attributes);
|
||||||
} else {
|
} else {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
}
|
}
|
||||||
int typeIndex = attributes.getIndex("type");
|
String type = attributes.get("type");
|
||||||
if (typeIndex != -1) {
|
if (type != null) {
|
||||||
if (attributes.getValue(typeIndex).indexOf("networkPool+xml") != -1) {
|
if (type.indexOf("networkPool+xml") != -1) {
|
||||||
networkPool = newNamedResource(attributes);
|
networkPool = newReferenceType(attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -63,31 +66,30 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equalsIgnoreCase("Task")) {
|
if (qName.equalsIgnoreCase("Task")) {
|
||||||
if (attributes.getIndex("href") != -1)// queued tasks may not have an
|
if (attributes.get("href") != null)// queued tasks may not have an
|
||||||
// href yet
|
// href yet
|
||||||
taskLink = Utils.newNamedResource(attributes);
|
taskLink = Utils.newReferenceType(attributes);
|
||||||
status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
|
status = TaskStatus.fromValue(attributes.get("status"));
|
||||||
if (attributes.getIndex("startTime") != -1)
|
if (attributes.containsKey("startTime"))
|
||||||
startTime = parseDate(attributes, "startTime");
|
startTime = parseDate(attributes.get("startTime"));
|
||||||
if (attributes.getIndex("endTime") != -1)
|
if (attributes.containsKey("endTime"))
|
||||||
endTime = parseDate(attributes, "endTime");
|
endTime = parseDate(attributes.get("endTime"));
|
||||||
if (attributes.getIndex("expiryTime") != -1)
|
if (attributes.containsKey("expiryTime"))
|
||||||
expiryTime = parseDate(attributes, "expiryTime");
|
expiryTime = parseDate(attributes.get("expiryTime"));
|
||||||
// TODO technically the old Result object should only be owner for copy and delete tasks
|
// TODO technically the old Result object should only be owner for copy and delete tasks
|
||||||
} else if (qName.equals("Owner") || qName.equals("Result")) {
|
} else if (qName.equals("Owner") || qName.equals("Result")) {
|
||||||
owner = Utils.newNamedResource(attributes);
|
owner = Utils.newReferenceType(attributes);
|
||||||
} else if (qName.equals("Link") && attributes.getIndex("rel") != -1
|
} else if (qName.equals("Link") && "self".equals(attributes.get("rel"))) {
|
||||||
&& attributes.getValue(attributes.getIndex("rel")).equals("self")) {
|
taskLink = Utils.newReferenceType(attributes);
|
||||||
taskLink = Utils.newNamedResource(attributes);
|
|
||||||
} else if (qName.equals("Error")) {
|
} else if (qName.equals("Error")) {
|
||||||
error = Utils.newError(attributes);
|
error = Utils.newError(attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Date parseDate(Attributes attributes, String attribute) {
|
private Date parseDate(String toParse) {
|
||||||
String toParse = attributes.getValue(attributes.getIndex(attribute));
|
|
||||||
try {
|
try {
|
||||||
return dateService.iso8601DateParse(toParse);
|
return dateService.iso8601DateParse(toParse);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -53,14 +56,14 @@ public class TasksListHandler extends ParseSax.HandlerWithResult<TasksList> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("TasksList")) {
|
if (qName.equals("TasksList")) {
|
||||||
resource = Utils.newNamedResource(attributes);
|
resource = Utils.newReferenceType(attributes);
|
||||||
} else if (qName.equals("Link") && attributes.getIndex("rel") != -1
|
} else if (qName.equals("Link") && "self".equals(attributes.get("rel"))) {
|
||||||
&& attributes.getValue(attributes.getIndex("rel")).equals("self")) {
|
resource = Utils.newReferenceType(attributes);
|
||||||
resource = Utils.newNamedResource(attributes);
|
|
||||||
} else {
|
} else {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -33,7 +35,6 @@ import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VApp;
|
import org.jclouds.vcloud.domain.VApp;
|
||||||
import org.jclouds.vcloud.domain.Vm;
|
import org.jclouds.vcloud.domain.Vm;
|
||||||
import org.jclouds.vcloud.domain.internal.VAppImpl;
|
import org.jclouds.vcloud.domain.internal.VAppImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -73,23 +74,23 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Children")) {
|
if (qName.equals("Children")) {
|
||||||
inChildren = true;
|
inChildren = true;
|
||||||
} else if (!inChildren && qName.equals("Tasks")) {
|
} else if (!inChildren && qName.equals("Tasks")) {
|
||||||
inTasks = true;
|
inTasks = true;
|
||||||
}
|
}
|
||||||
if (inChildren) {
|
if (inChildren) {
|
||||||
vmHandler.startElement(uri, localName, qName, attributes);
|
vmHandler.startElement(uri, localName, qName, attrs);
|
||||||
} else if (inTasks) {
|
} else if (inTasks) {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
} else if (qName.equals("VApp")) {
|
} else if (qName.equals("VApp")) {
|
||||||
template = newNamedResource(attributes);
|
template = newReferenceType(attributes);
|
||||||
String status = Utils.attrOrNull(attributes, "status");
|
if (attributes.containsKey("status"))
|
||||||
if (status != null)
|
this.status = Status.fromValue(Integer.parseInt(attributes.get("status")));
|
||||||
this.status = Status.fromValue(Integer.parseInt(status));
|
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
|
||||||
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
|
vdc = newReferenceType(attributes);
|
||||||
vdc = newNamedResource(attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -33,7 +35,6 @@ import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||||
import org.jclouds.vcloud.domain.Vm;
|
import org.jclouds.vcloud.domain.Vm;
|
||||||
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
|
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -74,23 +75,23 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Children")) {
|
if (qName.equals("Children")) {
|
||||||
inChildren = true;
|
inChildren = true;
|
||||||
} else if (!inChildren && qName.equals("Tasks")) {
|
} else if (!inChildren && qName.equals("Tasks")) {
|
||||||
inTasks = true;
|
inTasks = true;
|
||||||
}
|
}
|
||||||
if (inChildren) {
|
if (inChildren) {
|
||||||
vmHandler.startElement(uri, localName, qName, attributes);
|
vmHandler.startElement(uri, localName, qName, attrs);
|
||||||
} else if (inTasks) {
|
} else if (inTasks) {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
} else if (qName.equals("VAppTemplate")) {
|
} else if (qName.equals("VAppTemplate")) {
|
||||||
template = newNamedResource(attributes);
|
template = newReferenceType(attributes);
|
||||||
String status = Utils.attrOrNull(attributes, "status");
|
if (attributes.containsKey("status"))
|
||||||
if (status != null)
|
this.status = Status.fromValue(Integer.parseInt(attributes.get("status")));
|
||||||
this.status = Status.fromValue(Integer.parseInt(status));
|
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
|
||||||
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
|
vdc = newReferenceType(attributes);
|
||||||
vdc = newNamedResource(attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -33,7 +37,6 @@ import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
|
||||||
import org.jclouds.vcloud.domain.network.internal.VCloudExpressNetworkImpl;
|
import org.jclouds.vcloud.domain.network.internal.VCloudExpressNetworkImpl;
|
||||||
import org.jclouds.vcloud.domain.network.nat.NatProtocol;
|
import org.jclouds.vcloud.domain.network.nat.NatProtocol;
|
||||||
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
|
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -76,9 +79,10 @@ public class VCloudExpressNetworkHandler extends ParseSax.HandlerWithResult<VClo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Network")) {
|
if (qName.equals("Network")) {
|
||||||
network = Utils.newNamedResource(attributes);
|
network = newReferenceType(attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,11 @@
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -33,11 +36,10 @@ import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.vcloud.VCloudExpressMediaType;
|
import org.jclouds.vcloud.VCloudExpressMediaType;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.domain.ResourceAllocation;
|
import org.jclouds.vcloud.domain.ResourceAllocation;
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
|
||||||
import org.jclouds.vcloud.domain.Status;
|
import org.jclouds.vcloud.domain.Status;
|
||||||
|
import org.jclouds.vcloud.domain.VCloudExpressVApp;
|
||||||
import org.jclouds.vcloud.domain.VirtualSystem;
|
import org.jclouds.vcloud.domain.VirtualSystem;
|
||||||
import org.jclouds.vcloud.domain.internal.VCloudExpressVAppImpl;
|
import org.jclouds.vcloud.domain.internal.VCloudExpressVAppImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -78,37 +80,36 @@ public class VCloudExpressVAppHandler extends ParseSax.HandlerWithResult<VCloudE
|
||||||
protected ReferenceType vDC;
|
protected ReferenceType vDC;
|
||||||
|
|
||||||
public VCloudExpressVApp getResult() {
|
public VCloudExpressVApp getResult() {
|
||||||
return new VCloudExpressVAppImpl(name, location, status, size, vDC, networkToAddresses, osType, operatingSystemDescription,
|
return new VCloudExpressVAppImpl(name, location, status, size, vDC, networkToAddresses, osType,
|
||||||
system, allocations);
|
operatingSystemDescription, system, allocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("VApp")) {
|
if (qName.equals("VApp")) {
|
||||||
ReferenceType resource = Utils.newNamedResource(attributes);
|
ReferenceType resource = newReferenceType(attributes);
|
||||||
name = resource.getName();
|
name = resource.getName();
|
||||||
location = resource.getHref();
|
location = resource.getHref();
|
||||||
String statusString = attributes.getValue(attributes.getIndex("status"));
|
String statusString = attributes.get("status");
|
||||||
if (apiVersion.indexOf("0.8") != -1 && "2".equals(statusString))
|
if (apiVersion.indexOf("0.8") != -1 && "2".equals(statusString))
|
||||||
status = Status.OFF;
|
status = Status.OFF;
|
||||||
else
|
else
|
||||||
status = Status.fromValue(statusString);
|
status = Status.fromValue(statusString);
|
||||||
if (attributes.getIndex("size") != -1)
|
if (attributes.containsKey("size"))
|
||||||
size = new Long(attributes.getValue(attributes.getIndex("size")));
|
size = new Long(attributes.get("size"));
|
||||||
} else if (qName.equals("Link")) { // type should never be missing
|
} else if (qName.equals("Link")) { // type should never be missing
|
||||||
if (attributes.getIndex("type") != -1
|
if (attributes.containsKey("type") && attributes.get("type").equals(VCloudExpressMediaType.VDC_XML)) {
|
||||||
&& attributes.getValue(attributes.getIndex("type")).equals(VCloudExpressMediaType.VDC_XML)) {
|
vDC = newReferenceType(attributes);
|
||||||
vDC = Utils.newNamedResource(attributes);
|
|
||||||
}
|
}
|
||||||
} else if (qName.equals("OperatingSystemSection")) {
|
} else if (qName.equals("OperatingSystemSection")) {
|
||||||
inOs = true;
|
inOs = true;
|
||||||
for (int i = 0; i < attributes.getLength(); i++)
|
if (attributes.containsKey("id"))
|
||||||
if (attributes.getQName(i).indexOf("id") != -1)
|
osType = Integer.parseInt(attributes.get("id"));
|
||||||
osType = Integer.parseInt(attributes.getValue(i));
|
|
||||||
} else if (qName.endsWith("NetworkConnection")) {
|
} else if (qName.endsWith("NetworkConnection")) {
|
||||||
networkName = attributes.getValue(attributes.getIndex("Network"));
|
networkName = attributes.get("Network");
|
||||||
} else {
|
} else {
|
||||||
systemHandler.startElement(uri, localName, qName, attributes);
|
systemHandler.startElement(uri, localName, qName, attrs);
|
||||||
allocationHandler.startElement(uri, localName, qName, attributes);
|
allocationHandler.startElement(uri, localName, qName, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.domain.Status;
|
import org.jclouds.vcloud.domain.Status;
|
||||||
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
|
||||||
import org.jclouds.vcloud.domain.internal.VCloudExpressVAppTemplateImpl;
|
import org.jclouds.vcloud.domain.internal.VCloudExpressVAppTemplateImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -43,11 +47,12 @@ public class VCloudExpressVAppTemplateHandler extends ParseSax.HandlerWithResult
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("VAppTemplate")) {
|
if (qName.equals("VAppTemplate")) {
|
||||||
catalog = Utils.newNamedResource(attributes);
|
catalog = newReferenceType(attributes);
|
||||||
if (attributes.getIndex("status") != -1)
|
if (attributes.containsKey("status"))
|
||||||
status = Status.fromValue(attributes.getValue(attributes.getIndex("status")));
|
status = Status.fromValue(attributes.get("status"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
import static org.jclouds.vcloud.util.Utils.putNamedResource;
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.putReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -35,7 +36,6 @@ import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.VDC;
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
import org.jclouds.vcloud.domain.VDCStatus;
|
import org.jclouds.vcloud.domain.VDCStatus;
|
||||||
import org.jclouds.vcloud.domain.internal.VDCImpl;
|
import org.jclouds.vcloud.domain.internal.VDCImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -96,20 +96,21 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Vdc")) {
|
if (qName.equals("Vdc")) {
|
||||||
vDC = newNamedResource(attributes);
|
vDC = newReferenceType(attributes);
|
||||||
String status = Utils.attrOrNull(attributes, "status");
|
String status = attributes.get("status");
|
||||||
if (status != null)
|
if (status != null)
|
||||||
this.status = VDCStatus.fromValue(Integer.parseInt(status));
|
this.status = VDCStatus.fromValue(Integer.parseInt(status));
|
||||||
} else if (qName.equals("Network")) {
|
} else if (qName.equals("Network")) {
|
||||||
putNamedResource(availableNetworks, attributes);
|
putReferenceType(availableNetworks, attributes);
|
||||||
} else if (qName.equals("ResourceEntity")) {
|
} else if (qName.equals("ResourceEntity")) {
|
||||||
putNamedResource(resourceEntities, attributes);
|
putReferenceType(resourceEntities, attributes);
|
||||||
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
|
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
|
||||||
org = newNamedResource(attributes);
|
org = newReferenceType(attributes);
|
||||||
} else {
|
} else {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.xml;
|
package org.jclouds.vcloud.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -31,7 +33,6 @@ import org.jclouds.vcloud.domain.Status;
|
||||||
import org.jclouds.vcloud.domain.Task;
|
import org.jclouds.vcloud.domain.Task;
|
||||||
import org.jclouds.vcloud.domain.Vm;
|
import org.jclouds.vcloud.domain.Vm;
|
||||||
import org.jclouds.vcloud.domain.internal.VmImpl;
|
import org.jclouds.vcloud.domain.internal.VmImpl;
|
||||||
import org.jclouds.vcloud.util.Utils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
@ -65,19 +66,20 @@ public class VmHandler extends ParseSax.HandlerWithResult<Vm> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
if (qName.equals("Tasks")) {
|
if (qName.equals("Tasks")) {
|
||||||
inTasks = true;
|
inTasks = true;
|
||||||
}
|
}
|
||||||
if (inTasks) {
|
if (inTasks) {
|
||||||
taskHandler.startElement(uri, localName, qName, attributes);
|
taskHandler.startElement(uri, localName, qName, attrs);
|
||||||
} else if (qName.equals("Vm")) {
|
} else if (qName.equals("Vm")) {
|
||||||
vm = newNamedResource(attributes);
|
vm = newReferenceType(attributes);
|
||||||
String status = Utils.attrOrNull(attributes, "status");
|
String status = attributes.get("status");
|
||||||
if (status != null)
|
if (status != null)
|
||||||
this.status = Status.fromValue(Integer.parseInt(status));
|
this.status = Status.fromValue(Integer.parseInt(status));
|
||||||
} else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) {
|
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
|
||||||
vdc = newNamedResource(attributes);
|
vdc = newReferenceType(attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.terremark.xml;
|
package org.jclouds.vcloud.terremark.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.vcloud.domain.ReferenceType;
|
import org.jclouds.vcloud.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
|
import org.jclouds.vcloud.terremark.domain.TerremarkCatalogItem;
|
||||||
|
@ -37,20 +40,20 @@ public class TerremarkCatalogItemHandler extends CatalogItemHandler {
|
||||||
private ReferenceType computeOptions;
|
private ReferenceType computeOptions;
|
||||||
|
|
||||||
public TerremarkCatalogItem getResult() {
|
public TerremarkCatalogItem getResult() {
|
||||||
return new TerremarkCatalogItemImpl(catalogItem.getName(), catalogItem.getHref(), description,
|
return new TerremarkCatalogItemImpl(catalogItem.getName(), catalogItem.getHref(), description, computeOptions,
|
||||||
computeOptions, customizationOptions, entity, properties);
|
customizationOptions, entity, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
super.startElement(uri, localName, qName, attributes);
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
|
super.startElement(uri, localName, qName, attrs);
|
||||||
if (qName.equals("Link")) {
|
if (qName.equals("Link")) {
|
||||||
int nameIndex = attributes.getIndex("name");
|
if (attributes.containsKey("name")) {
|
||||||
if (nameIndex != -1) {
|
if (attributes.get("name").equals("Customization Options")) {
|
||||||
if (attributes.getValue(nameIndex).equals("Customization Options")) {
|
customizationOptions = newReferenceType(attributes);
|
||||||
customizationOptions = newNamedResource(attributes);
|
} else if (attributes.get("name").equals("Compute Options")) {
|
||||||
} else if (attributes.getValue(nameIndex).equals("Compute Options")) {
|
computeOptions = newReferenceType(attributes);
|
||||||
computeOptions = newNamedResource(attributes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,10 @@
|
||||||
package org.jclouds.vcloud.terremark.xml;
|
package org.jclouds.vcloud.terremark.xml;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType.KEYSLIST_XML;
|
import static org.jclouds.vcloud.terremark.TerremarkVCloudExpressMediaType.KEYSLIST_XML;
|
||||||
import static org.jclouds.vcloud.util.Utils.newNamedResource;
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
import static org.jclouds.vcloud.util.Utils.newReferenceType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ -49,13 +52,13 @@ public class TerremarkOrgHandler extends OrgHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
super.startElement(uri, localName, qName, attributes);
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
|
super.startElement(uri, localName, qName, attrs);
|
||||||
if (qName.equals("Link")) {
|
if (qName.equals("Link")) {
|
||||||
int typeIndex = attributes.getIndex("type");
|
if (attributes.containsKey("type")) {
|
||||||
if (typeIndex != -1) {
|
if (attributes.get("type").equals(KEYSLIST_XML)) {
|
||||||
if (attributes.getValue(typeIndex).equals(KEYSLIST_XML)) {
|
keysList = newReferenceType(attributes);
|
||||||
keysList = newNamedResource(attributes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
|
|
||||||
package org.jclouds.vcloud.terremark.xml;
|
package org.jclouds.vcloud.terremark.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.vcloud.VCloudExpressMediaType;
|
import org.jclouds.vcloud.VCloudExpressMediaType;
|
||||||
|
@ -54,18 +58,19 @@ public class TerremarkVDCHandler extends VDCHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||||
super.startElement(uri, localName, qName, attributes);
|
Map<String, String> attributes = cleanseAttributes(attrs);
|
||||||
|
super.startElement(uri, localName, qName, attrs);
|
||||||
if (qName.equals("Link")) {
|
if (qName.equals("Link")) {
|
||||||
String name = attributes.getValue(attributes.getIndex("name"));
|
String name = attributes.get("name");
|
||||||
if (name.equals("Internet Services")) {
|
if (name.equals("Internet Services")) {
|
||||||
internetServices = Utils.newNamedResource(attributes);
|
internetServices = Utils.newReferenceType(attributes);
|
||||||
} else if (name.equals("Public IPs")) {
|
} else if (name.equals("Public IPs")) {
|
||||||
publicIps = Utils.newNamedResource(attributes);
|
publicIps = Utils.newReferenceType(attributes);
|
||||||
} else {
|
} else {
|
||||||
String type = attributes.getValue(attributes.getIndex("type"));
|
String type = attributes.get("type");
|
||||||
if (type.equals(VCloudExpressMediaType.CATALOG_XML)) {
|
if (type.equals(VCloudExpressMediaType.CATALOG_XML)) {
|
||||||
catalog = Utils.newNamedResource(attributes);
|
catalog = Utils.newReferenceType(attributes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue