API java : DefaultPersistenceDelegate


java.beans
Class DefaultPersistenceDelegate

java.lang.Object
  extended by java.beans.PersistenceDelegate
      extended by java.beans.DefaultPersistenceDelegate

public class DefaultPersistenceDelegate
extends PersistenceDelegate

The DefaultPersistenceDelegate is a concrete implementation of the abstract PersistenceDelegate class and is the delegate used by default for classes about which no information is available. The DefaultPersistenceDelegate provides, version resilient, public API-based persistence for classes that follow the JavaBeans conventions without any class specific configuration.

The key assumptions are that the class has a nullary constructor and that its state is accurately represented by matching pairs of "setter" and "getter" methods in the order they are returned by the Introspector. In addition to providing code-free persistence for JavaBeans, the DefaultPersistenceDelegate provides a convenient means to effect persistent storage for classes that have a constructor that, while not nullary, simply requires some property values as arguments.

Since:
1.4
See Also:
DefaultPersistenceDelegate(String[]), Introspector

Constructor Summary
DefaultPersistenceDelegate()
          Creates a persistence delegate for a class with a nullary constructor.
DefaultPersistenceDelegate(String[] constructorPropertyNames)
          Creates a default persistence delegate for a class with a constructor whose arguments are the values of the property names as specified by constructorPropertyNames.
 
Method Summary
protected  void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out)
          This default implementation of the initialize method assumes all state held in objects of this type is exposed via the matching pairs of "setter" and "getter" methods in the order they are returned by the Introspector.
protected  Expression instantiate(Object oldInstance, Encoder out)
          This default implementation of the instantiate method returns an expression containing the predefined method name "new" which denotes a call to a constructor with the arguments as specified in the DefaultPersistenceDelegate's constructor.
protected  boolean mutatesTo(Object oldInstance, Object newInstance)
          If the number of arguments in the specified constructor is non-zero and the class of oldInstance explicitly declares an "equals" method this method returns the value of oldInstance.equals(newInstance).
 
Methods inherited from class java.beans.PersistenceDelegate
writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPersistenceDelegate

public DefaultPersistenceDelegate()
Creates a persistence delegate for a class with a nullary constructor.

See Also:
DefaultPersistenceDelegate(java.lang.String[])

DefaultPersistenceDelegate

public DefaultPersistenceDelegate(String[] constructorPropertyNames)
Creates a default persistence delegate for a class with a constructor whose arguments are the values of the property names as specified by constructorPropertyNames. The constructor arguments are created by evaluating the property names in the order they are supplied. To use this class to specify a single preferred constructor for use in the serialization of a particular type, we state the names of the properties that make up the constructor's arguments. For example, the Font class which does not define a nullary constructor can be handled with the following persistence delegate:
  1. new DefaultPersistenceDelegate(new String[]{"name", "style", "size"});

Parameters:
constructorPropertyNames - The property names for the arguments of this constructor.
See Also:
instantiate(java.lang.Object, java.beans.Encoder)
Method Detail

mutatesTo

protected boolean mutatesTo(Object oldInstance,
                            Object newInstance)
If the number of arguments in the specified constructor is non-zero and the class of oldInstance explicitly declares an "equals" method this method returns the value of oldInstance.equals(newInstance). Otherwise, this method uses the superclass's definition which returns true if the classes of the two instances are equal.

Overrides:
mutatesTo in class PersistenceDelegate
Parameters:
oldInstance - The instance to be copied.
newInstance - The instance that is to be modified.
Returns:
True if an equivalent copy of newInstance may be created by applying a series of mutations to oldInstance.
See Also:
DefaultPersistenceDelegate(String[])

instantiate

protected Expression instantiate(Object oldInstance,
                                 Encoder out)
This default implementation of the instantiate method returns an expression containing the predefined method name "new" which denotes a call to a constructor with the arguments as specified in the DefaultPersistenceDelegate's constructor.

Specified by:
instantiate in class PersistenceDelegate
Parameters:
oldInstance - The instance to be instantiated.
out - The code output stream.
Returns:
An expression whose value is oldInstance.
See Also:
DefaultPersistenceDelegate(String[])

initialize

protected void initialize(Class<?> type,
                          Object oldInstance,
                          Object newInstance,
                          Encoder out)
This default implementation of the initialize method assumes all state held in objects of this type is exposed via the matching pairs of "setter" and "getter" methods in the order they are returned by the Introspector. If a property descriptor defines a "transient" attribute with a value equal to Boolean.TRUE the property is ignored by this default implementation. Note that this use of the word "transient" is quite independent of the field modifier that is used by the ObjectOutputStream.

For each non-transient property, an expression is created in which the nullary "getter" method is applied to the oldInstance. The value of this expression is the value of the property in the instance that is being serialized. If the value of this expression in the cloned environment mutatesTo the target value, the new value is initialized to make it equivalent to the old value. In this case, because the property value has not changed there is no need to call the corresponding "setter" method and no statement is emitted. If not however, the expression for this value is replaced with another expression (normally a constructor) and the corresponding "setter" method is called to install the new property value in the object. This scheme removes default information from the output produced by streams using this delegate.

In passing these statements to the output stream, where they will be executed, side effects are made to the newInstance. In most cases this allows the problem of properties whose values depend on each other to actually help the serialization process by making the number of statements that need to be written to the output smaller. In general, the problem of handling interdependent properties is reduced to that of finding an order for the properties in a class such that no property value depends on the value of a subsequent property.

Overrides:
initialize in class PersistenceDelegate
Parameters:
oldInstance - The instance to be copied.
newInstance - The instance that is to be modified.
out - The stream to which any initialization statements should be written.
See Also:
Introspector.getBeanInfo(java.lang.Class), PropertyDescriptor

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

6 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-2805
Document créé le 31/08/06 03:54, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/beans/DefaultPersistenceDelegate.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,68 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Je pense que beaucoup de gens sont bons dans bien plus de domaines que ce que le monde ne leur laisse l'opportunité d'exploiter.

Ethan Hawke
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 15:04, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)