Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart4.png 84% of files have more coverage
438   1,039   140   10.19
106   805   0.32   43
43     3.26  
1    
 
  DefaultInternalKernelServices       Line # 74 438 140 35.6% 0.3560477
 
  (55)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.service;
17   
18    import java.io.File;
19    import java.io.FileFilter;
20    import java.io.FileNotFoundException;
21    import java.io.FileOutputStream;
22    import java.io.IOException;
23    import java.io.InputStream;
24    import java.io.Reader;
25    import java.io.UnsupportedEncodingException;
26    import java.lang.reflect.InvocationTargetException;
27    import java.net.HttpURLConnection;
28    import java.net.MalformedURLException;
29    import java.net.URL;
30    import java.net.URLConnection;
31    import java.net.URLEncoder;
32    import java.util.ArrayList;
33    import java.util.List;
34    import java.util.Map;
35   
36    import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
37    import org.apache.commons.httpclient.HttpClient;
38    import org.apache.commons.httpclient.HttpStatus;
39    import org.apache.commons.httpclient.methods.GetMethod;
40    import org.apache.commons.httpclient.params.HttpMethodParams;
41    import org.qedeq.base.io.IoUtility;
42    import org.qedeq.base.io.SourceArea;
43    import org.qedeq.base.io.SourcePosition;
44    import org.qedeq.base.io.TextInput;
45    import org.qedeq.base.trace.Trace;
46    import org.qedeq.base.utility.StringUtility;
47    import org.qedeq.base.utility.YodaUtility;
48    import org.qedeq.kernel.base.module.Qedeq;
49    import org.qedeq.kernel.base.module.Specification;
50    import org.qedeq.kernel.bo.QedeqBo;
51    import org.qedeq.kernel.bo.context.KernelContext;
52    import org.qedeq.kernel.bo.context.KernelProperties;
53    import org.qedeq.kernel.bo.context.KernelServices;
54    import org.qedeq.kernel.bo.log.QedeqLog;
55    import org.qedeq.kernel.bo.module.InternalKernelServices;
56    import org.qedeq.kernel.bo.module.KernelQedeqBo;
57    import org.qedeq.kernel.bo.module.QedeqFileDao;
58    import org.qedeq.kernel.common.DefaultModuleAddress;
59    import org.qedeq.kernel.common.DefaultSourceFileExceptionList;
60    import org.qedeq.kernel.common.LoadingState;
61    import org.qedeq.kernel.common.ModuleAddress;
62    import org.qedeq.kernel.common.ModuleDataException;
63    import org.qedeq.kernel.common.Plugin;
64    import org.qedeq.kernel.common.SourceFileException;
65    import org.qedeq.kernel.common.SourceFileExceptionList;
66    import org.qedeq.kernel.dto.module.QedeqVo;
67   
68   
69    /**
70    * This class provides a default implementation for the QEDEQ module services.
71    *
72    * @author Michael Meyling
73    */
 
