XMLEncoder
public class Encoder extends Object
Encoder
is a class which can be used to create files or streams that encode the state of a collection of JavaBeans in terms of their public APIs. The Encoder
, in conjunction with its persistence delegates, is responsible for breaking the object graph down into a series of Statement
s and Expression
s which can be used to create it. A subclass typically provides a syntax for these expressions using some human readable form - like Java source code or XML.Constructor | Description |
---|---|
Encoder() |
Constructs an Encoder . |
Modifier and Type | Method | Description |
---|---|---|
Object |
get |
Returns a tentative value for oldInstance in the environment created by this stream. |
ExceptionListener |
getExceptionListener() |
Gets the exception handler for this stream. |
PersistenceDelegate |
getPersistenceDelegate |
Returns the persistence delegate for the given type. |
Object |
remove |
Removes the entry for this instance, returning the old entry. |
void |
setExceptionListener |
Sets the exception handler for this stream to exceptionListener . |
void |
setPersistenceDelegate |
Associates the specified persistence delegate with the given type. |
void |
writeExpression |
The implementation first checks to see if an expression with this value has already been written. |
protected void |
writeObject |
Write the specified object to the output stream. |
void |
writeStatement |
Writes statement oldStm to the stream. |
public Encoder()
Encoder
.protected void writeObject(Object o)
o
- The object to be written to the stream.public void setExceptionListener(ExceptionListener exceptionListener)
exceptionListener
. The exception handler is notified when this stream catches recoverable exceptions.exceptionListener
- The exception handler for this stream; if null
the default exception listener will be used.public ExceptionListener getExceptionListener()
public PersistenceDelegate getPersistenceDelegate(Class<?> type)
setPersistenceDelegate(java.lang.Class<?>, java.beans.PersistenceDelegate)
method it is returned. Bean
class should be named BeanPersistenceDelegate
and located in the same package. public class Bean { ... } public class BeanPersistenceDelegate { ... }The instance of the
BeanPersistenceDelegate
class is returned for the Bean
class. null
, a shared internal persistence delegate is returned that encodes null
value. enum
declaration, a shared internal persistence delegate is returned that encodes constants of this enumeration by their names. Proxy.newProxyInstance(java.lang.ClassLoader, java.lang.Class<?>[], java.lang.reflect.InvocationHandler)
method. BeanInfo
for this type has a BeanDescriptor
which defined a "persistenceDelegate" attribute, the value of this named attribute is returned. Introspector
class. The default constructor is the constructor with the greatest number of parameters that has the ConstructorProperties
annotation. If none of the constructors has the ConstructorProperties
annotation, then the nullary constructor (constructor with no parameters) will be used. For example, in the following code fragment, the nullary constructor for the Foo
class will be used, while the two-parameter constructor for the Bar
class will be used. 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
- the class of the objectspublic void setPersistenceDelegate(Class<?> type, PersistenceDelegate delegate)
type
- the class of objects that the specified persistence delegate applies todelegate
- the persistence delegate for instances of the given typepublic Object remove(Object oldInstance)
oldInstance
- The entry that should be removed.public Object get(Object oldInstance)
oldInstance
in the environment created by this stream. A persistence delegate can use its mutatesTo
method to determine whether this value may be initialized to form the equivalent object at the output or whether a new object must be instantiated afresh. If the stream has not yet seen this value, null is returned.oldInstance
- The instance to be looked up.public void writeStatement(Statement oldStm)
oldStm
to the stream. The oldStm
should be written entirely in terms of the callers environment, i.e. the target and all arguments should be part of the object graph being written. These expressions represent a series of "what happened" expressions which tell the output stream how to produce an object graph like the original. The implementation of this method will produce a second expression to represent the same expression in an environment that will exist when the stream is read. This is achieved simply by calling writeObject
on the target and all the arguments and building a new expression with the results.
oldStm
- The expression to be written to the stream.public void writeExpression(Expression oldExp)
writeStatement
, and the value of this expression is reconciled with the value of the cloned expression by calling writeObject
.oldExp
- The expression to be written to the stream.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/java/beans/Encoder.html