提交 1752dae0 编写于 作者: M malenkov

4968536: DOC: Javadoc for java.beans.Encoder.getPersistenceDelegate is incomplete

Reviewed-by: peterz
上级 9f1775d5
/* /*
* Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -112,38 +112,67 @@ public class Encoder { ...@@ -112,38 +112,67 @@ public class Encoder {
/** /**
* Returns the persistence delegate for the given type. * Returns the persistence delegate for the given type.
* The persistence delegate is calculated * The persistence delegate is calculated by applying
* by applying the following of rules in order: * the following rules in order:
* <ul> * <ol>
* <li> * <li>
* If the type is an array, an internal persistence * If a persistence delegate is associated with the given type
* delegate is returned which will instantiate an * by using the {@link #setPersistenceDelegate} method
* array of the appropriate type and length, initializing * it is returned.
* each of its elements as if they are properties.
* <li> * <li>
* If the type is a proxy, an internal persistence * A persistence delegate is then looked up by the name
* delegate is returned which will instantiate a * composed of the the fully qualified name of the given type
* new proxy instance using the static * and the "PersistenceDelegate" postfix.
* "newProxyInstance" method defined in the * For example, a persistence delegate for the {@code Bean} class
* Proxy class. * should be named {@code BeanPersistenceDelegate}
* and located in the same package.
* <pre>
* public class Bean { ... }
* public class BeanPersistenceDelegate { ... }</pre>
* The instance of the {@code BeanPersistenceDelegate} class
* is returned for the {@code Bean} class.
* <li> * <li>
* If the BeanInfo for this type has a <code>BeanDescriptor</code> * If the type is {@code null},
* which defined a "persistenceDelegate" property, this * a shared internal persistence delegate is returned
* value is returned. * that encodes {@code null} value.
* <li> * <li>
* In all other cases the default persistence delegate * If the type is a {@code enum} declaration,
* is returned. The default persistence delegate assumes * a shared internal persistence delegate is returned
* the type is a <em>JavaBean</em>, implying that it has a default constructor * that encodes constants of this enumeration
* and that its state may be characterized by the matching pairs * by their names.
* of "setter" and "getter" methods returned by the Introspector. * <li>
* If the type is a primitive type or the corresponding wrapper,
* a shared internal persistence delegate is returned
* that encodes values of the given type.
* <li>
* If the type is an array,
* a shared internal persistence delegate is returned
* that encodes an array of the appropriate type and length,
* and each of its elements as if they are properties.
* <li>
* If the type is a proxy,
* a shared internal persistence delegate is returned
* that encodes a proxy instance by using
* the {@link java.lang.reflect.Proxy#newProxyInstance} method.
* <li>
* If the {@link BeanInfo} for this type has a {@link BeanDescriptor}
* which defined a "persistenceDelegate" attribute,
* the value of this named attribute is returned.
* <li>
* In all other cases the default persistence delegate is returned.
* The default persistence delegate assumes the type is a <em>JavaBean</em>,
* implying that it has a default constructor and that its state
* may be characterized by the matching pairs of "setter" and "getter"
* methods returned by the {@link Introspector} class.
* The default constructor is the constructor with the greatest number * The default constructor is the constructor with the greatest number
* of parameters that has the {@link ConstructorProperties} annotation. * of parameters that has the {@link ConstructorProperties} annotation.
* If none of the constructors have the {@code ConstructorProperties} annotation, * If none of the constructors has the {@code ConstructorProperties} annotation,
* then the nullary constructor (constructor with no parameters) will be used. * then the nullary constructor (constructor with no parameters) will be used.
* For example, in the following the nullary constructor * For example, in the following code fragment, the nullary constructor
* for {@code Foo} will be used, while the two parameter constructor * for the {@code Foo} class will be used,
* for {@code Bar} will be used. * while the two-parameter constructor
* <code> * for the {@code Bar} class will be used.
* <pre>
* public class Foo { * public class Foo {
* public Foo() { ... } * public Foo() { ... }
* public Foo(int x) { ... } * public Foo(int x) { ... }
...@@ -154,12 +183,11 @@ public class Encoder { ...@@ -154,12 +183,11 @@ public class Encoder {
* public Bar(int x) { ... } * public Bar(int x) { ... }
* &#64;ConstructorProperties({"x", "y"}) * &#64;ConstructorProperties({"x", "y"})
* public Bar(int x, int y) { ... } * public Bar(int x, int y) { ... }
* } * }</pre>
* </code> * </ol>
* </ul>
* *
* @param type The type of the object. * @param type the class of the objects
* @return The persistence delegate for this type of object. * @return the persistence delegate for the given type
* *
* @see #setPersistenceDelegate * @see #setPersistenceDelegate
* @see java.beans.Introspector#getBeanInfo * @see java.beans.Introspector#getBeanInfo
...@@ -176,21 +204,18 @@ public class Encoder { ...@@ -176,21 +204,18 @@ public class Encoder {
} }
/** /**
* Sets the persistence delegate associated with this <code>type</code> to * Associates the specified persistence delegate with the given type.
* <code>persistenceDelegate</code>.
* *
* @param type The class of objects that <code>persistenceDelegate</code> applies to. * @param type the class of objects that the specified persistence delegate applies to
* @param persistenceDelegate The persistence delegate for instances of <code>type</code>. * @param delegate the persistence delegate for instances of the given type
* *
* @see #getPersistenceDelegate * @see #getPersistenceDelegate
* @see java.beans.Introspector#getBeanInfo * @see java.beans.Introspector#getBeanInfo
* @see java.beans.BeanInfo#getBeanDescriptor * @see java.beans.BeanInfo#getBeanDescriptor
*/ */
public void setPersistenceDelegate(Class<?> type, public void setPersistenceDelegate(Class<?> type, PersistenceDelegate delegate) {
PersistenceDelegate persistenceDelegate)
{
synchronized (this.finder) { synchronized (this.finder) {
this.finder.register(type, persistenceDelegate); this.finder.register(type, delegate);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册