74    public class DefaultInternalKernelServices implements KernelServices, InternalKernelServices, Plugin {
75   
76    /** This class. */
77    private static final Class CLASS = DefaultInternalKernelServices.class;
78   
79    /** For synchronized waiting. */
80    private static final Object MONITOR = new Object();
81   
82    /** Number of method calls. */
83    private volatile int processCounter = 0;
84   
85    /** Collection of already known QEDEQ modules. */
86    private final KernelQedeqBoStorage modules;
87   
88    /** Kernel properties access. */
89    private final KernelProperties kernel;
90   
91    /** This instance nows how to load a module from the file system. */
92    private final QedeqFileDao qedeqFileDao;
93   
94    /** This instance manages plugins. */
95    private final PluginManager pluginManager;
96   
97    /** Validate module dependencies and status. */
98    private boolean validate = true;
99   
100    /**
101    * Constructor.
102    *
103    * @param kernel For kernel access.
104    * @param loader For loading QEDEQ modules.
105    */
 
106  54 toggle public DefaultInternalKernelServices(final KernelProperties kernel, final QedeqFileDao loader) {
107  54 modules = new KernelQedeqBoStorage();
108  54 pluginManager = new PluginManager();
109  54 pluginManager.addPlugin("org.qedeq.kernel.bo.service.latex.Qedeq2LatexPlugin");
110  54 this.kernel = kernel;
111  54 this.qedeqFileDao = loader;
112  54 loader.setServices(this);
113    }
114   
 
115  54 toggle public void startupServices() {
116  54 if (kernel.getConfig().isAutoReloadLastSessionChecked()) {
117  0 autoReloadLastSessionChecked();
118    }
119    }
120   
121    /**
122    * If configured load all QEDEQ modules that where successfully loaded the last time.
123    */
 
124  0 toggle public void autoReloadLastSessionChecked() {
125  0 if (kernel.getConfig().isAutoReloadLastSessionChecked()) {
126  0 final Thread thread = new Thread() {
 
127  0 toggle public void run() {
128  0 final String method = "autoReloadLastSessionChecked.thread.run()";
129  0 try {
130  0 Trace.begin(CLASS, this, method);
131  0 QedeqLog.getInstance().logMessage(
132    "Trying to load previously successfully loaded modules.");
133  0 final int number = kernel.getConfig().getPreviouslyCheckedModules().length;
134  0 if (loadPreviouslySuccessfullyLoadedModules()) {
135  0 QedeqLog.getInstance().logMessage(
136    "Loading of " + number + " previously successfully loaded module"
137  0 + (number != 1 ? "s" : "") + " successfully done.");
138    } else {
139  0 QedeqLog.getInstance().logMessage(
140    "Loading of all previously successfully checked modules failed. "
141  0 + number + " module" + (number != 1 ? "s" : "")
142    + " were tried.");
143    }
144    } catch (Exception e) {
145  0 Trace.trace(CLASS, this, method, e);
146    } finally {
147  0 Trace.end(CLASS, this, method);
148    }
149    }
150    };
151  0 thread.setDaemon(true);
152  0 thread.start();
153    }
154    }
155   
 
156  0 toggle public void removeAllModules() {
157  0 do {
158  0 synchronized (this) {
159  0 if (processCounter == 0) {
160  0 getModules().removeAllModules();
161  0 return;
162    }
163    }
164    // we must wait for the other processes to stop (so that processCounter == 0)
165  0 synchronized (MONITOR) {
166  0 try {
167  0 MONITOR.wait(10000);
168    } catch (InterruptedException e) {
169    }
170    }
171    } while (true);
172   
173    }
174   
175    /**
176    * Remove a QEDEQ module from memory.
177    *
178    * @param address Remove module identified by this address.
179    */
 
180  0 toggle public void removeModule(final ModuleAddress address) {
181  0 final QedeqBo prop = getQedeqBo(address);
182  0 if (prop != null) {
183  0 removeModule(getModules().getKernelQedeqBo(this, address));
184  0 if (validate) {
185  0 modules.validateDependencies();
186    }
187    }
188    }
189   
190    /**
191    * Remove a QEDEQ module from memory. This method must block all other methods and if this
192    * method runs no other is allowed to run
193    *
194    * @param prop Remove module identified by this property.
195    */
 
196  0 toggle private void removeModule(final DefaultKernelQedeqBo prop) {
197  0 do {
198  0 synchronized (this) {
199  0 if (processCounter == 0) { // no other method is allowed to run
200    // TODO mime 20080319: one could call prop.setLoadingProgressState(
201    // LoadingState.STATE_DELETED) alone but that would
202    // miss to inform the KernelQedeqBoPool. How do we inform the pool?
203    // must the StateManager have a reference to it?
204  0 prop.delete();
205  0 getModules().removeModule(prop);
206  0 return;
207    }
208    }
209    // we must wait for the other processes to stop (so that processCounter == 0)
210  0 synchronized (MONITOR) {
211  0 try {
212  0 MONITOR.wait(10000);
213    } catch (InterruptedException e) {
214    }
215    }
216    } while (true);
217   
218    }
219   
220    /**
221    * Clear local file buffer and all loaded QEDEQ modules.
222    *
223    * @throws IOException Deletion of all buffered file was not successful.
224    */
 
225  0 toggle public void clearLocalBuffer() throws IOException {
226  0 removeAllModules();
227  0 final File bufferDir = getBufferDirectory().getCanonicalFile();
228  0 if (bufferDir.exists() && !IoUtility.deleteDir(bufferDir, new FileFilter() {
 
229  0 toggle public boolean accept(final File pathname) {
230  0 return pathname.getName().endsWith(".xml");
231    }
232    })) {
233  0 throw new IOException("buffer could not be deleted: " + bufferDir);
234    }
235    }
236   
 
237  160 toggle public QedeqBo loadModule(final ModuleAddress address) throws SourceFileExceptionList {
238  160 final String method = "loadModule(ModuleAddress)";
239  160 processInc();
240  160 final DefaultKernelQedeqBo prop = getModules().getKernelQedeqBo(this, address);
241  160 try {
242  160 synchronized (prop) {
243  160 if (prop.isLoaded()) {
244  98 return prop;
245    }
246  62 QedeqLog.getInstance().logRequest("Load module \"" + IoUtility.easyUrl(address.getUrl()) + "\"");
247  62 if (prop.getModuleAddress().isFileAddress()) {
248  52 loadLocalModule(prop);
249    } else {
250    // search in local file buffer
251  10 try {
252  10 getCanonicalReadableFile(prop);
253    } catch (ModuleFileNotFoundException e) { // file not found
254    // we will continue by creating a local copy
255  0 saveQedeqFromWebToBuffer(prop);
256    }
257  10 loadBufferedModule(prop);
258    }
259  56 QedeqLog.getInstance().logSuccessfulReply(
260    "Module \"" + prop.getModuleAddress().getFileName()
261    + "\" was successfully loaded.");
262    }
263    } catch (SourceFileExceptionList e) {
264  6 Trace.trace(CLASS, this, method, e);
265  6 QedeqLog.getInstance().logFailureState("Loading of module failed!", IoUtility.easyUrl(address.getUrl()),
266    e.toString());
267  6 throw e;
268    } catch (final RuntimeException e) {
269  0 Trace.fatal(CLASS, this, method, "unexpected problem", e);
270  0 QedeqLog.getInstance().logFailureReply("Loading failed", e.getMessage());
271  0 throw e;
272    } finally {
273  160 processDec();
274    }
275  56 return prop;
276    }
277   
278    /**
279    * Load buffered QEDEQ module file.
280    *
281    * @param prop Load this.
282    * @throws SourceFileExceptionList Loading or QEDEQ module failed.
283    */
 
284  10 toggle private void loadBufferedModule(final DefaultKernelQedeqBo prop)
285    throws SourceFileExceptionList {
286  10 prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_BUFFER);
287  10 final File localFile;
288  10 try {
289  10 localFile = getCanonicalReadableFile(prop);
290    } catch (ModuleFileNotFoundException e) {
291  0 final SourceFileExceptionList sfl = createSourceFileExceptionList(prop.getUrl(), e);
292  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_BUFFER_FAILED, sfl);
293  0 throw sfl;
294    }
295   
296  10 prop.setQedeqFileDao(getQedeqFileDao()); // remember loader for this module
297  10 final Qedeq qedeq;
298  10 try {
299  10 qedeq = getQedeqFileDao().loadQedeq(prop, localFile);
300    } catch (SourceFileExceptionList sfl) {
301  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_BUFFER_FAILED, sfl);
302  0 throw sfl;
303    }
304  10 setCopiedQedeq(prop, qedeq);
305    }
306   
307    /**
308    * Load QEDEQ module file with file loader.
309    *
310    * @param prop Load this.
311    * @throws SourceFileExceptionList Loading or copying QEDEQ module failed.
312    */
 
