Example usage for java.text SimpleDateFormat setCalendar

List of usage examples for java.text SimpleDateFormat setCalendar

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setCalendar.

Prototype

public void setCalendar(Calendar newCalendar) 

Source Link

Document

Set the calendar to be used by this date format.

Usage

From source file:org.dspace.discovery.SolrServiceImpl.java

/**
 * Helper function to retrieve a date using a best guess of the potential
 * date encodings on a field/*from   ww  w  .  j  a  v  a2  s  .  c  o  m*/
 *
 * @param t the string to be transformed to a date
 * @return a date if the formatting was successful, null if not able to transform to a date
 */
public static Date toDate(String t) {
    SimpleDateFormat[] dfArr;

    // Choose the likely date formats based on string length
    switch (t.length()) {
    case 4:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy") };
        break;
    case 6:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyyMM") };
        break;
    case 7:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM") };
        break;
    case 8:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyyMMdd"), new SimpleDateFormat("yyyy MMM") };
        break;
    case 10:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd") };
        break;
    case 11:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy MMM dd") };
        break;
    case 20:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") };
        break;
    default:
        dfArr = new SimpleDateFormat[] { new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") };
        break;
    }

    for (SimpleDateFormat df : dfArr) {
        try {
            // Parse the date
            df.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC")));
            df.setLenient(false);
            return df.parse(t);
        } catch (ParseException pe) {
            log.error("Unable to parse date format", pe);
        }
    }

    return null;
}

From source file:org.opendatakit.services.sync.service.logic.HttpRestProtocolWrapper.java

/**
 * Simple Request for all server interactions.
 *
 * @param uri//www  .j a v a2s .  c  om
 * @param request
 * @return
 */
public void buildBasicRequest(URI uri, HttpRequestBase request) {

    String agg_uri = uri.toString();
    log.i(LOGTAG, "buildBasicRequest: agg_uri is " + agg_uri);

    if (uri == null) {
        throw new IllegalArgumentException("buildBasicRequest: URI cannot be null");
    }

    if (request == null) {
        throw new IllegalArgumentException("buildBasicRequest: HttpRequest cannot be null");
    }

    request.setURI(uri);

    // report our locale... (not currently used by server)
    request.addHeader("Accept-Language", Locale.getDefault().getLanguage());
    request.addHeader(ApiConstants.OPEN_DATA_KIT_VERSION_HEADER, ApiConstants.OPEN_DATA_KIT_VERSION);
    request.addHeader(ApiConstants.ACCEPT_CONTENT_ENCODING_HEADER, ApiConstants.GZIP_CONTENT_ENCODING);
    request.addHeader(HttpHeaders.USER_AGENT, sc.getUserAgent());

    GregorianCalendar g = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    Date now = new Date();
    g.setTime(now);
    SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz", Locale.US);
    formatter.setCalendar(g);
    request.addHeader(ApiConstants.DATE_HEADER, formatter.format(now));
}

From source file:com.verisign.epp.codec.gen.EPPUtil.java

/**
 * Decode an XML Schema date data type (YYYY-MM-DD) to a Java Date object.
 * //from w w w  . j ava 2 s.co  m
 * @param aDateValue
 *            XML Schema date data type string (YYYY-MM-DD).
 * @return Java Date object.
 */
public static Date decodeDate(String aDateValue) {

    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);

    // Set to UTC with no time element
    Calendar theCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    theCal.set(Calendar.HOUR_OF_DAY, 0);
    theCal.set(Calendar.MINUTE, 0);
    theCal.set(Calendar.SECOND, 0);
    theCal.set(Calendar.MILLISECOND, 0);
    formatter.setCalendar(theCal);

    Date theDate = formatter.parse(aDateValue, new ParsePosition(0));

    return theDate;
}

From source file:ddf.test.itests.platform.TestSecurity.java

