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

Convertors (Convertor) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.convertor/1 1.3

org.netbeans.api.convertor
Class Convertors

java.lang.Object
  extended by org.netbeans.api.convertor.Convertors

public final class Convertors
extends Object

Main API class with methods allowing conversion of object to namespace aware XML fragment and recreation of object from that fragment. Apart from methods doing the conversions there is couple of other helper methods, for example for listing all currently supported conversions that is listing of available convertor descriptors; listening on changes of available convertors; methods for testing convertibility of the XML fragment or object, etc.


Field Summary
static String CONVERTOR_DESCRIPTORS
          Property name of the list of convertor descriptors
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds listener on changes of this object.
static boolean canRead(Element element)
          Is there a convertor for the given XML element?
static boolean canRead(String namespace, String element)
          Is there a convertor for the given XML namespace and element name?
static boolean canWrite(Object o)
          Is there a convertor for the given object?
 Set getConvertorDescriptors()
          Gets set of all available convertors.
static Convertors getDefault()
          Get default instance of Convertors class.
static Object read(Element element)
          Creates instance from the given XML namespace aware fragment.
static Object read(InputStream is)
          Creates instance from the given input stream.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes listener on changes of this object.
static Element write(Document doc, Object o)
          Converts the object to XML namespace aware fragment.
static void write(OutputStream os, Object o)
          Converts the object to XML document and writes it into given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERTOR_DESCRIPTORS

public static final String CONVERTOR_DESCRIPTORS
Property name of the list of convertor descriptors

See Also:
Constant Field Values
Method Detail

getDefault

public static Convertors getDefault()
Get default instance of Convertors class. Can be used for listing of convertor descriptors and for listening on changes in that list.

Returns:
singleton instance of Convertors class

canRead

public static boolean canRead(Element element)
Is there a convertor for the given XML element?

Parameters:
element - XML element to convertor; cannot be null
Returns:
true if this element can be converted to an object

canRead

public static boolean canRead(String namespace,
                              String element)
Is there a convertor for the given XML namespace and element name?

Parameters:
namespace - XML namespace; cannot be null
element - element name; cannot be null
Returns:
true if element with this name from this namespace can be converted to an object

canWrite

public static boolean canWrite(Object o)
Is there a convertor for the given object?

Parameters:
o - an object; cannot be null
Returns:
true if there is registered convertor for the given object class

read

public static Object read(Element element)
Creates instance from the given XML namespace aware fragment. See also canRead(org.w3c.dom.Element) for how to test whether the element is convertible or not.

Parameters:
element - XML namespace aware element which will be converted to an object; cannot be null
Returns:
instance of the object created from the element; cannot be null
Throws:
ConvertorException - thrown when there is no convertor for the passed element or when there was a runtime error during conversion. Client should call canRead(org.w3c.dom.Element) to prevent this exception.

read

public static Object read(InputStream is)
                   throws SAXException,
                          IOException
Creates instance from the given input stream. The stream is expected to contain namespace aware XML document otherwise the SAXException is thrown. It is also expected that convertor exists for the root element of this XML document otherwise IOException is thrown. See also read(Element).

Parameters:
is - input stream containing XML namespace aware document
Returns:
instance of the object created from the stream; cannot be null
Throws:
SAXException - thrown when input stream does not contain valid XML document
IOException - thrown when XML document cannot be read from input stream or when convertor does not exist for root element of XML document.
ConvertorException - thrown when there was a runtime error during conversion.

write

public static Element write(Document doc,
                            Object o)
Converts the object to XML namespace aware fragment.

Parameters:
doc - document to which the returned element should belong
o - object to convert
Returns:
element describing converted object
Throws:
ConvertorException - thrown when there is no convertor for the passed object or when there was a runtime error during conversion. Client should call canWrite(java.lang.Object) to prevent this exception.

write

public static void write(OutputStream os,
                         Object o)
                  throws IOException
Converts the object to XML document and writes it into given output stream.

Parameters:
os - output stream to which the XML document will be written
o - object to convert
Throws:
ConvertorException - thrown when there is no convertor for the passed object or when there was a runtime error during conversion. Client should call canWrite(java.lang.Object) to prevent this exception.
IOException - thrown when XML document cannot be written to output stream

getConvertorDescriptors

public Set getConvertorDescriptors()
Gets set of all available convertors.

Returns:
set of ConvertorDescriptor instances. Method always returns new instance of set.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds listener on changes of this object.

Parameters:
listener - property change listener

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes listener on changes of this object.

Parameters:
listener - property change listener

org.netbeans.modules.convertor/1 1.3

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