* @throws PageException
*/
public static Array toArray(Object o) throws PageException {
if(o instanceof Array) return (Array)o;
else if(o instanceof Object[]) {
return new ArrayImpl((Object[])o);
}
else if(o instanceof List) {
return ListAsArray.toArray((List)o);//new ArrayImpl(((List) o).toArray());
}
else if(o instanceof Set) {
return toArray(((Set)o).toArray());//new ArrayImpl(((List) o).toArray());
}
else if(o instanceof XMLStruct) {
XMLMultiElementStruct xmes;
if(o instanceof XMLMultiElementStruct) {
xmes=(XMLMultiElementStruct)o;
}
else {
XMLStruct sct=(XMLStruct) o;
Array a=new ArrayImpl();
a.append(o);
xmes=new XMLMultiElementStruct(a, sct.getCaseSensitive());
}
return new XMLMultiElementArray(xmes);
}
else if(o instanceof ObjectWrap) {
return toArray(((ObjectWrap)o).getEmbededObject());
}
else if(o instanceof Struct) {
Struct sct=(Struct) o;
Array arr=new ArrayImpl();
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e=null;
try {
while(it.hasNext()) {
e = it.next();
arr.setE(toIntValue(e.getKey().getString()),e.getValue());
}
}
catch (ExpressionException ee) {
throw new ExpressionException("can't cast struct to a array, key ["+e.getKey().getString()+"] is not a number");
}
return arr;
}
else if(o instanceof boolean[])return new ArrayImpl(ArrayUtil.toReferenceType((boolean[])o));
else if(o instanceof byte[])return new ArrayImpl(ArrayUtil.toReferenceType((byte[])o));
else if(o instanceof char[])return new ArrayImpl(ArrayUtil.toReferenceType((char[])o));
else if(o instanceof short[])return new ArrayImpl(ArrayUtil.toReferenceType((short[])o));
else if(o instanceof int[])return new ArrayImpl(ArrayUtil.toReferenceType((int[])o));
else if(o instanceof long[])return new ArrayImpl(ArrayUtil.toReferenceType((long[])o));
else if(o instanceof float[])return new ArrayImpl(ArrayUtil.toReferenceType((float[])o));
else if(o instanceof double[])return new ArrayImpl(ArrayUtil.toReferenceType((double[])o));
throw new CasterException(o,"Array");
}