public class Encoder extends Object
Encoder是一个类,可用于创建根据其公共API编码JavaBean集合的状态的文件或流。
Encoder与其持续代表一起负责将对象图分解成一系列可用于创建它的Statements和Expression 。
子类通常使用一些人类可读的形式(如Java源代码或XML)为这些表达式提供语法。
| Constructor and Description |
|---|
Encoder() |
| Modifier and Type | Method and Description |
|---|---|
Object |
get(Object oldInstance)
在此流创建的
oldInstance中返回oldInstance的临时值。
|
ExceptionListener |
getExceptionListener()
获取此流的异常处理程序。
|
PersistenceDelegate |
getPersistenceDelegate(类<?> type)
返回给定类型的持久代理。
|
Object |
remove(Object oldInstance)
删除此实例的条目,返回旧条目。
|
void |
setExceptionListener(ExceptionListener exceptionListener)
将此流的异常处理程序设置为
exceptionListener 。
|
void |
setPersistenceDelegate(类<?> type, PersistenceDelegate delegate)
将指定的持久性委托与给定类型关联。
|
void |
writeExpression(Expression oldExp)
该实现首先检查是否已经写入了具有该值的表达式。
|
protected void |
writeObject(Object o)
将指定的对象写入输出流。
|
void |
writeStatement(Statement oldStm)
向流写入声明
oldStm 。
|
protected void writeObject(Object o)
o -
o的对象。
XMLDecoder.readObject()
public void setExceptionListener(ExceptionListener exceptionListener)
exceptionListener 。
当此流捕获可恢复的异常时,将通知异常处理程序。
exceptionListener - 此流的异常处理程序
如果null将使用默认异常侦听器。
getExceptionListener()
public ExceptionListener getExceptionListener()
setExceptionListener(java.beans.ExceptionListener)
public PersistenceDelegate getPersistenceDelegate(类<?> type)
setPersistenceDelegate(java.lang.Class<?>, java.beans.PersistenceDelegate)方法将持久代理与给定类型相关联 ,则返回它。 Bean类的持久代理应该命名为BeanPersistenceDelegate并位于同一个包中。 public class Bean { ... }
public class BeanPersistenceDelegate { ... } BeanPersistenceDelegate类的实例返回给Bean类。 null ,则返回一个共享的内部持久代理,编码null值。 枚举声明,那么返回一个共享的内部持久性委托,它将通过名称对该枚举的常量进行编码。 Proxy.newProxyInstance(java.lang.ClassLoader, java.lang.Class<?>[], java.lang.reflect.InvocationHandler)方法对代理实例进行编码的共享内部持久性委托。 BeanInfo这种类型有一个BeanDescriptor其定义的“persistenceDelegate”属性,则返回这个命名属性的值。 Introspector类返回的匹配的“setter”和“getter”方法进行表征 。 默认构造函数是具有最大数量参数的构造函数,它具有ConstructorProperties注释。 如果没有一个构造函数具有ConstructorProperties注释,那么将使用nullary构造函数(没有参数的构造函数)。 例如,在下面的代码段,用于在null构造Foo类将被使用,而这两个参数的构造为Bar类将被使用。 public class Foo {
public Foo() { ... }
public Foo(int x) { ... }
}
public class Bar {
public Bar() { ... }
@ConstructorProperties({"x"})
public Bar(int x) { ... }
@ConstructorProperties({"x", "y"})
public Bar(int x, int y) { ... }
} type - 对象的类
setPersistenceDelegate(java.lang.Class<?>, java.beans.PersistenceDelegate) ,
Introspector.getBeanInfo(java.lang.Class<?>) ,
BeanInfo.getBeanDescriptor()
public void setPersistenceDelegate(类<?> type, PersistenceDelegate delegate)
type - 指定的持久性委托应用于的对象类
delegate - 给定类型的实例的持久代理
getPersistenceDelegate(java.lang.Class<?>) ,
Introspector.getBeanInfo(java.lang.Class<?>) ,
BeanInfo.getBeanDescriptor()
public Object remove(Object oldInstance)
oldInstance - 应该删除的条目。
get(java.lang.Object)
public Object get(Object oldInstance)
oldInstance中返回oldInstance的暂定值。
持久代理可以使用其mutatesTo方法来确定此值是否可以被初始化以在输出处形成等效对象,或者是否必须重新实例化新对象。
如果流尚未看到此值,则返回null。
oldInstance - 要查找的实例。
public void writeStatement(Statement oldStm)
oldStm 。
oldStm应该完全根据调用者环境进行编写,即目标和所有参数应该是正在写入的对象图的一部分。
这些表达式表示一系列“发生了什么”的表达式,它们告诉输出流如何生成像原始的对象图。
该方法的实现将产生一个第二个表达式,以便在读取流时将存在的环境中表示相同的表达式。 这是通过调用简单地实现writeObject目标和所有参数,并建设有结果的新的表达方式。
oldStm - 要写入流的表达式。
public void writeExpression(Expression oldExp)
writeStatement ,并且通过调用writeObject将此表达式的值与克隆表达式的值进行writeObject 。
oldExp - 要写入流的表达式。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.