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