Path: blob/master/src/java.desktop/share/classes/java/beans/package-info.java
41152 views
/*1* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* Contains classes related to developing <em>beans</em> -- components based on27* the JavaBeans architecture. A few of the classes are used by beans28* while they run in an application. For example, the event classes are used by29* beans that fire property and vetoable change events (see30* {@link java.beans.PropertyChangeEvent}). However, most of the classes in this31* package are meant to be used by a bean editor (that is, a development32* environment for customizing and putting together beans to create an33* application). In particular, these classes help the bean editor create a user34* interface that the user can use to customize the bean. For example, a bean35* may contain a property of a special type that a bean editor may not know how36* to handle. By using the {@code PropertyEditor} interface, a bean developer37* can provide an editor for this special type.38* <p>39* To minimize the resources used by a bean, the classes used by bean editors40* are loaded only when the bean is being edited. They are not needed while the41* bean is running in an application and therefore not loaded. This information42* is kept in what's called a bean-info (see {@link java.beans.BeanInfo}).43* <p>44* Unless explicitly stated, null values or empty Strings are not valid45* parameters for the methods in this package. You may expect to see exceptions46* if these parameters are used.47*48* <h2>Long-Term Persistence</h2>49* As of v1.4, the {@code java.beans} package provides support for <em>long-term50* persistence</em> -- reading and writing a bean as a textual representation of51* its property values. The property values are treated as beans, and are52* recursively read or written to capture their publicly available state. This53* approach is suitable for long-term storage because it relies only on public54* API, rather than the likely-to-change private implementation.55*56* <blockquote><hr><b>Note:</b> The persistence scheme cannot automatically57* instantiate custom inner classes, such as you might use for event handlers.58* By using the {@link java.beans.EventHandler} class instead of inner classes59* for custom event handlers, you can avoid this problem.<hr></blockquote>60* <p>61* You read and write beans in XML format using the62* {@link java.beans.XMLDecoder} and {@link java.beans.XMLEncoder} classes,63* respectively. One notable feature of the persistence scheme is that reading64* in a bean requires no special knowledge of the bean.65* <p>66* Writing out a bean, on the other hand, sometimes requires special knowledge67* of the bean's type. If the bean's state can be expressed using only the68* no-argument constructor and public getter and setter methods for properties,69* no special knowledge is required. Otherwise, the bean requires a custom70* <em>persistence delegate</em> -- an object that is in charge of writing out71* beans of a particular type. All classes provided in the JDK that descend from72* {@code java.awt.Component}, as well as all their properties, automatically73* have persistence delegates.74* <p>75* If you need (or choose) to provide a persistence delegate for a bean, you can76* do so either by using a {@link java.beans.DefaultPersistenceDelegate}77* instance or by creating your own subclass of {@code PersistenceDelegate}. If78* the only reason a bean needs a persistence delegate is because you want to79* invoke the bean's constructor with property values as arguments, you can80* create the bean's persistence delegate with the one-argument81* {@code DefaultPersistenceDelegate} constructor. Otherwise, you need to82* implement your own persistence delegate, for which you're likely to need the83* following classes:84* <dl>85* <dt>{@link java.beans.PersistenceDelegate}</dt>86* <dd>The abstract class from which all persistence delegates descend. Your87* subclass should use its knowledge of the bean's type to provide whatever88* {@code Statement}s and {@code Expression}s are necessary to create the89* bean and restore its state.</dd>90* <dt>{@link java.beans.Statement}</dt>91* <dd>Represents the invocation of a single method on an object. Includes92* a set of arguments to the method.</dd>93* <dt>{@link java.beans.Expression}</dt>94* <dd>A subclass of {@code Statement} used for methods that return a95* value.</dd>96* </dl>97* <p>98* Once you create a persistence delegate, you register it using the99* {@code setPersistenceDelegate} method of {@code XMLEncoder}.100*101* <h2>Related Documentation</h2>102* For overview, architecture, and tutorial documentation, please see:103* <ul>104* <li><a href="https://docs.oracle.com/javase/tutorial/javabeans/">105* JavaBeans</a>, a trail in <em>The Java Tutorial</em>.</li>106* <li><a href="http://www.oracle.com/technetwork/java/persistence2-141443.html">107* Long-Term Persistence</a>, an article in108* <em>The Swing Connection</em>.</li>109* </ul>110*/111package java.beans;112113114