313  140 toggle private void loadLocalModule(final DefaultKernelQedeqBo prop) throws SourceFileExceptionList {
314  140 prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_LOCAL_FILE);
315  140 final File localFile;
316  140 try {
317  140 localFile = getCanonicalReadableFile(prop);
318    } catch (ModuleFileNotFoundException e) {
319  3 final SourceFileExceptionList sfl = createSourceFileExceptionList(prop.getUrl(), e);
320  3 prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_LOCAL_FILE_FAILED, sfl);
321  3 throw sfl;
322    }
323  137 prop.setQedeqFileDao(getQedeqFileDao()); // remember loader for this module
324   
325  137 final Qedeq qedeq;
326  137 try {
327  137 qedeq = getQedeqFileDao().loadQedeq(prop, localFile);
328    } catch (SourceFileExceptionList sfl) {
329  4 prop.setLoadingFailureState(LoadingState.STATE_LOADING_FROM_LOCAL_FILE_FAILED, sfl);
330  4 throw sfl;
331    }
332  133 setCopiedQedeq(prop, qedeq);
333    }
334   
 
335  143 toggle private void setCopiedQedeq(final DefaultKernelQedeqBo prop, final Qedeq qedeq)
336    throws SourceFileExceptionList {
337  143 final String method = "setCopiedQedeq(DefaultKernelQedeqBo, Qedeq)";
338  143 prop.setLoadingProgressState(LoadingState.STATE_LOADING_INTO_MEMORY);
339  143 QedeqVo vo = null;
340  143 try {
341  143 vo = QedeqVoBuilder.createQedeq(prop.getModuleAddress(), qedeq);
342    } catch (ModuleDataException e) {
343  0 Trace.trace(CLASS, this, method, e);
344  0 final SourceFileExceptionList xl = prop.createSourceFileExceptionList(this, e, qedeq);
345  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl);
346  0 throw xl;
347    }
348  143 prop.setQedeqVo(vo);
349  143 ModuleLabelsCreator moduleNodesCreator = new ModuleLabelsCreator(this, prop);
350  143 try {
351  143 prop.setLoaded(vo, moduleNodesCreator.createLabels());
352    } catch (SourceFileExceptionList sfl) {
353  2 prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, sfl);
354  2 throw sfl;
355    }
356    }
357   
358    /**
359    * Check if file exists and is readable. Checks the local buffer file for a buffered module or
360    * the module file address directly. Returns canonical file path.
361    *
362    * @param prop Check for this file.
363    * @return Canonical file path.
364    * @throws ModuleFileNotFoundException File doesn't exist or is not readable.
365    */
 
