From: <pat...@us...> - 2011-02-11 13:37:47
|
Revision: 1205 http://cishell.svn.sourceforge.net/cishell/?rev=1205&view=rev Author: pataphil Date: 2011-02-11 13:37:40 +0000 (Fri, 11 Feb 2011) Log Message: ----------- * Highlighting text on the Console depending on what Data is selected on the Data Manager is in the works. * Code cleanup. * Not reviewed. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2011-02-11 13:37:21 UTC (rev 1204) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2011-02-11 13:37:40 UTC (rev 1205) @@ -21,6 +21,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.app.service.scheduler.SchedulerService; import org.cishell.framework.CIShellContext; +import org.cishell.framework.ServiceReferenceDelegate; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; @@ -63,9 +64,9 @@ setText(label); setToolTipText((String)serviceReference.getProperty(AlgorithmProperty.DESCRIPTION)); - DataManagerService dataManager = (DataManagerService) - bundleContext.getService(bundleContext.getServiceReference( - DataManagerService.class.getName())); + DataManagerService dataManager = + (DataManagerService) bundleContext.getService(bundleContext.getServiceReference( + DataManagerService.class.getName())); dataManager.addDataManagerListener(this); dataSelected(dataManager.getSelectedData()); @@ -73,10 +74,12 @@ public void run() { try { - printAlgorithmInformation(this.serviceReference, this.ciShellContext); + ServiceReference uniqueServiceReference = + new ServiceReferenceDelegate(this.serviceReference); + printAlgorithmInformation(uniqueServiceReference, this.ciShellContext); Algorithm algorithm = new AlgorithmWrapper( - this.serviceReference, + uniqueServiceReference, this.bundleContext, this.ciShellContext, this.originalData, @@ -84,43 +87,44 @@ this.converters); SchedulerService scheduler = (SchedulerService) getService(SchedulerService.class); - scheduler.schedule(algorithm, this.serviceReference); + scheduler.schedule(algorithm, uniqueServiceReference); } catch (Throwable exception) { // Just in case an uncaught exception occurs. Eclipse will swallow errors thrown here. exception.printStackTrace(); } } - private void printAlgorithmInformation(ServiceReference ref, CIShellContext ciContext) { + private void printAlgorithmInformation( + ServiceReference serviceReference, CIShellContext ciContext) { // Adjust to log the whole acknowledgement in one block. LogService logger = (LogService) ciContext.getService(LogService.class.getName()); StringBuffer acknowledgement = new StringBuffer(); - String label = (String)ref.getProperty(LABEL); + String label = (String) serviceReference.getProperty(LABEL); if (label != null) { acknowledgement.append("..........\n" + label + " was selected.\n"); } - String authors = (String)ref.getProperty(AUTHORS); + String authors = (String) serviceReference.getProperty(AUTHORS); if (authors != null) { acknowledgement.append("Author(s): " + authors + "\n"); } - String implementers = (String)ref.getProperty(IMPLEMENTERS); + String implementers = (String) serviceReference.getProperty(IMPLEMENTERS); if (implementers != null) { acknowledgement.append("Implementer(s): " + implementers + "\n"); } - String integrators = (String)ref.getProperty(INTEGRATORS); + String integrators = (String) serviceReference.getProperty(INTEGRATORS); if (integrators != null) { acknowledgement.append("Integrator(s): " + integrators + "\n"); } - String reference = (String)ref.getProperty(REFERENCE); - String reference_url = (String)ref.getProperty(REFERENCE_URL); + String reference = (String) serviceReference.getProperty(REFERENCE); + String reference_url = (String) serviceReference.getProperty(REFERENCE_URL); if ((reference != null) && (reference_url != null)) { acknowledgement.append( @@ -129,14 +133,14 @@ acknowledgement.append("Reference: " + reference + "\n"); } - String docu = (String)ref.getProperty(DOCUMENTATION_URL); + String documentationURL = (String) serviceReference.getProperty(DOCUMENTATION_URL); - if (docu != null) { - acknowledgement.append("Documentation: " + docu + "\n"); + if (documentationURL != null) { + acknowledgement.append("Documentation: " + documentationURL + "\n"); } if (acknowledgement.length() > 1) { - logger.log(LogService.LOG_INFO, acknowledgement.toString()); + logger.log(serviceReference, LogService.LOG_INFO, acknowledgement.toString()); } } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2011-02-11 13:37:21 UTC (rev 1204) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2011-02-11 13:37:40 UTC (rev 1205) @@ -24,6 +24,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; +import org.cishell.framework.CIShellContextDelegate; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmCanceledException; import org.cishell.framework.algorithm.AlgorithmCreationCanceledException; @@ -85,15 +86,15 @@ /** * @see org.cishell.framework.algorithm.Algorithm#execute() */ - public Data[] execute() { + public Data[] execute() throws AlgorithmExecutionException { try { - AlgorithmFactory factory = getAlgorithmFactory(bundleContext, serviceReference); + AlgorithmFactory factory = getAlgorithmFactory(bundleContext, this.serviceReference); if (factory == null) { return null; } - String pid = (String) serviceReference.getProperty(Constants.SERVICE_PID); + String pid = (String) this.serviceReference.getProperty(Constants.SERVICE_PID); // Convert input data to the correct format. boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); @@ -109,7 +110,7 @@ } // Create algorithm parameters. - String metatypePID = getMetaTypeID(serviceReference); + String metatypePID = getMetaTypeID(this.serviceReference); // TODO: Refactor this. MetaTypeProvider provider = null; @@ -122,11 +123,15 @@ "provided. (Reason: %s)"; String logMessage = String.format( format, - serviceReference.getProperty(AlgorithmProperty.LABEL), + this.serviceReference.getProperty(AlgorithmProperty.LABEL), e.getMessage()); - log(LogService.LOG_WARNING, logMessage, e); + log(LogService.LOG_ERROR, logMessage, e); return null; + } catch (Exception e) { + log(LogService.LOG_ERROR, e.getMessage(), e); + + return null; } Dictionary<String, Object> parameters = @@ -140,7 +145,11 @@ printParameters(metatypePID, provider, parameters); // Create the algorithm. - algorithm = createAlgorithm(factory, data, parameters, ciShellContext); + algorithm = createAlgorithm( + factory, + data, + parameters, + new CIShellContextDelegate(this.serviceReference, this.ciShellContext)); if (algorithm == null) { return null; @@ -151,9 +160,15 @@ // Execute the algorithm. Data[] outData = tryExecutingAlgorithm(algorithm); - if (outData == null) + if (outData == null) { return null; + } + // TODO: Refactor this into a method? + for (Data datum : outData) { + datum.getMetadata().put(DataProperty.SERVICE_REFERENCE, this.serviceReference); + } + // Process and return the algorithm's output. doParentage(outData); outData = removeNullData(outData); @@ -162,11 +177,11 @@ return outData; } catch (Exception e) { - GUIBuilderService builder = (GUIBuilderService)ciShellContext.getService - (GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) this.ciShellContext.getService( + GUIBuilderService.class.getName()); String errorMessage = "An error occurred while preparing to run " - + "the algorithm \"" + serviceReference.getProperty(AlgorithmProperty.LABEL) + + "the algorithm \"" + this.serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\""; builder.showError("Error!", errorMessage, e); @@ -188,10 +203,10 @@ String details = "The algorithm's pid was \"" + serviceReference.getProperty(Constants.SERVICE_PID) + "\" (potentially useful for debugging purposes)."; - GUIBuilderService builder = - (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) this.ciShellContext.getService( + GUIBuilderService.class.getName()); builder.showError("Error!", errorMessage, details); - this.logger(LogService.LOG_ERROR, errorMessage); + this.log(LogService.LOG_ERROR, errorMessage); } return algorithmFactory; @@ -203,7 +218,7 @@ Dictionary<String, Object> parameters, CIShellContext ciContext) { final String algorithmName = - (String) serviceReference.getProperty(AlgorithmProperty.LABEL); + (String) this.serviceReference.getProperty(AlgorithmProperty.LABEL); // TODO: Call on algorithm invocation service here. try { return factory.createAlgorithm(data, parameters, ciContext); @@ -274,7 +289,7 @@ protected Data[] tryExecutingAlgorithm(Algorithm algorithm) { Data[] outData = null; final String algorithmName = - (String) serviceReference.getProperty(AlgorithmProperty.LABEL); + (String) this.serviceReference.getProperty(AlgorithmProperty.LABEL); try { outData = algorithm.execute(); @@ -291,8 +306,8 @@ e.getMessage()); log(LogService.LOG_ERROR, logMessage, e); } catch (RuntimeException e) { - GUIBuilderService builder = - (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) this.ciShellContext.getService( + GUIBuilderService.class.getName()); String errorMessage = String.format( "An unxpected error occurred while executing the algorithm \"%s\".", algorithmName); @@ -316,7 +331,7 @@ } if (data[i] == null && i < (data.length - 1)) { - logger(LogService.LOG_ERROR, "The converter: " + log(LogService.LOG_ERROR, "The converter: " + converters[i].getClass().getName() + " returned a null result where data was " + "expected when converting the data to give " @@ -330,18 +345,17 @@ return true; } - protected boolean testDataValidityIfPossible(AlgorithmFactory factory, - Data[] data) { + protected boolean testDataValidityIfPossible(AlgorithmFactory factory, Data[] data) { if (factory instanceof DataValidator) { String validation = ((DataValidator) factory).validate(data); if (validation != null && validation.length() > 0) { - String label = (String) serviceReference.getProperty(LABEL); + String label = (String) this.serviceReference.getProperty(LABEL); if (label == null) { label = "Algorithm"; } - logger(LogService.LOG_ERROR, + log(LogService.LOG_ERROR, "INVALID DATA: The data given to \"" + label + "\" is incompatible for this reason: " + validation); return false; @@ -369,7 +383,7 @@ MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); if (metaTypeService != null) { - provider = metaTypeService.getMetaTypeInformation(serviceReference.getBundle()); + provider = metaTypeService.getMetaTypeInformation(this.serviceReference.getBundle()); } if ((factory instanceof ParameterMutator) && (provider != null)) { @@ -397,7 +411,7 @@ } if (provider != null) { - provider = wrapProvider(serviceReference, provider); + provider = wrapProvider(this.serviceReference, provider); } return provider; @@ -414,8 +428,8 @@ Dictionary<String, Object> parameters = new Hashtable<String, Object>(); if (provider != null) { - GUIBuilderService builder = - (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) this.ciShellContext.getService( + GUIBuilderService.class.getName()); // TODO: Make builder.createGUIAndWait return a Dictionary<String, Object>. parameters = builder.createGUIandWait(metatypePID, provider); @@ -465,21 +479,22 @@ UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE); } - protected void logger(int logLevel, String message) { - LogService log = - (LogService) ciShellContext.getService(LogService.class.getName()); - if (log != null) { - log.log(logLevel, message); + protected void log(int logLevel, String message) { + LogService logger = + (LogService) this.ciShellContext.getService(LogService.class.getName()); + if (logger != null) { + logger.log(this.serviceReference, logLevel, message); } else { System.out.println(message); } } protected void log(int logLevel, String message, Throwable exception) { - LogService log = - (LogService) ciShellContext.getService(LogService.class.getName()); - if (log != null) { - log.log(logLevel, message, exception); + LogService logger = + (LogService) this.ciShellContext.getService(LogService.class.getName()); + + if (logger != null) { + logger.log(this.serviceReference, logLevel, message, exception); } else { System.out.println(message); exception.printStackTrace(); @@ -505,7 +520,7 @@ inputParams.append("\n" + key + ": " + value); } - logger.log(LogService.LOG_INFO, inputParams.toString()); + logger.log(this.serviceReference, LogService.LOG_INFO, inputParams.toString()); } } @@ -562,7 +577,7 @@ } // Check and act on parentage settings - String parentage = (String) serviceReference.getProperty("parentage"); + String parentage = (String) this.serviceReference.getProperty("parentage"); if (parentage != null) { parentage = parentage.trim(); if (parentage.equalsIgnoreCase("default")) { @@ -611,7 +626,7 @@ } private void logNullOCDWarning(String pid, String metatype_pid) { - this.logger(LogService.LOG_WARNING, + this.log(LogService.LOG_WARNING, "Warning: could not get object class definition '" + metatype_pid + "' from the algorithm '" + pid + "'"); } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2011-02-11 13:37:21 UTC (rev 1204) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2011-02-11 13:37:40 UTC (rev 1205) @@ -139,7 +139,7 @@ this.actionsToMenuManagers = new HashMap<Action, IMenuManager>(); this.pidsToServiceReferences = new HashMap<String, ServiceReference>(); this.pidsToServiceReferencesCopy = new HashMap<String, ServiceReference>(); - this.logger = (LogService)this.ciShellContext.getService(LogService.class.getName()); + this.logger = (LogService) this.ciShellContext.getService(LogService.class.getName()); /* * The intention of this clearShortcuts was to programmatically clear all of the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |