http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/util/ConflictManagementPredicate.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/util/ConflictManagementPredicate.java b/azurecompute/src/main/java/org/jclouds/azurecompute/util/ConflictManagementPredicate.java deleted file mode 100644 index 1f940bf..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/util/ConflictManagementPredicate.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.azurecompute.domain.Operation.Status.FAILED; -import java.util.concurrent.CancellationException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.azurecompute.AzureComputeApi; -import org.jclouds.azurecompute.domain.Operation; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.logging.Logger; -import org.jclouds.util.Predicates2; - -import com.google.common.base.Predicate; - -/** - * Conflict errors (409 response status code) management predicate. - */ -public class ConflictManagementPredicate implements Predicate<String> { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private AzureComputeApi api; - - private Predicate<String> operationSucceeded; - - private final long timeout = 600000; - private final long interval = 15000; - - public ConflictManagementPredicate() { - this(null); - } - - /** - * Constructor. - * - * @param api azure api. - */ - public ConflictManagementPredicate(final AzureComputeApi api) { - this(api, Predicates2.retry(new OperationSucceededPredicate(api), 600, 5, 5, SECONDS)); - } - - /** - * Constructor. - * - * @param api azure api. - * @param timeout predicate timeout. - * @param period predicate period. - * @param maxPeriod max period - * @param unit timeout and period time unit. - */ - public ConflictManagementPredicate( - final AzureComputeApi api, long timeout, long period, long maxPeriod, TimeUnit unit) { - this(api, Predicates2.retry(new OperationSucceededPredicate(api), timeout, period, maxPeriod, unit)); - } - - /** - * Constructor. - * - * @param api azure api. - * @param operationSucceeded predicate to be applied to the requestId. - */ - public ConflictManagementPredicate(final AzureComputeApi api, final Predicate<String> operationSucceeded) { - this.api = api; - this.operationSucceeded = operationSucceeded; - } - - /** - * Operation to be executed. - * - * @return requestId. - */ - protected String operation() { - throw new UnsupportedOperationException(); - } - - /** - * {@inheritDoc } - * - * @param input interested object/operation description or requestId. - * @return predicate evaluation. - */ - @Override - public final boolean apply(final String input) { - Operation operation = null; - String requestId = null; - - boolean retry = true; - - long now = System.currentTimeMillis(); - long end = now + timeout; - - while (retry && now < end) { - try { - requestId = operation(); - logger.debug("Executed operation on %s", input); - - // If request id is not available let's assume operation succeeded. - if (requestId == null) { - logger.debug("No request id available. Assume operation succeeded."); - return true; - } - - operation = api.getOperationApi().get(requestId); - logger.debug("Operation %s status: %s", operation.id(), operation.status().name()); - - if (operation.status() == FAILED) { - // rise an exception based on HTTP status code - if (operation.httpStatusCode() == 409 || operation.httpStatusCode() == 500) { - logger.info("Retry operation %s with (code %d)", operation.id(), operation.httpStatusCode()); - } else { - logger.info("Not retriable operation %s (code %d)", operation.id(), operation.httpStatusCode()); - retry = false; - } - } else { - logger.debug("Tracking for operation %s ...", operation.id()); - retry = false; - } - } catch (UnsupportedOperationException e) { - requestId = input; - retry = false; - logger.debug("Tracking for operation %s ...", input); - } catch (RuntimeException e) { - final HttpResponseException re = (e instanceof HttpResponseException) - ? HttpResponseException.class.cast(e) : (e.getCause() instanceof HttpResponseException) - ? HttpResponseException.class.cast(e.getCause()) - : null; - if (re == null) { - throw e; - } else { - final HttpResponse res = re.getResponse(); - logger.info("[%s (%d)] Performing operation on %s", res.getStatusLine(), res.getStatusCode(), input); - if (res.getStatusCode() == 409 || res.getStatusCode() == 500) { - logger.info("Retry operation %s", operation == null ? "" : operation.id(), res.getStatusCode()); - } else { - throw re; - } - } - } - - if (retry) { - try { - Thread.sleep(interval); - } catch (InterruptedException ex) { - // ignore - } - - now = System.currentTimeMillis(); - } - } - - if (now >= end) { - throw new RuntimeException(new TimeoutException(requestId)); - } - - return operationSucceeded.apply(requestId); - } - - private static class OperationSucceededPredicate implements Predicate<String> { - - private final AzureComputeApi api; - - public OperationSucceededPredicate(final AzureComputeApi api) { - this.api = checkNotNull(api, "api must not be null"); - } - - @Override - public boolean apply(final String input) { - final Operation operation = api.getOperationApi().get(input); - switch (operation.status()) { - case SUCCEEDED: - return true; - - case IN_PROGRESS: - case UNRECOGNIZED: - return false; - - case FAILED: - throw new RuntimeException(new CancellationException(input)); - - default: - throw new IllegalStateException("Operation is in invalid status: " + operation.status().name()); - } - } - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/util/NetworkSecurityGroups.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/util/NetworkSecurityGroups.java b/azurecompute/src/main/java/org/jclouds/azurecompute/util/NetworkSecurityGroups.java deleted file mode 100644 index 7035d70..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/util/NetworkSecurityGroups.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.util; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.jclouds.azurecompute.domain.NetworkSecurityGroup; -import org.jclouds.azurecompute.domain.Rule; - -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.FluentIterable; - -public class NetworkSecurityGroups { - - public static List<Rule> getCustomRules(final NetworkSecurityGroup networkSecurityGroup) { - final List<Rule> rules = networkSecurityGroup.rules(); - return FluentIterable.from(rules) - .filter(Predicates.notNull()) - .filter(new Predicate<Rule>() { - @Override - public boolean apply(final Rule rule) { - return rule.isDefault() == null || !rule.isDefault(); - } - }) - .toSortedList(new Comparator<Rule>() { - @Override - public int compare(final Rule r1, final Rule r2) { - final int p1 = Integer.parseInt(r1.priority()); - final int p2 = Integer.parseInt(r2.priority()); - return p1 < p2 ? -1 : p1 == p2 ? 0 : 1; - - } - }); - } - - public static int getFirstAvailablePriority(final List<Rule> rules) { - int priority; - if (rules.isEmpty()) { - priority = 100; - } else { - priority = Integer.parseInt(Collections.max(rules, new Comparator<Rule>() { - @Override - public int compare(final Rule rule1, final Rule rule2) { - return Integer.valueOf(rule1.priority()).compareTo(Integer.valueOf(rule2.priority())); - } - }).priority()) + 1; - } - return priority; - } - - public static String createRuleName(final String format, final int fromPort, final int toPort) { - return String.format(format, fromPort, toPort); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AddressSpaceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AddressSpaceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AddressSpaceHandler.java deleted file mode 100644 index ad2d52d..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AddressSpaceHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.NetworkConfiguration.AddressSpace; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public class AddressSpaceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<AddressSpace> { - - private String addressPrefix; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { - } - - @Override - public AddressSpace getResult() { - AddressSpace result = AddressSpace.create(addressPrefix); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - addressPrefix = null; - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if (qName.equals("AddressPrefix")) { - addressPrefix = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AffinityGroupHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AffinityGroupHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AffinityGroupHandler.java deleted file mode 100644 index 05dff68..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AffinityGroupHandler.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.io.BaseEncoding.base64; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.util.Date; -import java.util.List; - -import com.google.common.collect.Lists; -import com.google.inject.Inject; - -import org.jclouds.http.functions.ParseSax; -import org.jclouds.azurecompute.domain.AffinityGroup; -import org.jclouds.azurecompute.domain.AffinityGroup.Capability; -import org.jclouds.azurecompute.domain.ComputeCapabilities; -import org.jclouds.date.internal.SimpleDateFormatDateService; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/jj157191">api</a> - */ -public final class AffinityGroupHandler extends ParseSax.HandlerForGeneratedRequestWithResult<AffinityGroup> { - - private final StringBuilder currentText = new StringBuilder(); - - private final ComputeCapabilitiesHandler computeCapabilitiesHandler; - - private String name; - - private String label; - - private String description; - - private String location; - - private final List<Capability> capabilities = Lists.newArrayList(); - - private Date createdTime; - - private ComputeCapabilities computeCapabilities; - - private boolean inComputeCapabilities = false; - - @Inject - AffinityGroupHandler(final ComputeCapabilitiesHandler computeCapabilitiesHandler) { - this.computeCapabilitiesHandler = computeCapabilitiesHandler; - } - - @Override - public AffinityGroup getResult() { - final AffinityGroup result = AffinityGroup.create( - name, label, description, location, capabilities, createdTime, computeCapabilities); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = null; - label = null; - description = null; - location = null; - capabilities.clear(); - createdTime = null; - computeCapabilities = null; - } - - @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) - throws SAXException { - - if ("ComputeCapabilities".equals(qName)) { - inComputeCapabilities = true; - } else if (inComputeCapabilities) { - computeCapabilitiesHandler.startElement(uri, localName, qName, attributes); - } - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if ("Name".equals(qName)) { - name = currentOrNull(currentText); - } else if ("Label".equals(qName)) { - label = new String(base64().decode(currentOrNull(currentText)), UTF_8); - } else if ("Description".equals(qName)) { - description = currentOrNull(currentText); - } else if ("Location".equals(qName)) { - location = currentOrNull(currentText); - } else if ("Capability".equals(qName)) { - final String capabilityText = currentOrNull(currentText); - if (capabilityText != null) { - capabilities.add(Capability.valueOf(capabilityText)); - } - } else if ("CreatedTime".equals(qName)) { - final String createdTimeText = currentOrNull(currentText); - if (createdTimeText != null) { - createdTime = new SimpleDateFormatDateService().iso8601DateOrSecondsDateParse(createdTimeText); - } - } else if ("ComputeCapabilities".equals(qName)) { - inComputeCapabilities = false; - computeCapabilities = computeCapabilitiesHandler.getResult(); - } else if (inComputeCapabilities) { - computeCapabilitiesHandler.endElement(ignoredUri, ignoredName, qName); - } - - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - if (inComputeCapabilities) { - computeCapabilitiesHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java deleted file mode 100644 index 5b7e658..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AttachmentHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Disk.Attachment; -import org.jclouds.http.functions.ParseSax; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/jj157176" >api</a> - */ -final class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Attachment> { - - private String hostedService; - - private String deployment; - - private String virtualMachine; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public Attachment getResult() { - final Attachment result = Attachment.create(hostedService, deployment, virtualMachine); - hostedService = deployment = virtualMachine = null; // handler could be called in a loop. - return result; - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if (qName.equals("HostedServiceName")) { - hostedService = currentOrNull(currentText); - } else if (qName.equals("DeploymentName")) { - deployment = currentOrNull(currentText); - } else if (qName.equals("RoleName")) { - virtualMachine = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AvailabilityHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AvailabilityHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AvailabilityHandler.java deleted file mode 100644 index e7b1d7b..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/AvailabilityHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Availability; -import org.jclouds.http.functions.ParseSax; - -public class AvailabilityHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Availability> { - - private Boolean result; - - private String reason; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public Availability getResult() { - return Availability.create(result, reason); - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Result")) { - String resultText = currentOrNull(currentText); - if (resultText != null) { - result = Boolean.valueOf(resultText); - } - } else if (qName.equals("Reason")) { - reason = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java deleted file mode 100644 index 9af6141..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.io.BaseEncoding.base64; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.util.Date; -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.date.DateService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >Response body description</a> - */ -public final class CloudServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<CloudService> { - - private String name; - - private String location; - - private String affinityGroup; - - private String label; - - private String description; - - private CloudService.Status status; - - private Date created; - - private Date lastModified; - - private Map<String, String> extendedProperties = Maps.newLinkedHashMap(); - - private boolean inHostedServiceProperties; - - private String propertyName; - - private StringBuilder currentText = new StringBuilder(); - - private final DateService dateService; - - @Inject - CloudServiceHandler(DateService dateService) { - this.dateService = dateService; - } - - @Override - public CloudService getResult() { - CloudService result = CloudService.create(name, location, affinityGroup, label, description, status, created, // - lastModified, ImmutableMap.copyOf(extendedProperties)); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = description = location = affinityGroup = label = null; - status = null; - created = lastModified = null; - extendedProperties.clear(); - inHostedServiceProperties = false; - propertyName = null; - } - - @Override - public void startElement(String ignoredUri, String ignoredLocalName, String qName, Attributes ignoredAttributes) { - if (qName.equals("HostedServiceProperties")) { - inHostedServiceProperties = true; - } - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("HostedServiceProperties")) { - inHostedServiceProperties = false; - } else if (inHostedServiceProperties) { - if (qName.equals("DateCreated")) { - created = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("DateLastModified")) { - lastModified = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("Status")) { - String statusText = currentOrNull(currentText); - status = CloudService.Status.fromString(UPPER_CAMEL.to(UPPER_UNDERSCORE, statusText)); - } else if (qName.equals("Name")) { - propertyName = currentOrNull(currentText); - } else if (qName.equals("Value")) { - extendedProperties.put(propertyName, currentOrNull(currentText)); - propertyName = null; - } else if (qName.equals("Description")) { - description = currentOrNull(currentText); - } else if (qName.equals("Location")) { - location = currentOrNull(currentText); - } else if (qName.equals("AffinityGroup")) { - affinityGroup = currentOrNull(currentText); - } else if (qName.equals("Label")) { - label = new String(base64().decode(currentOrNull(currentText)), UTF_8); - } - } else if (qName.equals("ServiceName")) { - name = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandler.java deleted file mode 100644 index a692df2..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServicePropertiesHandler.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import org.jclouds.azurecompute.domain.CloudServiceProperties; -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.date.DateService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import javax.inject.Inject; - -import java.net.URI; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static org.jclouds.util.SaxUtils.currentOrNull; - -/** - * @see <a href="https://msdn.microsoft.com/en-us/library/azure/ee460806.aspx" >Response body description</a> - */ -public final class CloudServicePropertiesHandler - extends ParseSax.HandlerForGeneratedRequestWithResult<CloudServiceProperties> { - private String name; - private URI url; - private String location; - private String affinityGroup; - private String label; - private String description; - private CloudServiceProperties.Status status; - private Date created; - private Date lastModified; - private Map<String, String> extendedProperties = Maps.newLinkedHashMap(); - private List<Deployment> deploymentList = Lists.newArrayList(); - - private boolean inHostedServiceProperties; - private boolean inDeployment; - private String propertyName; - private StringBuilder currentText = new StringBuilder(); - private final DateService dateService; - private final DeploymentHandler deploymentHandler; - - @Inject CloudServicePropertiesHandler(DateService dateService, DeploymentHandler deploymentHandler) { - this.dateService = dateService; - this.deploymentHandler = deploymentHandler; - } - - @Override public CloudServiceProperties getResult() { - CloudServiceProperties result = CloudServiceProperties - .create(name, url, location, affinityGroup, label, description, status, created, // - lastModified, ImmutableMap.copyOf(extendedProperties), ImmutableList.copyOf(deploymentList)); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = description = location = affinityGroup = label = null; - status = null; - created = lastModified = null; - extendedProperties.clear(); - inHostedServiceProperties = false; - propertyName = null; - } - - @Override public void startElement(String ignoredUri, String ignoredLocalName, String qName, - Attributes ignoredAttributes) { - if (qName.equals("HostedServiceProperties")) { - inHostedServiceProperties = true; - } else if (qName.equals("Deployment")) { - inDeployment = true; - } - if (inDeployment) { - deploymentHandler.startElement(ignoredUri, ignoredLocalName, qName, ignoredAttributes); - } - } - - @Override public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("HostedServiceProperties")) { - inHostedServiceProperties = false; - } else if (inHostedServiceProperties) { - if (qName.equals("DateCreated")) { - created = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("DateLastModified")) { - lastModified = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("Status")) { - String statusText = currentOrNull(currentText); - if (statusText != null) { - status = status(statusText); - } - } else if (qName.equals("Name")) { - propertyName = currentOrNull(currentText); - } else if (qName.equals("Value")) { - extendedProperties.put(propertyName, currentOrNull(currentText)); - propertyName = null; - } else if (qName.equals("Description")) { - description = currentOrNull(currentText); - } else if (qName.equals("Location")) { - location = currentOrNull(currentText); - } else if (qName.equals("AffinityGroup")) { - affinityGroup = currentOrNull(currentText); - } else if (qName.equals("Label")) { - label = currentOrNull(currentText); - } - } else if (qName.equals("ServiceName")) { - name = currentOrNull(currentText); - } else if (qName.equals("Deployment")) { - deploymentList.add(deploymentHandler.getResult()); - inDeployment = false; - } else if (inDeployment) { - deploymentHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("Url")) { - String link = currentOrNull(currentText); - if (link != null) { - url = URI.create(link); - } - } - currentText.setLength(0); - } - - @Override public void characters(char[] ch, int start, int length) { - if (inDeployment) { - deploymentHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - - private static CloudServiceProperties.Status status(String status) { - try { - return CloudServiceProperties.Status.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, status)); - } catch (IllegalArgumentException e) { - return CloudServiceProperties.Status.UNRECOGNIZED; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ComputeCapabilitiesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ComputeCapabilitiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ComputeCapabilitiesHandler.java deleted file mode 100644 index 706e6d7..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ComputeCapabilitiesHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import com.google.common.collect.Lists; -import java.util.List; -import org.jclouds.azurecompute.domain.ComputeCapabilities; -import org.jclouds.azurecompute.domain.RoleSize; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; - -public class ComputeCapabilitiesHandler - extends ParseSax.HandlerForGeneratedRequestWithResult<ComputeCapabilities> { - - private final StringBuilder currentText = new StringBuilder(); - - private final List<RoleSize.Type> virtualMachineRoleSizes = Lists.newArrayList(); - - private final List<RoleSize.Type> webWorkerRoleSizes = Lists.newArrayList(); - - private boolean inVirtualMachineRoleSizes = false; - - private boolean inWebWorkerRoleSizes = false; - - @Override - public ComputeCapabilities getResult() { - final ComputeCapabilities result = ComputeCapabilities.create(virtualMachineRoleSizes, webWorkerRoleSizes); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - virtualMachineRoleSizes.clear(); - webWorkerRoleSizes.clear(); - } - - @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) - throws SAXException { - - if ("WebWorkerRoleSizes".equals(qName)) { - inWebWorkerRoleSizes = true; - } else if ("VirtualMachinesRoleSizes".equals(qName)) { - inVirtualMachineRoleSizes = true; - } - } - - @Override - public void endElement(final String ignoredUri, final String ignoredName, final String qName) { - if ("RoleSize".equals(qName)) { - final RoleSize.Type roleSizeType = RoleSize.Type.fromString(currentOrNull(currentText)); - if (inVirtualMachineRoleSizes) { - virtualMachineRoleSizes.add(roleSizeType); - } else if (inWebWorkerRoleSizes) { - webWorkerRoleSizes.add(roleSizeType); - } - } else if ("WebWorkerRoleSizes".equals(qName)) { - inWebWorkerRoleSizes = false; - } else if ("VirtualMachinesRoleSizes".equals(qName)) { - inVirtualMachineRoleSizes = false; - } - - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ConfigurationSetHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ConfigurationSetHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ConfigurationSetHandler.java deleted file mode 100644 index 4065f72..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ConfigurationSetHandler.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; -import java.util.List; - -import org.jclouds.azurecompute.domain.Role.ConfigurationSet; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.InputEndpoint; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.PublicIP; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.SubnetName; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; -import com.google.inject.Inject; - -public class ConfigurationSetHandler extends ParseSax.HandlerForGeneratedRequestWithResult<ConfigurationSet> { - - private String configurationSetType; - - private List<InputEndpoint> inputEndpoint = Lists.newArrayList(); - - private List<SubnetName> subnetNames = Lists.newArrayList(); - - private String staticVirtualNetworkIPAddress; - - private List<PublicIP> publicIPs = Lists.newArrayList(); - - private String networkSecurityGroup; - - private boolean inInputEndpoint; - - private boolean inSubnetNames; - - private final InputEndpointHandler inputEndpointHandler; - - private final SubnetNameHandler subnetNameHandler; - - private final StringBuilder currentText = new StringBuilder(); - - @Inject - ConfigurationSetHandler(InputEndpointHandler inputEndpointHandler, SubnetNameHandler subnetNameHandler) { - this.inputEndpointHandler = inputEndpointHandler; - this.subnetNameHandler = subnetNameHandler; - } - - @Override - public ConfigurationSet getResult() { - ConfigurationSet result = ConfigurationSet.create(configurationSetType, inputEndpoint, subnetNames, - staticVirtualNetworkIPAddress, publicIPs, networkSecurityGroup); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - configurationSetType = staticVirtualNetworkIPAddress = networkSecurityGroup = null; - inputEndpoint = Lists.newArrayList(); - subnetNames = Lists.newArrayList(); - publicIPs = Lists.newArrayList(); - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("InputEndpoint")) { - inInputEndpoint = true; - } - if (inInputEndpoint) { - inputEndpointHandler.startElement(uri, localName, qName, attributes); - } - if (qName.equals("SubnetNames")) { - inSubnetNames = true; - } - if (inSubnetNames) { - subnetNameHandler.startElement(uri, localName, qName, attributes); - } - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("InputEndpoint")) { - inInputEndpoint = false; - inputEndpoint.add(inputEndpointHandler.getResult()); - } else if (qName.equals("SubnetNames")) { - inSubnetNames = false; - subnetNames.add(subnetNameHandler.getResult()); - } else if (inInputEndpoint) { - inputEndpointHandler.endElement(ignoredUri, ignoredName, qName); - } else if (inSubnetNames) { - subnetNameHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("ConfigurationSetType")) { - configurationSetType = currentOrNull(currentText); - } else if (qName.equals("NetworkSecurityGroup")) { - networkSecurityGroup = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inInputEndpoint) { - inputEndpointHandler.characters(ch, start, length); - } else if (inSubnetNames) { - subnetNameHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java deleted file mode 100644 index 22472bb..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DataVirtualHardDiskHandler.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static org.jclouds.util.SaxUtils.currentOrNull; -import java.net.URI; - -import org.jclouds.azurecompute.domain.DataVirtualHardDisk; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -/** - * @see <a href="https://msdn.microsoft.com/en-us/library/azure/jj157193.aspx#DataVirtualHardDisks" >api</a> - */ -final class DataVirtualHardDiskHandler extends ParseSax.HandlerForGeneratedRequestWithResult<DataVirtualHardDisk> { - - private DataVirtualHardDisk.Caching hostCaching; - - private String diskName; - - private Integer lun; - - private Integer logicalDiskSizeInGB; - - private URI mediaLink; - - private String ioType; - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - } - - @Override - public DataVirtualHardDisk getResult() { - DataVirtualHardDisk result = DataVirtualHardDisk - .create(hostCaching, diskName, lun, logicalDiskSizeInGB, mediaLink, ioType); - return result; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - - if (qName.equals("HostCaching")) { - String hostCachingText = currentOrNull(currentText); - if (hostCachingText != null) - hostCaching = DataVirtualHardDisk.Caching.fromString(UPPER_CAMEL.to(UPPER_UNDERSCORE, hostCachingText)); - } else if (qName.equals("DiskName") || qName.equals("Name")) { - diskName = currentOrNull(currentText); - } else if (qName.equals("Lun")) { - String lunText = currentOrNull(currentText); - if (lunText != null) { - lun = Integer.parseInt(lunText); - } - } else if (qName.equals("LogicalDiskSizeInGB")) { - String gb = currentOrNull(currentText); - if (gb != null) { - logicalDiskSizeInGB = Integer.parseInt(gb); - } - } else if (qName.equals("MediaLink")) { - String link = currentOrNull(currentText); - if (link != null) { - mediaLink = URI.create(link); - } - } else if (qName.equals("IOType")) { - ioType = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java deleted file mode 100644 index a3fc96f..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DeploymentHandler.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.io.BaseEncoding.base64; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.util.List; - -import org.jclouds.azurecompute.domain.Deployment; -import org.jclouds.azurecompute.domain.Deployment.Slot; -import org.jclouds.azurecompute.domain.Deployment.Status; -import org.jclouds.azurecompute.domain.Role; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.Lists; -import com.google.inject.Inject; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/ee460804" >Response body description</a>. - */ -public final class DeploymentHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Deployment> { - - private String name; - - private Slot slot; - - private Status status; - - private String label; - - private String instanceStateDetails; - - private String virtualNetworkName; - - private List<Deployment.VirtualIP> virtualIPs = Lists.newArrayList(); - - private List<Deployment.RoleInstance> roleInstanceList = Lists.newArrayList(); - - private List<Role> roleList = Lists.newArrayList(); - - private String instanceErrorCode; - - private boolean inRoleInstanceList; - - private boolean inRoleList; - - private boolean inListVirtualIPs; - - private final VirtualIPHandler virtualIPHandler; - - private final RoleInstanceHandler roleInstanceHandler; - - private final RoleHandler roleHandler; - - private final StringBuilder currentText = new StringBuilder(); - - @Inject - DeploymentHandler(VirtualIPHandler virtualIPHandler, RoleInstanceHandler roleInstanceHandler, RoleHandler roleHandler) { - this.virtualIPHandler = virtualIPHandler; - this.roleInstanceHandler = roleInstanceHandler; - this.roleHandler = roleHandler; - } - - @Override - public Deployment getResult() { // Fields don't need to be reset as this isn't used in a loop. - return Deployment.create(name, slot, status, label, // - instanceStateDetails, instanceErrorCode, virtualIPs, roleInstanceList, roleList, virtualNetworkName); - } - - @Override - public void startElement(String url, String name, String qName, Attributes attributes) { - if (qName.equals("VirtualIPs")) { - inListVirtualIPs = true; - } else if (qName.equals("RoleInstanceList")) { - inRoleInstanceList = true; - } else if (qName.equals("RoleList")) { - inRoleList = true; - } - if (inRoleInstanceList) { - roleInstanceHandler.startElement(url, name, qName, attributes); - } - if (inRoleList) { - roleHandler.startElement(url, name, qName, attributes); - } - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("RoleInstanceList")) { - inRoleInstanceList = false; - } else if (qName.equals("RoleInstance")) { - roleInstanceList.add(roleInstanceHandler.getResult()); - } else if (inRoleInstanceList) { - roleInstanceHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("RoleList")) { - inRoleList = false; - } else if (qName.equals("Role")) { - roleList.add(roleHandler.getResult()); - } else if (inRoleList) { - roleHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("VirtualIPs")) { - inListVirtualIPs = false; - } else if (qName.equals("VirtualIP")) { - virtualIPs.add(virtualIPHandler.getResult()); - } else if (inListVirtualIPs) { - virtualIPHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("Name") && name == null) { - name = currentOrNull(currentText); - } else if (qName.equals("DeploymentSlot")) { - String slotText = currentOrNull(currentText); - slot = Slot.fromString(UPPER_CAMEL.to(UPPER_UNDERSCORE, slotText)); - } else if (qName.equals("Status")) { - String statusText = currentOrNull(currentText); - if (status == null && statusText != null) { - status = Status.fromString(statusText); - } - } else if (qName.equals("Label")) { - String labelText = currentOrNull(currentText); - if (labelText != null) { - label = new String(base64().decode(labelText), UTF_8); - } - } else if (qName.equals("InstanceStateDetails")) { - instanceStateDetails = currentOrNull(currentText); - } else if (qName.equals("InstanceErrorCode")) { - instanceErrorCode = currentOrNull(currentText); - } else if (qName.equals("VirtualNetworkName")) { - virtualNetworkName = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inListVirtualIPs) { - virtualIPHandler.characters(ch, start, length); - } else if (inRoleInstanceList) { - roleInstanceHandler.characters(ch, start, length); - } else if (inRoleList) { - roleHandler.characters(ch, start, length); - } else if (!inListVirtualIPs && !inRoleInstanceList && !inRoleList) { - currentText.append(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java deleted file mode 100644 index 0800d51..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DiskHandler.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.net.URI; - -import org.jclouds.azurecompute.domain.Disk; -import org.jclouds.azurecompute.domain.Disk.Attachment; -import org.jclouds.azurecompute.domain.OSImage; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/jj157176" >api</a> - */ -final class DiskHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Disk> { - - private String name; - - private String location; - - private String affinityGroup; - - private String description; - - private OSImage.Type os; - - private URI mediaLink; - - private Integer logicalSizeInGB; - - private Attachment attachedTo; - - private String sourceImage; - - private boolean inAttachment; - - private final AttachmentHandler attachmentHandler = new AttachmentHandler(); - - private final StringBuilder currentText = new StringBuilder(); - - @Override - public Disk getResult() { - Disk result = Disk.create(name, location, affinityGroup, description, os, mediaLink, logicalSizeInGB, attachedTo, - sourceImage); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = location = affinityGroup = description = sourceImage = null; - os = null; - mediaLink = null; - logicalSizeInGB = null; - attachedTo = null; - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("AttachedTo")) { - inAttachment = true; - } - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("AttachedTo")) { - attachedTo = attachmentHandler.getResult(); - inAttachment = false; - } else if (inAttachment) { - attachmentHandler.endElement(ignoredUri, ignoredName, qName); - } else if (qName.equals("OS")) { - String osText = currentOrNull(currentText); - if (osText != null) { - os = OSImage.Type.valueOf(osText.toUpperCase()); - } - } else if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("LogicalDiskSizeInGB")) { - String gb = currentOrNull(currentText); - if (gb != null) { - logicalSizeInGB = Integer.parseInt(gb); - } - } else if (qName.equals("Description")) { - description = currentOrNull(currentText); - } else if (qName.equals("Location")) { - location = currentOrNull(currentText); - } else if (qName.equals("AffinityGroup")) { - affinityGroup = currentOrNull(currentText); - } else if (qName.equals("MediaLink")) { - String link = currentOrNull(currentText); - if (link != null) { - mediaLink = URI.create(link); - } - } else if (qName.equals("SourceImageName")) { - sourceImage = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inAttachment) { - attachmentHandler.characters(ch, start, length); - } else { - currentText.append(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java deleted file mode 100644 index 8ab50dd..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ErrorHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Error; -import org.jclouds.azurecompute.domain.Error.Code; -import org.jclouds.http.functions.ParseSax; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/ee460801" >api</a> - */ -public final class ErrorHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Error> { - - private Code code; - - private String message; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public Error getResult() { - return Error.create(code, message); - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Code")) { - String codeText = currentOrNull(currentText); - code = Code.fromString(UPPER_CAMEL.to(UPPER_UNDERSCORE, codeText)); - } else if (qName.equals("Message")) { - message = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ExtendedPropertiesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ExtendedPropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ExtendedPropertiesHandler.java deleted file mode 100644 index be675b8..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ExtendedPropertiesHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import com.google.common.collect.Lists; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.xml.sax.helpers.DefaultHandler; - -public class ExtendedPropertiesHandler extends DefaultHandler { - - private final List<String> extendedProperties = Lists.newArrayList(); - - private final StringBuilder currentText = new StringBuilder(); - - public Map<String, String> getResult() { - final Map<String, String> result = new HashMap<String, String>(); - for (int i = 0; i < extendedProperties.size(); i += 2) { - result.put(extendedProperties.get(i), extendedProperties.get(i + 1)); - } - extendedProperties.clear(); - return result; - } - - @Override - public void endElement(final String uri, final String localName, final String qName) { - if ("Name".equals(qName) || "Value".equals(qName)) { - extendedProperties.add(currentOrNull(currentText)); - } - - currentText.setLength(0); - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InputEndpointHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InputEndpointHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InputEndpointHandler.java deleted file mode 100644 index ad5a13f..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InputEndpointHandler.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.InputEndpoint; -import org.jclouds.azurecompute.domain.Role.ConfigurationSet.InputEndpoint.LoadBalancerProbe; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public class InputEndpointHandler extends ParseSax.HandlerForGeneratedRequestWithResult<InputEndpoint> { - - private Integer localPort; - - private String name; - - private Integer port; - - private String protocol; - - private Boolean enableDirectServerReturn; - - private String vip; - - private String loadBalancerName; - - private LoadBalancerProbe loadBalancerProbe; - - private Integer idleTimeoutInMinutes; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - } - - @Override - public InputEndpoint getResult() { - InputEndpoint result = InputEndpoint.create(name, protocol, localPort, port, vip, - enableDirectServerReturn, loadBalancerName, loadBalancerProbe, idleTimeoutInMinutes); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = vip = protocol = null; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("Vip")) { - vip = currentOrNull(currentText); - } else if (qName.equals("LocalPort")) { - String localPortText = currentOrNull(currentText); - if (localPortText != null) { - localPort = Integer.parseInt(localPortText); - } - } else if (qName.equals("Port")) { - String portText = currentOrNull(currentText); - if (portText != null) { - port = Integer.parseInt(portText); - } - } else if (qName.equals("Protocol")) { - protocol = currentOrNull(currentText); - } else if (qName.equals("EnableDirectServerReturn")) { - String enableDirectServerReturnText = currentOrNull(currentText); - if (enableDirectServerReturnText != null) { - enableDirectServerReturn = Boolean.parseBoolean(enableDirectServerReturnText); - } - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InstanceEndpointHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InstanceEndpointHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InstanceEndpointHandler.java deleted file mode 100644 index 2d254d4..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/InstanceEndpointHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import static org.jclouds.util.SaxUtils.currentOrNull; - -import org.jclouds.azurecompute.domain.Deployment.InstanceEndpoint; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -public class InstanceEndpointHandler extends ParseSax.HandlerForGeneratedRequestWithResult<InstanceEndpoint> { - - private String name; - - private String vip; - - private Integer publicPort; - - private Integer localPort; - - private String protocol; - - private StringBuilder currentText = new StringBuilder(); - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - } - - @Override - public InstanceEndpoint getResult() { - InstanceEndpoint result = InstanceEndpoint.create(name, vip, publicPort, localPort, protocol); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = vip = protocol = null; - publicPort = localPort = null; - } - - @Override - public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("Name")) { - name = currentOrNull(currentText); - } else if (qName.equals("Vip")) { - vip = currentOrNull(currentText); - } else if (qName.equals("PublicPort")) { - String publicPortText = currentOrNull(currentText); - if (publicPortText != null) { - publicPort = Integer.parseInt(publicPortText); - } - } else if (qName.equals("LocalPort")) { - String localPortText = currentOrNull(currentText); - if (localPortText != null) { - localPort = Integer.parseInt(localPortText); - } - } else if (qName.equals("Protocol")) { - protocol = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override - public void characters(char[] ch, int start, int length) { - currentText.append(ch, start, length); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandler.java deleted file mode 100644 index 98d3d63..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListAffinityGroupsHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import java.util.List; - -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.inject.Inject; -import org.jclouds.azurecompute.domain.AffinityGroup; -import org.xml.sax.SAXException; - -public final class ListAffinityGroupsHandler - extends ParseSax.HandlerForGeneratedRequestWithResult<List<AffinityGroup>> { - - private final Builder<AffinityGroup> affinityGroups = ImmutableList.builder(); - - private final AffinityGroupHandler affinityGroupHandler; - - private boolean inAffinityGroup; - - @Inject - ListAffinityGroupsHandler(AffinityGroupHandler affinityGroupHandler) { - this.affinityGroupHandler = affinityGroupHandler; - } - - @Override - public List<AffinityGroup> getResult() { - return affinityGroups.build(); - } - - @Override - public void startElement(final String url, final String name, final String qName, final Attributes attributes) - throws SAXException { - - if ("AffinityGroup".equals(qName)) { - inAffinityGroup = true; - } else if (inAffinityGroup) { - affinityGroupHandler.startElement(url, qName, qName, attributes); - } - } - - @Override - public void endElement(final String uri, final String name, final String qName) { - if ("AffinityGroup".equals(qName)) { - inAffinityGroup = false; - affinityGroups.add(affinityGroupHandler.getResult()); - } else if (inAffinityGroup) { - affinityGroupHandler.endElement(uri, name, qName); - } - } - - @Override - public void characters(final char[] ch, final int start, final int length) { - if (inAffinityGroup) { - affinityGroupHandler.characters(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java deleted file mode 100644 index 98eae83..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import java.util.List; - -import javax.inject.Inject; - -import org.jclouds.azurecompute.domain.CloudService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">Response body description</a> - */ -public final class ListCloudServicesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<CloudService>> { - - private boolean inHostedService; - - private final CloudServiceHandler cloudServiceHandler; - - private final Builder<CloudService> hostedServices = ImmutableList.builder(); - - @Inject - ListCloudServicesHandler(CloudServiceHandler cloudServiceHandler) { - this.cloudServiceHandler = cloudServiceHandler; - } - - @Override - public List<CloudService> getResult() { - return hostedServices.build(); - } - - @Override - public void startElement(String url, String name, String qName, Attributes attributes) { - if (qName.equals("HostedService")) { - inHostedService = true; - } - if (inHostedService) { - cloudServiceHandler.startElement(url, name, qName, attributes); - } - } - - @Override - public void endElement(String uri, String name, String qName) { - if (qName.equals("HostedService")) { - inHostedService = false; - hostedServices.add(cloudServiceHandler.getResult()); - } else if (inHostedService) { - cloudServiceHandler.endElement(uri, name, qName); - } - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inHostedService) { - cloudServiceHandler.characters(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java deleted file mode 100644 index a37bc41..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDataVirtualHardDisksHandler.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.inject.Inject; -import org.jclouds.azurecompute.domain.DataVirtualHardDisk; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import java.util.List; - -public final class ListDataVirtualHardDisksHandler - extends ParseSax.HandlerForGeneratedRequestWithResult<List<DataVirtualHardDisk>> { - - private boolean inDataVHD; - - private final DataVirtualHardDiskHandler dataVirtualHardDiskHandler; - - private final Builder<DataVirtualHardDisk> VHDs = ImmutableList.builder(); - - @Inject - ListDataVirtualHardDisksHandler(DataVirtualHardDiskHandler dataVirtualHardDiskHandler) { - this.dataVirtualHardDiskHandler = dataVirtualHardDiskHandler; - } - - @Override - public List<DataVirtualHardDisk> getResult() { - return VHDs.build(); - } - - @Override - public void startElement(String url, String name, String qName, Attributes attributes) { - if (qName.equals("DataVirtualHardDisk")) { - inDataVHD = true; - } - } - - @Override - public void endElement(String uri, String name, String qName) { - if (qName.equals("DataVirtualHardDisk")) { - inDataVHD = false; - VHDs.add(dataVirtualHardDiskHandler.getResult()); - } else if (inDataVHD) { - dataVirtualHardDiskHandler.endElement(uri, name, qName); - } - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inDataVHD) { - dataVirtualHardDiskHandler.characters(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/eb990020/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java deleted file mode 100644 index 4014647..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListDisksHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.xml; - -import java.util.List; - -import org.jclouds.azurecompute.domain.Disk; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.inject.Inject; - -public final class ListDisksHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Disk>> { - - private boolean inDisk; - - private final DiskHandler diskHandler; - - private final Builder<Disk> disks = ImmutableList.builder(); - - @Inject - ListDisksHandler(DiskHandler diskHandler) { - this.diskHandler = diskHandler; - } - - @Override - public List<Disk> getResult() { - return disks.build(); - } - - @Override - public void startElement(String url, String name, String qName, Attributes attributes) { - if (qName.equals("Disk")) { - inDisk = true; - } - if (inDisk) { - diskHandler.startElement(url, name, qName, attributes); - } - } - - @Override - public void endElement(String uri, String name, String qName) { - if (qName.equals("Disk")) { - inDisk = false; - disks.add(diskHandler.getResult()); - } else if (inDisk) { - diskHandler.endElement(uri, name, qName); - } - } - - @Override - public void characters(char[] ch, int start, int length) { - if (inDisk) { - diskHandler.characters(ch, start, length); - } - } -}
