org.carrot2.util.simplexml
Class SimpleXmlWrappers

java.lang.Object
  extended by org.carrot2.util.simplexml.SimpleXmlWrappers

public class SimpleXmlWrappers
extends Object

Enables SimpleXML-based serialization of collections of arbitrary types, also those contained in libraries. Depending on the actual type, 3 wrapping scenarios are possible:


Constructor Summary
SimpleXmlWrappers()
           
 
Method Summary
static
<T> void
addWrapper(Class<T> wrappedClass, Class<? extends ISimpleXmlWrapper<? super T>> wrapperClass)
          Registers a new ISimpleXmlWrapper.
static
<T> void
addWrapper(Class<T> wrappedClass, Class<? extends ISimpleXmlWrapper<? super T>> wrapperClass, boolean strict)
          Registers a new ISimpleXmlWrapper.
static Collection<Object> unwrap(Collection<SimpleXmlWrapperValue> wrapped, Collection<Object> unwrapped)
          Unwraps the provided collection after deserialization.
static List<Object> unwrap(List<SimpleXmlWrapperValue> wrapped)
          Unwraps the provided list after deserialization.
static
<K> Map<K,Object>
unwrap(Map<K,SimpleXmlWrapperValue> wrapped)
          Unwraps the provided map after deserialization.
static Set<Object> unwrap(Set<SimpleXmlWrapperValue> wrapped)
          Unwraps the provided set after deserialization.
static
<T> T
unwrap(SimpleXmlWrapperValue value)
          Unwraps an object after deserialization.
static Collection<SimpleXmlWrapperValue> wrap(Collection<?> toWrap, Collection<SimpleXmlWrapperValue> wrapped)
          Wraps the provided collection for serialization.
static List<SimpleXmlWrapperValue> wrap(List<?> toWrap)
          Wraps the provided list for serialization.
static
<K> Map<K,SimpleXmlWrapperValue>
wrap(Map<K,?> toWrap)
          Wraps the provided map for serialization.
static SimpleXmlWrapperValue wrap(Object value)
          Wraps an individual object for serialization.
static Set<SimpleXmlWrapperValue> wrap(Set<?> toWrap)
          Wraps the provided set for serialization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleXmlWrappers

public SimpleXmlWrappers()
Method Detail

addWrapper

public static <T> void addWrapper(Class<T> wrappedClass,
                                  Class<? extends ISimpleXmlWrapper<? super T>> wrapperClass)
Registers a new ISimpleXmlWrapper. If a wrapper for the provide wrappedClass already exists, it will be replaced with the new value. The wrapper mapping added using this method will be strict, it will apply only to objects of wrappedClass, but not its subclasses.

Parameters:
wrappedClass - type to be wrapped
wrapperClass - class name of the ISimpleXmlWrapper implementation to wrap wrappedClass
See Also:
addWrapper(Class, Class, boolean)

addWrapper

public static <T> void addWrapper(Class<T> wrappedClass,
                                  Class<? extends ISimpleXmlWrapper<? super T>> wrapperClass,
                                  boolean strict)
Registers a new ISimpleXmlWrapper. If a wrapper for the provide wrappedClass already exists, it will be replaced with the new value.

Parameters:
wrappedClass - type to be wrapped
wrapperClass - class name of the ISimpleXmlWrapper implementation to wrap wrappedClass
strict - if true, the mapping will apply only to objects of wrappedClass, but not to its subclasses. If false, if no exact mapping is found for wrappedClass, the first available superclass mapping will be sought.

wrap

public static <K> Map<K,SimpleXmlWrapperValue> wrap(Map<K,?> toWrap)
Wraps the provided map for serialization.

Returns:
map for SimpleXML serialization

unwrap

public static <K> Map<K,Object> unwrap(Map<K,SimpleXmlWrapperValue> wrapped)
Unwraps the provided map after deserialization.

Returns:
map with original values

wrap

public static List<SimpleXmlWrapperValue> wrap(List<?> toWrap)
Wraps the provided list for serialization.

Returns:
list for SimpleXML serialization

unwrap

public static List<Object> unwrap(List<SimpleXmlWrapperValue> wrapped)
Unwraps the provided list after deserialization.

Returns:
list with original values

wrap

public static Set<SimpleXmlWrapperValue> wrap(Set<?> toWrap)
Wraps the provided set for serialization.

Returns:
set for SimpleXML serialization

unwrap

public static Set<Object> unwrap(Set<SimpleXmlWrapperValue> wrapped)
Unwraps the provided set after deserialization.

Returns:
set with original values

wrap

public static Collection<SimpleXmlWrapperValue> wrap(Collection<?> toWrap,
                                                     Collection<SimpleXmlWrapperValue> wrapped)
Wraps the provided collection for serialization.

Parameters:
toWrap - collection to wrap
wrapped - collection to which wrapped values will be added
Returns:
the wrapped collection for convenience

unwrap

public static Collection<Object> unwrap(Collection<SimpleXmlWrapperValue> wrapped,
                                        Collection<Object> unwrapped)
Unwraps the provided collection after deserialization.

Parameters:
wrapped - the SimpleXML-deserialized collection
unwrapped - collection to which the original values should be added
Returns:
the unwrapped collection for convenience

wrap

public static SimpleXmlWrapperValue wrap(Object value)
Wraps an individual object for serialization.


unwrap

public static <T> T unwrap(SimpleXmlWrapperValue value)
Unwraps an object after deserialization.

Returns:
original value


Copyright (c) Dawid Weiss, Stanislaw Osinski