List of usage examples for java.util EventObject getSource
public Object getSource()
From source file:it.geosolutions.geobatch.actions.ds2ds.geoserver.DSGeoServerAction.java
@Override public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.started();/*from w ww .j a va 2 s .c o m*/ // return object final Queue<EventObject> outputEvents = new LinkedList<EventObject>(); //check global configurations //Geoserver config //---------------- updateTask("Check GeoServer configuration"); final String url = conf.getGeoserverURL(); final String user = conf.getGeoserverUID(); final String password = conf.getGeoserverPWD(); GeoServerRESTManager gsMan = null; try { gsMan = new GeoServerRESTManager(new URL(url), user, password); } catch (MalformedURLException e) { failAction("Wrong GeoServer URL"); } catch (IllegalArgumentException e) { failAction("Unable to create the GeoServer Manager using a null argument"); } //TODO how to check if GS user/password are correct? listenerForwarder.progressing(5, "GeoServer configuration checked"); //Check operation //--------------- updateTask("Check operation"); String op = conf.getOperation(); if (op == null || !(op.equalsIgnoreCase("PUBLISH") || op.equalsIgnoreCase("REMOVE"))) { failAction("Bad operation: " + op + " in configuration"); } listenerForwarder.progressing(10, "Operation checked"); //Check WorkSpace //--------------- updateTask("Check workspace configuration"); String ws = conf.getDefaultNamespace(); String wsUri = conf.getDefaultNamespaceUri(); Boolean existWS = false; synchronized (existWS) { existWS = gsMan.getReader().getWorkspaceNames().contains(ws); if (!existWS) { boolean createWS = conf.getCreateNameSpace(); if (createWS) { //try to create the workspace updateTask("Create workspace " + ws + " in GeoServer"); boolean created = false; if (wsUri == null) { created = gsMan.getPublisher().createWorkspace(ws); } else { try { created = gsMan.getPublisher().createWorkspace(ws, new URI(wsUri)); } catch (URISyntaxException e) { failAction("Invalid NameSpace URI " + wsUri + " in configuration"); } } if (!created) { failAction("FATAL: unable to create workspace " + ws + " in GeoServer"); } } else { failAction("Bad workspace (namespace): " + ws + " in configuration"); } } } listenerForwarder.progressing(25, "GeoServer workspace checked"); //event-based business logic while (events.size() > 0) { final EventObject ev; try { if ((ev = events.remove()) != null) { updateTask("Working on incoming event: " + ev.getSource()); updateTask("Check acceptable file"); FileSystemEvent fileEvent = (FileSystemEvent) ev; //set FeatureConfiguration updateTask("Set Feature Configuration"); this.createFeatureConfiguration(fileEvent); FeatureConfiguration featureConfig = conf.getFeatureConfiguration(); //TODO check FeatureConfiguration updateTask("Check Feature Configuration"); if (featureConfig.getTypeName() == null) { failAction("feature typeName cannot be null"); } //TODO check if the typeName already exists for the target workspace? //datastore check (and eventually creation) updateTask("Check datastore configuration"); String ds = conf.getStoreName(); Boolean existDS = false; synchronized (existDS) { existDS = gsMan.getReader().getDatastores(ws).getNames().contains(ds); if (!existDS) { boolean createDS = conf.getCreateDataStore(); if (createDS) { //create datastore updateTask("Create datastore in GeoServer"); Map<String, Object> datastore = this.deserialize(featureConfig.getDataStore()); String dbType = (String) datastore.get("dbtype"); boolean created = false; if (dbType.equalsIgnoreCase("postgis")) { GSPostGISDatastoreEncoder encoder = new GSPostGISDatastoreEncoder(ds); encoder.setName(ds); encoder.setEnabled(true); encoder.setHost((String) datastore.get("host")); encoder.setPort(Integer.parseInt((String) datastore.get("port"))); encoder.setDatabase((String) datastore.get("database")); encoder.setSchema((String) datastore.get("schema")); encoder.setUser((String) datastore.get("user")); encoder.setPassword((String) datastore.get("passwd")); created = gsMan.getStoreManager().create(ws, encoder); if (!created) { failAction("FATAL: unable to create PostGIS datastore " + ds + " in GeoServer"); } } else if (dbType.equalsIgnoreCase("oracle")) { String dbname = (String) datastore.get("database"); GSOracleNGDatastoreEncoder encoder = new GSOracleNGDatastoreEncoder(ds, dbname); encoder.setName(ds); encoder.setEnabled(true); encoder.setHost((String) datastore.get("host")); encoder.setPort(Integer.parseInt((String) datastore.get("port"))); encoder.setDatabase(dbname); encoder.setSchema((String) datastore.get("schema")); encoder.setUser((String) datastore.get("user")); encoder.setPassword((String) datastore.get("passwd")); created = gsMan.getStoreManager().create(ws, encoder); if (!created) { failAction("FATAL: unable to create Oracle NG datastore " + ds + " in GeoServer"); } } else { failAction("The datastore type " + dbType + " is not supported"); } } else { failAction("Bad datastore:" + ds + " in configuration. Datastore " + ds + " doesn't exist in workspace (namespace) " + ws); } } } listenerForwarder.progressing(50, "Check GeoServer datastore"); //feature type publication/removal boolean done = false; if (op.equalsIgnoreCase("PUBLISH")) { if (!gsMan.getReader().getLayers().getNames().contains(featureConfig.getTypeName())) { updateTask("Publish DBLayer " + featureConfig.getTypeName() + " in GeoServer"); //featuretype final GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); fte.setName(featureConfig.getTypeName()); fte.setTitle(featureConfig.getTypeName()); String crs = featureConfig.getCrs(); if (crs != null) { fte.setSRS(featureConfig.getCrs()); } else { fte.setSRS("EPSG:4326"); } fte.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); //layer & styles final GSLayerEncoder layerEncoder = new GSLayerEncoder(); layerEncoder.setDefaultStyle(this.defineLayerStyle(featureConfig, gsMan)); //default style if (conf.getStyles() != null) { //add available styles for (String style : conf.getStyles()) { layerEncoder.addStyle(style); } } //publish done = gsMan.getPublisher().publishDBLayer(ws, ds, fte, layerEncoder); if (!done) { failAction("Impossible to publish DBLayer " + featureConfig.getTypeName() + " in GeoServer"); } } } else if (op.equalsIgnoreCase("REMOVE")) { if (gsMan.getReader().getLayers().getNames().contains(featureConfig.getTypeName())) { //remove updateTask("Remove DBLayer " + featureConfig.getTypeName() + " from GeoServer"); done = gsMan.getPublisher().unpublishFeatureType(ws, ds, featureConfig.getTypeName()); if (!done) { failAction("Impossible to remove DBLayer " + featureConfig.getTypeName() + " in GeoServer"); } } } listenerForwarder.progressing(100F, "Successful Geoserver " + op + " operation"); listenerForwarder.completed(); outputEvents.add(ev); } else { if (LOGGER.isErrorEnabled()) { LOGGER.error("Encountered a NULL event: SKIPPING..."); } continue; } } catch (Exception ioe) { failAction("Unable to produce the output: " + ioe.getLocalizedMessage(), ioe); } } return outputEvents; }
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();/*from w w w.ja va2s . co 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:it.geosolutions.geobatch.actions.freemarker.FreeMarkerAction.java
/** * Act as a Gateway interface (EIP):<br> * Try to adapt the effective input EventObject to the expected input a * TemplateDataModel//from ww w.j av a 2 s.com * * @param ieo * The Event Object to test or to transform * @return Adapted data model or null if event cannot be adapted */ public TemplateModelEvent adapter(EventObject ieo) throws ActionException { if (ieo instanceof TemplateModelEvent) { return (TemplateModelEvent) ieo; } else if (ieo instanceof FileSystemEvent) { Map<String, Object> map = new HashMap<String, Object>(); final File file = ((FileSystemEvent) ieo).getSource().getAbsoluteFile(); map.put(FILE_EVENT_PARENTFILE_KEY, file.getParent()); map.put(FILE_EVENT_NAMEFILE_KEY, FilenameUtils.getBaseName(file.getName())); map.put(FILE_EVENT_EXTENSION_KEY, FilenameUtils.getExtension(file.getName())); return new TemplateModelEvent(map); } else { try { return new TemplateModelEvent(processor.wrapRoot(ieo.getSource())); } catch (NullPointerException npe) { // NullPointerException - if tm is null if (LOGGER.isErrorEnabled()) LOGGER.error("The passed event object is null"); } catch (TemplateModelException tme) { // TemplateModelException - if defined objectWrapper can't wrap // the passed object if (LOGGER.isErrorEnabled()) LOGGER.error("Default wrapper can't wrap the passed object"); } } return null; }
From source file:com.twinsoft.convertigo.eclipse.editors.connector.HtmlConnectorDesignComposite.java
private boolean checkEventSource(EventObject event) { boolean isSourceFromConnector = false; Object source = event.getSource(); if (event instanceof EngineEvent) { if (source instanceof DatabaseObject) { Connector connector = ((DatabaseObject) source).getConnector(); if ((connector != null) && (connector.equals(htmlConnector))) isSourceFromConnector = true; }// ww w .j a v a 2 s . co m } return isSourceFromConnector; }
From source file:gtu._work.ui.DirectoryCompareUI.java
/** * TODO//from w ww .j av a 2 s . com */ private void totalScanFiles(EventObject event) { try { // ? final Map<String, Object> searchTextMap = new HashMap<String, Object>(); if (event != null && event.getSource() == searchText && // StringUtils.isNotBlank(searchText.getText()) && ((KeyEvent) event).getKeyCode() != 10)// { return; } else { String text = searchText.getText(); Matcher matcher = SEARCHTEXTPATTERN.matcher(text); if (matcher.matches()) { final String left = StringUtils.trim(matcher.group(1)); String operator = StringUtils.trim(matcher.group(2)); String condition = StringUtils.trim(matcher.group(3)); System.out.println("left = " + left); System.out.println("operator = " + operator); System.out.println("condition = " + condition); SearchTextEnum currentSearchType = null; for (SearchTextEnum e : SearchTextEnum.values()) { if (StringUtils.equals(e.name(), left)) { currentSearchType = e; break; } } Validate.notNull(currentSearchType, "??? : " + left); searchTextMap.put("currentSearchType", currentSearchType); searchTextMap.put("operator", operator); searchTextMap.put("condition", condition); } else if (event != null && event instanceof KeyEvent && ((KeyEvent) event).getKeyCode() == 10) { JCommonUtil._jOptionPane_showMessageDialog_error( "?:" + SEARCHTEXTPATTERN.pattern()); } } // ? final List<DiffMergeStatus> chkList = new ArrayList<DiffMergeStatus>(); A: for (DiffMergeStatus diff2 : DiffMergeStatus.values()) { for (int ii = 0; ii < diffMergeChkBox.length; ii++) { if (StringUtils.equals(diffMergeChkBox[ii].getText(), diff2.toString()) && diffMergeChkBox[ii].isSelected()) { chkList.add(diff2); continue A; } } } // ??? String extensionName = (String) extensionNameComboBox.getSelectedItem(); SingletonMap extensionNameMessageMap = new SingletonMap(); final SingletonMap extensionNameMap = new SingletonMap(); if (StringUtils.equals(EXTENSION_CUSTOM, extensionName)) { String result = JCommonUtil._jOptionPane_showInputDialog("???", EXTENSION_ALL); if (StringUtils.isNotBlank(result)) { String[] arry = result.split(",", -1); extensionNameMap.setValue(arry); extensionNameMessageMap.setValue(Arrays.toString(arry)); } else { extensionNameMap.setValue(new String[] { EXTENSION_ALL }); extensionNameMessageMap.setValue(EXTENSION_ALL); } } else { extensionNameMap.setValue(new String[] { extensionName }); extensionNameMessageMap.setValue(extensionName); } if (extensionNameCache == null) { extensionNameCache = new ExtensionNameCache(); extensionNameCache.extensionNameMap = extensionNameMap; extensionNameCache.extensionNameMessageMap = extensionNameMessageMap; } if (event != null && event.getSource() != extensionNameComboBox) { extensionNameMap.setValue(extensionNameCache.extensionNameMap.getValue()); extensionNameMessageMap.setValue(extensionNameCache.extensionNameMessageMap.getValue()); } FileSearch search = new FileSearch(DirectoryCompareUI.this) { @Override boolean isMatch(InfoObj infoObj) { boolean searchTextResult = true; if (searchTextMap.containsKey("currentSearchType") && searchTextMap.containsKey("operator") && searchTextMap.containsKey("condition")) { SearchTextEnum currentSearchType = (SearchTextEnum) searchTextMap.get("currentSearchType"); String operator = (String) searchTextMap.get("operator"); String condition = (String) searchTextMap.get("condition"); searchTextResult = currentSearchType.isMatch(infoObj, operator, condition); } boolean extensionNameResult = true; if (extensionNameMap.getValue() != null) { String[] extensionNameArray = (String[]) extensionNameMap.getValue(); if (StringUtils.indexOfAny(EXTENSION_ALL, extensionNameArray) == -1) { boolean findOk = false; for (String extension : extensionNameArray) { if ((infoObj.mainFile.isFile() && infoObj.mainFile.getName().toLowerCase().endsWith(extension)) || (infoObj.compareToFile.isFile() && infoObj.compareToFile.getName() .toLowerCase().endsWith(extension))) { findOk = true; break; } } if (!findOk) { extensionNameResult = false; } } } boolean chkListResult = chkList.contains(infoObj.status2); return chkListResult && extensionNameResult && searchTextResult; } }; search.execute(DirectoryCompareUI.this, // "?[?:" + StringUtils.defaultString(searchText.getText()) + "][??:" + extensionNameMessageMap.getValue() + "][:" + chkList + "]"); } catch (Exception ex) { JCommonUtil.handleException(ex, false); } }
From source file:org.jaffa.modules.printing.components.formselectionmaintenance.ui.FormSelectionMaintenanceComponent.java
/** * Show the AdditionalData Component./* w w w . j a va 2 s . c o m*/ * Pass the Additional Data Object if there is one. */ public FormKey doUpdateDetail(GridModelRow selectedRow, String actionPath) throws ApplicationExceptions, FrameworkException { FormKey fk = null; String additionalComponent = null; try { final FormSelectionMaintenanceOutRowDto rowDto = (FormSelectionMaintenanceOutRowDto) selectedRow .get("object"); additionalComponent = rowDto.getAdditionalDataComponent(); Component comp = (Component) run(additionalComponent); BeanUtils.setProperty(comp, getKey1(), getValue1()); if (getKey2() != null) { BeanUtils.setProperty(comp, getKey2(), getValue2()); } if (getKey3() != null) { BeanUtils.setProperty(comp, getKey3(), getValue3()); } if (getKey4() != null) { BeanUtils.setProperty(comp, getKey4(), getValue4()); } if (getKey5() != null) { BeanUtils.setProperty(comp, getKey5(), getValue5()); } if (getKey6() != null) { BeanUtils.setProperty(comp, getKey6(), getValue6()); } // Add a listener and set the additionalDataObject if the additional data component // implements IAdditionalDataObject. if (comp instanceof IAdditionalDataObject) { ((IAdditionalDataObject) comp).setAdditionalDataObject(rowDto.getAdditionalDataObject()); ((IUpdateComponent) comp).addUpdateListener(new IUpdateListener() { public void updateDone(EventObject source) { try { rowDto.setAdditionalDataObject( ((IAdditionalDataObject) source.getSource()).getAdditionalDataObject()); } catch (Exception e) { log.warn("Error setting the Additional Data Object after the Update", e); } } }); } comp.setReturnToFormKey(getResultsFormKey()); // Populate info to allow Web 2.0 component to return to this component if (comp instanceof RiaWrapperComponent) { RiaWrapperComponent c = (RiaWrapperComponent) comp; c.getParameters().setProperty("returnToActionPath", actionPath); c.getParameters().setProperty("returnToFormKey_componentId", comp.getReturnToFormKey().getComponentId()); } fk = comp.display(); } catch (SecurityException se) { log.error("SecurityException Occurred ", se); throw new ApplicationExceptions(new FormSelectionException(FormSelectionException.SECURITY_EXCEPTION)); } catch (IllegalAccessException e) { log.error("IllegalAccessException Occurred ", e); } catch (InvocationTargetException e) { log.error("InvocationTargetException Occurred ", e); } catch (IllegalArgumentException e) { log.error("IllegalArgumentException Occurred ", e); } catch (ApplicationExceptions applicationException) { throw applicationException; } catch (FrameworkException frameworkException) { throw frameworkException; } return fk; }
From source file:org.josso.util.config.SSOConfigurationEventHandler.java
/** * Only handles events of type : "jmx.attribute.change" for the supported resource. */// w w w. java2 s . c o m public boolean isEventEnabled(String eventType, EventObject event) { // This will only handle SSOAgent related events : return source.equals(event.getSource()); }
From source file:org.mule.tck.testmodels.fruit.Banana.java
public void peelEvent(EventObject e) { logger.debug(/*from w w w .jav a 2 s .com*/ "Banana got peel event in peelEvent(EventObject)! MuleEvent says: " + e.getSource().toString()); peel(); }
From source file:org.polymap.core.data.ui.featureselection.FeatureSelectionView.java
protected void init(ILayer _layer) { try {/*from w w w .j av a 2s .c om*/ this.layer = _layer; this.basePartName = layer.getLabel(); setPartName(basePartName); // PropertyChangeListener: layer layer.addPropertyChangeListener(modelListener); // FeatureSelectionListener LayerFeatureSelectionManager fsm = LayerFeatureSelectionManager.forLayer(layer); filter = fsm.getFilter(); fsm.addSelectionChangeListener(selectionListener); // FeatureChangeListener EventManager.instance().subscribe(changeListener = new FeatureChangeListener() { public void featureChanges(List<FeatureChangeEvent> events) { viewer.refresh(); } }, new EventFilter<EventObject>() { public boolean apply(EventObject ev) { return viewer != null && layer.equals(ev.getSource()); } }); this.fs = PipelineFeatureSource.forLayer(layer, false); } catch (Exception e) { PolymapWorkbench.handleError(DataPlugin.PLUGIN_ID, this, "", e); } }
From source file:org.polymap.core.mapeditor.RenderManager.java
public RenderManager(IMap map, MapEditor mapEditor) { super();/*from w ww.j a v a 2 s. c o m*/ this.map = map; this.mapEditor = mapEditor; // model listener EventFilter eventFilter = new EventFilter<EventObject>() { public boolean apply(EventObject ev) { if (RenderManager.this.map == null || ev.getSource() == null) { return false; } if (ev.getSource() instanceof IMap) { IMap eventMap = (IMap) ev.getSource(); return RenderManager.this.map.equals(eventMap); } else if (ev.getSource() instanceof ILayer) { ILayer layer = (ILayer) ev.getSource(); return RenderManager.this.map.equals(layer.getMap()); } return false; } }; ProjectRepository module = ProjectRepository.instance(); module.addEntityListener(modelListener, eventFilter); // feature listener EventManager em = EventManager.instance(); em.subscribe(featureListener, new EventFilter<FeatureChangeEvent>() { public boolean apply(FeatureChangeEvent ev) { return RenderManager.this.map != null && ev.getSource() != null && RenderManager.this.map.equals(ev.getSource().getMap()); } }); }