当前位置: 首页>>代码示例>>Java>>正文


Java Encoder类代码示例

本文整理汇总了Java中java.beans.Encoder的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Encoder类属于java.beans包,在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: instantiate

import java.beans.Encoder; //导入依赖的package包/类
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class type = oldInstance.getClass().getComponentType();

  // oldInstance is expected to be an array, then
  // getClass().getComponentType() should lead
  // to its component type.
  assert (type != null);

  // Not handling primitive types in a special way here
  // causes that Class.forName("int") is built as an Expression
  // later which would cause an exception if executed. A special
  // handling to avoid the execution for primitive types can be
  // java.beans.Encoder.writeExpression() .
  return new Expression(
                        oldInstance,
                        Array.class,
                        "newInstance",
                        new Object[] {
                          type,
                          new Integer(Array.getLength(oldInstance)) });
}
 
开发者ID:vilie,项目名称:javify,代码行数:23,代码来源:ArrayPersistenceDelegate.java

示例2: testInitialize_NullClass

import java.beans.Encoder; //导入依赖的package包/类
public void testInitialize_NullClass() {
    MockPersistenceDelegate pd = new MockPersistenceDelegate();
    Encoder enc = new Encoder();
    Object o1 = new Object();
    Object o2 = new Object();
    // enc.setPersistenceDelegate(MockFooStop.class,
    // new MockPersistenceDelegate());
    try {
        enc.setExceptionListener(new ExceptionListener() {
            public void exceptionThrown(Exception e) {
                CallVerificationStack.getInstance().push(e);
            }
        });
        pd.initialize(null, o1, o2, enc);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
    assertTrue(CallVerificationStack.getInstance().empty());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:DefaultPersistenceDelegateTest.java

示例3: instantiate

import java.beans.Encoder; //导入依赖的package包/类
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;

  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class.
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
 
开发者ID:vilie,项目名称:javify,代码行数:18,代码来源:ClassPersistenceDelegate.java

示例4: instantiate

import java.beans.Encoder; //导入依赖的package包/类
protected Expression instantiate(Object oldInstance, Encoder out)
{
  Class oldClass = (Class) oldInstance;
  
  // Due to the special handling of String instances in the Encoder
  // this Expression does not lead to further class resolutions.
  if (oldClass == String.class)
    return new Expression(oldClass, "", "getClass", null);

  // This Expression will lead to the class resolution of String.class.
  if (oldClass == Class.class)
    return new Expression(oldClass, String.class, "getClass", null);

  // This Expression will lead to the class resolution of Class.class. 
  return new Expression(oldClass, Class.class, "forName",
                        new Object[] { oldClass.getName() });
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:18,代码来源:ClassPersistenceDelegate.java

示例5: instantiate

import java.beans.Encoder; //导入依赖的package包/类
@Override
protected Expression instantiate( Object oldInstance, Encoder out ) {
    Class type = oldInstance.getClass();
    if ( !Modifier.isPublic( type.getModifiers() ) )
        throw new IllegalArgumentException( "Could not instantiate instance of non-public class: " + oldInstance );
    
    for ( Field field : type.getFields() ) {
        int mod = field.getModifiers();
        if ( Modifier.isPublic( mod ) && Modifier.isStatic( mod ) && Modifier.isFinal( mod ) && ( type == field.getDeclaringClass() ) ) {
            try {
                if ( oldInstance == field.get( null ) )
                    return new Expression( oldInstance, field, "get", new Object[]{null} );
            } catch ( IllegalAccessException exception ) {
                throw new IllegalArgumentException( "Could not get value of the field: " + field, exception );
            }
        }
    }
    throw new IllegalArgumentException( "Could not instantiate value: " + oldInstance );
}
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:20,代码来源:PainterUtil.java

示例6: initialize

import java.beans.Encoder; //导入依赖的package包/类
@Override
        protected void initialize(Class type, Object oldInstance,
                Object newInstance, Encoder out) {
//            p("image painter delegate called");
            super.initialize(type, oldInstance,  newInstance, out);
            //p("old instance = " + oldInstance);
            //p("owner = " + ((XMLEncoder)out).getOwner());
            PersistenceOwner owner = (PersistenceOwner)((XMLEncoder)out).getOwner();
            ImagePainter ip = (ImagePainter)oldInstance;
//            p("need to convert string: " + ip.getImageString());
//            String s = owner.toXMLURL(ip.getImageString());
//            p("converted to: " + s);
                //out.writeExpression(new Expression(oldInstance,owner,"fromXMLURL",new Object[]{ip.getImageString()}));
                //out.writeStatement(new Statement(owner,"fromXMLURL",new Object[]{ip.getImageString()}));
                //out.writeStatement(new Statement(oldInstance,"setImageString",new Object[]{
                //new Expression(oldInstance,owner,"fromXMLURL",new Object[]{ip.getImageString()})
                //}));
                
            out.writeStatement(new Statement(oldInstance,"setResolver",new Object[]{owner}));
//            out.writeStatement(new Statement(oldInstance,"setImageString",new Object[]{s}));
        }
 
开发者ID:RockManJoe64,项目名称:swingx,代码行数:22,代码来源:PainterUtil.java

示例7: test_initialize

import java.beans.Encoder; //导入依赖的package包/类
public void test_initialize() {
    MockBean3 bean1 = new MockBean3();
    bean1.setValue("bean1");
    MockBean3 bean2 = new MockBean3();
    bean2.setValue("bean2");

    // clear flags
    bean1.setValueCalled = false;
    bean2.setValueCalled = false;

    MockPersistenceDelegate mockPersistenceDelegate = new MockPersistenceDelegate();
    mockPersistenceDelegate.initialize(MockBean3.class, bean1, bean2,
            new Encoder());
    assertEquals("bean1", bean1.getValue());
    assertEquals("bean2", bean2.getValue());
    assertFalse(bean1.setValueCalled);
    assertFalse(bean2.setValueCalled);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:DefaultPersistenceDelegateTest.java

示例8: testInitialize_NullInstances

import java.beans.Encoder; //导入依赖的package包/类
public void testInitialize_NullInstances() {
    MockPersistenceDelegate pd = new MockPersistenceDelegate();
    Encoder enc = new Encoder();
    MockFoo b = new MockFoo();
    b.setName("myName");
    // enc.setPersistenceDelegate(MockFooStop.class,
    // new MockPersistenceDelegate());
    enc.setExceptionListener(new ExceptionListener() {
        public void exceptionThrown(Exception e) {
            CallVerificationStack.getInstance().push(e);
        }
    });
    try {
        pd.initialize(MockFoo.class, null, b, enc);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
    assertTrue(CallVerificationStack.getInstance().empty());
    pd.initialize(MockFoo.class, b, null, enc);
    assertFalse(CallVerificationStack.getInstance().empty());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:23,代码来源:DefaultPersistenceDelegateTest.java

示例9: testGetPersistenceDelegate_Default

import java.beans.Encoder; //导入依赖的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);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:EncoderTest.java

示例10: instantiate

import java.beans.Encoder; //导入依赖的package包/类
@Override
protected Expression instantiate(Object oldInstance, Encoder out) {
    byte[] e = (byte[]) oldInstance;
    return new Expression(e, ByteArrayPersistenceDelegate.class,
            "decode",
            new Object[] { ByteArrayPersistenceDelegate.encode(e) });
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:8,代码来源:XMLSerializer.java

示例11: initialize

import java.beans.Encoder; //导入依赖的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});
        }
    });
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:Test5023552.java

示例12: initialize

import java.beans.Encoder; //导入依赖的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]);
                }
            }
    );
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:Test4936682.java

示例13: initialize

import java.beans.Encoder; //导入依赖的package包/类
@Override
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
    super.initialize(type, oldInstance, newInstance, out);

    Public<String, String> map = (Public) oldInstance;
    for (Entry<String, String> entry : map.getAll()) {
        String[] args = {entry.getKey(), entry.getValue()};
        out.writeStatement(new Statement(oldInstance, "put", args));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Test8013416.java

示例14: initialize

import java.beans.Encoder; //导入依赖的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[] {});
        }
    });
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:Test4679556.java

示例15: test

import java.beans.Encoder; //导入依赖的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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:Test4968523.java


注:本文中的java.beans.Encoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。