KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > doclet > Archiver


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.doclet;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.Map JavaDoc;
10
11 import com.sun.javadoc.ClassDoc;
12
13 /**
14  * This class archives away the page data so it may
15  * be retrieved later.
16  *
17  * @author Rob Gordon.
18  */

19 public class Archiver {
20
21     private final JobsAndTypes jats;
22     
23     private Map JavaDoc jobData = new HashMap JavaDoc();
24     private Map JavaDoc typeData = new HashMap JavaDoc();
25     private Map JavaDoc otherData = new HashMap JavaDoc();
26     
27     public Archiver(JobsAndTypes jats) {
28         this.jats = jats;
29     }
30     
31     public void archive(ClassDoc classDoc) {
32     
33         String JavaDoc fqcn = Processor.fqcnFor(classDoc);
34         if (!jats.contains(fqcn)) {
35             return;
36         }
37         
38         Processor processor = new Processor(jats, classDoc);
39         PageData pageData = processor.process();
40         
41         if (jats.isJob(fqcn)) {
42             jobData.put(pageData.getName(), pageData);
43         }
44         else if (jats.isType(fqcn)) {
45             typeData.put(pageData.getName(), pageData);
46         }
47         else {
48             otherData.put(pageData.getName(), pageData);
49         }
50         
51     }
52     
53     /**
54      * Jobs in index order.
55      *
56      * @return An array of PageData objects.
57      */

58     public PageData[] getJobData() {
59         List JavaDoc results = new ArrayList JavaDoc();
60         String JavaDoc[] jobs = jats.jobs();
61         for (int i = 0; i < jobs.length; ++i) {
62             PageData pageData = (PageData) jobData.get(jobs[i]);
63             if (pageData != null) {
64                 results.add(pageData);
65             }
66         }
67             
68         return (PageData[]) results.toArray(new PageData[0]);
69     }
70     
71     /**
72      * Types in index order.
73      *
74      * @return An array of PageData objects
75      */

76     public PageData[] getTypeData() {
77         List JavaDoc results = new ArrayList JavaDoc();
78         String JavaDoc[] types = jats.types();
79         for (int i = 0; i < types.length; ++i) {
80             PageData pageData = (PageData) typeData.get(types[i]);
81             if (pageData != null) {
82                 results.add(pageData);
83             }
84         }
85             
86         return (PageData[]) results.toArray(new PageData[0]);
87     }
88     
89     public List JavaDoc getAll() {
90         List JavaDoc all = new ArrayList JavaDoc();
91         all.addAll(jobData.values());
92         all.addAll(typeData.values());
93         all.addAll(otherData.values());
94         return all;
95     }
96
97     
98 }
99
Popular Tags