/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.NonCloseableOutputStream
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.policy.GenericEntity
 *  com.l7tech.util.Charsets
 *  com.l7tech.util.PoolByteArrayOutputStream
 *  com.l7tech.util.ResourceUtils
 */
package com.l7tech.server.entity;

import com.l7tech.common.io.NonCloseableOutputStream;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.GenericEntity;
import com.l7tech.util.Charsets;
import com.l7tech.util.PoolByteArrayOutputStream;
import com.l7tech.util.ResourceUtils;
import java.beans.XMLEncoder;
import java.io.Closeable;
import java.io.OutputStream;

public class GenericEntityUtils {
    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static void regenerateValueXml(GenericEntity genericEntity) {
        PoolByteArrayOutputStream poolByteArrayOutputStream = new PoolByteArrayOutputStream(1024);
        String string = genericEntity.getValueXml();
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(genericEntity.getClass().getClassLoader());
        try {
            genericEntity.setValueXml("");
            XMLEncoder xMLEncoder = new XMLEncoder((OutputStream)new NonCloseableOutputStream((OutputStream)poolByteArrayOutputStream));
            xMLEncoder.setPersistenceDelegate(Goid.class, Goid.getPersistenceDelegate());
            xMLEncoder.writeObject(genericEntity);
            xMLEncoder.close();
            string = poolByteArrayOutputStream.toString(Charsets.UTF8);
        }
        finally {
            ResourceUtils.closeQuietly((Closeable)poolByteArrayOutputStream);
            genericEntity.setValueXml(string);
            Thread.currentThread().setContextClassLoader(classLoader);
        }
    }
}

