Clone a Display Unit

This example illustrates how to clone a display unit.

Sometimes, network operators find that their display units require complex day parts or a complex frame layout. Cloning a display unit will save you time and effort.

Cloning a display unit requires the following SOAP API methods:

  1. Select the display unit that you want to clone. See display_unit_mgr_list_many.
  2. Clone the “shell” display unit. See display_unit_mgr_add.
  3. Update the display unit. See display_unit_mgr_update.
  4. List all loop slots of the display unit to be cloned. See skin_slot_mgr_list_by_display_unit.
  5. Clone criteria associated with the display unit:
  6. Clone contacts associated with the display unit:
  7. Clone date ranges/network controls associated with the display unit:
  8. Clone device controls associated with the display unit:
  9. Clone day parts associated with the display unit:
  10. Clone frames associated with the display unit:
  11. Remove skin slots attached to inactive frames of the cloned display unit.

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

import java.util.ArrayList;
import java.util.List;

import org.apache.axis2.Constants.Configuration;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
import org.apache.axis2.transport.http.HTTPConstants;

import com.broadsign.www.wsdl_ops.BsapiStub;

class Main {

	public static void main(String[] args) throws Exception
	{
		setupKeystore();
		BsapiStub javaStub = createStub();

		String basicDomainId = "12345678";
		List<String> duList = new ArrayList<String>();
		duList.add("23456789");
		duList.add("34567890");

		DisplayUnitFactory displayUnitFactory = new DisplayUnitFactory(javaStub);
		displayUnitFactory.clone(duList, basicDomainId);
		
	}

	private static BsapiStub createStub()
	{
		try {
			ConfigurationContext config = ConfigurationContextFactory.createDefaultConfigurationContext();
			TransportOutDescription transport = new TransportOutDescription("https_mutual_auth");
			CommonsHTTPTransportSender sender = new CommonsHTTPTransportSender();

			sender.init(config, transport);
			BsapiStub javaStub = new BsapiStub();
			transport.setSender(sender);
			javaStub._getServiceClient().getOptions().setProperty(Configuration.CHARACTER_SET_ENCODING, "utf-16");
			javaStub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, "false");
			javaStub._getServiceClient().getOptions().setTransportOut(transport);
			return javaStub;
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}
		return null;
	}
	private static void setupKeystore()
	{
		// NOTE: Make sure to update the folders where your keystore files are located
		//       as well as the actual passwords for your keystores.
		System.setProperty("javax.net.ssl.keyStoreType", "jks");
		System.setProperty("javax.net.ssl.keyStore", "YOUR_SOAP_KEYSTORE_HERE.keystore");
		System.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SOAP_KEYSTORE_PASSWORD_HERE");
		System.setProperty("javax.net.ssl.trustStoreType", "jks");
		System.setProperty("javax.net.ssl.trustStore", "YOUR_TRUSTED_KEYSTORE_HERE.keystore");
		System.setProperty("javax.net.ssl.trustStorePassword", "YOUR_TRUSTED_KEYSTORE_PASSWORD_HERE");
	}
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * DisplayUnitFactory Class
 *
 * This class allows the creation of display units
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.XmlObject;

import com.broadsign.www.wsdl_ops.BsapiStub;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrAddRequestBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrAddResponseBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrListManyRequestBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrListManyResponseBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrListRequestBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrListResponseBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrUpdateRequestBody;
import com.broadsign.www.wsdl_ops.DisplayUnitMgrUpdateResponseBody;
import com.broadsign.www.wsdl_ops.RequestDocument;
import com.broadsign.www.wsdl_ops.ResponseDocument;
import com.broadsign.www.wsdl_ops.WsdlRequest;
import com.broadsign.www.wsdl_ops.WsdlResponse;

class DisplayUnitFactory {
	public DisplayUnitFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting.
	public String createDisplayUnit(String name,
			Object displayUnitTypeId,
			Object containerId,
			Boolean enforceDayParts,
			String domainId)
	{
		return createDisplayUnit(name,
				((BigInteger) displayUnitTypeId).toString(),
				((BigInteger) containerId).toString(),
				enforceDayParts,
				domainId);
	}

