1 package org.bookmodule; 2 3 import org.openide.cookies.InstanceCookie; 4 import org.openide.filesystems.FileObject; 5 import org.openide.loaders.DataObject; 6 import org.openide.loaders.Environment; 7 import org.openide.util.Lookup; 8 import org.openide.util.lookup.Lookups; 9 10 import java.io.IOException ; 11 12 13 public class BookFactory implements Environment.Provider { 14 public BookFactory() { 15 } 16 17 public static Book createBook() { 18 return new Book(); 19 } 20 21 22 public static Book createBookWithParams(FileObject fo) { 23 String author = (String ) fo.getAttribute("author"); 24 String title = (String ) fo.getAttribute("title"); 25 return new Book(author, title); 26 } 27 28 public Lookup getEnvironment(DataObject obj) { 29 return Lookups.fixed(new Object []{new InstanceCookie() { 30 Book book = new Book(); 31 32 public String instanceName() { 33 return book.getClass().getName(); 34 } 35 36 public Class instanceClass() 37 throws IOException , ClassNotFoundException { 38 return book.getClass(); 39 } 40 41 public Object instanceCreate() 42 throws IOException , ClassNotFoundException { 43 return book; 44 } 45 }}); 46 } 47 48 } 49 50 | Popular Tags |