本文整理汇总了Java中java.beans.PersistenceDelegate类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceDelegate类的具体用法?Java PersistenceDelegate怎么用?Java PersistenceDelegate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceDelegate类属于java.beans包,在下文中一共展示了PersistenceDelegate类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPersistenceDelegates
import java.beans.PersistenceDelegate; //导入依赖的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.PersistenceDelegate; //导入依赖的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: recordCall
import java.beans.PersistenceDelegate; //导入依赖的package包/类
private void recordCall(Object param) {
StackTraceElement[] eles = (new Throwable()).getStackTrace();
int i = 0;
// skip Throwable.init()
while (eles[i].getClassName().equals("java.lang.Throwable")) {
i++;
}
// skip calls from MockEncoder
while (eles[i].getClassName().equals(MockEncoder.class.getName())) {
i++;
}
// skip calls from DefaultPersistenceDelegate & PersistenceDelegate
while (eles[i].getClassName().equals(
DefaultPersistenceDelegate.class.getName())
|| eles[i].getClassName().equals(
PersistenceDelegate.class.getName())) {
i++;
}
if (i > 2
&& eles[++i].getClassName().equals(
DefaultPersistenceDelegateTest.class.getName())) {
CallVerificationStack.getInstance().push(param);
}
}
示例4: testGetPersistenceDelegate_Default
import java.beans.PersistenceDelegate; //导入依赖的package包/类
public void testGetPersistenceDelegate_Default() {
Encoder enc = new Encoder();
Encoder enc2 = new Encoder();
PersistenceDelegate pd1 = enc.getPersistenceDelegate(SampleBean.class);
assertTrue(pd1 instanceof DefaultPersistenceDelegate);
PersistenceDelegate pd2 = enc.getPersistenceDelegate(SampleBean.class);
assertTrue(pd2 instanceof DefaultPersistenceDelegate);
PersistenceDelegate pd3 = enc2
.getPersistenceDelegate(MockBean4Codec.class);
assertTrue(pd3 instanceof DefaultPersistenceDelegate);
assertSame(pd1, pd2);
assertSame(pd1, pd3);
}
示例5: register
import java.beans.PersistenceDelegate; //导入依赖的package包/类
public void register(Class<?> type, PersistenceDelegate delegate) {
synchronized (this.registry) {
if (delegate != null) {
this.registry.put(type, delegate);
}
else {
this.registry.remove(type);
}
}
}
示例6: find
import java.beans.PersistenceDelegate; //导入依赖的package包/类
@Override
public PersistenceDelegate find(Class<?> type) {
PersistenceDelegate delegate;
synchronized (this.registry) {
delegate = this.registry.get(type);
}
return (delegate != null) ? delegate : super.find(type);
}
示例7: test
import java.beans.PersistenceDelegate; //导入依赖的package包/类
private static void test(Class<?> type, Class<? extends PersistenceDelegate> expected) {
PersistenceDelegate actual = ENCODER.getPersistenceDelegate(type);
if ((actual == null) && (expected != null)) {
throw new Error("expected delegate is not found");
}
if ((actual != null) && !actual.getClass().equals(expected)) {
throw new Error("found unexpected delegate");
}
}
示例8: initialize
import java.beans.PersistenceDelegate; //导入依赖的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});
}
});
}
示例9: test
import java.beans.PersistenceDelegate; //导入依赖的package包/类
private static void test(Class<?> type, PersistenceDelegate pd) {
Encoder encoder1 = new Encoder();
Encoder encoder2 = new XMLEncoder(System.out);
PersistenceDelegate pd1 = encoder1.getPersistenceDelegate(type);
PersistenceDelegate pd2 = encoder2.getPersistenceDelegate(type);
encoder1.setPersistenceDelegate(type, pd);
if (pd1 == encoder1.getPersistenceDelegate(type))
throw new Error("first persistence delegate is not changed");
if (pd2 != encoder2.getPersistenceDelegate(type))
throw new Error("second persistence delegate is changed");
}