站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

org.netbeans.api.convertor (Convertor) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.convertor/1 1.3

Package org.netbeans.api.convertor

The Convertor API allows to convertor object to namespace aware XML fragment and vice versa.

See:
          Description

Class Summary
ConvertorDescriptor Convertor descriptor describes basic capability of the convertor, that is the XML namespace and element name which the convertor is capable to read, and (optional) class name which instances the convertor is capable to persist.
Convertors Main API class with methods allowing conversion of object to namespace aware XML fragment and recreation of object from that fragment.
 

Exception Summary
ConvertorException Unchecked exception thrown when convertor does not exist for the requested read or write operation or when there is general runtime error during the conversion.
 

Package org.netbeans.api.convertor Description

The Convertor API allows to convertor object to namespace aware XML fragment and vice versa.

API Overview

The API part is quite straightforward. There is one main class with couple of static helper methods working on all registered convertors in the system.

Learn by example

The typical workflow of storing and loading of an object is illustrated below. It expect that there is registered convertor for the object which does the actual conversion. For how to write a convertor see SPI package overview.

1.) test whether there is a convertor for the object

    boolean canWrite = Convertors.canWrite(anObject);

2.) if yes then save it to a file

    OutputStream os = new FileOutputStream("somefilename.xml");
    try {
        Convertors.write(os, anObject);
    } finally {
        os.close();
    }

That's all for writing. The reading is adequately simple:

    InputStream is = new FileInputStream("somefilename.xml");
    try {
       
theObject = Convertors.read(is);
    } catch (SAXException ex) {
        // file is not valid XML document.
        // notify user and/or ignore file.
    } catch (IOException ex) {
        // file cannot be read or there is no convertor for root element
        // notify user and/or ignore file.
    } finally {
        is.close();
    }



org.netbeans.modules.convertor/1 1.3

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.