private String getSoapEnvelope(String body, String onBehalfOf) {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.500Z'");
    format.setCalendar(calendar);
    String created = format.format(new Date(calendar.getTimeInMillis()));
    long now = calendar.getTimeInMillis();
    now += 60000;/*from  ww  w . j  a v a  2  s  . c o m*/
    String expires = format.format(new Date(now));
    if (onBehalfOf != null) {
        body = body.replace("ON_BEHALF_OF", onBehalfOf);
    }
    body = body.replace("CREATED", created);
    body = body.replace("EXPIRES", expires);
    return body;
}

From source file:org.dasein.cloud.aws.AWSCloud.java

public String getV4HeaderDate(Date date) {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
    Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    fmt.setCalendar(cal);
    if (date == null) {
        return fmt.format(new Date());
    } else {//from  www. j  ava  2 s . c o  m
        return fmt.format(date);
    }
}

From source file:org.opendatakit.aggregate.odktables.api.perf.AggregateSynchronizer.java

/**
 * Simple Resource for all server interactions.
 * /*from w  ww. j a v  a2  s  .c om*/
 * @param uri
 * @return
 * @throws InvalidAuthTokenException 
 */
private Resource buildBasicResource(URI uri) throws InvalidAuthTokenException {

    Resource rsc = rt.resource(uri);

    // report our locale... (not currently used by server)
    rsc.acceptLanguage(Locale.getDefault());

    // set the access token...
    rsc.header(ApiConstants.ACCEPT_CONTENT_ENCODING_HEADER, ApiConstants.GZIP_CONTENT_ENCODING);
    rsc.header(ApiConstants.OPEN_DATA_KIT_VERSION_HEADER, ApiConstants.OPEN_DATA_KIT_VERSION);
    rsc.header(HttpHeaders.USER_AGENT, "Sync it (gzip)");
    GregorianCalendar g = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    Date now = new Date();
    g.setTime(now);
    SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz", Locale.US);
    formatter.setCalendar(g);
    rsc.header(ApiConstants.DATE_HEADER, formatter.format(now));

    if (accessToken != null && baseUri != null) {
        if (uri.getHost().equals(baseUri.getHost()) && uri.getPort() == baseUri.getPort()) {
            rsc.header("Authorization", "Bearer " + accessToken);
        }
    }

    return rsc;
}

From source file:org.opendatakit.sync.aggregate.AggregateSynchronizer.java

/**
 * Simple Resource for all server interactions.
 * /*from   www. j av a2  s  . c om*/
 * @param uri
 * @return
 * @throws InvalidAuthTokenException
 */
private Resource buildBasicResource(URI uri) throws InvalidAuthTokenException {

    Resource rsc = rt.resource(uri);

    // report our locale... (not currently used by server)
    rsc.acceptLanguage(Locale.getDefault());

    // set the access token...
    rsc.header(ApiConstants.ACCEPT_CONTENT_ENCODING_HEADER, ApiConstants.GZIP_CONTENT_ENCODING);
    rsc.header(ApiConstants.OPEN_DATA_KIT_VERSION_HEADER, ApiConstants.OPEN_DATA_KIT_VERSION);
    rsc.header(HttpHeaders.USER_AGENT, "Sync " + Sync.getInstance().getVersionCodeString() + " (gzip)");
    GregorianCalendar g = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    Date now = new Date();
    g.setTime(now);
    SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz", Locale.US);
    formatter.setCalendar(g);
    rsc.header(ApiConstants.DATE_HEADER, formatter.format(now));

    if (accessToken != null && baseUri != null) {
        if (uri.getHost().equals(baseUri.getHost()) && uri.getPort() == baseUri.getPort()) {
            rsc.header("Authorization", "Bearer " + accessToken);
        }
    }

    return rsc;
}

From source file:org.dasein.cloud.aws.compute.EC2Instance.java

private Set<Metric> calculate(String metric, String unit, String id, boolean idIsVolumeId, long startTimestamp,
        long endTimestamp) throws CloudException, InternalException {
    APITrace.begin(getProvider(), "calculateVMAnalytics");
    try {/*from w  ww . ja v a 2  s .  com*/
        if (!getProvider().getEC2Provider().isAWS()) {
            return new TreeSet<Metric>();
        }
        Map<String, String> parameters = getProvider().getStandardCloudWatchParameters(getContext(),
                EC2Method.GET_METRIC_STATISTICS);
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        fmt.setCalendar(UTC_CALENDAR);
        EC2Method method;
        NodeList blocks;
        Document doc;

        parameters.put("EndTime", fmt.format(new Date(endTimestamp)));
        parameters.put("StartTime", fmt.format(new Date(startTimestamp)));
        parameters.put("MetricName", metric);
        parameters.put("Namespace", idIsVolumeId ? "AWS/EBS" : "AWS/EC2");
        parameters.put("Unit", unit);
        parameters.put("Dimensions.member.Name.1", idIsVolumeId ? "VolumeId" : "InstanceId");
        parameters.put("Dimensions.member.Value.1", id);
        parameters.put("Statistics.member.1", "Average");
        parameters.put("Statistics.member.2", "Minimum");
        parameters.put("Statistics.member.3", "Maximum");
        parameters.put("Period", "60");
        method = new EC2Method("monitoring", getProvider(), parameters);
        try {
            doc = method.invoke();
        } catch (EC2Exception e) {
            logger.error(e.getSummary());
            throw new CloudException(e);
        }
        TreeSet<Metric> metrics = new TreeSet<Metric>();
        fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        fmt.setCalendar(UTC_CALENDAR);
        blocks = doc.getElementsByTagName("member");
        for (int i = 0; i < blocks.getLength(); i++) {
            NodeList items = blocks.item(i).getChildNodes();
            Metric m = new Metric();

            for (int j = 0; j < items.getLength(); j++) {
                Node item = items.item(j);

                if (item.getNodeName().equals("Timestamp")) {
                    String dateString = item.getFirstChild().getNodeValue();

                    try {
                        m.timestamp = fmt.parse(dateString).getTime();
                    } catch (ParseException e) {
                        logger.error(e);
                        throw new InternalException(e);
                    }
                } else if (item.getNodeName().equals("Average")) {
                    m.average = Double.parseDouble(item.getFirstChild().getNodeValue());
                } else if (item.getNodeName().equals("Minimum")) {
                    m.minimum = Double.parseDouble(item.getFirstChild().getNodeValue());
                } else if (item.getNodeName().equals("Maximum")) {
                    m.maximum = Double.parseDouble(item.getFirstChild().getNodeValue());
                } else if (item.getNodeName().equals("Samples")) {
                    m.samples = (int) Double.parseDouble(item.getFirstChild().getNodeValue());
                }
            }
            metrics.add(m);
        }
        return metrics;
    } finally {
        APITrace.end();
    }
}

From source file:org.dasein.cloud.aws.compute.EC2Instance.java

@Override
public @Nonnull String getConsoleOutput(@Nonnull String instanceId) throws InternalException, CloudException {
    APITrace.begin(getProvider(), "getConsoleOutput");
    try {//w  w w.  ja  va 2  s  .c o  m
        Map<String, String> parameters = getProvider().getStandardParameters(getProvider().getContext(),
                EC2Method.GET_CONSOLE_OUTPUT);
        String output = null;
        EC2Method method;
        NodeList blocks;
        Document doc;

        parameters.put("InstanceId", instanceId);
        method = new EC2Method(getProvider(), parameters);
        try {
            doc = method.invoke();
        } catch (EC2Exception e) {
            String code = e.getCode();

            if (code != null && code.startsWith("InvalidInstanceID")) {
                return "";
            }
            logger.error(e.getSummary());
            throw new CloudException(e);
        }
        blocks = doc.getElementsByTagName("timestamp");
        for (int i = 0; i < blocks.getLength(); i++) {
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
            fmt.setCalendar(UTC_CALENDAR);
            String ts = blocks.item(i).getFirstChild().getNodeValue();
            long timestamp;

            try {
                timestamp = fmt.parse(ts).getTime();
            } catch (ParseException e) {
                logger.error(e);
                throw new CloudException(e);
            }
            if (timestamp > -1L) {
                break;
            }
        }
        blocks = doc.getElementsByTagName("output");
        for (int i = 0; i < blocks.getLength(); i++) {
            Node item = blocks.item(i);

            if (item.hasChildNodes()) {
                output = item.getFirstChild().getNodeValue().trim();
                break;
            }
        }
        if (output != null) {
            try {
                return new String(Base64.decodeBase64(output.getBytes("utf-8")), "utf-8");
            } catch (UnsupportedEncodingException e) {
                logger.error(e);
                throw new InternalException(e);
            }
        }
        return "";
    } finally {
        APITrace.end();
    }
}

