/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */

package net.ranides.assira.reflection.util;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import net.ranides.assira.io.StringInput;
import net.ranides.assira.io.StringOutput;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public final class BeanUtils {
    
    private BeanUtils() {
        /* utility class */
    }

    public static Object fromXML(String xml) {
        XMLDecoder dec = new XMLDecoder(new StringInput(xml));
        Object object = dec.readObject();
        dec.close();
        return object;
    }
    
    public static String toXML(Object object) {
        StringOutput output = new StringOutput();
        XMLEncoder encoder = new XMLEncoder(output);
        encoder.writeObject(object);
        encoder.close();
        return output.toString();
    }
    
    public static Object copy(Object object) {
        return fromXML( toXML(object) );
    }
    
}
