All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ksyun.api.sdk.kec.transform.DescribeInstancesResultStaxUnmarshaller Maven / Gradle / Ivy

There is a newer version: 2.1.8
Show newest version
package com.ksyun.api.sdk.kec.transform;

import javax.xml.stream.events.XMLEvent;

import com.ksc.transform.SimpleTypeStaxUnmarshallers.IntegerStaxUnmarshaller;
import com.ksc.transform.SimpleTypeStaxUnmarshallers.StringStaxUnmarshaller;
import com.ksyun.api.sdk.kec.model.DescribeInstancesResult;
import com.ksc.transform.StaxUnmarshallerContext;
import com.ksc.transform.Unmarshaller;

/**
 * DescribeInstancesResult StAX Unmarshaller
 */
public class DescribeInstancesResultStaxUnmarshaller implements
		Unmarshaller {

	public DescribeInstancesResult unmarshall(StaxUnmarshallerContext context)
			throws Exception {
		DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult();
		int originalDepth = context.getCurrentDepth();
		int targetDepth = originalDepth + 1;

		if (context.isStartOfDocument())
			targetDepth += 1;

		while (true) {
			XMLEvent xmlEvent = context.nextEvent();
			if (xmlEvent.isEndDocument())
				return describeInstancesResult;

			if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
				// no use reservation
				if (context.testExpression("InstancesSet/Item", targetDepth)) {
					describeInstancesResult
							.withInstancesSet(InstanceDetailStaxUnmarshaller
									.getInstance().unmarshall(context));
					continue;
				}

				if (context.testExpression("Marker", targetDepth)) {
					describeInstancesResult.setMarker(IntegerStaxUnmarshaller
							.getInstance().unmarshall(context));
					continue;
				}

				if (context.testExpression("InstanceCount", targetDepth)) {
					describeInstancesResult
							.setInstanceCount(IntegerStaxUnmarshaller
									.getInstance().unmarshall(context));
					continue;
				}

				if (context.testExpression("RequestId", targetDepth)) {
					describeInstancesResult.setRequestId(StringStaxUnmarshaller
							.getInstance().unmarshall(context));
					continue;
				}
			} else if (xmlEvent.isEndElement()) {
				if (context.getCurrentDepth() < originalDepth) {
					return describeInstancesResult;
				}
			}
		}
	}

	private static DescribeInstancesResultStaxUnmarshaller instance;

	public static DescribeInstancesResultStaxUnmarshaller getInstance() {
		if (instance == null)
			instance = new DescribeInstancesResultStaxUnmarshaller();
		return instance;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy