|
org.netbeans.modules.convertor/1 1.3 | |||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
Convertor | Base interface for object conversion to XML namespace aware fragment and conversion of this fragment back to the object. |
SimplyConvertible | SimplyConvertible is way how to persist your object by Convertor infrastructure without writing any convertor. |
The Convertor SPI defines interface describing the convertor.
package com.mycompany.book;
class Book {
private String author;
private String title;
public Book(String author, String title) { ... };
public String getAuthor() { ... };
public void setAuthor(String author) { ... };
public String getTitle() { ... };
public void setTitle(String title) { ... };
}
String NAMESPACE = "http://www.mycompany.com/namespace/book";
String ELEMENT = "book";
package com.mycompany.book;
public class BookConvertor implements Convertor {
public BookConvertor() {
}
public Object read(Element element) {
String author;
String title;
// read author and title from element or
its child elements
// whatever way you store it and like it
return new Book(author, title);
}
public Element write(Document doc, Object inst) {
Book book = (Book)inst;
Element element = doc.createElementNS(NAMESPACE, BOOK);
// write author and title whatever way you prefer
// to the element and return that element
return element;
}
}
Name:
com/mycompany/book/BookConvertor.class
NetBeans-Convertor: {
http://www.mycompany.com/namespace/book}
book,
com.mycompany.book.Book
openide/convertor/test/unit/src/org/netbeans/api/convertor/data
can be found Ant build script for building three separate JARs each
containing one convertor example and its registration. There is also
example of usage of SimplyConvertible and compound convertor which
are discussed in next chapters. class Book implements SimplyConvertible {
private static final String AUTHOR = "author";
private static final
String TITLE = "title";
public void read(Properties p) {
author = p.getProperty(AUTHOR);
title = p.getProperty(TITLE);
}
public void write(Properties p) {
p.setProperty(AUTHOR, author);
p.setProperty(TITLE, title);
}
// and the rest ...
}
String NAMESPACE = "http://www.mycompany.com/namespace/book2";
String ELEMENT = "book2";
Name:
com/mycompany/book/Book.class
NetBeans-Simply-Convertible: {
http://www.mycompany.com/namespace/book2}book2
<book2 xmlns="
http://www.mycompany.com/namespace/book2
">
<author>A Book Author</author>
<title>A Book Title</title>
</book2
>
<instance xmlns="http://www.netbeans.org/ns/registry">
<class>com.mycompany.SomeClass</class>
</instance>
<instance xmlns="http://www.netbeans.org/ns/registry">
<method>com.mycompany.SomeClass.getDefault</method>
</instance>
<instance xmlns="http://www.netbeans.org/ns/registry">
<class>com.mycompany.SomeClass</class>
<property name="prop1">Value of Prop1</property>
<property name="prop2">
Value of Prop2
</property>
</instance>
|
org.netbeans.modules.convertor/1 1.3 | |||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |