<div><span style="font-family: Arial, Helvetica, sans-serif;">package com.fms.xx.common;</span></div>
import java.util.ArrayList;import java.util.List;import flex.messaging.io.amf.ASObject;import flex.messaging.io.amf.translator.ASTranslator;/** * as对象和java对象相互装换 * @author gjl * */public class ConvertAsObjectToJavaObejct { /** * 前台Flex端传过来的List ASobject转换为javaObaject List* * @param <E> * @param sourceObjects * @param targetObjectClass * @return * @throws InstantiationException * @throws IllegalAccessException */ @SuppressWarnings("unchecked") public static <E> List<E> convertASObject2JavaObject(List<ASObject> sourceObjects, Class<E> targetObjectClass) { List<E> targetObjects = new ArrayList<E>(); ASTranslator ast = new ASTranslator(); for (ASObject aso:sourceObjects) { aso.setType(targetObjectClass.getName()); targetObjects.add((E) ast.convert(aso, targetObjectClass)); } return targetObjects; } /**前台Flex端传过来的 ASobject转换为javaObaject * * @param sourceObject * @param targetObjectClass * @return */@SuppressWarnings("unchecked") public static <E> E convertASObject2JavaObject(ASObject sourceObject, Class<E> targetObjectClass){ ASTranslator ast = new ASTranslator(); sourceObject.setType(targetObjectClass.getName()); return (E)ast.convert(sourceObject, targetObjectClass); } /** * * @param sourceObject * @return */public static Object convertASObject2JavaObject(ASObject sourceObject){ ASTranslator ast = new ASTranslator(); Object targetObject = null; try { targetObject = ast.convert(sourceObject, Class.forName(sourceObject.getType())); } catch (ClassNotFoundException e) { e.printStackTrace(); } return targetObject; } }