366  160 toggle private File getCanonicalReadableFile(final QedeqBo prop) throws ModuleFileNotFoundException {
367  160 final String method = "getCanonicalReadableFile(File)";
368  160 final File localFile = getLocalFilePath(prop.getModuleAddress());
369  160 final File file;
370  160 try {
371  160 file = localFile.getCanonicalFile();
372    } catch (IOException e) {
373  0 Trace.trace(CLASS, this, method, e);
374  0 throw new ModuleFileNotFoundException("file path not correct: " + localFile);
375    }
376  160 if (!file.canRead()) {
377  3 Trace.trace(CLASS, this, method, "file not readable=" + file);
378  3 throw new ModuleFileNotFoundException("file not readable: " + file);
379    }
380  157 return file;
381    }
382   
383    /**
384    * Load specified QEDEQ module from QEDEQ parent module.
385    *
386    * @param parent Parent module address.
387    * @param spec Specification for another QEDEQ module.
388    * @return Loaded module.
389    * @throws SourceFileExceptionList Loading failed.
390    */
 
391  161 toggle public KernelQedeqBo loadModule(final ModuleAddress parent, final Specification spec)
392    throws SourceFileExceptionList {
393   
394  161 final String method = "loadModule(Module, Specification)";
395  161 Trace.begin(CLASS, this, method);
396  161 Trace.trace(CLASS, this, method, spec);
397  161 processInc();
398  161 DefaultKernelQedeqBo prop = null; // currently tried module
399  161 try {
400  161 final ModuleAddress[] modulePaths;
401  161 try {
402  161 modulePaths = parent.getModulePaths(spec);
403    } catch (IOException e) {
404  0 Trace.trace(CLASS, this, method, e);
405  0 throw createSourceFileExceptionList(parent.getUrl(), e);
406    }
407   
408    // now we iterate over the possible module addresses
409  161 for (int i = 0; i < modulePaths.length; i++) {
410  161 prop = getModules().getKernelQedeqBo(this, modulePaths[i]);
411  161 Trace.trace(CLASS, this, method, "synchronizing at prop=" + prop);
412  161 synchronized (prop) {
413  161 if (prop.isLoaded()) {
414  73 return (prop);
415    }
416  88 try {
417  88 if (prop.getModuleAddress().isFileAddress()) {
418  88 loadLocalModule(prop);
419    } else {
420    // search in local file buffer
421  0 try {
422  0 getCanonicalReadableFile(prop);
423    } catch (ModuleFileNotFoundException e) { // file not found
424    // we will continue by creating a local copy
425  0 saveQedeqFromWebToBuffer(prop);
426    }
427  0 loadBufferedModule(prop);
428    }
429    // success!
430  85 return prop;
431    } catch (SourceFileExceptionList e) {
432  3 Trace.trace(CLASS, this, method, e);
433  3 if (i + 1 < modulePaths.length) {
434  0 QedeqLog.getInstance().logMessage("trying alternate path");
435    // we continue with the next path
436    } else {
437    // we surrender
438  3 throw e;
439    }
440    }
441    }
442    }
443  0 return prop; // never called, only here to soothe the compiler
444    } catch (final RuntimeException e) {
445  0 Trace.fatal(CLASS, this, method, "unexpected problem", e);
446  0 QedeqLog.getInstance().logFailureReply("Loading failed", e.getMessage());
447  0 throw e;
448    } finally {
449  161 processDec();
450  161 Trace.end(CLASS, this, method);
451    }
452    }
453   
 
