public static Object convertObject()

in taverna-wsdl-generic/src/main/java/org/apache/taverna/wsdl/soap/ObjectConverter.java [49:157]


	public static Object convertObject(Object theObject) {

		if (theObject == null) {
			return null;
		}
		// If an array type...
		Class<?> theClass = theObject.getClass();
		if (theClass.isArray()) {
			// Special case for byte[]
			if (theObject instanceof byte[]) {
				// System.out.println("Found a byte[], returning it.");
				return theObject;
			} //extra primitive object checks for those fun edge cases!
			else if (theObject instanceof int[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((int[])theObject).length;i++) {
					Object a = ((int[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else if (theObject instanceof short[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((short[])theObject).length;i++) {
					Object a = ((short[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else if (theObject instanceof long[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((long[])theObject).length;i++) {
					Object a = ((long[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else if (theObject instanceof float[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((float[])theObject).length;i++) {
					Object a = ((float[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else if (theObject instanceof double[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((double[])theObject).length;i++) {
					Object a = ((double[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else if (theObject instanceof boolean[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((boolean[])theObject).length;i++) {
					Object a = ((boolean[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else if (theObject instanceof char[]){
				List<Object> l = new ArrayList<Object>();
				for (int i = 0; i<((char[])theObject).length;i++) {
					Object a = ((char[])theObject)[i];
					l.add(convertObject(a));
				}
				return l;
			} else {
				// For all other arrays, create a new
				// List and iterate over the array,
				// unpackaging the item and recursively
				// putting it into the new List after
				// conversion				
				
				// System.out.println("Found an array length
				// "+theArray.length+", repacking as List...");
				
				List<Object> l = new ArrayList<Object>();				
				Object[] theArray = (Object[]) theObject;
				for (int i = 0; i < theArray.length; i++) {
					l.add(convertObject(theArray[i]));
				}
				return l;
			}
		}
		// If a collection, iterate over it and copy
		if (theObject instanceof Collection) {
			if (theObject instanceof List) {
				// System.out.println("Re-packing a list...");
				List<Object> l = new ArrayList<Object>();
				for (Iterator<?> i = ((List<?>) theObject).iterator(); i.hasNext();) {
					l.add(convertObject(i.next()));
				}
				return l;
			} else if (theObject instanceof Set) {
				// System.out.println("Re-packing a set...");
				Set<Object> s = new HashSet<Object>();
				for (Iterator<?> i = ((Set<?>) theObject).iterator(); i.hasNext();) {
					s.add(convertObject(i.next()));
				}
				return s;
			}
		}
		// If a number then return the string representation for it
		if (theObject instanceof Number) {
			// System.out.println("Found a number, converting it to a
			// string...");
			return theObject.toString();
		}
		// Otherwise just return the object
		// System.out.println("Found a "+theObject.getClass().getName()+",
		// returning it");
		return theObject;
	}