List of usage examples for java.util EventObject EventObject
public EventObject(Object source)
From source file:it.geosolutions.geobatch.opensdi.ndvi.NDVIIngestAction.java
/** * // w w w .ja v a 2 s .co m */ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.progressing(1f, "Check config"); listenerForwarder.started(); NDVIIngestConfiguration configuration = getConfiguration(); if (configuration == null) { throw new IllegalStateException("ActionConfig is null."); } // List<File> ndviFiles = new ArrayList<File>(); Map<File, Calendar[]> inputFiles = new TreeMap<File, Calendar[]>(); while (!events.isEmpty()) { EventObject event = events.poll(); if (event instanceof FileSystemEvent) { FileSystemEvent fse = (FileSystemEvent) event; File source = fse.getSource(); if (!source.exists()) { LOGGER.error("File does not exist: " + source); continue; } Calendar interval[]; try { interval = parseDekDate(source.getName()); } catch (ActionException e) { LOGGER.error("Error parsing source name: " + e.getMessage()); continue; } inputFiles.put(source, interval); } else { throw new ActionException(this, "EventObject not handled " + event); } } listenerForwarder.progressing(10f, "Process file"); ImageMosaicCommand imc = processFiles(inputFiles); LinkedList<EventObject> ret = new LinkedList<EventObject>(); ret.add(new EventObject(imc)); return ret; }
From source file:it.geosolutions.geobatch.nrl.ndvi.NDVIIngestAction.java
/** * /*from w ww . ja va2s .com*/ */ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.setTask("Check config"); listenerForwarder.started(); NDVIIngestConfiguration configuration = getConfiguration(); if (configuration == null) { throw new IllegalStateException("ActionConfig is null."); } // List<File> ndviFiles = new ArrayList<File>(); Map<File, Calendar[]> inputFiles = new TreeMap<File, Calendar[]>(); while (!events.isEmpty()) { EventObject event = events.poll(); if (event instanceof FileSystemEvent) { FileSystemEvent fse = (FileSystemEvent) event; File source = fse.getSource(); if (!source.exists()) { LOGGER.error("File does not exist: " + source); continue; } Calendar interval[]; try { interval = parseDekDate(source.getName()); } catch (ActionException e) { LOGGER.error("Error parsing source name: " + e.getMessage()); continue; } inputFiles.put(source, interval); } else { throw new ActionException(this, "EventObject not handled " + event); } } ImageMosaicCommand imc = processFiles(inputFiles); LinkedList<EventObject> ret = new LinkedList<EventObject>(); ret.add(new EventObject(imc)); return ret; }
From source file:it.geosolutions.geobatch.actions.xstream.XstreamAction.java
public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { // the output final Queue<EventObject> ret = new LinkedList<EventObject>(); listenerForwarder.started();// www .j a v a 2s . c o m while (events.size() > 0) { final EventObject event = events.remove(); if (event == null) { final String message = "The passed event object is null"; if (LOGGER.isWarnEnabled()) LOGGER.warn(message); if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } if (event instanceof FileSystemEvent) { // generate an object final File sourceFile = File.class.cast(event.getSource()); if (!sourceFile.exists() || !sourceFile.canRead()) { final String message = "XstreamAction.adapter(): The passed FileSystemEvent " + "reference to a not readable or not existent file: " + sourceFile.getAbsolutePath(); if (LOGGER.isWarnEnabled()) LOGGER.warn(message); if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } FileInputStream inputStream = null; try { inputStream = new FileInputStream(sourceFile); final Map<String, String> aliases = conf.getAlias(); if (aliases != null && aliases.size() > 0) { for (String alias : aliases.keySet()) { final Class<?> clazz = Class.forName(aliases.get(alias)); xstream.alias(alias, clazz); } } listenerForwarder.setTask("Converting file to a java object"); // deserialize final Object res = xstream.fromXML(inputStream); // generate event final EventObject eo = new EventObject(res); // append to the output ret.add(eo); } catch (XStreamException e) { // the object cannot be deserialized if (LOGGER.isErrorEnabled()) LOGGER.error("The passed FileSystemEvent reference to a not deserializable file: " + sourceFile.getAbsolutePath(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } catch (Throwable e) { // the object cannot be deserialized if (LOGGER.isErrorEnabled()) LOGGER.error("XstreamAction.adapter(): " + e.getLocalizedMessage(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } finally { IOUtils.closeQuietly(inputStream); } } else { // try to serialize // build the output absolute file name File outputDir; try { outputDir = new File(conf.getOutput()); // the output if (!outputDir.isAbsolute()) outputDir = it.geosolutions.tools.commons.file.Path.findLocation(outputDir, getTempDir()); if (!outputDir.exists()) { if (!outputDir.mkdirs()) { final String message = "Unable to create the ouptut dir named: " + outputDir.toString(); if (LOGGER.isInfoEnabled()) LOGGER.info(message); if (conf.isFailIgnored()) { continue; } else { final ActionException e = new ActionException(this, message); listenerForwarder.failed(e); throw e; } } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Output dir name: " + outputDir.toString()); } } catch (NullPointerException npe) { final String message = "Unable to get the output file path from :" + conf.getOutput(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, npe); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(npe); throw new ActionException(this, npe.getLocalizedMessage()); } } final File outputFile; try { outputFile = File.createTempFile(conf.getOutput(), null, outputDir); } catch (IOException ioe) { final String message = "Unable to build the output file writer: " + ioe.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, ioe); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(ioe); throw new ActionException(this, ioe.getLocalizedMessage()); } } // try to open the file to write into FileWriter fw = null; try { listenerForwarder.setTask("Serializing java object to " + outputFile); fw = new FileWriter(outputFile); final Map<String, String> aliases = conf.getAlias(); if (aliases != null && aliases.size() > 0) { for (String alias : aliases.keySet()) { final Class<?> clazz = Class.forName(aliases.get(alias)); xstream.alias(alias, clazz); } } xstream.toXML(event.getSource(), fw); } catch (XStreamException e) { if (LOGGER.isErrorEnabled()) LOGGER.error( "The passed event object cannot be serialized to: " + outputFile.getAbsolutePath(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } catch (Throwable e) { // the object cannot be deserialized if (LOGGER.isErrorEnabled()) LOGGER.error(e.getLocalizedMessage(), e); if (conf.isFailIgnored()) { continue; } else { listenerForwarder.failed(e); throw new ActionException(this, e.getLocalizedMessage()); } } finally { IOUtils.closeQuietly(fw); } // add the file to the queue ret.add(new FileSystemEvent(outputFile.getAbsoluteFile(), FileSystemEventType.FILE_ADDED)); } } listenerForwarder.completed(); return ret; }
From source file:nl.tue.gale.geb.GEBManager.java
public void responseEvent(String eventId, String previousEventId, String method, String body) { CallbackListener listener = callbackMap.get(previousEventId); if (listener != null) listener.callback(new EventObject(body)); else/* w w w . j av a 2s .c om*/ System.out.println( "unhandled response event " + eventId + " on " + previousEventId + " (" + method + ": " + body); }
From source file:org.nuclos.client.ui.collect.SubForm.java
public void fireFocusGained() { AWTEvent event = EventQueue.getCurrentEvent(); if (event instanceof KeyEvent) { if (getJTable().getModel().getRowCount() > 0) { getJTable().editCellAt(0, 0); getSubformTable().changeSelection(0, 0, false, false); } else if (getJTable().getModel().getRowCount() == 0) { for (FocusActionListener fal : getFocusActionLister()) { fal.focusAction(new EventObject(this)); if (getJTable().editCellAt(0, 0)) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Component editor = getJTable().getEditorComponent(); if (editor != null) editor.requestFocusInWindow(); }// w w w.ja v a 2 s .c o m }); } } } } }