KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bookmodule > BookFactory


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 JavaDoc;
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 JavaDoc author = (String JavaDoc) fo.getAttribute("author");
24         String JavaDoc title = (String JavaDoc) fo.getAttribute("title");
25         return new Book(author, title);
26     }
27
28     public Lookup getEnvironment(DataObject obj) {
29         return Lookups.fixed(new Object JavaDoc[]{new InstanceCookie() {
30             Book book = new Book();
31
32             public String JavaDoc instanceName() {
33                 return book.getClass().getName();
34             }
35
36             public Class JavaDoc instanceClass()
37                     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
38                 return book.getClass();
39             }
40
41             public Object JavaDoc instanceCreate()
42                     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
43                 return book;
44             }
45         }});
46     }
47
48 }
49
50
Popular Tags