Package org.codehaus.enunciate.modules.amf

Source Code of org.codehaus.enunciate.modules.amf.EnunciateAMFDataReader

package org.codehaus.enunciate.modules.amf;

import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.Amf3Input;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;

/**
* An AMF data reader that assumes Enunciate-generated JAXB beans.
*
* @author Ryan Heaton
*/
public class EnunciateAMFDataReader implements AMFDataReader {

  public boolean isReadable(Class realType, Type genericType) {
    AMFMapper mapper = AMFMapperIntrospector.getAMFMapper(realType, genericType);
    if (mapper instanceof CustomAMFMapper) {
      return realType.isAssignableFrom(((CustomAMFMapper) mapper).getJaxbClass());
    }
    else {
      return ((mapper instanceof CollectionAMFMapper) || (mapper instanceof MapAMFMapper));
    }   
  }

  public Object readFrom(Class realType, Type genericType, InputStream stream) throws IOException {
    AMFMapper mapper = AMFMapperIntrospector.getAMFMapper(realType, genericType);
    SerializationContext context = new SerializationContext();
    Amf3Input input = new Amf3Input(context);
    input.setInputStream(stream);
    try {
      return mapper.toJAXB(input.readObject(), new AMFMappingContext());
    }
    catch (ClassNotFoundException e) {
      throw new IOException("Invalid request: " + e.getMessage());
    }
  }
}
TOP

Related Classes of org.codehaus.enunciate.modules.amf.EnunciateAMFDataReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.