本文整理汇总了Java中java.beans.XMLEncoder.setPersistenceDelegate方法的典型用法代码示例。如果您正苦于以下问题:Java XMLEncoder.setPersistenceDelegate方法的具体用法?Java XMLEncoder.setPersistenceDelegate怎么用?Java XMLEncoder.setPersistenceDelegate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.XMLEncoder
的用法示例。
在下文中一共展示了XMLEncoder.setPersistenceDelegate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPersistenceDelegates
import java.beans.XMLEncoder; //导入方法依赖的package包/类
private static void setPersistenceDelegates(XMLEncoder encoder,
Class<?>[] types) {
if (types != null && types.length > 0) {
PersistenceDelegate persistenceDelegate = new EnumPersistenceDelegate();
for (int i = 0; i < types.length; i++) {
encoder.setPersistenceDelegate(types[i], persistenceDelegate);
}
}
// Handle "BiGDecimal" manually (has no default constructor)
encoder.setPersistenceDelegate(BigDecimal.class,
new BigDecimalPersistenceDelegate());
encoder.setPersistenceDelegate(byte[].class,
new ByteArrayPersistenceDelegate());
encoder.setPersistenceDelegate(UUID.class, new UUIDDelegate());
}
示例2: main
import java.beans.XMLEncoder; //导入方法依赖的package包/类
public static void main(String[] args) {
XMLEncoder encoder = new XMLEncoder(System.out);
encoder.setPersistenceDelegate(Test4646747.class, new MyPersistenceDelegate());
// WARNING: This can eat up a lot of memory
Object[] obs = new Object[10000];
while (obs != null) {
try {
obs = new Object[obs.length + obs.length / 3];
}
catch (OutOfMemoryError error) {
obs = null;
}
}
PersistenceDelegate pd = encoder.getPersistenceDelegate(Test4646747.class);
if (!(pd instanceof MyPersistenceDelegate))
throw new Error("persistence delegate has been lost");
}
示例3: test
import java.beans.XMLEncoder; //导入方法依赖的package包/类
static void test(AbstractTest object) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(output);
encoder.setPersistenceDelegate(
object.getClass(),
new DefaultPersistenceDelegate(new String[] {"value"}));
encoder.writeObject(object);
encoder.close();
System.out.print(output);
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
XMLDecoder decoder = new XMLDecoder(input);
AbstractTest result = (AbstractTest) decoder.readObject();
decoder.close();
if (object.getValue() != result.getValue())
throw new Error("Should be " + object);
}
示例4: setupXML
import java.beans.XMLEncoder; //导入方法依赖的package包/类
/**
* Configure the serialization of the File.
*/
@Override
protected void setupXML(XMLEncoder enc) {
super.setupXML(enc);
PropertyDescriptor[] pdArr;
try {
pdArr = Introspector.getBeanInfo(VirtualFileSystemFile.class)
.getPropertyDescriptors();
} catch (IntrospectionException e) {
logger.error("I don't know what to do here", e);
throw new RuntimeException(e);
}
for (PropertyDescriptor pd : pdArr) {
// logger.debug("PropertyDescriptor - VirtualFileSystemFile - "
// + pd.getDisplayName());
if (transientListFile.contains(pd.getName())) {
pd.setValue("transient", Boolean.TRUE);
}
}
// needed to create a VFSFile object during unserialization
enc.setPersistenceDelegate(VirtualFileSystemFile.class,
new DefaultPersistenceDelegate(new String[] { "username",
"group", "size", "slaves" }));
}
示例5: getXMLEncoder
import java.beans.XMLEncoder; //导入方法依赖的package包/类
/**
* Sets up the XMLEnconder.
*/
public XMLEncoder getXMLEncoder(OutputStream out) {
XMLEncoder e = new XMLEncoder(out);
e.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e1) {
logger.error("", e1);
}
});
e.setPersistenceDelegate(BeanUser.class,
new DefaultPersistenceDelegate(new String[] { "name" }));
e.setPersistenceDelegate(Key.class, new DefaultPersistenceDelegate(
new String[] { "owner", "key" }));
e.setPersistenceDelegate(HostMask.class,
new DefaultPersistenceDelegate(new String[] { "mask" }));
return e;
}
示例6: setupXML
import java.beans.XMLEncoder; //导入方法依赖的package包/类
@Override
protected void setupXML(XMLEncoder enc) {
super.setupXML(enc);
PropertyDescriptor[] pdArr;
try {
pdArr = Introspector.getBeanInfo(VirtualFileSystemLink.class)
.getPropertyDescriptors();
} catch (IntrospectionException e) {
logger.error("I don't know what to do here", e);
throw new RuntimeException(e);
}
for (int x = 0; x < pdArr.length; x++) {
// logger.debug("PropertyDescriptor - VirtualFileSystemLink - "
// + pdArr[x].getDisplayName());
if (transientListLink.contains(pdArr[x].getName())) {
pdArr[x].setValue("transient", Boolean.TRUE);
}
}
enc.setPersistenceDelegate(VirtualFileSystemLink.class,
new DefaultPersistenceDelegate(new String[] { "username",
"group", "linkPath" }));
}
示例7: initialize
import java.beans.XMLEncoder; //导入方法依赖的package包/类
protected void initialize(XMLEncoder encoder) {
encoder.setPersistenceDelegate(Container.class, new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
Container container = (Container) oldInstance;
Component component = container.getComponent();
return new Expression(container, component, "create", new Object[] {component});
}
});
}
示例8: initialize
import java.beans.XMLEncoder; //导入方法依赖的package包/类
protected void initialize(XMLEncoder encoder) {
encoder.setPersistenceDelegate(
OuterClass.InnerClass.class,
new DefaultPersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
OuterClass.InnerClass inner = (OuterClass.InnerClass) oldInstance;
OuterClass outer = inner.getOuter();
return new Expression(inner, outer, "getInner", new Object[0]);
}
}
);
}
示例9: initialize
import java.beans.XMLEncoder; //导入方法依赖的package包/类
protected void initialize(XMLEncoder encoder) {
encoder.setPersistenceDelegate(C.class, new DefaultPersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
C c = (C) oldInstance;
return new Expression(c, c.getX(), "createC", new Object[] {});
}
});
}
示例10: initialize
import java.beans.XMLEncoder; //导入方法依赖的package包/类
@Override
protected void initialize(XMLEncoder encoder) {
encoder.setOwner(this.owner);
encoder.setPersistenceDelegate(A.class, new ADelegate());
encoder.setPersistenceDelegate(B.class, new BDelegate());
encoder.setPersistenceDelegate(C.class, new CDelegate());
}
示例11: toXMLString
import java.beans.XMLEncoder; //导入方法依赖的package包/类
private static String toXMLString( AbstractEnergySkateParkModule module ) {
ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
XMLEncoder e = new XMLEncoder( out );
e.setPersistenceDelegate( Point2D.Double.class, new Point2DPersistenceDelegate() );
e.writeObject( new EnergySkateParkModuleBean( module ) );
e.writeObject( new JButton( "My Button" ) );
e.close();
return out.toString();
}
示例12: getXMLEncoder
import java.beans.XMLEncoder; //导入方法依赖的package包/类
@Override
public XMLEncoder getXMLEncoder(OutputStream out) {
XMLEncoder e = super.getXMLEncoder(out);
e.setPersistenceDelegate(EncryptedBeanUser.class,
new DefaultPersistenceDelegate(new String[] { "name" }));
return e;
}
示例13: setupXML
import java.beans.XMLEncoder; //导入方法依赖的package包/类
/**
* Configure the serialization of the Directory.
*/
@Override
protected void setupXML(XMLEncoder enc) {
super.setupXML(enc);
PropertyDescriptor[] pdArr;
try {
pdArr = Introspector.getBeanInfo(VirtualFileSystemDirectory.class)
.getPropertyDescriptors();
} catch (IntrospectionException e) {
logger.error("I don't know what to do here", e);
throw new RuntimeException(e);
}
for (int x = 0; x < pdArr.length; x++) {
//logger.debug("PropertyDescriptor - VirtualFileSystemDirectory - " + pdArr[x].getDisplayName());
if (transientListDirectory.contains(pdArr[x].getName())) {
pdArr[x].setValue("transient", Boolean.TRUE);
}
}
enc.setPersistenceDelegate(VirtualFileSystemDirectory.class,
new DefaultPersistenceDelegate(new String[] { "username",
"group" }));
enc.setPersistenceDelegate(AtomicInteger.class,
new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance, Encoder out) {
AtomicInteger ai = (AtomicInteger) oldInstance;
return new Expression(oldInstance,
oldInstance.getClass(),
"new",
new Object[] { ai.get() });
}
});
}
示例14: initialize
import java.beans.XMLEncoder; //导入方法依赖的package包/类
@Override
protected void initialize(XMLEncoder encoder) {
encoder.setPersistenceDelegate(B.class, new BDelegate());
encoder.setPersistenceDelegate(C.class, new CDelegate());
}
示例15: initialize
import java.beans.XMLEncoder; //导入方法依赖的package包/类
@Override
protected void initialize(XMLEncoder encoder) {
super.initialize(encoder);
encoder.setPersistenceDelegate(Public.class, new PublicPersistenceDelegate());
}