454  54 toggle public ModuleAddress[] getAllLoadedModules() {
455  54 return getModules().getAllLoadedModules();
456    }
457   
 
458  70 toggle public void loadRequiredModules(final ModuleAddress address) throws SourceFileExceptionList {
459  70 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) loadModule(address);
460  70 if (prop.hasBasicFailures()) {
461  2 throw prop.getErrors();
462    }
463  68 LoadRequiredModules.loadRequired(this, prop);
464    }
465   
466    /**
467    * Load all previously checked QEDEQ modules.
468    *
469    * @return Successfully reloaded all modules.
470    */
 
471  0 toggle public boolean loadPreviouslySuccessfullyLoadedModules() {
472  0 processInc();
473  0 try {
474  0 final String[] list = kernel.getConfig().getPreviouslyCheckedModules();
475  0 boolean errors = false;
476  0 for (int i = 0; i < list.length; i++) {
477  0 try {
478  0 final ModuleAddress address = getModuleAddress(list[i]);
479  0 final QedeqBo prop = loadModule(address);
480  0 if (prop.hasErrors()) {
481  0 errors = true;
482    }
483    } catch (IOException e) {
484  0 Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules",
485    "internal error: " + "saved URLs are malformed", e);
486  0 errors = true;
487    } catch (SourceFileExceptionList e) {
488  0 Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules",
489    "loading error: " + "module could not be loaded", e);
490  0 errors = true;
491    }
492    }
493  0 return !errors;
494    } finally {
495  0 processDec();
496    }
497    }
498   
499    // LATER mime 20070326: dynamic loading from web page directory
 
500  0 toggle public boolean loadAllModulesFromQedeq() {
501  0 processInc();
502  0 try {
503  0 final String prefix = "http://www.qedeq.org/" + kernel.getKernelVersionDirectory() + "/";
504  0 final String[] list = new String[] {
505    prefix + "doc/math/qedeq_logic_v1.xml",
506    prefix + "doc/math/qedeq_set_theory_v1.xml",
507    prefix + "doc/project/qedeq_basic_concept.xml",
508    prefix + "doc/project/qedeq_logic_language.xml",
509    prefix + "sample/qedeq_sample1.xml", prefix + "sample/qedeq_error_sample_00.xml",
510    prefix + "sample/qedeq_error_sample_01.xml",
511    prefix + "sample/qedeq_error_sample_02.xml",
512    prefix + "sample/qedeq_error_sample_03.xml",
513    prefix + "sample/qedeq_error_sample_04.xml",
514    prefix + "sample/qedeq_sample2_error.xml",
515    prefix + "sample/qedeq_sample3_error.xml",
516    prefix + "sample/qedeq_sample4_error.xml",
517    prefix + "sample/qedeq_sample5_error.xml",
518    prefix + "sample/qedeq_sample6_error.xml",
519    prefix + "sample/qedeq_sample7_error.xml",
520    prefix + "sample/qedeq_sample8_error.xml", };
521  0 boolean errors = false;
522  0 for (int i = 0; i < list.length; i++) {
523  0 try {
524  0 final ModuleAddress address = getModuleAddress(list[i]);
525  0 final QedeqBo prop = loadModule(address);
526  0 if (prop.hasErrors()) {
527  0 errors = true;
528    }
529    } catch (IOException e) {
530  0 Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules",
531    "internal error: " + "saved URLs are malformed", e);
532  0 errors = true;
533    } catch (SourceFileExceptionList e) {
534  0 Trace.fatal(CLASS, this, "loadPreviouslySuccessfullyLoadedModules",
535    "loading error: " + "module could not be loaded", e);
536  0 errors = true;
537    }
538    }
539  0 return !errors;
540    } finally {
541  0 processDec();
542    }
543    }
544   
545    /**
546    * Make local copy of a module if it is no file address.
547    *
548    * @param prop Module properties.
549    * @throws SourceFileExceptionList Address was malformed or the file can not be found.
550    */
 