	public String createDisplayUnit(String name,
			String displayUnitTypeId,
			String containerId,
			Boolean enforceDayParts,
			String domainId)
	{
		String displayUnitId = null;

		try {
			DisplayUnitMgrAddRequestBody requestBody = DisplayUnitMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setContainerId(containerId);
			requestBody.setDisplayUnitTypeId(displayUnitTypeId);
			requestBody.setEnforceDayParts(enforceDayParts);
			requestBody.setDomainId(domainId);
			requestBody.setName(name);
			wsdlRequest.setName("display_unit_mgr_add");
			wsdlRequest.setVersion(10);
			wsdlRequest.setDisplayUnit(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.display_unit_mgr_add_v10(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getDisplayUnitArray();

			if (xmlBodies.length == 1) {
				DisplayUnitMgrAddResponseBody du = DisplayUnitMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());
				displayUnitId = du.getId().toString();
			} else {
				System.out.println("Error: Failed to create display unit.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return displayUnitId;
	}

	public String createDefaultDisplayUnitTree(String name,
			String displayUnitTypeId,
			String loopPolicyId,
			String containerId,
			String domainId)
	{
		String duId = createDisplayUnit(name, displayUnitTypeId, containerId, false, domainId);

		if (duId.isEmpty()) {
			System.out.println("Error: Failed to create display unit.");
		} else {
			DayPartFactory dpFactory = new DayPartFactory(m_stub);
			String dpId = dpFactory.createDefaultDayPart(duId, domainId);

			if (dpId.isEmpty()) {
				System.out.println("Error: Failed to create day part.");
			} else {
				FrameFactory frameFactory = new FrameFactory(m_stub);
				String frameId = frameFactory.createDefaultFrame(dpId, loopPolicyId, domainId);

				if (frameId.isEmpty())
					System.out.println("Error: Failed to create frame.");
			}
		}

		return duId;
	}

	public List<String> list(String domainId) throws Exception
	{
		List<String> displayUnits = new ArrayList<String>();
		DisplayUnitMgrListRequestBody requestBody = DisplayUnitMgrListRequestBody.Factory.newInstance();
		WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
		XmlObject xmlBodies[];
		RequestDocument requestDocument = RequestDocument.Factory.newInstance();
		ResponseDocument responseDocument;

		requestBody.setDomainId(domainId);
		wsdlRequest.setName("display_unit_mgr_list");
		wsdlRequest.setVersion(10);
		wsdlRequest.setDisplayUnit(requestBody);
		requestDocument.setRequest(wsdlRequest);
		requestDocument.documentProperties().setEncoding("utf-16");
		System.out.println(requestDocument.xmlText());
		responseDocument = m_stub.display_unit_mgr_list_v10(requestDocument);
		System.out.println(responseDocument.xmlText());
		WsdlResponse response = responseDocument.getResponse();
		xmlBodies = response.getDisplayUnitArray();

		if (xmlBodies.length > 0) {
			for (XmlObject xmlBody : xmlBodies) {
				DisplayUnitMgrListResponseBody displayUnit = DisplayUnitMgrListResponseBody.Factory.parse(xmlBody.xmlText());
				displayUnits.add(displayUnit.getName());
			}
		}

		return displayUnits;
	}

	public List<DisplayUnitMgrListManyResponseBody> listByIds(String displayUnitIds, String domainId) throws Exception
	{
		List<DisplayUnitMgrListManyResponseBody> result = new ArrayList<DisplayUnitMgrListManyResponseBody>();
		DisplayUnitMgrListManyRequestBody requestBody = DisplayUnitMgrListManyRequestBody.Factory.newInstance();
		WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
		XmlObject xmlBodies[];
		RequestDocument requestDocument = RequestDocument.Factory.newInstance();
		ResponseDocument responseDocument;

		requestBody.setDomainId(domainId);
		requestBody.setIds(displayUnitIds);
		wsdlRequest.setName("display_unit_mgr_list_many");
		wsdlRequest.setVersion(10);
		wsdlRequest.setDisplayUnit(requestBody);
		requestDocument.setRequest(wsdlRequest);
		requestDocument.documentProperties().setEncoding("utf-16");
		System.out.println(requestDocument.xmlText());
		responseDocument = m_stub.display_unit_mgr_list_many_v10(requestDocument);
		System.out.println(responseDocument.xmlText());
		WsdlResponse response = responseDocument.getResponse();
		xmlBodies = response.getDisplayUnitArray();

		if (xmlBodies.length > 0) {
			for (XmlObject xmlBody : xmlBodies) {
				DisplayUnitMgrListManyResponseBody displayUnit = DisplayUnitMgrListManyResponseBody.Factory.parse(xmlBody.xmlText());
				result.add(displayUnit);
			}
		}

		return result;
	}

	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting
	public String update(boolean active,
			String address,
			Object displayUnitTypeId,
			String domainId,
			boolean enforceDayParts,
			boolean enforceScreenControls,
			String externalId,
			String id,
			String name,
			String timezone,
			String zipcode,
			Object bmbHostId,
			Object containerId,
			String geolocation,
			int virtualHostScreenCount,
			String virtualId) {
		return update(active,
				address,
				((BigInteger) displayUnitTypeId).toString(),
				domainId,
				enforceDayParts,
				enforceScreenControls,
				externalId,
				id,
				name,
				timezone,
				zipcode,
				((BigInteger) bmbHostId).toString(),
				((BigInteger) containerId).toString(),
				geolocation,
				virtualHostScreenCount,
				virtualId);
	}
	
	public String update(boolean active,
			String address,
			String displayUnitTypeId,
			String domainId,
			boolean enforceDayParts,
			boolean enforceScreenControls,
			String externalId,
			String id,
			String name,
			String timezone,
			String zipcode,
			String bmbHostId,
			String containerId,
			String geolocation,
			int virtualHostScreenCount,
			String virtualId) {
		String result = "";

		try {
			DisplayUnitMgrUpdateRequestBody requestBody = DisplayUnitMgrUpdateRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject bodies[];
			ResponseDocument responseDocument;

			requestBody.setActive(active);
			requestBody.setAddress(address);
			requestBody.setDisplayUnitTypeId(displayUnitTypeId);
			requestBody.setDomainId(domainId);
			requestBody.setEnforceDayParts(enforceDayParts);
			requestBody.setEnforceScreenControls(enforceScreenControls);
			requestBody.setExternalId(externalId);
			requestBody.setId(id);
			requestBody.setName(name);
			requestBody.setTimezone(timezone);
			requestBody.setZipcode(zipcode);
			requestBody.setBmbHostId(bmbHostId);
			requestBody.setContainerId(containerId);
			requestBody.setGeolocation(geolocation);
			requestBody.setVirtualHostScreenCount(virtualHostScreenCount);
			requestBody.setVirtualId(virtualId);


			wsdlRequest.setName("display_unit_mgr_update");
			wsdlRequest.setVersion(10);
			wsdlRequest.setDisplayUnit(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.display_unit_mgr_update_v10(requestDocument);
			System.out.println(responseDocument.xmlText());
			bodies = responseDocument.getResponse().getDisplayUnitArray();

			if (bodies.length == 1) {
				DisplayUnitMgrUpdateResponseBody displayUnit = DisplayUnitMgrUpdateResponseBody.Factory.parse(bodies[0].xmlText());
				result = displayUnit.getId().toString();
			} else {
				System.out.println("Error: Failed to update day part.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}


		return result;
	}

	/**
	 * Given a list of display unit IDs, clone all the active ones
	 * and clone all required resources to make the new display unit
	 * a perfect clone.
	 * 
	 * @param idList - List of display unit IDs to be cloned
	 * @param domainId - the ID of your domain
	 * @return true if every resource was properly cloned, otherwise false
	 * @throws Exception
	 */
	public boolean clone(List<String> idList, String domainId) throws Exception {
		String duListString = "";

		// The listByIds operation requires a comma-separated list of DU ids
		for(String duId : idList) { 
			if(!duListString.isEmpty()) {
				duListString += ",";
			}
			duListString += duId;
		}
		
		List<DisplayUnitMgrListManyResponseBody> response = listByIds(duListString, domainId);
		
		for(DisplayUnitMgrListManyResponseBody body : response) {
			cloneSingle(body); // For each DU received, clone it
		}
		
		return true;
	}
	
	
	private boolean cloneSingle(DisplayUnitMgrListManyResponseBody responseBody) {
		System.out.println("*** Cloning operation started ***");
		System.out.println("ID of the DU to be cloned: " + ((BigInteger) responseBody.getId()).toString());
		System.out.println("Name of the DU to be cloned: " + responseBody.getName());
		System.out.println("Status of the DU to be cloned: " + responseBody.getActive());
		String originalId = ((BigInteger) responseBody.getId()).toString();
		String cloneId = "";
		String domainId = ((BigInteger) responseBody.getDomainId()).toString();

		if(responseBody.getActive()) { // Only clone a DU if it is active
			String cloneName = "Clone of " + responseBody.getName();

			cloneId = createDisplayUnit(cloneName, 
					responseBody.getDisplayUnitTypeId(), 
					responseBody.getContainerId(), 
					responseBody.getEnforceDayParts(),
					domainId);

			if(cloneId == null || cloneId.isEmpty()) {
				System.out.println("Could not clone Display Unit");
				return false;
			} else {
				// Need to update the DU after creation
				// because some fields can only be set on update.
				update(responseBody.getActive(), 
						responseBody.getAddress(), 
						responseBody.getDisplayUnitTypeId(), 
						domainId, 
						responseBody.getEnforceDayParts(), 
						responseBody.getEnforceScreenControls(), 
						responseBody.getExternalId(), 
						cloneId, 
						cloneName, 
						responseBody.getTimezone(), 
						responseBody.getZipcode(), 
						responseBody.getBmbHostId(), 
						responseBody.getContainerId(), 
						responseBody.getGeolocation(), 
						responseBody.getVirtualHostScreenCount(), 
						responseBody.getVirtualId());
			}
		} else {
			System.out.println("The Display Unit " + responseBody.getId() + " is inactive, skipping");
			return false;
		}
		
		if(!cloneRelatedResources(originalId, cloneId, domainId)) {
			System.out.println("Failed to clone related resources");
			return false;
		}

		System.out.println("Created the Display Unit " + cloneId);
		System.out.println("*** Cloning operation finished ***");
		return true;
	}
	
	private boolean cloneRelatedResources(String oldDisplayUnitId, String newDisplayUnitId, String domainId) {
		// Clone DU criteria and conditions
		ResourceCriteriaFactory rCritFactory = new ResourceCriteriaFactory(m_stub);
		if(!rCritFactory.clone(oldDisplayUnitId, newDisplayUnitId, domainId)) {
			return false;
		}
		
		// Clone DU contacts
		ResourceContactFactory rConFactory = new ResourceContactFactory(m_stub);
		if(!rConFactory.clone(oldDisplayUnitId, newDisplayUnitId, domainId)) {
			return false;
		}
		
		// Clone DU parameters
		ResourceParameterFactory rParFactory = new ResourceParameterFactory(m_stub);
		if(!rParFactory.clone(oldDisplayUnitId, newDisplayUnitId)) {
			return false;
		}
		
		// Clone network controls and device controls
		// and their associated device opcodes and incident thresholds.
		DateRangeFactory drFactory = new DateRangeFactory(m_stub);
		if(!drFactory.clone(oldDisplayUnitId, newDisplayUnitId, domainId)) {
			return false;
		}
		
		// Clone day parts and all associated resources 
		// such as frames/skins, frame/skin slots, etc.
		DayPartFactory dpFactory = new DayPartFactory(m_stub);
		if(!dpFactory.clone(oldDisplayUnitId, newDisplayUnitId, domainId)) {
			return false;
		}
		
		return true;
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * DayPartFactory Class
 *
 * This class allows the creation of day parts
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;

class DayPartFactory {

	public DayPartFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public String createDefaultDayPart(String displayUnitId, String domainId)
	{
		try {
			return createDayPart("24/7",
					displayUnitId,
					127,
					null,
					null,
					"00:00:00",
					"00:00:00",
					"1756-01-01",
					"8000-12-31",
					-1,
					0,
					domainId);
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return "";
	}

	public String createDayPart(String name,
			String displayUnitId,
			int dayMask,
			String startDate,
			String endDate,
			String startTime,
			String endTime,
			String virtualStartDate,
			String virtualEndDate,
			int impressionsPerHour,
			int weight,
			String domainId)
	{
		String dpId = null;

		try {
			DayPartMgrAddRequestBody requestBody = DayPartMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setName(name);
			requestBody.setDayMask(dayMask);
			requestBody.setParentId(displayUnitId);
			requestBody.setEndDate(endDate);
			requestBody.setEndTime(endTime);
			requestBody.setStartDate(startDate);
			requestBody.setStartTime(startTime);
			requestBody.setImpressionsPerHour(impressionsPerHour);
			requestBody.setVirtualEndDate(virtualEndDate);
			requestBody.setVirtualStartDate(virtualStartDate);
			requestBody.setWeight(weight);
			requestBody.setDomainId(domainId);
			wsdlRequest.setName("day_part_mgr_add");
			wsdlRequest.setVersion(5);
			wsdlRequest.setDayPart(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.day_part_mgr_add_v5(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getDayPartArray();

			if (xmlBodies.length == 1) {
				DayPartMgrAddResponseBody dayPart = DayPartMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());

				dpId = dayPart.getId().toString();
			} else {
				System.out.println("Error: Failed to create day part.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return dpId;
	}

	public List<DayPartMgrListResponseBody> list(String domainId)
	{
		List<DayPartMgrListResponseBody> results = new ArrayList<DayPartMgrListResponseBody>();

		try {
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			XmlObject xmlBodies[];
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			ResponseDocument responseDocument;
			WsdlResponse response;

			DayPartMgrListRequestBody requestBody = DayPartMgrListRequestBody.Factory.newInstance();

			requestBody.setDomainId(domainId);
			wsdlRequest.setName("day_part_mgr_list");
			wsdlRequest.setVersion(5);
			wsdlRequest.setDayPart(requestBody);

			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());

			responseDocument = m_stub.day_part_mgr_list_v5(requestDocument);

			System.out.println(responseDocument.xmlText());
			response = responseDocument.getResponse();
			xmlBodies = response.getDayPartArray();

			if (xmlBodies.length > 0) {
				for (XmlObject xmlBody : xmlBodies) {
					DayPartMgrListResponseBody dayPart = DayPartMgrListResponseBody.Factory.parse(xmlBody.xmlText());
					results.add(dayPart);
				}
			} else {
				System.out.println("Error: Failed to create day part.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error: " + e.toString());
		}

		return results;
	}

	public List<DayPartMgrListScopedResponseBody> list(String domainId, String parentContainerIds) throws Exception
	{
		List<DayPartMgrListScopedResponseBody> results = new ArrayList<DayPartMgrListScopedResponseBody>();

		try {
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			XmlObject xmlBodies[];
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			ResponseDocument responseDocument;
			WsdlResponse response;

			DayPartMgrListScopedRequestBody requestBody = DayPartMgrListScopedRequestBody.Factory.newInstance();

			requestBody.setDomainId(domainId);
			requestBody.setParentContainerIds(parentContainerIds);
			wsdlRequest.setName("day_part_mgr_list_scoped");
			wsdlRequest.setVersion(5);
			wsdlRequest.setDayPart(requestBody);

			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());

			responseDocument = m_stub.day_part_mgr_list_scoped_v5(requestDocument);


			System.out.println(responseDocument.xmlText());
			response = responseDocument.getResponse();
			xmlBodies = response.getDayPartArray();

			if (xmlBodies.length > 0) {
				for (XmlObject xmlBody : xmlBodies) {
					DayPartMgrListScopedResponseBody dayPart = DayPartMgrListScopedResponseBody.Factory.parse(xmlBody.xmlText());
					results.add(dayPart);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error: " + e.toString());
		}

		return results;
	}

	public DayPartMgrListManyResponseBody listMany(String ids)
	{
		try {
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			XmlObject xmlBodies[];
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			ResponseDocument responseDocument;
			WsdlResponse response;

			DayPartMgrListManyRequestBody requestBody = DayPartMgrListManyRequestBody.Factory.newInstance();

			requestBody.setIds(ids);
			wsdlRequest.setName("day_part_mgr_list_many");
			wsdlRequest.setVersion(5);
			wsdlRequest.setDayPart(requestBody);


			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());

			responseDocument = m_stub.day_part_mgr_list_many_v5(requestDocument);

			System.out.println(responseDocument.xmlText());
			response = responseDocument.getResponse();
			xmlBodies = response.getDayPartArray();

			if (xmlBodies.length > 0) {
				for (XmlObject xmlBody : xmlBodies) {
					DayPartMgrListManyResponseBody dayPart = DayPartMgrListManyResponseBody.Factory.parse(xmlBody.xmlText());
					return dayPart;
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error: " + e.toString());
		}

		return null;
	}

	public String updateDayPart(String name,
			String id,
			int dayMask,
			String startDate,
			String endDate,
			String startTime,
			String endTime,
			String virtualStartDate,
			String virtualEndDate,
			int impressionsPerHour,
			String minuteMask,
			int weight,
			String domainId,
			boolean active)
	{
		String dpId = null;

		try {
			DayPartMgrUpdateRequestBody requestBody = DayPartMgrUpdateRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setName(name);
			requestBody.setDayMask(dayMask);
			requestBody.setId(id);
			requestBody.setEndDate(endDate);
			requestBody.setEndTime(endTime);
			requestBody.setStartDate(startDate);
			requestBody.setStartTime(startTime);
			requestBody.setImpressionsPerHour(impressionsPerHour);
			requestBody.setMinuteMask(minuteMask);
			requestBody.setVirtualEndDate(virtualEndDate);
			requestBody.setVirtualStartDate(virtualStartDate);
			requestBody.setWeight(weight);
			requestBody.setDomainId(domainId);
			requestBody.setActive(active);
			wsdlRequest.setName("day_part_mgr_update");
			wsdlRequest.setVersion(5);
			wsdlRequest.setDayPart(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.day_part_mgr_update_v5(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getDayPartArray();

			if (xmlBodies.length == 1) {
				DayPartMgrUpdateResponseBody dayPart = DayPartMgrUpdateResponseBody.Factory.parse(xmlBodies[0].xmlText());
				dpId = dayPart.getId().toString();
			} else {
				System.out.println("Error: Failed to create day part.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return dpId;
	}
	
	/**
	 * Clone the day parts from one display unit into another.
	 * 
	 * @param oldDisplayUnitId - the old display unit that is being cloned from.
	 * @param newDisplayUnitId - the new display unit that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldDisplayUnitId, String newDisplayUnitId, String domainId) {
		List<DayPartMgrListResponseBody> oldDayParts = list(domainId);
		int totalActive = 0;
		int totalDayParts = 0;

		// Find all the day parts associated with the oldDisplayUnitId
		// and create copies of those day parts into the newDisplayUnitId.
		// Since there is no operation to find only those day parts 
		// associated with the DU we will need to list them all and select
		// only those where the day part's parent ID equals the DU's ID.
		System.out.println("---> Active Day Parts <---");
		for(DayPartMgrListResponseBody oldDayPartBody : oldDayParts) {
			String dayPartParentId = ((BigInteger) oldDayPartBody.getParentId()).toString();
			if(oldDisplayUnitId.equals(dayPartParentId)) {
				totalDayParts++;

				if(oldDayPartBody.getActive()) {
					System.out.println("\tFound day part: " + ((BigInteger) oldDayPartBody.getId()).toString());
					totalActive++;

					String cloneId = createDayPart(
							oldDayPartBody.getName(),
							newDisplayUnitId,
							oldDayPartBody.getDayMask(),
							oldDayPartBody.getStartDate(),
							oldDayPartBody.getEndDate(),
							oldDayPartBody.getStartTime(),
							oldDayPartBody.getEndTime(),
							oldDayPartBody.getVirtualStartDate(),
							oldDayPartBody.getVirtualEndDate(),
							oldDayPartBody.getImpressionsPerHour(),
							oldDayPartBody.getWeight(),
							domainId);
					
					if(cloneId.isEmpty()) {
						System.out.println("Failed to clone control...Exiting.");
						return false;
					}
					
					// Clone the business hours of the newly created day part
					if(!cloneBusinessHours(cloneId, oldDayPartBody.getMinuteMask(), domainId)) {
						return false;
					}
					
					
					// Copy the frames from the old day part to the new day part
					FrameFactory fFactory = new FrameFactory(m_stub);
					if(!fFactory.clone(oldDayPartBody.getId(), cloneId, domainId)) {
						return false;
					}

					System.out.println("\tCloned day part! As ... " + cloneId);
				}
			}
		}

		System.out.println("\nTotal day parts: " + totalDayParts);
		System.out.println("Total active day parts: " + totalActive);
		
		return true;
	}
	
	/**
	 * Update the business hours of a given day part with the business
	 * hours of another day part.
	 * 
	 * @param dayPartId - the day part whose business hours must be updated.
	 * @param minuteMask - the new business hours to be applied to the day part.
	 * @param domainId - your domain ID.
	 * @return true if the business hours were successfully updated.
	 */
	private boolean cloneBusinessHours(String dayPartId, String minuteMask, String domainId) {
		DayPartMgrListManyResponseBody responseBody = listMany(dayPartId);
		// Keeps everything the same but changes the minute mask.
		// The minute mask cannot be set during the creation of the day part.
		// To set the minute mask, the day part must be updated after creation.
		String updatedId = updateDayPart(
				responseBody.getName(), 
				dayPartId, 
				responseBody.getDayMask(), 
				responseBody.getStartDate(), 
				responseBody.getEndDate(), 
				responseBody.getStartTime(), 
				responseBody.getEndTime(), 
				responseBody.getVirtualStartDate(), 
				responseBody.getVirtualEndDate(),
				responseBody.getImpressionsPerHour(),
				minuteMask,
				responseBody.getWeight(),
				domainId,
				responseBody.getActive());
		if(updatedId.isEmpty()) {
			System.out.println("\tFailed to update business hours");
			return false;
		}
		
		System.out.println("\tUpdated business hours!");
		return true;
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * FrameFactory Class
 *
 * This class allows the creation of frames
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;
import com.broadsign.www.wsdl_types.GeometryType;

class FrameFactory {
	public FrameFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public String createDefaultFrame(String parentId,
			String loopPolicyId,
			String domainId)
	{
		return addFrame("Fullscreen",
				parentId,
				GeometryType.X_1,
				100,
				100,
				loopPolicyId,
				1,
				0,
				0,
				0,
				domainId,
				0,
				"");
	}

	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting.
	public String addFrame(String name,
			String parentId,
			GeometryType.Enum type,
			int height,
			int width,
			Object loopPolicyId,
			int screenNumber,
			int x,
			int y,
			int z,
			String domainId,
			int interactivityTimeout,
			Object interactivityTriggerId)
	{
		return addFrame(name,
				parentId,
				type,
				height,
				width,
				((BigInteger) loopPolicyId).toString(),
				screenNumber,
				x,
				y,
				z,
				domainId,
				interactivityTimeout,
				((BigInteger) interactivityTriggerId).toString());
	}

	public String addFrame(String name,
			String parentId,
			GeometryType.Enum type,
			int height,
			int width,
			String loopPolicyId,
			int screenNumber,
			int x,
			int y,
			int z,
			String domainId,
			int interactivityTimeout,
			String interactivityTriggerId)
	{
		String skinId = null;

		try {
			SkinMgrAddRequestBody requestBody = SkinMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setParentId(parentId);
			requestBody.setDomainId(domainId);
			requestBody.setGeometryType(type);
			requestBody.setHeight(height);
			requestBody.setWidth(width);
			requestBody.setName(name);
			requestBody.setLoopPolicyId(loopPolicyId);
			requestBody.setScreenNo(screenNumber);
			requestBody.setX(x);
			requestBody.setY(y);
			requestBody.setZ(z);
			requestBody.setInteractivityTimeout(interactivityTimeout);
			requestBody.setInteractivityTriggerId(interactivityTriggerId);
			wsdlRequest.setName("skin_mgr_add");
			wsdlRequest.setVersion(7);
			wsdlRequest.setSkin(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.skin_mgr_add_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getSkinArray();

			if (xmlBodies.length == 1) {
				SkinMgrAddResponseBody skin = SkinMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());
				skinId = skin.getId().toString();
			} else {
				System.out.println("Error: Failed to create frame.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return skinId;
	}

	public List<SkinMgrListResponseBody> list(String domainId)
	{
		List<SkinMgrListResponseBody> result = new ArrayList<SkinMgrListResponseBody>();

		try {
			SkinMgrListRequestBody requestBody = SkinMgrListRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			XmlObject bodies[];
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			ResponseDocument responseDocument;

			requestBody.setDomainId(domainId);
			wsdlRequest.setName("skin_mgr_list");
			wsdlRequest.setVersion(7);
			wsdlRequest.setSkin(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.skin_mgr_list_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			WsdlResponse response = responseDocument.getResponse();
			bodies = response.getSkinArray();

			if (bodies.length > 0) {
				for (XmlObject body : bodies) {
					SkinMgrListResponseBody skin = SkinMgrListResponseBody.Factory.parse(body.xmlText());
					result.add(skin);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error: " + e.toString());
		}

		return result;
	}

	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting.
	public boolean clone(Object oldDayPartId, String newDayPartId, String domainId) {
		return clone(((BigInteger) oldDayPartId).toString(), newDayPartId, domainId);
	}

	/**
	 * Clone all frames from one day part into another one.
	 * Note that frames are also known as skins.
	 * 
	 * @param oldDayPartId - the old day part that is being cloned from.
	 * @param newDayPartId - the new day part that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldDayPartId, String newDayPartId, String domainId) {
		List<SkinMgrListResponseBody> oldFrames = list(domainId);

		// Find all the frames associated with the oldDayPartId
		// and create copies of those frames into the newDayPartId.
		System.out.println("---> Active Frames <---");
		for(SkinMgrListResponseBody oldFrame : oldFrames) {
			String frameParentId = ((BigInteger) oldFrame.getParentId()).toString();

			if(oldFrame.getActive() && oldDayPartId.equals(frameParentId)) {
				System.out.println("\tFound frame: " + ((BigInteger) oldFrame.getId()).toString());
				String cloneId = cloneSingle(oldFrame, newDayPartId, domainId);

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone frame...Exiting.");
					return false;
				}

				System.out.println("\tCloned frame! As ... " + cloneId);
			}
		}

		return true;
	}

	private String cloneSingle(SkinMgrListResponseBody responseBody, String newDayPartId, String domainId) {
		String oldFrameId = ((BigInteger) responseBody.getId()).toString();

		// Create the new frame
		String cloneId = addFrame(
				responseBody.getName(), 
				newDayPartId, 
				responseBody.getGeometryType(), 
				responseBody.getHeight(), 
				responseBody.getWidth(), 
				responseBody.getLoopPolicyId(), 
				responseBody.getScreenNo(), 
				responseBody.getX(), 
				responseBody.getY(), 
				responseBody.getZ(), 
				domainId,
				responseBody.getInteractivityTimeout(),
				responseBody.getInteractivityTriggerId());

		if(!cloneId.isEmpty()) {
			// Copy the criteria from the old frame to the new one
			ResourceCriteriaFactory rcFactory = new ResourceCriteriaFactory(m_stub);
			if(!rcFactory.clone(oldFrameId, cloneId, domainId)) {
				return "";
			}

			// Copy the frame slots from the old frame to the new one
			FrameSlotFactory fsFactory = new FrameSlotFactory(m_stub);
			if(!fsFactory.clone(oldFrameId, cloneId, domainId)) {
				return "";
			}
		}

		return cloneId;
	}



	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * FrameSlotFactory Class
 *
 * This class allows the creation of frame slots (aka skin slots)
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;

class FrameSlotFactory {
	public FrameSlotFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public String createDefaultFrameSlot(String parentId,
			String skinId)
	{
		return add(parentId,
				skinId,"");
	}
	
	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting.
	public String add(Object parentId,
			String skinId,
			String dayMask)
	{
		return add(((BigInteger) parentId).toString(),
				skinId,
				dayMask);
	}

	public String add(String parentId,
			String skinId,
			String dayMask)
	{
		String result = "";

		try {
			SkinSlotMgrAddRequestBody requestBody = SkinSlotMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setParentId(parentId);
			requestBody.setSkinId(skinId);
			requestBody.setDayMask(dayMask);
			wsdlRequest.setName("skin_slot_mgr_add");
			wsdlRequest.setVersion(7);
			wsdlRequest.setSkinSlot(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.skin_slot_mgr_add_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getSkinSlotArray();

			if (xmlBodies.length == 1) {
				SkinSlotMgrAddResponseBody frameSlot = SkinSlotMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());
				result = frameSlot.getId().toString();
			} else {
				System.out.println("Error: Failed to create frame slot.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<SkinSlotMgrListByDisplayUnitResponseBody> listByDisplayUnit(String displayUnitId, String domainId) {
		List<SkinSlotMgrListByDisplayUnitResponseBody> result = new ArrayList<SkinSlotMgrListByDisplayUnitResponseBody>();

		try {
			SkinSlotMgrListByDisplayUnitRequestBody requestBody = SkinSlotMgrListByDisplayUnitRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setDisplayUnitId(displayUnitId);
			requestBody.setDomainId(domainId);
			wsdlRequest.setName("skin_slot_mgr_list_by_display_unit");
			wsdlRequest.setVersion(7);
			wsdlRequest.setSkinSlot(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.skin_slot_mgr_list_by_display_unit_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getSkinSlotArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					SkinSlotMgrListByDisplayUnitResponseBody frameSlot = SkinSlotMgrListByDisplayUnitResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(frameSlot);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<SkinSlotMgrListBySkinResponseBody> listByFrame(String frameId, String domainId) {
		List<SkinSlotMgrListBySkinResponseBody> result = new ArrayList<SkinSlotMgrListBySkinResponseBody>();

		try {
			SkinSlotMgrListBySkinRequestBody requestBody = SkinSlotMgrListBySkinRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setSkinId(frameId);
			requestBody.setDomainId(domainId);
			wsdlRequest.setName("skin_slot_mgr_list_by_skin");
			wsdlRequest.setVersion(7);
			wsdlRequest.setSkinSlot(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.skin_slot_mgr_list_by_skin_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getSkinSlotArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					SkinSlotMgrListBySkinResponseBody frameSlot = SkinSlotMgrListBySkinResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(frameSlot);
				}
			} else {
				System.out.println("Error: Failed to list frame slot.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}
	
	/**
	 * Clone the frame slots from one frame into another one.
	 * Note that frame slots are also known as skin slots.
	 * 
	 * @param oldFrameId - the old frame that is being cloned from.
	 * @param newFrameId - the new frame that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldFrameId, String newFrameId, String domainId) {
		List<SkinSlotMgrListBySkinResponseBody> oldFrameSlots = listByFrame(oldFrameId, domainId);

		// Find all the frame slots associated with the oldFrameId
		// and create copies of those frame slots into the newFrameId.
		System.out.println("---> Active Frame Slots <---");
		for(SkinSlotMgrListBySkinResponseBody oldFrameSlot : oldFrameSlots) {
			// Only accept active frame slots.
			// Do not accept temporary frame slots as those have not finished booking.
			if(oldFrameSlot.getActive() && !oldFrameSlot.getTemporary()) {
				System.out.println("\tFound frame slot: " + ((BigInteger) oldFrameSlot.getId()).toString());

				String cloneId = add(oldFrameSlot.getParentId(), 
						newFrameId, 
						oldFrameSlot.getDayMask());

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone frame slot...Exiting.");
					return false;
				}

				System.out.println("\tCloned frame slot! As ... " + cloneId);
			}
		}
		
		return true;
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * DateRangeFactory Class
 *
 * This class allows the creation of date ranges
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;
import com.broadsign.www.wsdl_types.TimeSpanGroup;

class DateRangeFactory {
	public DateRangeFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public String add(int dayMask,
			String domainId,
			String endTime,
			TimeSpanGroup.Enum groupId,
			String name,
			String parentId,
			String startTime,
			String endDate,
			String startDate)
	{
		String result = "";

		try {
			DateRangeMgrAddRequestBody requestBody = DateRangeMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setDayOfWeekMask(dayMask);
			requestBody.setDomainId(domainId);
			requestBody.setEndTime(endTime);
			requestBody.setGroupId(groupId);
			requestBody.setName(name);
			requestBody.setParentId(parentId);
			requestBody.setStartTime(startTime);
			requestBody.setEndDate(endDate);
			requestBody.setStartDate(startDate);
			wsdlRequest.setName("date_range_mgr_add");
			wsdlRequest.setVersion(4);
			wsdlRequest.setDateRange(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.date_range_mgr_add_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getDateRangeArray();

			if (xmlBodies.length == 1) {
				DateRangeMgrAddResponseBody dateRange = DateRangeMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());

				result = dateRange.getId().toString();
			} else {
				System.out.println("Error: Failed to create date range.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<DateRangeMgrListResponseBody> list(String domainId, String parentId) {
		List<DateRangeMgrListResponseBody> result = new ArrayList<DateRangeMgrListResponseBody>();

		try {
			DateRangeMgrListRequestBody requestBody = DateRangeMgrListRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setDomainId(domainId);
			requestBody.setParentId(parentId);
			wsdlRequest.setName("date_range_mgr_list");
			wsdlRequest.setVersion(4);
			wsdlRequest.setDateRange(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.date_range_mgr_list_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getDateRangeArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					DateRangeMgrListResponseBody dateRange = DateRangeMgrListResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(dateRange);
				}
			} else {
				System.out.println("Error: Failed to list date range.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	/**
	 * Clone the date ranges from one display unit into another one.
	 * A date range can be a network control or a device control.
	 * Which is which can be determined by the Group ID of the date range.
	 * 
	 * @param oldDisplayUnitId - the old display unit that is being cloned from.
	 * @param newDisplayUnitId - the new display unit that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldDisplayUnitId, String newDisplayUnitId, String domainId) {
		List<DateRangeMgrListResponseBody> oldControls = list(domainId, oldDisplayUnitId);
		int totalActive = 0;

		// Find all the date ranges associated with the oldDisplayUnitId
		// and create copies of those date ranges into the newDisplayUnitId.
		System.out.println("---> Active Controls <---");
		for(DateRangeMgrListResponseBody oldControlBody : oldControls) {
			if(oldControlBody.getActive()) {
				System.out.println("\tFound control: " + ((BigInteger) oldControlBody.getId()).toString());
				totalActive++;

				String cloneId = cloneSingle(oldControlBody, newDisplayUnitId, domainId);

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone control...Exiting.");
					return false;
				}

				System.out.println("\tCloned control! As ... " + cloneId);
			}
		}

		System.out.println("\nTotal controls: " + oldControls.size());
		System.out.println("Total active controls: " + totalActive);

		return true;
	}

	private String cloneSingle(DateRangeMgrListResponseBody responseBody, String newDisplayUnitId, String domainId) {
		String cloneId = add(
				responseBody.getDayOfWeekMask(),
				domainId,
				responseBody.getEndTime(),
				responseBody.getGroupId(),
				responseBody.getName(),
				newDisplayUnitId,
				responseBody.getStartTime(),
				responseBody.getEndDate(),
				responseBody.getStartDate());

		// Only date ranges that are device controls have device opcodes
		if(responseBody.getGroupId() == TimeSpanGroup.X_4) {
			DeviceOpcodeFactory doFactory = new DeviceOpcodeFactory(m_stub);
			if(!doFactory.clone(((BigInteger) responseBody.getId()).toString(), cloneId, domainId)) {
				return ""; // Return nothing if the device opcodes failed to clone
			}
		}

		return cloneId;
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * IncidentThresholdFactory Class
 *
 * This class allows the creation of incident thresholds
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;
import com.broadsign.www.wsdl_types.IncidentThresholdAction;
import com.broadsign.www.wsdl_types.IncidentType;

class IncidentThresholdFactory {
	public IncidentThresholdFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public String add(IncidentThresholdAction.Enum criticalAction,
			long criticalActionThreshold,
			String domainId,
			IncidentType.Enum incidentType,
			String parentId,
			IncidentThresholdAction.Enum warningAction,
			long warningActionThreshold)
	{
		String result = "";

		try {
			IncidentThresholdMgrAddRequestBody requestBody = IncidentThresholdMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setCriticalAction(criticalAction);
			requestBody.setCriticalActionThreshold(criticalActionThreshold);
			requestBody.setDomainId(domainId);
			requestBody.setIncidentType(incidentType);
			requestBody.setParentId(parentId);
			requestBody.setWarningAction(warningAction);
			requestBody.setWarningActionThreshold(warningActionThreshold);
			wsdlRequest.setName("incident_threshold_mgr_add");
			wsdlRequest.setVersion(4);
			wsdlRequest.setIncidentThreshold(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.incident_threshold_mgr_add_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getIncidentThresholdArray();

			if (xmlBodies.length == 1) {
				IncidentThresholdMgrAddResponseBody incidentThreshold = IncidentThresholdMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());

				result = incidentThreshold.getId().toString();
			} else {
				System.out.println("Error: Failed to create incident threshold.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}
	
	public List<IncidentThresholdMgrListResponseBody> list(String domainId) {
		List<IncidentThresholdMgrListResponseBody> result = new ArrayList<IncidentThresholdMgrListResponseBody>();

		try {
			IncidentThresholdMgrListRequestBody requestBody = IncidentThresholdMgrListRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setDomainId(domainId);
			wsdlRequest.setName("incident_threshold_mgr_list");
			wsdlRequest.setVersion(4);
			wsdlRequest.setIncidentThreshold(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.incident_threshold_mgr_list_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getIncidentThresholdArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					IncidentThresholdMgrListResponseBody incidentThreshold = IncidentThresholdMgrListResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(incidentThreshold);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<IncidentThresholdMgrListManyResponseBody> listMany(String domainId, String ids) {
		List<IncidentThresholdMgrListManyResponseBody> result = new ArrayList<IncidentThresholdMgrListManyResponseBody>();

		try {
			IncidentThresholdMgrListManyRequestBody requestBody = IncidentThresholdMgrListManyRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setDomainId(domainId);
			requestBody.setIds(ids);
			wsdlRequest.setName("incident_threshold_mgr_list_many");
			wsdlRequest.setVersion(4);
			wsdlRequest.setIncidentThreshold(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.incident_threshold_mgr_list_many_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getIncidentThresholdArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					IncidentThresholdMgrListManyResponseBody incidentThreshold = IncidentThresholdMgrListManyResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(incidentThreshold);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	/**
	 * Clone the incident thresholds from one parent resource into another one.
	 * In the context of this use case, parent resources would be any device 
	 * opcodes and potentially their error handling opcodes.
	 * 
	 * @param oldParentId - the old parent resource that is being cloned from.
	 * @param newParentId - the new parent resource that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldParentId, String newParentId, String domainId) {
		List<IncidentThresholdMgrListResponseBody> oldIncidentThresholds = list(domainId);

		// Find all the device opcodes associated with the oldParentId
		// and create copies of those device opcodes into the newParentId.
		for(IncidentThresholdMgrListResponseBody oldIncidentThresholdBody : oldIncidentThresholds) {
			String oldIncidentThresholdParentId = ((BigInteger) oldIncidentThresholdBody.getParentId()).toString();
			
			// Find incident thresholds linked to old parent and only clone the active ones
			if(oldIncidentThresholdParentId.equals(oldParentId) && oldIncidentThresholdBody.getActive()) {
				String oldIncidentThresholdId = ((BigInteger) oldIncidentThresholdBody.getId()).toString();
				
				System.out.println("\tFound incident threshold: " + oldIncidentThresholdId);
				String cloneId = cloneSingle(oldIncidentThresholdBody, newParentId, domainId);

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone incident threshold " + oldIncidentThresholdId + "...Exiting.");
					return false;
				}

				System.out.println("\tCloned incident threshold " + oldIncidentThresholdId + "! As ... " + cloneId);
			}
		}

		return true;
	}

	private String cloneSingle(IncidentThresholdMgrListResponseBody responseBody, String newParentId, String domainId) {
		String cloneId = "";

		cloneId = add(
				responseBody.getCriticalAction(),
				responseBody.getCriticalActionThreshold(),
				domainId,
				responseBody.getIncidentType(),
				newParentId,
				responseBody.getWarningAction(),
				responseBody.getWarningActionThreshold());

		return cloneId;
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * ResourceContactFactory Class
 *
 * This class allows the creation of resource contacts
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;

class ResourceContactFactory {
	public ResourceContactFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}
	
	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting.
	public String add(String domainId,
			String parentId,
			Object personId)
	{
		return add(domainId,
				parentId,
				((BigInteger) personId).toString());
	}

	public String add(String domainId,
			String parentId,
			String personId)
	{
		String result = "";

		try {
			ResourceContactMgrAddRequestBody requestBody = ResourceContactMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setDomainId(domainId);
			requestBody.setParentId(parentId);
			requestBody.setPersonId(personId);
			wsdlRequest.setName("resource_contact_mgr_add");
			wsdlRequest.setVersion(4);
			wsdlRequest.setResourceContact(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.resource_contact_mgr_add_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getResourceContactArray();

			if (xmlBodies.length == 1) {
				ResourceContactMgrAddResponseBody resourceContact = ResourceContactMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());
				result = resourceContact.getId().toString();
			} else {
				System.out.println("Error: Failed to create resource contact.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<ResourceContactMgrListResponseBody> list(String parentId, String domainId) {
		List<ResourceContactMgrListResponseBody> result = new ArrayList<ResourceContactMgrListResponseBody>();

		try {
			ResourceContactMgrListRequestBody requestBody = ResourceContactMgrListRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setParentId(parentId);
			requestBody.setDomainId(domainId);
			wsdlRequest.setName("resource_contact_mgr_list");
			wsdlRequest.setVersion(4);
			wsdlRequest.setResourceContact(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.resource_contact_mgr_list_v4(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getResourceContactArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					ResourceContactMgrListResponseBody resourceContact = ResourceContactMgrListResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(resourceContact);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}
	
	/**
	 * Clone the resource contacts from one display unit into another one.
	 * 
	 * @param oldDisplayUnitId - the old display unit that is being cloned from.
	 * @param newDisplayUnitId - the new display unit that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldDisplayUnitId, String newDisplayUnitId, String domainId) {
		List<ResourceContactMgrListResponseBody> oldContacts = list(oldDisplayUnitId, domainId);
		int totalActive = 0;

		System.out.println("---> Active Contacts <---");
		for(ResourceContactMgrListResponseBody oldContactBody : oldContacts) {
			if(oldContactBody.getActive()) {
				System.out.println("\tFound resource contact: " + ((BigInteger) oldContactBody.getId()).toString());
				totalActive++;

				String cloneId = add(
						domainId, 
						newDisplayUnitId,
						oldContactBody.getPersonId());

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone contact...Exiting.");
					return false;
				}

				System.out.println("\tCloned contact! As ... " + cloneId);
			}
		}

		System.out.println("\nTotal resource contacts: " + oldContacts.size());
		System.out.println("Total active resource contacts: " + totalActive);
		
		return true;
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * ResourceCriteriaFactory Class
 *
 * This class allows the creation of resource criteria
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;
import com.broadsign.www.wsdl_types.ResourceCriteriaType;

class ResourceCriteriaFactory {
	public ResourceCriteriaFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	// Overloaded method to make it easier to use the results
	// directly from the list operation which require casting.
	public String add(Object criteriaId,
			String domainId,
			String parentId,
			boolean active,
			ResourceCriteriaType.Enum type)
	{
		return add(
				((BigInteger) criteriaId).toString(),
				domainId,
				parentId,
				active,
				type);
	}

	public String add(String criteriaId,
			String domainId,
			String parentId,
			boolean active,
			ResourceCriteriaType.Enum type)
	{
		String result = "";

		try {
			ResourceCriteriaMgrAddRequestBody requestBody = ResourceCriteriaMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setCriteriaId(criteriaId);
			requestBody.setDomainId(domainId);
			requestBody.setParentId(parentId);
			requestBody.setActive(active);
			requestBody.setType(type);
			wsdlRequest.setName("resource_criteria_mgr_add");
			wsdlRequest.setVersion(7);
			wsdlRequest.setResourceCriteria(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.resource_criteria_mgr_add_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getResourceCriteriaArray();

			if (xmlBodies.length == 1) {
				ResourceCriteriaMgrAddResponseBody resourceCriteria = ResourceCriteriaMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());

				result = resourceCriteria.getId().toString();
			} else {
				System.out.println("Error: Failed to create resource criteria.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<ResourceCriteriaMgrListResponseBody> list(String parentId, String domainId) {
		List<ResourceCriteriaMgrListResponseBody> result = new ArrayList<ResourceCriteriaMgrListResponseBody>();

		try {
			ResourceCriteriaMgrListRequestBody requestBody = ResourceCriteriaMgrListRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setParentId(parentId);
			requestBody.setDomainId(domainId);
			wsdlRequest.setName("resource_criteria_mgr_list");
			wsdlRequest.setVersion(7);
			wsdlRequest.setResourceCriteria(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.resource_criteria_mgr_list_v7(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getResourceCriteriaArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					ResourceCriteriaMgrListResponseBody resourceCriteria = ResourceCriteriaMgrListResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(resourceCriteria);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	/**
	 * Clone all the resource criteria from one display unit into another one.
	 * A resource criteria represents a relationship between a resource and
	 * a criteria.
	 * 
	 * In the case of this use case, that resource is a display unit.
	 * 
	 * Note that fundamentally, a criteria and a condition are the same resource.
	 * The difference is in their relationship with a given resource, which is
	 * represented by a resource criteria. So the type of a resource criteria
	 * determines whether a "criteria" is a true criterion, or a condition.
	 * 
	 * @param oldDisplayUnitId - the old display unit that is being cloned from.
	 * @param newDisplayUnitId - the new display unit that is being cloned to.
	 * @param domainId - your domain ID.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldDisplayUnitId, String newDisplayUnitId, String domainId) {
		List<ResourceCriteriaMgrListResponseBody> oldCriteria = list(oldDisplayUnitId, domainId);
		int totalActive = 0;

		System.out.println("---> Active Criteria <---");
		for(ResourceCriteriaMgrListResponseBody oldCriteriaBody : oldCriteria) {
			if(oldCriteriaBody.getActive()) {
				System.out.println("\tFound resource criteria: " + ((BigInteger) oldCriteriaBody.getId()).toString());
				totalActive++;

				String cloneId = cloneSingle(oldCriteriaBody, newDisplayUnitId, domainId);

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone criteria...Exiting.");
					return false;
				}

				System.out.println("\tCloned criterion! As ... " + cloneId);
			}
		}
		System.out.println("\nTotal resource criteria: " + oldCriteria.size());
		System.out.println("Total active resource criteria: " + totalActive);
		
		return true;
	}
	
	private String cloneSingle(ResourceCriteriaMgrListResponseBody responseBody, String newDisplayUnitId, String domainId) {
		return add(responseBody.getCriteriaId(), 
				domainId, 
				newDisplayUnitId, 
				true, 
				responseBody.getType());
	}

	private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2016 BroadSign International, LLC
 */

/*
 * ResourceParameterFactory Class
 *
 * This class allows the creation of resource parameters
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;

class ResourceParameterFactory {
	public ResourceParameterFactory(BsapiStub stub)
	{
		assert(stub != null);
		m_stub = stub;
	}

	public String add(String parentId,
			String flashParameters)
	{
		String result = "";

		try {
			ResourceParameterMgrAddRequestBody requestBody = ResourceParameterMgrAddRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setParentId(parentId);
			requestBody.setFlashParameters(flashParameters);
			wsdlRequest.setName("resource_parameter_mgr_add");
			wsdlRequest.setVersion(1);
			wsdlRequest.setResourceParameter(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.resource_parameter_mgr_add_v1(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getResourceParameterArray();

			if (xmlBodies.length == 1) {
				ResourceParameterMgrAddResponseBody resourceParameter = ResourceParameterMgrAddResponseBody.Factory.parse(xmlBodies[0].xmlText());

				result = resourceParameter.getId().toString();
			} else {
				System.out.println("Error: Failed to create resource parameter.");
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}

	public List<ResourceParameterMgrListResponseBody> list(String parentId) {
		List<ResourceParameterMgrListResponseBody> result = new ArrayList<ResourceParameterMgrListResponseBody>();

		try {
			ResourceParameterMgrListRequestBody requestBody = ResourceParameterMgrListRequestBody.Factory.newInstance();
			WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
			RequestDocument requestDocument = RequestDocument.Factory.newInstance();
			XmlObject xmlBodies[];
			ResponseDocument responseDocument;

			requestBody.setParentId(parentId);
			wsdlRequest.setName("resource_parameter_mgr_list");
			wsdlRequest.setVersion(1);
			wsdlRequest.setResourceParameter(requestBody);
			requestDocument.setRequest(wsdlRequest);
			requestDocument.documentProperties().setEncoding("utf-16");
			System.out.println(requestDocument.xmlText());
			responseDocument = m_stub.resource_parameter_mgr_list_v1(requestDocument);
			System.out.println(responseDocument.xmlText());
			xmlBodies = responseDocument.getResponse().getResourceParameterArray();

			if (xmlBodies.length > 0) {
				for(XmlObject xmlBody : xmlBodies) {
					ResourceParameterMgrListResponseBody resourceParameter = ResourceParameterMgrListResponseBody.Factory.parse(xmlBody.xmlText());
					result.add(resourceParameter);
				}
			}
		} catch (java.lang.Exception e) {
			System.out.println("Error:" + e.toString());
		}

		return result;
	}
	
	/**
	 * Clone the resource parameters from one display unit into another one.
	 * 
	 * @param oldDisplayUnitId - the old display unit that is being cloned from.
	 * @param newDisplayUnitId - the new display unit that is being cloned to.
	 * @return true if all the resources were cloned successfully.
	 */
	public boolean clone(String oldDisplayUnitId, String newDisplayUnitId) {
		List<ResourceParameterMgrListResponseBody> oldParameters = list(oldDisplayUnitId);
		int totalActive = 0;

		System.out.println("---> Active Parameters <---");
		for(ResourceParameterMgrListResponseBody oldParameterBody : oldParameters) {
			if(oldParameterBody.getActive()) {
				System.out.println("\tFound resource parameter: " + ((BigInteger) oldParameterBody.getId()).toString());
				totalActive++;

				String cloneId = add(
						newDisplayUnitId,
						(String) oldParameterBody.getFlashParameters());

				if(cloneId.isEmpty()) {
					System.out.println("Failed to clone parameter...Exiting.");
					return false;
				}

				System.out.println("\tCloned parameter! As ... " + cloneId);
			}
		}

		System.out.println("\nTotal resource parameters: " + oldParameters.size());
		System.out.println("Total active resource parameters: " + totalActive);
		
		return true;
	}

	private BsapiStub m_stub = null;
}