Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2014 Dell, Inc ==================================================================== Licensed 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.dasein.cloud.azure;
 
 
 import  javax.annotation.Nonnegative;
 import  javax.annotation.Nullable;
Created by IntelliJ IDEA. User: greese Date: 5/18/12 Time: 7:15 PM To change this template use File | Settings | File Templates.
 
 public class AzureException extends CloudException {
     static public class ExceptionItems {
         public CloudErrorType type;
         public int code;
         public String message;
         public String details;
     }
 
     static public @Nullable ExceptionItems parseException(@Nonnegative int code, @Nullable String xml) {
         ifxml == null ) {
             return null;
         }
         ExceptionItems items = new ExceptionItems();
         
         items.code = code;
         items.type = .;
 
         Document doc;
         
         try {
             ByteArrayInputStream bas = new ByteArrayInputStream(xml.getBytes());
 
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             DocumentBuilder parser = factory.newDocumentBuilder();
             
             doc = parser.parse(bas);
             bas.close();
         }
         catchIOException e ) {
             return null;
         }
         catchParserConfigurationException e ) {
             return null;
         }
         catchSAXException e ) {
             return null;
         }
         NodeList errors = doc.getElementsByTagName("Error");
 
         items.message = "Unknown";
         items.details = xml;
         iferrors.getLength() > 0 ) {
             Node error = errors.item(0);
             NodeList attributes = error.getChildNodes();
 
             forint i=0; i<attributes.getLength(); i++ ) {
                 Node attribute = attributes.item(i);
 
                 ifattribute.getNodeName().equalsIgnoreCase("code") && attribute.hasChildNodes() ) {
                     items.message = attribute.getFirstChild().getNodeValue().trim();
                 }
                 else ifattribute.getNodeName().equalsIgnoreCase("message") ) {
                     items.details = attribute.getFirstChild().getNodeValue().trim();
                 }
             }
         }
        return items;
    }
    public AzureException(ExceptionItems items) {
        super(items.typeitems.codeitems.messageitems.details);
    }
    public AzureException(CloudErrorType typeint codeString messageString details) {
        super(typecodemessagedetails);
    }
New to GrepCode? Check out our FAQ X