jdk/src/share/classes/java/beans/package.html
author lana
Tue, 01 Jun 2010 14:17:38 -0700
changeset 5597 ab490f66d2cf
parent 5506 202f599c92aa
child 8760 83843c0b84f7
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<!--
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
<body bgcolor="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
Contains classes related to developing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
<em>beans</em> -- components
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
based on the JavaBeans<sup><font size=-2>TM</font></sup> architecture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
A few of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
classes are used by beans while they run in an application. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
For example, the event classes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
used by beans that fire property and vetoable change 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
events (see 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
{@link java.beans.PropertyChangeEvent}). However, most of the classes in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package are meant to be used by a bean editor (that is, a development environment 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
for customizing and putting together beans to create an application). In
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
particular, these classes help the bean editor create a user 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
interface that the user can use to customize the bean. For example, a bean may 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
contain a property of a special type that a bean editor may not know how to handle. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
By using the <code>PropertyEditor</code> interface, a bean developer can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
provide an editor for this special type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
To minimize the resources used by a bean, the classes used by bean editors are loaded only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
when the bean is being edited. They are not needed while the bean is running in an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
and therefore not loaded. This information is kept in what's called a bean-info (see {@link java.beans.BeanInfo}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
Unless explicitly stated, null values or empty Strings are not valid 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
parameters for the methods in this package. You may expect to see 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
exceptions if these parameters are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
<h2>Long-Term Persistence</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
As of v1.4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
the <code>java.beans</code> package provides support for 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
<em>long-term persistence</em> -- reading and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
writing a bean as a textual representation of its property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
The property values are treated as beans,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
and are recursively read or written to capture 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
their publicly available state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
This approach is suitable for long-term storage 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
because it relies only on public API,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
rather than the likely-to-change private implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
<hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
<b>Note:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
The persistence scheme cannot automatically instantiate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
custom inner classes, such as you might use for event handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
By using the {@link java.beans.EventHandler} class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
instead of inner classes for custom event handlers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
you can avoid this problem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
<hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
You read and write beans in XML format using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{@link java.beans.XMLDecoder}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
and 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
{@link java.beans.XMLEncoder}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
classes, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
One notable feature of the persistence scheme is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
reading in a bean requires no special knowledge of the bean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
Writing out a bean, on the other hand,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
sometimes requires special knowledge of the bean's type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
If the bean's state can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
expressed using only the no-argument constructor and 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
public getter and setter methods for properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
no special knowledge is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
Otherwise, the bean requires a custom <em>persistence delegate</em> --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
an object that is in charge of writing out beans of a particular type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
All classes provided in the JDK that descend 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
from <code>java.awt.Component</code>, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
as well as all their properties, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
automatically have persistence delegates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
If you need (or choose) to provide a persistence delegate for a bean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
you can do so either by using a 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
{@link java.beans.DefaultPersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
or by creating your own subclass of <code>PersistenceDelegate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
If the only reason a bean needs a persistence delegate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
is because you want to invoke the bean's constructor with 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
property values as arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
you can create the bean's persistence delegate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
with the one-argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
<code>DefaultPersistenceDelegate</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
you need to implement your own persistence delegate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
for which you're likely to need the following classes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
<dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
<dt> {@link java.beans.PersistenceDelegate}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
<dd> The abstract class from which all persistence delegates descend.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     Your subclass should use its knowledge of the bean's type to provide 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     whatever <code>Statement</code>s and <code>Expression</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     are necessary to create the bean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     and restore its state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
<dt> {@link java.beans.Statement}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
<dd> Represents the invocation of a single method on an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     Includes a set of arguments to the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
<dt> {@link java.beans.Expression}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
<dd> A subclass of <code>Statement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     used for methods that return a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
</dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
Once you create a persistence delegate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
you register it using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
<code>setPersistenceDelegate</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
<code>XMLEncoder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
<h2>Related Documentation</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
For overview, architecture, and tutorial documentation, please see:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  <li><a href="http://java.sun.com/docs/books/tutorial/javabeans/">JavaBeans</a>, a trail in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  <li><a href="http://java.sun.com/products/jfc/tsc/articles/persistence2/">Long-Term Persistence</a>, an article in <em>The Swing Connection</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
</body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
</html>