|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.spi.convertor; import java.util.Properties; /** * SimplyConvertible is way how to persist your object by Convertor infrastructure * without writing any convertor. * * Default public constructor is necessary because Convertor infrastructure will * use it to create instance of your class. * * SimplyConvertible interface has two methods. The {@link #write} method * will be called on your object whenever your instance needs to be persist. The * method will pass you empty {@link java.util.Properties} object to which you * can store all relevant data of your instance. All String properties will be * then persisted by the Convertor infrastructure. Second method is {@link #read} * method which does opposite. Instance of your class is first created by * default constructor and then this method will pass you Properties object * with all properties which you stored in write() method. That allows you to * reinitialize your instance to the state before it was persisted. * The Convertor infrastructure guarantees that it will not call the read() * method more than once and it will call it immediatelly after the instance * was created by your default constructor. * * The Properties object content will be persisted as XML namespace aware * fragment with following structure: * *
Property keys are used as XML element names and so the * same restrictions as for XML element names are valid for property keys. * Similarly the property values need to be valid XML text content (i.e. no * control characters, newlines will be normalized, etc.). Invalid property * key or property value will result in runtime * {@link org.netbeans.api.convertor.ConvertorException}. The XML elements * are created in lexicographical order according to property keys. * * Declarative registration looks like: * *
where * * Name: is fully qualified name of your class which
* implements SimplyConvertible interfaceNetBeans-Simply-Convertible: declaration of simply
* convertibleyournamespace is XML namespace
* to which your class will be persistedyourelement is element name
* to which your class will be persistedAlthough it was said that simply convertible object must implement * SimplyConvertible interface there are cases when this is not desirable and * so it does not have implement it. For example it might be desirable to hide * fact that object is simply convertible when object is part of an API contract. * In such a case you do not have to implement SimplyConvertible interface. * However your object must have two methods with the same signatures * as SimplyConvertible methods have and default constructor. The methods * and constructor do not have to have public access. * * See also {@link Convertor} for information about how to write regular * convertor. * * @author David Konecny */ public interface SimplyConvertible { /** * Read object state from the given Properties instance. * The method will be called only once by Convertor infrastructure just * after the instance was created by default constructor. * * @param p properties instance with properties stored by write() method * @throws org.netbeans.api.convertor.ConvertorException can throw this * exception when content of Properties instance is malformed */ void read(Properties p); /** * Write object state to the given Properties instance. * The Convertor infrastructure will take care about persistence of * content of Properties instance. Non-String properties are forbidden. * For naming restrictions on property keys see the class Javadoc. * * @param p empty properties instance for the data to be persisted */ void write(Properties p); } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.