1 | package org.greenstone.gsdl3.build;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 |
|
---|
5 | import org.greenstone.gsdl3.util.*;
|
---|
6 | //import java.util.Thread
|
---|
7 | import javax.swing.event.EventListenerList;
|
---|
8 | import org.w3c.dom.Element;
|
---|
9 |
|
---|
10 | /** base class for collection construction */
|
---|
11 | public abstract class CollectionConstructor extends Thread
|
---|
12 | {
|
---|
13 |
|
---|
14 | /** the site in which building is to take place */
|
---|
15 | protected String site_home = null;
|
---|
16 | /** the name of the site */
|
---|
17 | protected String site_name = null;
|
---|
18 | /** the name of the collection */
|
---|
19 | protected String collection_name = null;
|
---|
20 | /** the stage of construction */
|
---|
21 | protected int process_type = -1;
|
---|
22 | /** other arguments/parameters for the construction process - in a paramList */
|
---|
23 | protected Element process_params = null;
|
---|
24 | /** the list of listeners for the process */
|
---|
25 | protected EventListenerList listeners = null;
|
---|
26 | /** A flag used to determine if this process has been asked to cancel. */
|
---|
27 | protected boolean cancel = false;
|
---|
28 |
|
---|
29 | public CollectionConstructor(String name)
|
---|
30 | {
|
---|
31 | super(name);
|
---|
32 | this.listeners = new EventListenerList();
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * carry out any set up stuff - returns false if couldn't set up properly
|
---|
37 | */
|
---|
38 | public boolean configure()
|
---|
39 | {
|
---|
40 | return true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void stopAction()
|
---|
44 | {
|
---|
45 | this.cancel = true;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void setActionType(int type)
|
---|
49 | {
|
---|
50 | this.process_type = type;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public void setSiteHome(String site_home)
|
---|
54 | {
|
---|
55 | this.site_home = site_home;
|
---|
56 |
|
---|
57 | File siteHomeFile = new File(site_home);
|
---|
58 | this.site_name = siteHomeFile.getName();
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void setCollectionName(String coll_name)
|
---|
62 | {
|
---|
63 | this.collection_name = coll_name;
|
---|
64 | }
|
---|
65 |
|
---|
66 | public void setProcessParams(Element params)
|
---|
67 | {
|
---|
68 | this.process_params = params;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public boolean addListener(ConstructionListener listener)
|
---|
72 | {
|
---|
73 | this.listeners.add(ConstructionListener.class, listener);
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public boolean removeListener(ConstructionListener listener)
|
---|
78 | {
|
---|
79 | this.listeners.remove(ConstructionListener.class, listener);
|
---|
80 | return true;
|
---|
81 | }
|
---|
82 |
|
---|
83 | protected void sendProcessBegun(ConstructionEvent evt)
|
---|
84 | {
|
---|
85 | Object[] concerned = this.listeners.getListenerList();
|
---|
86 | for (int i = 0; i < concerned.length; i += 2)
|
---|
87 | {
|
---|
88 | if (concerned[i] == ConstructionListener.class)
|
---|
89 | {
|
---|
90 | ((ConstructionListener) concerned[i + 1]).processBegun(evt);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected void sendProcessComplete(ConstructionEvent evt)
|
---|
96 | {
|
---|
97 | Object[] concerned = this.listeners.getListenerList();
|
---|
98 | for (int i = 0; i < concerned.length; i += 2)
|
---|
99 | {
|
---|
100 | if (concerned[i] == ConstructionListener.class)
|
---|
101 | {
|
---|
102 | ((ConstructionListener) concerned[i + 1]).processComplete(evt);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | protected void sendProcessStatus(ConstructionEvent evt)
|
---|
108 | {
|
---|
109 |
|
---|
110 | Object[] concerned = this.listeners.getListenerList();
|
---|
111 | for (int i = 0; i < concerned.length; i += 2)
|
---|
112 | {
|
---|
113 | if (concerned[i] == ConstructionListener.class)
|
---|
114 | {
|
---|
115 | ((ConstructionListener) concerned[i + 1]).processStatus(evt);
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | protected void sendMessage(ConstructionEvent evt)
|
---|
121 | {
|
---|
122 |
|
---|
123 | Object[] concerned = this.listeners.getListenerList();
|
---|
124 | for (int i = 0; i < concerned.length; i += 2)
|
---|
125 | {
|
---|
126 | if (concerned[i] == ConstructionListener.class)
|
---|
127 | {
|
---|
128 | ((ConstructionListener) concerned[i + 1]).message(evt);
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | abstract public void run();
|
---|
134 | }
|
---|