org.jclouds.http.functions
Class ParseXMLWithJAXB<T>

java.lang.Object
  extended by org.jclouds.http.functions.ParseXMLWithJAXB<T>
All Implemented Interfaces:
com.google.common.base.Function<HttpResponse,T>

@Singleton
public class ParseXMLWithJAXB<T>
extends Object
implements com.google.common.base.Function<HttpResponse,T>

This object will parse the body of an HttpResponse and return the result of type back to the caller.

JAXBContext works with Class objects instead of Type. This could be a limitation if we are trying to parse typed collections of objects. However, when using JAXB we expect to have well formed XML documents with one single root element, so the objects to parse should not be collections but objects that wrap collections of elements, and that should work fine.

Author:
Ignasi Barrera

Field Summary
protected  Logger logger
           
protected  com.google.inject.TypeLiteral<T> type
           
protected  XMLParser xml
           
 
Constructor Summary
ParseXMLWithJAXB(XMLParser xml, com.google.inject.TypeLiteral<T> type)
           
 
Method Summary
 T apply(HttpResponse from)
           
 T apply(InputStream stream)
           
<V> V
apply(InputStream stream, Class<V> type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.common.base.Function
equals
 

Field Detail

logger

protected Logger logger

xml

protected XMLParser xml

type

protected final com.google.inject.TypeLiteral<T> type
Constructor Detail

ParseXMLWithJAXB

@Inject
public ParseXMLWithJAXB(XMLParser xml,
                               com.google.inject.TypeLiteral<T> type)
Method Detail

apply

public T apply(HttpResponse from)
Specified by:
apply in interface com.google.common.base.Function<HttpResponse,T>

apply

public T apply(InputStream stream)
        throws IOException
Throws:
IOException

apply

public <V> V apply(InputStream stream,
                   Class<V> type)
        throws IOException
Throws:
IOException


Copyright © 2009-2012 jclouds. All Rights Reserved.