Source Code Cross Referenced for HarvestManager.java in  » GIS » geonetwork » org » fao » geonet » kernel » harvest » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » geonetwork » org.fao.geonet.kernel.harvest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //=============================================================================
002:        //===	Copyright (C) 2001-2007 Food and Agriculture Organization of the
003:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
004:        //===	and United Nations Environment Programme (UNEP)
005:        //===
006:        //===	This program is free software; you can redistribute it and/or modify
007:        //===	it under the terms of the GNU General Public License as published by
008:        //===	the Free Software Foundation; either version 2 of the License, or (at
009:        //===	your option) any later version.
010:        //===
011:        //===	This program is distributed in the hope that it will be useful, but
012:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
013:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:        //===	General Public License for more details.
015:        //===
016:        //===	You should have received a copy of the GNU General Public License
017:        //===	along with this program; if not, write to the Free Software
018:        //===	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019:        //===
020:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021:        //===	Rome - Italy. email: geonetwork@osgeo.org
022:        //==============================================================================
023:
024:        package org.fao.geonet.kernel.harvest;
025:
026:        import java.sql.SQLException;
027:        import java.util.HashMap;
028:        import jeeves.exceptions.BadInputEx;
029:        import jeeves.exceptions.JeevesException;
030:        import jeeves.exceptions.MissingParameterEx;
031:        import jeeves.resources.dbms.Dbms;
032:        import jeeves.server.context.ServiceContext;
033:        import jeeves.utils.Log;
034:        import jeeves.utils.Xml;
035:        import org.fao.geonet.constants.Edit;
036:        import org.fao.geonet.constants.Geonet;
037:        import org.fao.geonet.kernel.DataManager;
038:        import org.fao.geonet.kernel.harvest.Common.OperResult;
039:        import org.fao.geonet.kernel.harvest.harvester.AbstractHarvester;
040:        import org.fao.geonet.kernel.setting.SettingManager;
041:        import org.jdom.Element;
042:
043:        //=============================================================================
044:
045:        public class HarvestManager {
046:            //---------------------------------------------------------------------------
047:            //---
048:            //--- Constructor
049:            //---
050:            //---------------------------------------------------------------------------
051:
052:            public HarvestManager(ServiceContext context, SettingManager sm,
053:                    DataManager dm) throws Exception {
054:                this .context = context;
055:
056:                xslPath = context.getAppPath() + Geonet.Path.STYLESHEETS
057:                        + "/xml/harvesting/";
058:                settingMan = sm;
059:                dataMan = dm;
060:
061:                AbstractHarvester.staticInit(context);
062:
063:                Element entries = settingMan.get("harvesting", -1).getChild(
064:                        "children");
065:
066:                if (entries != null)
067:                    for (Object o : entries.getChildren()) {
068:                        Element node = transform((Element) o);
069:                        String type = node.getAttributeValue("type");
070:
071:                        AbstractHarvester ah = AbstractHarvester.create(type,
072:                                context, sm, dm);
073:                        ah.init(node);
074:                        hmHarvesters.put(ah.getID(), ah);
075:                        hmHarvestLookup.put(ah.getParams().uuid, ah);
076:                    }
077:            }
078:
079:            //---------------------------------------------------------------------------
080:
081:            private Element transform(Element node) throws Exception {
082:                String type = node.getChildText("value");
083:
084:                node = (Element) node.clone();
085:
086:                return Xml.transform(node, xslPath + type + ".xsl");
087:            }
088:
089:            //---------------------------------------------------------------------------
090:            //---
091:            //--- API methods
092:            //---
093:            //---------------------------------------------------------------------------
094:
095:            public Element get(String id) throws Exception {
096:                Element result = (id == null) ? settingMan
097:                        .get("harvesting", -1) : settingMan.get(
098:                        "harvesting/id:" + id, -1);
099:
100:                if (result == null)
101:                    return null;
102:
103:                if (id != null) {
104:                    result = transform(result);
105:                    addInfo(result);
106:                }
107:
108:                else {
109:                    Element nodes = result.getChild("children");
110:
111:                    result = new Element("nodes");
112:
113:                    if (nodes != null)
114:                        for (Object o : nodes.getChildren()) {
115:                            Element node = transform((Element) o);
116:                            addInfo(node);
117:                            result.addContent(node);
118:                        }
119:                }
120:
121:                return result;
122:            }
123:
124:            //---------------------------------------------------------------------------
125:
126:            public String add(Dbms dbms, Element node) throws JeevesException,
127:                    SQLException {
128:                Log.debug(Geonet.HARVEST_MAN, "Adding harvesting node : \n"
129:                        + Xml.getString(node));
130:
131:                String type = node.getAttributeValue("type");
132:
133:                AbstractHarvester ah = AbstractHarvester.create(type, context,
134:                        settingMan, dataMan);
135:
136:                ah.add(dbms, node);
137:                hmHarvesters.put(ah.getID(), ah);
138:                hmHarvestLookup.put(ah.getParams().uuid, ah);
139:                Log.debug(Geonet.HARVEST_MAN, "Added node with id : \n"
140:                        + ah.getID());
141:
142:                return ah.getID();
143:            }
144:
145:            //---------------------------------------------------------------------------
146:
147:            public synchronized boolean update(Dbms dbms, Element node)
148:                    throws BadInputEx, SQLException {
149:                Log.debug(Geonet.HARVEST_MAN, "Updating harvesting node : \n"
150:                        + Xml.getString(node));
151:
152:                String id = node.getAttributeValue("id");
153:
154:                if (id == null)
155:                    throw new MissingParameterEx("attribute:id", node);
156:
157:                AbstractHarvester ah = hmHarvesters.get(id);
158:
159:                if (ah == null)
160:                    return false;
161:
162:                ah.update(dbms, node);
163:                return true;
164:            }
165:
166:            //---------------------------------------------------------------------------
167:            /** This method must be synchronized because it cannot run if we are updating some entries */
168:
169:            public synchronized OperResult remove(Dbms dbms, String id)
170:                    throws Exception {
171:                Log.debug(Geonet.HARVEST_MAN, "Removing harvesting with id : "
172:                        + id);
173:
174:                AbstractHarvester ah = hmHarvesters.get(id);
175:
176:                if (ah == null)
177:                    return OperResult.NOT_FOUND;
178:
179:                hmHarvestLookup.remove(ah.getParams().uuid);
180:                ah.destroy(dbms);
181:                hmHarvesters.remove(id);
182:                settingMan.remove(dbms, "harvesting/id:" + id);
183:
184:                return OperResult.OK;
185:            }
186:
187:            //---------------------------------------------------------------------------
188:
189:            public OperResult start(Dbms dbms, String id) throws SQLException {
190:                Log.debug(Geonet.HARVEST_MAN, "Starting harvesting with id : "
191:                        + id);
192:
193:                AbstractHarvester ah = hmHarvesters.get(id);
194:
195:                if (ah == null)
196:                    return OperResult.NOT_FOUND;
197:
198:                return ah.start(dbms);
199:            }
200:
201:            //---------------------------------------------------------------------------
202:
203:            public OperResult stop(Dbms dbms, String id) throws SQLException {
204:                Log.debug(Geonet.HARVEST_MAN, "Stopping harvesting with id : "
205:                        + id);
206:
207:                AbstractHarvester ah = hmHarvesters.get(id);
208:
209:                if (ah == null)
210:                    return OperResult.NOT_FOUND;
211:
212:                return ah.stop(dbms);
213:            }
214:
215:            //---------------------------------------------------------------------------
216:
217:            public OperResult run(String id) {
218:                Log.debug(Geonet.HARVEST_MAN, "Running harvesting with id : "
219:                        + id);
220:
221:                AbstractHarvester ah = hmHarvesters.get(id);
222:
223:                if (ah == null)
224:                    return OperResult.NOT_FOUND;
225:
226:                return ah.run();
227:            }
228:
229:            //---------------------------------------------------------------------------
230:
231:            public Element getHarvestInfo(String harvestUuid, String id,
232:                    String uuid) {
233:                Element info = new Element(Edit.Info.Elem.HARVEST_INFO);
234:
235:                AbstractHarvester ah = hmHarvestLookup.get(harvestUuid);
236:
237:                if (ah != null)
238:                    ah.addHarvestInfo(info, id, uuid);
239:
240:                return info;
241:            }
242:
243:            //---------------------------------------------------------------------------
244:
245:            public AbstractHarvester getHarvester(String harvestUuid) {
246:                return hmHarvestLookup.get(harvestUuid);
247:            }
248:
249:            //---------------------------------------------------------------------------
250:            //---
251:            //--- Private methods
252:            //---
253:            //---------------------------------------------------------------------------
254:
255:            private void addInfo(Element node) {
256:                String id = node.getAttributeValue("id");
257:                hmHarvesters.get(id).addInfo(node);
258:            }
259:
260:            //---------------------------------------------------------------------------
261:            //---
262:            //--- Vars
263:            //---
264:            //---------------------------------------------------------------------------
265:
266:            private String xslPath;
267:            private SettingManager settingMan;
268:            private DataManager dataMan;
269:            private ServiceContext context;
270:
271:            private HashMap<String, AbstractHarvester> hmHarvesters = new HashMap<String, AbstractHarvester>();
272:            private HashMap<String, AbstractHarvester> hmHarvestLookup = new HashMap<String, AbstractHarvester>();
273:        }
274:
275:        //=============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.