From source file:org.dasein.cloud.aws.compute.EC2Instance.java

private @Nullable VirtualMachine toVirtualMachine(@Nonnull ProviderContext ctx, @Nullable Node instance,
        @Nonnull Iterable<IpAddress> addresses) throws CloudException {
    if (instance == null) {
        return null;
    }//from  w  ww. j a  va2 s.  c  o  m
    String rootDeviceName = null;
    NodeList attrs = instance.getChildNodes();
    VirtualMachine server = new VirtualMachine();

    server.setPersistent(false);
    server.setProviderOwnerId(ctx.getAccountNumber());
    server.setCurrentState(VmState.PENDING);
    server.setName(null);
    server.setDescription(null);
    for (int i = 0; i < attrs.getLength(); i++) {
        Node attr = attrs.item(i);
        String name;

        name = attr.getNodeName();
        if (name.equals("instanceId")) {
            String value = attr.getFirstChild().getNodeValue().trim();

            server.setProviderVirtualMachineId(value);
        } else if (name.equals("architecture")) {
            String value = attr.getFirstChild().getNodeValue().trim();
            Architecture architecture;

            if (value.equalsIgnoreCase("i386")) {
                architecture = Architecture.I32;
            } else {
                architecture = Architecture.I64;
            }
            server.setArchitecture(architecture);
        } else if (name.equals("imageId")) {
            String value = attr.getFirstChild().getNodeValue().trim();

            server.setProviderMachineImageId(value);
        } else if (name.equals("kernelId")) {
            String value = attr.getFirstChild().getNodeValue().trim();

            server.setTag("kernelImageId", value);
            server.setProviderKernelImageId(value);
        } else if (name.equals("ramdiskId")) {
            String value = attr.getFirstChild().getNodeValue().trim();

            server.setTag("ramdiskImageId", value);
            server.setProviderRamdiskImageId(value);
        } else if (name.equalsIgnoreCase("subnetId")) {
            server.setProviderSubnetId(attr.getFirstChild().getNodeValue().trim());
        } else if (name.equalsIgnoreCase("vpcId")) {
            server.setProviderVlanId(attr.getFirstChild().getNodeValue().trim());
        } else if (name.equals("instanceState")) {
            NodeList details = attr.getChildNodes();

            for (int j = 0; j < details.getLength(); j++) {
                Node detail = details.item(j);

                name = detail.getNodeName();
                if (name.equals("name")) {
                    String value = detail.getFirstChild().getNodeValue().trim();

                    server.setCurrentState(getServerState(value));
                }
            }
        } else if (name.equals("privateDnsName")) {
            if (attr.hasChildNodes()) {
                String value = attr.getFirstChild().getNodeValue();
                RawAddress[] addrs = server.getPrivateAddresses();

                server.setPrivateDnsAddress(value);
                if (addrs == null || addrs.length < 1) {
                    value = guess(value);
                    if (value != null) {
                        server.setPrivateAddresses(new RawAddress(value));
                    }
                }
            }
        } else if (name.equals("dnsName")) {
            if (attr.hasChildNodes()) {
                String value = attr.getFirstChild().getNodeValue();
                server.setPublicDnsAddress(value);
            }
        } else if (name.equals("privateIpAddress")) {
            if (attr.hasChildNodes()) {
                String value = attr.getFirstChild().getNodeValue();
                server.setPrivateAddresses(new RawAddress(value));
            }
        } else if (name.equals("ipAddress")) {
            if (attr.hasChildNodes()) {
                String value = attr.getFirstChild().getNodeValue();

                server.setPublicAddresses(new RawAddress(value));
                for (IpAddress addr : addresses) {
                    if (value.equals(addr.getRawAddress().getIpAddress())) {
                        server.setProviderAssignedIpAddressId(addr.getProviderIpAddressId());
                        break;
                    }
                }
            }
        } else if (name.equals("rootDeviceType")) {
            if (attr.hasChildNodes()) {
                server.setPersistent(attr.getFirstChild().getNodeValue().equalsIgnoreCase("ebs"));
            }
        } else if (name.equals("tagSet")) {

            Map<String, String> tags = getProvider().getTagsFromTagSet(attr);
            if (tags != null && tags.size() > 0) {
                server.setTags(tags);
                for (Map.Entry<String, String> entry : tags.entrySet()) {
                    if (entry.getKey().equalsIgnoreCase("name")) {
                        server.setName(entry.getValue());
                    } else if (entry.getKey().equalsIgnoreCase("description")) {
                        server.setDescription(entry.getValue());
                    }
                }
            }
        } else if (name.equals("instanceType")) {
            String value = attr.getFirstChild().getNodeValue().trim();

            server.setProductId(value);
        } else if (name.equals("launchTime")) {
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
            fmt.setCalendar(UTC_CALENDAR);
            String value = attr.getFirstChild().getNodeValue().trim();

            try {
                server.setLastBootTimestamp(fmt.parse(value).getTime());
                server.setCreationTimestamp(server.getLastBootTimestamp());
            } catch (ParseException e) {
                logger.error(e);
                throw new CloudException(e);
            }
        } else if (name.equals("platform")) {
            if (attr.hasChildNodes()) {
                Platform platform = Platform.guess(attr.getFirstChild().getNodeValue());
                if (platform.equals(Platform.UNKNOWN)) {
                    platform = Platform.UNIX;
                }
                server.setPlatform(platform);
            }
        } else if (name.equals("placement")) {
            NodeList details = attr.getChildNodes();

            for (int j = 0; j < details.getLength(); j++) {
                Node detail = details.item(j);

                name = detail.getNodeName();
                if (name.equals("availabilityZone")) {
                    if (detail.hasChildNodes()) {
                        String value = detail.getFirstChild().getNodeValue().trim();

                        server.setProviderDataCenterId(value);
                    }
                }
            }
        } else if (name.equals("networkInterfaceSet")) {
            ArrayList<String> networkInterfaceIds = new ArrayList<String>();
            if (attr.hasChildNodes()) {
                NodeList items = attr.getChildNodes();
                for (int j = 0; j < items.getLength(); j++) {
                    Node item = items.item(j);

                    if (item.getNodeName().equals("item") && item.hasChildNodes()) {
                        NodeList parts = item.getChildNodes();
                        String networkInterfaceId = null;

                        for (int k = 0; k < parts.getLength(); k++) {
                            Node part = parts.item(k);

                            if (part.getNodeName().equalsIgnoreCase("networkInterfaceId")) {
                                if (part.hasChildNodes()) {
                                    networkInterfaceId = part.getFirstChild().getNodeValue().trim();
                                }
                            }
                        }
                        if (networkInterfaceId != null) {
                            networkInterfaceIds.add(networkInterfaceId);
                        }
                    }
                }
            }
            if (networkInterfaceIds.size() > 0) {
                server.setProviderNetworkInterfaceIds(
                        networkInterfaceIds.toArray(new String[networkInterfaceIds.size()]));
            }
            /*
              [FIXME?] TODO: Really networkInterfaceSet needs to be own type/resource
              Example:
              <networkInterfaceSet>
                <item>
                  <networkInterfaceId>eni-1a2b3c4d</networkInterfaceId>
                  <subnetId>subnet-1a2b3c4d</subnetId>
                  <vpcId>vpc-1a2b3c4d</vpcId>
                  <description>Primary network interface</description>
                  <ownerId>111122223333</ownerId>
                  <status>in-use</status>
                  <macAddress>1b:2b:3c:4d:5e:6f</macAddress>
                  <privateIpAddress>10.0.0.12</privateIpAddress>
                  <sourceDestCheck>true</sourceDestCheck>
                  <groupSet>
                    <item>
                      <groupId>sg-1a2b3c4d</groupId>
                      <groupName>my-security-group</groupName>
                    </item>
                  </groupSet>
                  <attachment>
                    <attachmentId>eni-attach-1a2b3c4d</attachmentId>
                    <deviceIndex>0</deviceIndex>
                    <status>attached</status>
                    <attachTime>YYYY-MM-DDTHH:MM:SS+0000</attachTime>
                    <deleteOnTermination>true</deleteOnTermination>
                  </attachment>
                  <association>
                    <publicIp>198.51.100.63</publicIp>
                    <ipOwnerId>111122223333</ipOwnerId>
                  </association>
                  <privateIpAddressesSet>
                    <item>
                      <privateIpAddress>10.0.0.12</privateIpAddress>
                      <primary>true</primary>
                      <association>
            <publicIp>198.51.100.63</publicIp>
            <ipOwnerId>111122223333</ipOwnerId>
                      </association>
                    </item>
                    <item>
                      <privateIpAddress>10.0.0.14</privateIpAddress>
                      <primary>false</primary>
                      <association>
            <publicIp>198.51.100.177</publicIp>
            <ipOwnerId>111122223333</ipOwnerId>
                      </association>
                    </item>
                  </privateIpAddressesSet>
                </item>
              </networkInterfaceSet>
             */
        } else if (name.equals("keyName")) {
            server.setProviderKeypairId(AWSCloud.getTextValue(attr));
        } else if (name.equals("groupSet")) {
            ArrayList<String> firewalls = new ArrayList<String>();
            if (attr.hasChildNodes()) {
                NodeList tags = attr.getChildNodes();

                for (int j = 0; j < tags.getLength(); j++) {
                    Node tag = tags.item(j);

                    if (tag.getNodeName().equals("item") && tag.hasChildNodes()) {
                        NodeList parts = tag.getChildNodes();
                        String groupId = null;

                        for (int k = 0; k < parts.getLength(); k++) {
                            Node part = parts.item(k);

                            if (part.getNodeName().equalsIgnoreCase("groupId")) {
                                if (part.hasChildNodes()) {
                                    groupId = part.getFirstChild().getNodeValue().trim();
                                }
                            }
                        }
                        if (groupId != null) {
                            firewalls.add(groupId);
                        }
                    }
                }
            }
            if (firewalls.size() > 0) {
                server.setProviderFirewallIds(firewalls.toArray(new String[firewalls.size()]));
            }
        } else if ("blockDeviceMapping".equals(name) && attr.hasChildNodes()) {
            List<Volume> volumes = new ArrayList<Volume>();
            if (attr.hasChildNodes()) {
                NodeList blockDeviceMapping = attr.getChildNodes();

                for (int j = 0; j < blockDeviceMapping.getLength(); j++) {
                    Node bdmItems = blockDeviceMapping.item(j);

                    if (bdmItems.getNodeName().equals("item") && bdmItems.hasChildNodes()) {
                        NodeList items = bdmItems.getChildNodes();
                        Volume volume = new Volume();

                        for (int k = 0; k < items.getLength(); k++) {
                            Node item = items.item(k);
                            String itemNodeName = item.getNodeName();

                            if ("deviceName".equals(itemNodeName)) {
                                volume.setDeviceId(AWSCloud.getTextValue(item));
                            } else if ("ebs".equals(itemNodeName)) {
                                NodeList ebsNodeList = item.getChildNodes();

                                for (int l = 0; l < ebsNodeList.getLength(); l++) {
                                    Node ebsNode = ebsNodeList.item(l);
                                    String ebsNodeName = ebsNode.getNodeName();

                                    if ("volumeId".equals(ebsNodeName)) {
                                        volume.setProviderVolumeId(AWSCloud.getTextValue(ebsNode));
                                    } else if ("status".equals(ebsNodeName)) {
                                        volume.setCurrentState(EBSVolume.toVolumeState(ebsNode));
                                    } else if ("deleteOnTermination".equals(ebsNodeName)) {
                                        volume.setDeleteOnVirtualMachineTermination(
                                                AWSCloud.getBooleanValue(ebsNode));
                                    }
                                }

                            }
                        }

                        if (volume.getDeviceId() != null) {
                            volumes.add(volume);
                        }
                    }
                }
            }
            if (volumes.size() > 0) {
                server.setVolumes(volumes.toArray(new Volume[volumes.size()]));
            }
        } else if ("rootDeviceName".equals(name) && attr.hasChildNodes()) {
            rootDeviceName = AWSCloud.getTextValue(attr);
        } else if ("ebsOptimized".equals(name) && attr.hasChildNodes()) {
            server.setIoOptimized(AWSCloud.getBooleanValue(attr));
        } else if ("sourceDestCheck".equals(name) && attr.hasChildNodes()) {
            /**
             * note: a value of <sourceDestCheck>true</sourceDestCheck> means this instance cannot
             * function as a NAT instance, so we negate the value to indicate if it is allowed
             */
            server.setIpForwardingAllowed(!AWSCloud.getBooleanValue(attr));
        } else if ("stateReasonMessage".equals(name)) {
            server.setStateReasonMessage(AWSCloud.getTextValue(attr));
        } else if ("iamInstanceProfile".equals(name) && attr.hasChildNodes()) {
            NodeList details = attr.getChildNodes();

            for (int j = 0; j < details.getLength(); j++) {
                Node detail = details.item(j);

                name = detail.getNodeName();
                if (name.equals("arn")) {
                    if (detail.hasChildNodes()) {
                        String value = detail.getFirstChild().getNodeValue().trim();
                        server.setProviderRoleId(value);
                    }
                }
            }
        } else if ("instanceLifecycle".equals(name)) {
            String value = AWSCloud.getTextValue(attr);
            if (value != null && "spot".equalsIgnoreCase(value)) {
                server.setLifecycle(VirtualMachineLifecycle.SPOT);
            }
        } else if ("spot-instance-request-id".equals(name)) {
            server.setSpotRequestId(AWSCloud.getTextValue(attr));
        }
    }
    if (server.getPlatform() == null) {
        server.setPlatform(Platform.UNKNOWN);
    }
    server.setProviderRegionId(ctx.getRegionId());
    if (server.getName() == null) {
        server.setName(server.getProviderVirtualMachineId());
    }
    if (server.getDescription() == null) {
        server.setDescription(server.getName() + " (" + server.getProductId() + ")");
    }
    if (server.getArchitecture() == null && server.getProductId() != null) {
        server.setArchitecture(getArchitecture(server.getProductId()));
    } else if (server.getArchitecture() == null) {
        server.setArchitecture(Architecture.I64);
    }

    // find the root device in the volumes list and set boolean value
    if (rootDeviceName != null && server.getVolumes() != null) {
        for (Volume volume : server.getVolumes()) {
            if (rootDeviceName.equals(volume.getDeviceId())) {
                volume.setRootVolume(true);
                break;
            }
        }
    }

    return server;
}