source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/CollectionConstructor.java@ 31572

Last change on this file since 31572 was 31572, checked in by ak19, 7 years ago

Minor changes ahead of more major ones. Explicitly marking ConstructionEvent members immutable by declaring them final, to make them thread safe (to make them safe to share across multiple threads).

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1package org.greenstone.gsdl3.build;
2
3import java.io.File;
4
5import org.greenstone.gsdl3.util.*;
6//import java.util.Thread
7import javax.swing.event.EventListenerList;
8import org.w3c.dom.Element;
9
10/** base class for collection construction */
11public 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 /** Stores the name of the manifest file (if one is needed) */
29 protected String manifest_file = null;
30 /** The URL params constructed as a query string, representing the CGI QUERY_STRING to the process */
31 protected String query_string = null;
32
33 public CollectionConstructor(String name)
34 {
35 super(name);
36 this.listeners = new EventListenerList();
37 }
38
39 /**
40 * carry out any set up stuff - returns false if couldn't set up properly
41 */
42 public boolean configure()
43 {
44 return true;
45 }
46
47 // this method never gets called. And, the way subclass GS2PerlConstructor.runPerlCommand() was originally
48 // coded, setting cancel to true never had any effect anyway in stopping any perl command that was run.
49 public void stopAction()
50 {
51 this.cancel = true;
52 }
53
54 public void setActionType(int type)
55 {
56 this.process_type = type;
57 }
58
59 public void setSiteHome(String site_home)
60 {
61 this.site_home = site_home;
62
63 File siteHomeFile = new File(site_home);
64 this.site_name = siteHomeFile.getName();
65 }
66
67 public void setCollectionName(String coll_name)
68 {
69 this.collection_name = coll_name;
70 }
71
72 public void setQueryString(String querystring)
73 {
74 this.query_string = querystring;
75 }
76
77 public void setProcessParams(Element params)
78 {
79 this.process_params = params;
80 }
81
82 public void setManifestFile(String manifestFile)
83 {
84 this.manifest_file = manifestFile;
85 }
86
87 public boolean addListener(ConstructionListener listener)
88 {
89 this.listeners.add(ConstructionListener.class, listener);
90 return true;
91 }
92
93 public boolean removeListener(ConstructionListener listener)
94 {
95 this.listeners.remove(ConstructionListener.class, listener);
96 return true;
97 }
98
99 protected void sendProcessBegun(ConstructionEvent evt)
100 {
101 Object[] concerned = this.listeners.getListenerList();
102 for (int i = 0; i < concerned.length; i += 2)
103 {
104 if (concerned[i] == ConstructionListener.class)
105 {
106 ((ConstructionListener) concerned[i + 1]).processBegun(evt);
107 }
108 }
109 }
110
111 protected void sendProcessComplete(ConstructionEvent evt)
112 {
113 Object[] concerned = this.listeners.getListenerList();
114 for (int i = 0; i < concerned.length; i += 2)
115 {
116 if (concerned[i] == ConstructionListener.class)
117 {
118 ((ConstructionListener) concerned[i + 1]).processComplete(evt);
119 }
120 }
121 }
122
123 protected void sendProcessStatus(ConstructionEvent evt)
124 {
125
126 Object[] concerned = this.listeners.getListenerList();
127 for (int i = 0; i < concerned.length; i += 2)
128 {
129 if (concerned[i] == ConstructionListener.class)
130 {
131 ((ConstructionListener) concerned[i + 1]).processStatus(evt);
132 }
133 }
134 }
135
136 protected void sendMessage(ConstructionEvent evt)
137 {
138
139 Object[] concerned = this.listeners.getListenerList();
140 for (int i = 0; i < concerned.length; i += 2)
141 {
142 if (concerned[i] == ConstructionListener.class)
143 {
144 ((ConstructionListener) concerned[i + 1]).message(evt);
145 }
146 }
147 }
148
149 abstract public void run();
150}
Note: See TracBrowser for help on using the repository browser.