551  0 toggle private void saveQedeqFromWebToBuffer(final DefaultKernelQedeqBo prop)
552    throws SourceFileExceptionList {
553  0 final String method = "saveQedeqFromWebToBuffer(DefaultKernelQedeqBo)";
554  0 Trace.begin(CLASS, this, method);
555   
556    // if we are not web started and running under Java 1.4 we use apache commons
557    // httpclient library (so we can set timeouts)
558  0 if (!KernelContext.getInstance().isSetConnectionTimeOutSupported()
559    && !IoUtility.isWebStarted()) {
560  0 saveQedeqFromWebToBufferApache(prop);
561  0 Trace.end(CLASS, this, method);
562  0 return;
563    }
564   
565    // set proxy properties according to kernel configuration (if not webstarted)
566  0 if (!IoUtility.isWebStarted()) {
567  0 if (kernel.getConfig().getHttpProxyHost() != null) {
568  0 System.setProperty("http.proxyHost", kernel.getConfig().getHttpProxyHost());
569    }
570  0 if (kernel.getConfig().getHttpProxyPort() != null) {
571  0 System.setProperty("http.proxyPort", kernel.getConfig().getHttpProxyPort());
572    }
573  0 if (kernel.getConfig().getHttpNonProxyHosts() != null) {
574  0 System.setProperty("http.nonProxyHosts", kernel.getConfig().getHttpNonProxyHosts());
575    }
576    }
577   
578  0 if (prop.getModuleAddress().isFileAddress()) { // this is already a local file
579  0 Trace.fatal(CLASS, this, method, "tried to make a local copy for a local module", null);
580  0 Trace.end(CLASS, this, method);
581  0 return;
582    }
583  0 prop.setLoadingProgressState(LoadingState.STATE_LOADING_FROM_WEB);
584   
585  0 FileOutputStream out = null;
586  0 InputStream in = null;
587  0 final File f = getLocalFilePath(prop.getModuleAddress());
588  0 try {
589  0 final URLConnection connection = new URL(prop.getUrl()).openConnection();
590   
591  0 if (connection instanceof HttpURLConnection) {
592  0 final HttpURLConnection httpConnection = (HttpURLConnection) connection;
593    // if we are running at least under Java 1.5 the following code should be executed
594  0 if (KernelContext.getInstance().isSetConnectionTimeOutSupported()) {
595  0 try {
596  0 YodaUtility.executeMethod(httpConnection, "setConnectTimeout",
597    new Class[] {Integer.TYPE}, new Object[] {new Integer(
598    kernel.getConfig().getConnectTimeout())});
599    } catch (NoSuchMethodException e) {
600  0 Trace.fatal(CLASS, this, method,
601    "URLConnection.setConnectTimeout was previously found", e);
602    } catch (InvocationTargetException e) {
603  0 Trace.fatal(CLASS, this, method,
604    "URLConnection.setConnectTimeout throwed an error", e);
605    }
606    }
607    // if we are running at least under Java 1.5 the following code should be executed
608  0 if (KernelContext.getInstance().isSetReadTimeoutSupported()) {
609  0 try {
610  0 YodaUtility.executeMethod(httpConnection, "setReadTimeout",
611    new Class[] {Integer.TYPE}, new Object[] {new Integer(
612    kernel.getConfig().getReadTimeout())});
613    } catch (NoSuchMethodException e) {
614  0 Trace.fatal(CLASS, this, method,
615    "URLConnection.setReadTimeout was previously found", e);
616    } catch (InvocationTargetException e) {
617  0 Trace.fatal(CLASS, this, method,
618    "URLConnection.setReadTimeout throwed an error", e);
619    }
620    }
621  0 int responseCode = httpConnection.getResponseCode();
622  0 if (responseCode == 200) {
623  0 in = httpConnection.getInputStream();
624    } else {
625  0 in = httpConnection.getErrorStream();
626  0 final String errorText = IoUtility.loadStreamWithoutException(in, 1000);
627  0 throw new IOException("Response code from HTTP server was " + responseCode
628  0 + (errorText.length() > 0 ? "\nResponse text from HTTP server was:\n"
629    + errorText : ""));
630    }
631    } else {
632  0 Trace.paramInfo(CLASS, this, method, "connection.getClass", connection.getClass()
633    .toString());
634  0 in = connection.getInputStream();
635    }
636   
637  0 if (!prop.getUrl().equals(connection.getURL().toString())) {
638  0 throw new FileNotFoundException("\"" + prop.getUrl() + "\" was substituted by "
639    + "\"" + connection.getURL() + "\" from server");
640    }
641  0 final int maximum = connection.getContentLength();
642  0 IoUtility.createNecessaryDirectories(f);
643  0 out = new FileOutputStream(f);
644  0 final byte[] buffer = new byte[4096];
645