From: <mwl...@us...> - 2008-07-25 20:39:35
|
Revision: 789 http://cishell.svn.sourceforge.net/cishell/?rev=789&view=rev Author: mwlinnem Date: 2008-07-25 20:39:33 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Small renaming refactor. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2008-07-24 16:23:24 UTC (rev 788) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-07-25 20:39:33 UTC (rev 789) @@ -230,7 +230,7 @@ return metatype_pid; } - protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatype_pid, String pid, AlgorithmFactory factory) { + protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatypePID, String pid, AlgorithmFactory factory) { MetaTypeProvider provider = null; MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); if (metaTypeService != null) { @@ -239,14 +239,14 @@ if (factory instanceof ParameterMutator && provider != null) { try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatype_pid, null); - if (ocd == null) logNullOCDWarning(pid, metatype_pid); + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); + if (ocd == null) logNullOCDWarning(pid, metatypePID); ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); if (ocd != null) { provider = new BasicMetaTypeProvider(ocd); } } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatype_pid); + log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatypePID); } catch (Exception e) { GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-07-25 21:00:12
|
Revision: 790 http://cishell.svn.sourceforge.net/cishell/?rev=790&view=rev Author: mwlinnem Date: 2008-07-25 21:00:08 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Fixed bug in assigning parents that can cause infinite loop. This bug has been around since Oct 2006! Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2008-07-25 20:39:33 UTC (rev 789) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-07-25 21:00:08 UTC (rev 790) @@ -389,7 +389,7 @@ Object parent = outData[i].getMetadata().get(DataProperty.PARENT); if (parent != null) { - for (int j=0; j < data.length; i++) { + for (int j=0; j < data.length; j++) { if (parent == data[j]) { outData[i].getMetadata().put(DataProperty.PARENT, originalData[j]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-08-05 18:20:02
|
Revision: 796 http://cishell.svn.sourceforge.net/cishell/?rev=796&view=rev Author: mwlinnem Date: 2008-08-05 18:19:56 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Now handles error case for when AlgorithmFactory cannot be created. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2008-08-01 18:19:19 UTC (rev 795) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2008-08-05 18:19:56 UTC (rev 796) @@ -52,241 +52,251 @@ import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; - public class AlgorithmWrapper implements Algorithm, AlgorithmProperty, ProgressTrackable { - protected ServiceReference ref; - protected BundleContext bContext; - protected CIShellContext ciContext; - protected Data[] originalData; - protected Data[] data; - protected Converter[][] converters; - protected ProgressMonitor progressMonitor; - protected Algorithm algorithm; - - public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, - CIShellContext ciContext, Data[] originalData, Data[] data, - Converter[][] converters) { - this.ref = ref; - this.bContext = bContext; - this.ciContext = ciContext; - this.originalData = originalData; - this.data = data; - this.converters = converters; - this.progressMonitor = null; - } + protected ServiceReference ref; + protected BundleContext bContext; + protected CIShellContext ciContext; + protected Data[] originalData; + protected Data[] data; + protected Converter[][] converters; + protected ProgressMonitor progressMonitor; + protected Algorithm algorithm; - /** - * @see org.cishell.framework.algorithm.Algorithm#execute() - */ - public Data[] execute() { - AlgorithmFactory factory = (AlgorithmFactory) bContext.getService(ref); - String pid = (String)ref.getProperty(Constants.SERVICE_PID); - - // convert input data to the correct format - boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); - if (!conversionSuccessful) return null; - boolean inputIsValid = testDataValidityIfPossible(factory, data); - if (!inputIsValid) return null; - - // create algorithm parameters - String metatype_pid = getMetaTypeID(ref); - - MetaTypeProvider provider = getPossiblyMutatedMetaTypeProvider(metatype_pid, pid, factory); - Dictionary parameters = getUserEnteredParameters(metatype_pid, provider); - - // check to see if the user cancelled the operation - if(parameters == null) return null; - - printParameters(metatype_pid, provider, parameters); - - // create the algorithm - algorithm = createAlgorithm(factory, data, parameters, ciContext); - if (algorithm == null) return null; - trackAlgorithmIfPossible(algorithm); - - // execute the algorithm - Data[] outData = tryExecutingAlgorithm(algorithm); - if (outData == null) return null; - - // process and return the algorithm's output - doParentage(outData); - outData = removeNullData(outData); - addDataToDataManager(outData); + public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, + Data[] originalData, Data[] data, Converter[][] converters) { + this.ref = ref; + this.bContext = bContext; + this.ciContext = ciContext; + this.originalData = originalData; + this.data = data; + this.converters = converters; + this.progressMonitor = null; + } - return outData; - } - - protected Algorithm createAlgorithm(AlgorithmFactory factory, Data[] data, Dictionary parameters, CIShellContext ciContext) { - try { - return factory.createAlgorithm(data, parameters, ciContext); - } catch (Exception e) { - String errorMessage = "Unexpected error occurred while creating algorithm " + - " \""+ref.getProperty(AlgorithmProperty.LABEL)+".\""; - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - builder.showError("Error!", errorMessage, e); - log(LogService.LOG_ERROR, errorMessage, e); - return null; - } - } - - protected Data[] removeNullData(Data[] outData) { - if (outData != null) { - List goodData = new ArrayList(); - for (int i=0; i < outData.length; i++) { - if (outData[i] != null) { - goodData.add(outData[i]); - } - } - - outData = (Data[]) goodData.toArray(new Data[0]); - } - - return outData; - } - - protected void addDataToDataManager(Data[] outData) { - if (outData != null) { - DataManagerService dataManager = (DataManagerService) - bContext.getService(bContext.getServiceReference( - DataManagerService.class.getName())); - - if (outData.length != 0) { - dataManager.setSelectedData(outData); - } - } - } - - protected Data[] tryExecutingAlgorithm(Algorithm algorithm) { - Data[] outData = null; - try { - outData = algorithm.execute(); - } catch (AlgorithmExecutionException e) { - log(LogService.LOG_ERROR, - "The Algorithm: \""+ref.getProperty(AlgorithmProperty.LABEL)+ - "\" had an error while executing: "+e.getMessage()); - } catch (RuntimeException e) { - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - - builder.showError("Error!", "An unexpected exception occurred while " - +"executing \""+ref.getProperty(AlgorithmProperty.LABEL)+".\"", e); - } - - return outData; - } - - protected boolean tryConvertingDataToRequiredFormat(Data[] data, Converter[][] converters) { - for (int i=0; i < data.length; i++) { - if (converters[i] != null) { - try { - data[i] = converters[i][0].convert(data[i]); - } catch (ConversionException e) { - log(LogService.LOG_ERROR,"The conversion of data to give" + - " the algorithm failed for this reason: "+e.getMessage(), e); - return false; - } + /** + * @see org.cishell.framework.algorithm.Algorithm#execute() + */ + public Data[] execute() { + AlgorithmFactory factory = getAlgorithmFactory(bContext, ref); + if (factory == null) return null; + String pid = (String) ref.getProperty(Constants.SERVICE_PID); - if (data[i] == null && i < (data.length - 1)) { - log(LogService.LOG_ERROR, "The converter: " + - converters[i].getClass().getName() + - " returned a null result where data was expected when" + - " converting the data to give the algorithm."); - return false; - } - converters[i] = null; - } - } - - return true; - } - - 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) ref.getProperty(LABEL); - if (label == null) { - label = "Algorithm"; - } - - log(LogService.LOG_ERROR,"INVALID DATA: The data given to \""+label+"\" is incompatible for this reason: "+validation); - return false; - } - } - - return true; - } - - protected String getMetaTypeID(ServiceReference ref) { - String pid = (String)ref.getProperty(Constants.SERVICE_PID); - String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); - - if (metatype_pid == null) { - metatype_pid = pid; - } - - return metatype_pid; - } - - protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatypePID, String pid, AlgorithmFactory factory) { - MetaTypeProvider provider = null; - MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); - if (metaTypeService != null) { - provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); - } + // convert input data to the correct format + boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); + if (!conversionSuccessful) return null; + boolean inputIsValid = testDataValidityIfPossible(factory, data); + if (!inputIsValid) return null; - if (factory instanceof ParameterMutator && provider != null) { - try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); - if (ocd == null) logNullOCDWarning(pid, metatypePID); - ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); - if (ocd != null) { - provider = new BasicMetaTypeProvider(ocd); - } - } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid+" has an invalid metatype id: "+metatypePID); - } catch (Exception e) { - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - String errorMessage = "An error occurred while preparing to run the algorithm " - +ref.getProperty(AlgorithmProperty.LABEL)+".\""; - builder.showError("Error!", errorMessage, e); - log(LogService.LOG_ERROR, errorMessage, e); - } - } - - if (provider != null) { - provider = wrapProvider(ref, provider); - } - - return provider; - } - - protected void trackAlgorithmIfPossible(Algorithm algorithm) { - if (progressMonitor != null && algorithm instanceof ProgressTrackable) { - ((ProgressTrackable)algorithm).setProgressMonitor(progressMonitor); - } - } - - protected Dictionary getUserEnteredParameters(String metatype_pid, MetaTypeProvider provider) { - Dictionary parameters = new Hashtable(); - if (provider != null) { - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); - - parameters = builder.createGUIandWait(metatype_pid, provider); - } - - return parameters; - } - + // create algorithm parameters + String metatype_pid = getMetaTypeID(ref); + + MetaTypeProvider provider = getPossiblyMutatedMetaTypeProvider(metatype_pid, pid, factory); + Dictionary parameters = getUserEnteredParameters(metatype_pid, provider); + + // check to see if the user cancelled the operation + if (parameters == null) return null; + + printParameters(metatype_pid, provider, parameters); + + // create the algorithm + algorithm = createAlgorithm(factory, data, parameters, ciContext); + if (algorithm == null) return null; + trackAlgorithmIfPossible(algorithm); + + // execute the algorithm + Data[] outData = tryExecutingAlgorithm(algorithm); + if (outData == null) return null; + + // process and return the algorithm's output + doParentage(outData); + outData = removeNullData(outData); + addDataToDataManager(outData); + + return outData; + } + + protected AlgorithmFactory getAlgorithmFactory(BundleContext bContext, ServiceReference ref) { + AlgorithmFactory algorithmFactory = (AlgorithmFactory) bContext.getService(ref); + if (algorithmFactory == null) { + String errorMessage = "Could not create AlgorithmFactory for the algorithm " + "\"" + + ref.getProperty(AlgorithmProperty.LABEL) + "\"."; + String details = "The algorithm's pid was \"" + ref.getProperty(Constants.SERVICE_PID) + + "\" (potentially useful for debugging purposes)."; + GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + builder.showError("Error!", errorMessage, details); + log(LogService.LOG_ERROR, errorMessage); + } + + return algorithmFactory; + } + + protected Algorithm createAlgorithm(AlgorithmFactory factory, Data[] data, Dictionary parameters, + CIShellContext ciContext) { + try { + return factory.createAlgorithm(data, parameters, ciContext); + } catch (Exception e) { + String errorMessage = "Unexpected error occurred while creating algorithm " + " \"" + + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; + GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); + return null; + } + } + + protected Data[] removeNullData(Data[] outData) { + if (outData != null) { + List goodData = new ArrayList(); + for (int i = 0; i < outData.length; i++) { + if (outData[i] != null) { + goodData.add(outData[i]); + } + } + + outData = (Data[]) goodData.toArray(new Data[0]); + } + + return outData; + } + + protected void addDataToDataManager(Data[] outData) { + if (outData != null) { + DataManagerService dataManager = (DataManagerService) bContext.getService(bContext + .getServiceReference(DataManagerService.class.getName())); + + if (outData.length != 0) { + dataManager.setSelectedData(outData); + } + } + } + + protected Data[] tryExecutingAlgorithm(Algorithm algorithm) { + Data[] outData = null; + try { + outData = algorithm.execute(); + } catch (AlgorithmExecutionException e) { + log(LogService.LOG_ERROR, "The Algorithm: \"" + ref.getProperty(AlgorithmProperty.LABEL) + + "\" had an error while executing: " + e.getMessage()); + } catch (RuntimeException e) { + GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + + builder.showError("Error!", "An unexpected exception occurred while " + "executing \"" + + ref.getProperty(AlgorithmProperty.LABEL) + ".\"", e); + } + + return outData; + } + + protected boolean tryConvertingDataToRequiredFormat(Data[] data, Converter[][] converters) { + for (int i = 0; i < data.length; i++) { + if (converters[i] != null) { + try { + data[i] = converters[i][0].convert(data[i]); + } catch (ConversionException e) { + log(LogService.LOG_ERROR, "The conversion of data to give" + + " the algorithm failed for this reason: " + e.getMessage(), e); + return false; + } + + if (data[i] == null && i < (data.length - 1)) { + log(LogService.LOG_ERROR, "The converter: " + converters[i].getClass().getName() + + " returned a null result where data was expected when" + + " converting the data to give the algorithm."); + return false; + } + converters[i] = null; + } + } + + return true; + } + + 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) ref.getProperty(LABEL); + if (label == null) { + label = "Algorithm"; + } + + log(LogService.LOG_ERROR, "INVALID DATA: The data given to \"" + label + + "\" is incompatible for this reason: " + validation); + return false; + } + } + + return true; + } + + protected String getMetaTypeID(ServiceReference ref) { + String pid = (String) ref.getProperty(Constants.SERVICE_PID); + String metatype_pid = (String) ref.getProperty(PARAMETERS_PID); + + if (metatype_pid == null) { + metatype_pid = pid; + } + + return metatype_pid; + } + + protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatypePID, String pid, + AlgorithmFactory factory) { + MetaTypeProvider provider = null; + MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); + if (metaTypeService != null) { + provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); + } + + if (factory instanceof ParameterMutator && provider != null) { + try { + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); + if (ocd == null) logNullOCDWarning(pid, metatypePID); + ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + if (ocd != null) { + provider = new BasicMetaTypeProvider(ocd); + } + } catch (IllegalArgumentException e) { + log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID); + } catch (Exception e) { + GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + String errorMessage = "An error occurred while preparing to run the algorithm " + + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); + } + } + + if (provider != null) { + provider = wrapProvider(ref, provider); + } + + return provider; + } + + protected void trackAlgorithmIfPossible(Algorithm algorithm) { + if (progressMonitor != null && algorithm instanceof ProgressTrackable) { + ((ProgressTrackable) algorithm).setProgressMonitor(progressMonitor); + } + } + + protected Dictionary getUserEnteredParameters(String metatype_pid, MetaTypeProvider provider) { + Dictionary parameters = new Hashtable(); + if (provider != null) { + GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + + parameters = builder.createGUIandWait(metatype_pid, provider); + } + + return parameters; + } + // wrap the provider to provide special functionality, such as overriding default values of attributes through // preferences. protected MetaTypeProvider wrapProvider(ServiceReference algRef, MetaTypeProvider unwrappedProvider) { ConfigurationAdmin ca = getConfigurationAdmin(); - + if (ca != null && hasParamDefaultPreferences(algRef)) { String standardServicePID = (String) algRef.getProperty(Constants.SERVICE_PID); String paramOverrideConfPID = standardServicePID + UserPrefsProperty.PARAM_PREFS_CONF_SUFFIX; @@ -304,7 +314,7 @@ return unwrappedProvider; } - + protected boolean hasParamDefaultPreferences(ServiceReference algRef) { String prefsToPublish = (String) algRef.getProperty(UserPrefsProperty.PREFS_PUBLISHED_KEY); if (prefsToPublish == null) { @@ -313,147 +323,141 @@ return prefsToPublish.contains(UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE); } - - protected void log(int logLevel, String message) { - LogService log = (LogService) ciContext.getService(LogService.class.getName()); - if (log != null) { - log.log(logLevel, message); - } else { - System.out.println(message); - } - } - protected void log(int logLevel, String message, Throwable exception) { - LogService log = (LogService) ciContext.getService(LogService.class.getName()); - if (log != null) { - log.log(logLevel, message, exception); - } else { - System.out.println(message); - exception.printStackTrace(); - } - } - - protected void printParameters(String metatype_pid, MetaTypeProvider provider, Dictionary parameters) { - LogService logger = getLogService(); - Map idToLabelMap = setupIdToLabelMap(metatype_pid, provider); - - if (logger != null && !parameters.isEmpty()) { - //adjust to log all input parameters in one block - StringBuffer inputParams = new StringBuffer("\n"+"Input Parameters:"); - - for (Enumeration e = parameters.keys(); e - .hasMoreElements();) { - String key = (String) e.nextElement(); - Object value = parameters.get(key); - - key = (String) idToLabelMap.get(key); - inputParams.append("\n"+key+": "+value); - - } - logger.log(LogService.LOG_INFO, inputParams.toString()); - } - } - - protected Map setupIdToLabelMap(String metatype_pid, MetaTypeProvider provider) { - Map idToLabelMap = new HashMap(); - if (provider != null) { - ObjectClassDefinition ocd = null; - try { - ocd = provider.getObjectClassDefinition(metatype_pid, null); - - if (ocd != null) { - AttributeDefinition[] attr = - ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - - for (int i=0; i < attr.length; i++) { - String id = attr[i].getID(); - String label = attr[i].getName(); - - idToLabelMap.put(id, label); - } - } - } catch (IllegalArgumentException e) {} - } - - return idToLabelMap; - } - - //only does anything if parentage=default so far... - protected void doParentage(Data[] outData) { - //make sure the parent set is the original Data and not the - //converted data... - if (outData != null && data != null && originalData != null - && originalData.length == data.length) { - for (int i=0; i < outData.length; i++) { - if (outData[i] != null) { - Object parent = outData[i].getMetadata().get(DataProperty.PARENT); - - if (parent != null) { - for (int j=0; j < data.length; j++) { - if (parent == data[j]) { - outData[i].getMetadata().put(DataProperty.PARENT, - originalData[j]); - break; - } - } - } - } - } - } - - //check and act on parentage settings - String parentage = (String)ref.getProperty("parentage"); - if (parentage != null) { - parentage = parentage.trim(); - if (parentage.equalsIgnoreCase("default")) { - if (originalData != null && originalData.length > 0 && originalData[0] != null) { - - for (int i=0; i < outData.length; i++) { - //if they don't have a parent set already then we set one - if (outData[i] != null && - outData[i].getMetadata().get(DataProperty.PARENT) == null) { - outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); - } - } - } - } - } - } - + protected void log(int logLevel, String message) { + LogService log = (LogService) ciContext.getService(LogService.class.getName()); + if (log != null) { + log.log(logLevel, message); + } else { + System.out.println(message); + } + } + + protected void log(int logLevel, String message, Throwable exception) { + LogService log = (LogService) ciContext.getService(LogService.class.getName()); + if (log != null) { + log.log(logLevel, message, exception); + } else { + System.out.println(message); + exception.printStackTrace(); + } + } + + protected void printParameters(String metatype_pid, MetaTypeProvider provider, Dictionary parameters) { + LogService logger = getLogService(); + Map idToLabelMap = setupIdToLabelMap(metatype_pid, provider); + + if (logger != null && !parameters.isEmpty()) { + // adjust to log all input parameters in one block + StringBuffer inputParams = new StringBuffer("\n" + "Input Parameters:"); + + for (Enumeration e = parameters.keys(); e.hasMoreElements();) { + String key = (String) e.nextElement(); + Object value = parameters.get(key); + + key = (String) idToLabelMap.get(key); + inputParams.append("\n" + key + ": " + value); + + } + logger.log(LogService.LOG_INFO, inputParams.toString()); + } + } + + protected Map setupIdToLabelMap(String metatype_pid, MetaTypeProvider provider) { + Map idToLabelMap = new HashMap(); + if (provider != null) { + ObjectClassDefinition ocd = null; + try { + ocd = provider.getObjectClassDefinition(metatype_pid, null); + + if (ocd != null) { + AttributeDefinition[] attr = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); + + for (int i = 0; i < attr.length; i++) { + String id = attr[i].getID(); + String label = attr[i].getName(); + + idToLabelMap.put(id, label); + } + } + } catch (IllegalArgumentException e) { + } + } + + return idToLabelMap; + } + + // only does anything if parentage=default so far... + protected void doParentage(Data[] outData) { + // make sure the parent set is the original Data and not the + // converted data... + if (outData != null && data != null && originalData != null && originalData.length == data.length) { + for (int i = 0; i < outData.length; i++) { + if (outData[i] != null) { + Object parent = outData[i].getMetadata().get(DataProperty.PARENT); + + if (parent != null) { + for (int j = 0; j < data.length; j++) { + if (parent == data[j]) { + outData[i].getMetadata().put(DataProperty.PARENT, originalData[j]); + break; + } + } + } + } + } + } + + // check and act on parentage settings + String parentage = (String) ref.getProperty("parentage"); + if (parentage != null) { + parentage = parentage.trim(); + if (parentage.equalsIgnoreCase("default")) { + if (originalData != null && originalData.length > 0 && originalData[0] != null) { + + for (int i = 0; i < outData.length; i++) { + // if they don't have a parent set already then we set one + if (outData[i] != null && outData[i].getMetadata().get(DataProperty.PARENT) == null) { + outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); + } + } + } + } + } + } + private LogService getLogService() { ServiceReference serviceReference = bContext.getServiceReference(DataManagerService.class.getName()); LogService log = null; - + if (serviceReference != null) { - log = (LogService) bContext.getService( - bContext.getServiceReference(LogService.class.getName())); + log = (LogService) bContext.getService(bContext.getServiceReference(LogService.class.getName())); } - + return log; } - + private ConfigurationAdmin getConfigurationAdmin() { ServiceReference serviceReference = bContext.getServiceReference(ConfigurationAdmin.class.getName()); ConfigurationAdmin ca = null; - + if (serviceReference != null) { - ca = (ConfigurationAdmin) bContext.getService( - bContext.getServiceReference(ConfigurationAdmin.class.getName())); + ca = (ConfigurationAdmin) bContext.getService(bContext.getServiceReference(ConfigurationAdmin.class + .getName())); } - + return ca; } - + private void logNullOCDWarning(String pid, String metatype_pid) { - this.log(LogService.LOG_WARNING, - "Warning: could not get object class definition '" + metatype_pid + "' from the algorithm '" + pid + "'"); + this.log(LogService.LOG_WARNING, "Warning: could not get object class definition '" + metatype_pid + + "' from the algorithm '" + pid + "'"); } public ProgressMonitor getProgressMonitor() { if (algorithm instanceof ProgressTrackable) { return progressMonitor; - } - else { + } else { return null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-01-05 17:54:26
|
Revision: 827 http://cishell.svn.sourceforge.net/cishell/?rev=827&view=rev Author: pataphil Date: 2009-01-05 17:54:22 +0000 (Mon, 05 Jan 2009) Log Message: ----------- Modified to actually log exceptions where appropriate. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2009-01-02 17:59:21 UTC (rev 826) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2009-01-05 17:54:22 UTC (rev 827) @@ -176,7 +176,7 @@ outData = algorithm.execute(); } catch (AlgorithmExecutionException e) { log(LogService.LOG_ERROR, "The Algorithm: \"" + ref.getProperty(AlgorithmProperty.LABEL) - + "\" had an error while executing: " + e.getMessage()); + + "\" had an error while executing: " + e.getMessage(), e); } catch (RuntimeException e) { GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); @@ -258,7 +258,7 @@ provider = new BasicMetaTypeProvider(ocd); } } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID); + log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e); } catch (Exception e) { GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); String errorMessage = "An error occurred while preparing to run the algorithm " This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-02-20 18:25:52
|
Revision: 862 http://cishell.svn.sourceforge.net/cishell/?rev=862&view=rev Author: pataphil Date: 2009-02-20 18:25:45 +0000 (Fri, 20 Feb 2009) Log Message: ----------- * Changed AlgorithmWrapper to "fail" upon the target algorithm's mutateParameters failing. * Cleaned up code a little bit. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2009-02-20 17:54:54 UTC (rev 861) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2009-02-20 18:25:45 UTC (rev 862) @@ -77,42 +77,74 @@ * @see org.cishell.framework.algorithm.Algorithm#execute() */ public Data[] execute() { - AlgorithmFactory factory = getAlgorithmFactory(bContext, ref); - if (factory == null) return null; - String pid = (String) ref.getProperty(Constants.SERVICE_PID); + try { + AlgorithmFactory factory = getAlgorithmFactory(bContext, ref); + + if (factory == null) + return null; + + String pid = (String)ref.getProperty(Constants.SERVICE_PID); - // convert input data to the correct format - boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); - if (!conversionSuccessful) return null; - boolean inputIsValid = testDataValidityIfPossible(factory, data); - if (!inputIsValid) return null; + // Convert input data to the correct format. + boolean conversionSuccessful = + tryConvertingDataToRequiredFormat(data, converters); + + if (!conversionSuccessful) + return null; + + boolean inputIsValid = testDataValidityIfPossible(factory, data); + + if (!inputIsValid) + return null; - // create algorithm parameters - String metatype_pid = getMetaTypeID(ref); + // Create algorithm parameters. + String metatype_pid = getMetaTypeID(ref); - MetaTypeProvider provider = getPossiblyMutatedMetaTypeProvider(metatype_pid, pid, factory); - Dictionary parameters = getUserEnteredParameters(metatype_pid, provider); + MetaTypeProvider provider = + getPossiblyMutatedMetaTypeProvider(metatype_pid, pid, factory); + + Dictionary parameters = + getUserEnteredParameters(metatype_pid, provider); - // check to see if the user cancelled the operation - if (parameters == null) return null; + // Check to see if the user cancelled the operation. + if (parameters == null) + return null; - printParameters(metatype_pid, provider, parameters); + printParameters(metatype_pid, provider, parameters); - // create the algorithm - algorithm = createAlgorithm(factory, data, parameters, ciContext); - if (algorithm == null) return null; - trackAlgorithmIfPossible(algorithm); + // Create the algorithm. + algorithm = createAlgorithm(factory, data, parameters, ciContext); + + if (algorithm == null) + return null; + + trackAlgorithmIfPossible(algorithm); - // execute the algorithm - Data[] outData = tryExecutingAlgorithm(algorithm); - if (outData == null) return null; + // Execute the algorithm. + Data[] outData = tryExecutingAlgorithm(algorithm); + + if (outData == null) + return null; - // process and return the algorithm's output - doParentage(outData); - outData = removeNullData(outData); - addDataToDataManager(outData); + // Process and return the algorithm's output. + doParentage(outData); + outData = removeNullData(outData); + addDataToDataManager(outData); - return outData; + return outData; + } + catch (Exception e) { + GUIBuilderService builder = (GUIBuilderService)ciContext.getService + (GUIBuilderService.class.getName()); + + String errorMessage = "An error occurred while preparing to run the " + + "algorithm \"" + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; + + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); + } + + return null; } protected AlgorithmFactory getAlgorithmFactory(BundleContext bContext, ServiceReference ref) { @@ -259,12 +291,6 @@ } } catch (IllegalArgumentException e) { log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e); - } catch (Exception e) { - GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); - String errorMessage = "An error occurred while preparing to run the algorithm " - + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; - builder.showError("Error!", errorMessage, e); - log(LogService.LOG_ERROR, errorMessage, e); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-06-20 20:02:27
|
Revision: 871 http://cishell.svn.sourceforge.net/cishell/?rev=871&view=rev Author: pataphil Date: 2009-06-20 20:02:22 +0000 (Sat, 20 Jun 2009) Log Message: ----------- * Now when algorithms output multiple data items, only the first one is selected in the Data Manager. * Reviewed Chintan. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2009-06-18 19:36:47 UTC (rev 870) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2009-06-20 20:02:22 UTC (rev 871) @@ -197,7 +197,12 @@ .getServiceReference(DataManagerService.class.getName())); if (outData.length != 0) { - dataManager.setSelectedData(outData); + for (int ii = 0; ii < outData.length; ii++) { + dataManager.addData(outData[ii]); + } + + Data[] dataToSelect = new Data[] { outData[0] }; + dataManager.setSelectedData(dataToSelect); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-07-28 20:27:56
|
Revision: 903 http://cishell.svn.sourceforge.net/cishell/?rev=903&view=rev Author: jrbibers Date: 2009-07-28 20:27:43 +0000 (Tue, 28 Jul 2009) Log Message: ----------- Wrapped to 80 characters while reading. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2009-07-27 16:07:28 UTC (rev 902) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2009-07-28 20:27:43 UTC (rev 903) @@ -52,7 +52,8 @@ import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; -public class AlgorithmWrapper implements Algorithm, AlgorithmProperty, ProgressTrackable { +public class AlgorithmWrapper + implements Algorithm, AlgorithmProperty, ProgressTrackable { protected ServiceReference ref; protected BundleContext bContext; protected CIShellContext ciContext; @@ -62,8 +63,12 @@ protected ProgressMonitor progressMonitor; protected Algorithm algorithm; - public AlgorithmWrapper(ServiceReference ref, BundleContext bContext, CIShellContext ciContext, - Data[] originalData, Data[] data, Converter[][] converters) { + public AlgorithmWrapper(ServiceReference ref, + BundleContext bContext, + CIShellContext ciContext, + Data[] originalData, + Data[] data, + Converter[][] converters) { this.ref = ref; this.bContext = bContext; this.ciContext = ciContext; @@ -80,8 +85,9 @@ try { AlgorithmFactory factory = getAlgorithmFactory(bContext, ref); - if (factory == null) + if (factory == null) { return null; + } String pid = (String)ref.getProperty(Constants.SERVICE_PID); @@ -89,8 +95,9 @@ boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); - if (!conversionSuccessful) + if (!conversionSuccessful) { return null; + } boolean inputIsValid = testDataValidityIfPossible(factory, data); @@ -107,16 +114,18 @@ getUserEnteredParameters(metatype_pid, provider); // Check to see if the user cancelled the operation. - if (parameters == null) + if (parameters == null) { return null; + } printParameters(metatype_pid, provider, parameters); // Create the algorithm. algorithm = createAlgorithm(factory, data, parameters, ciContext); - if (algorithm == null) + if (algorithm == null) { return null; + } trackAlgorithmIfPossible(algorithm); @@ -137,8 +146,9 @@ GUIBuilderService builder = (GUIBuilderService)ciContext.getService (GUIBuilderService.class.getName()); - String errorMessage = "An error occurred while preparing to run the " + - "algorithm \"" + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; + String errorMessage = "An error occurred while preparing to run " + + "the algorithm \"" + ref.getProperty(AlgorithmProperty.LABEL) + + ".\""; builder.showError("Error!", errorMessage, e); log(LogService.LOG_ERROR, errorMessage, e); @@ -147,14 +157,19 @@ return null; } - protected AlgorithmFactory getAlgorithmFactory(BundleContext bContext, ServiceReference ref) { - AlgorithmFactory algorithmFactory = (AlgorithmFactory) bContext.getService(ref); + protected AlgorithmFactory getAlgorithmFactory(BundleContext bContext, + ServiceReference ref) { + AlgorithmFactory algorithmFactory = + (AlgorithmFactory) bContext.getService(ref); if (algorithmFactory == null) { - String errorMessage = "Could not create AlgorithmFactory for the algorithm " + "\"" - + ref.getProperty(AlgorithmProperty.LABEL) + "\"."; - String details = "The algorithm's pid was \"" + ref.getProperty(Constants.SERVICE_PID) + - "\" (potentially useful for debugging purposes)."; - GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + String errorMessage = + "Could not create AlgorithmFactory for the algorithm " + + "\"" + ref.getProperty(AlgorithmProperty.LABEL) + "\"."; + String details = "The algorithm's pid was \"" + + ref.getProperty(Constants.SERVICE_PID) + + "\" (potentially useful for debugging purposes)."; + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); builder.showError("Error!", errorMessage, details); log(LogService.LOG_ERROR, errorMessage); } @@ -162,14 +177,18 @@ return algorithmFactory; } - protected Algorithm createAlgorithm(AlgorithmFactory factory, Data[] data, Dictionary parameters, - CIShellContext ciContext) { + protected Algorithm createAlgorithm(AlgorithmFactory factory, + Data[] data, + Dictionary parameters, + CIShellContext ciContext) { try { return factory.createAlgorithm(data, parameters, ciContext); } catch (Exception e) { - String errorMessage = "Unexpected error occurred while creating algorithm " + " \"" + String errorMessage = + "Unexpected error occurred while creating algorithm " + " \"" + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; - GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); builder.showError("Error!", errorMessage, e); log(LogService.LOG_ERROR, errorMessage, e); return null; @@ -193,8 +212,10 @@ protected void addDataToDataManager(Data[] outData) { if (outData != null) { - DataManagerService dataManager = (DataManagerService) bContext.getService(bContext - .getServiceReference(DataManagerService.class.getName())); + DataManagerService dataManager = (DataManagerService) + bContext.getService( + bContext.getServiceReference( + DataManagerService.class.getName())); if (outData.length != 0) { for (int ii = 0; ii < outData.length; ii++) { @@ -212,33 +233,40 @@ try { outData = algorithm.execute(); } catch (AlgorithmExecutionException e) { - log(LogService.LOG_ERROR, "The Algorithm: \"" + ref.getProperty(AlgorithmProperty.LABEL) + log(LogService.LOG_ERROR, "The Algorithm: \"" + + ref.getProperty(AlgorithmProperty.LABEL) + "\" had an error while executing: " + e.getMessage(), e); } catch (RuntimeException e) { - GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); - builder.showError("Error!", "An unexpected exception occurred while " + "executing \"" + builder.showError("Error!", + "An unexpected exception occurred while " + "executing \"" + ref.getProperty(AlgorithmProperty.LABEL) + ".\"", e); } return outData; } - protected boolean tryConvertingDataToRequiredFormat(Data[] data, Converter[][] converters) { + protected boolean tryConvertingDataToRequiredFormat( + Data[] data, Converter[][] converters) { for (int i = 0; i < data.length; i++) { if (converters[i] != null) { try { data[i] = converters[i][0].convert(data[i]); } catch (ConversionException e) { - log(LogService.LOG_ERROR, "The conversion of data to give" - + " the algorithm failed for this reason: " + e.getMessage(), e); + log(LogService.LOG_ERROR, + "Error: Unable to convert data for use by the " + + "algorithm:\n " + e.getMessage(), e); return false; } if (data[i] == null && i < (data.length - 1)) { - log(LogService.LOG_ERROR, "The converter: " + converters[i].getClass().getName() - + " returned a null result where data was expected when" - + " converting the data to give the algorithm."); + log(LogService.LOG_ERROR, "The converter: " + + converters[i].getClass().getName() + + " returned a null result where data was " + + "expected when converting the data to give " + + "the algorithm."); return false; } converters[i] = null; @@ -248,7 +276,8 @@ 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); @@ -258,7 +287,8 @@ label = "Algorithm"; } - log(LogService.LOG_ERROR, "INVALID DATA: The data given to \"" + label + log(LogService.LOG_ERROR, + "INVALID DATA: The data given to \"" + label + "\" is incompatible for this reason: " + validation); return false; } @@ -278,24 +308,27 @@ return metatype_pid; } - protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider(String metatypePID, String pid, - AlgorithmFactory factory) { + protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider( + String metatypePID, String pid, AlgorithmFactory factory) { MetaTypeProvider provider = null; - MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); + MetaTypeService metaTypeService = (MetaTypeService) + Activator.getService(MetaTypeService.class.getName()); if (metaTypeService != null) { provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); } if (factory instanceof ParameterMutator && provider != null) { try { - ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); + ObjectClassDefinition ocd = + provider.getObjectClassDefinition(metatypePID, null); if (ocd == null) logNullOCDWarning(pid, metatypePID); ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); if (ocd != null) { provider = new BasicMetaTypeProvider(ocd); } } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e); + log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + + metatypePID, e); } } @@ -312,10 +345,12 @@ } } - protected Dictionary getUserEnteredParameters(String metatype_pid, MetaTypeProvider provider) { + protected Dictionary getUserEnteredParameters(String metatype_pid, + MetaTypeProvider provider) { Dictionary parameters = new Hashtable(); if (provider != null) { - GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = (GUIBuilderService) + ciContext.getService(GUIBuilderService.class.getName()); parameters = builder.createGUIandWait(metatype_pid, provider); } @@ -323,19 +358,26 @@ return parameters; } - // wrap the provider to provide special functionality, such as overriding default values of attributes through - // preferences. - protected MetaTypeProvider wrapProvider(ServiceReference algRef, MetaTypeProvider unwrappedProvider) { + /* Wrap the provider to provide special functionality, such as overriding + * default values of attributes through preferences. + */ + protected MetaTypeProvider wrapProvider( + ServiceReference algRef, MetaTypeProvider unwrappedProvider) { ConfigurationAdmin ca = getConfigurationAdmin(); if (ca != null && hasParamDefaultPreferences(algRef)) { - String standardServicePID = (String) algRef.getProperty(Constants.SERVICE_PID); - String paramOverrideConfPID = standardServicePID + UserPrefsProperty.PARAM_PREFS_CONF_SUFFIX; + String standardServicePID = + (String) algRef.getProperty(Constants.SERVICE_PID); + String paramOverrideConfPID = + standardServicePID + UserPrefsProperty.PARAM_PREFS_CONF_SUFFIX; try { - Configuration defaultParamValueOverrider = ca.getConfiguration(paramOverrideConfPID, null); - Dictionary defaultParamOverriderDict = defaultParamValueOverrider.getProperties(); - MetaTypeProvider wrappedProvider = new ParamMetaTypeProvider(unwrappedProvider, - defaultParamOverriderDict); + Configuration defaultParamValueOverrider = + ca.getConfiguration(paramOverrideConfPID, null); + Dictionary defaultParamOverriderDict = + defaultParamValueOverrider.getProperties(); + MetaTypeProvider wrappedProvider = + new ParamMetaTypeProvider(unwrappedProvider, + defaultParamOverriderDict); return wrappedProvider; } catch (IOException e) { return unwrappedProvider; @@ -347,16 +389,19 @@ } protected boolean hasParamDefaultPreferences(ServiceReference algRef) { - String prefsToPublish = (String) algRef.getProperty(UserPrefsProperty.PREFS_PUBLISHED_KEY); + String prefsToPublish = + (String) algRef.getProperty(UserPrefsProperty.PREFS_PUBLISHED_KEY); if (prefsToPublish == null) { return false; } - return prefsToPublish.contains(UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE); + return prefsToPublish.contains( + UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE); } protected void log(int logLevel, String message) { - LogService log = (LogService) ciContext.getService(LogService.class.getName()); + LogService log = + (LogService) ciContext.getService(LogService.class.getName()); if (log != null) { log.log(logLevel, message); } else { @@ -365,7 +410,8 @@ } protected void log(int logLevel, String message, Throwable exception) { - LogService log = (LogService) ciContext.getService(LogService.class.getName()); + LogService log = + (LogService) ciContext.getService(LogService.class.getName()); if (log != null) { log.log(logLevel, message, exception); } else { @@ -374,13 +420,16 @@ } } - protected void printParameters(String metatype_pid, MetaTypeProvider provider, Dictionary parameters) { + protected void printParameters(String metatype_pid, + MetaTypeProvider provider, + Dictionary parameters) { LogService logger = getLogService(); Map idToLabelMap = setupIdToLabelMap(metatype_pid, provider); if (logger != null && !parameters.isEmpty()) { // adjust to log all input parameters in one block - StringBuffer inputParams = new StringBuffer("\n" + "Input Parameters:"); + StringBuffer inputParams = + new StringBuffer("\n" + "Input Parameters:"); for (Enumeration e = parameters.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); @@ -394,7 +443,8 @@ } } - protected Map setupIdToLabelMap(String metatype_pid, MetaTypeProvider provider) { + protected Map setupIdToLabelMap(String metatype_pid, + MetaTypeProvider provider) { Map idToLabelMap = new HashMap(); if (provider != null) { ObjectClassDefinition ocd = null; @@ -402,7 +452,8 @@ ocd = provider.getObjectClassDefinition(metatype_pid, null); if (ocd != null) { - AttributeDefinition[] attr = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); + AttributeDefinition[] attr = + ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); for (int i = 0; i < attr.length; i++) { String id = attr[i].getID(); @@ -422,15 +473,20 @@ protected void doParentage(Data[] outData) { // make sure the parent set is the original Data and not the // converted data... - if (outData != null && data != null && originalData != null && originalData.length == data.length) { + if (outData != null + && data != null + && originalData != null + && originalData.length == data.length) { for (int i = 0; i < outData.length; i++) { if (outData[i] != null) { - Object parent = outData[i].getMetadata().get(DataProperty.PARENT); + Object parent = + outData[i].getMetadata().get(DataProperty.PARENT); if (parent != null) { for (int j = 0; j < data.length; j++) { if (parent == data[j]) { - outData[i].getMetadata().put(DataProperty.PARENT, originalData[j]); + outData[i].getMetadata().put( + DataProperty.PARENT, originalData[j]); break; } } @@ -439,17 +495,21 @@ } } - // check and act on parentage settings + // Check and act on parentage settings String parentage = (String) ref.getProperty("parentage"); if (parentage != null) { parentage = parentage.trim(); if (parentage.equalsIgnoreCase("default")) { - if (originalData != null && originalData.length > 0 && originalData[0] != null) { + if (originalData != null + && originalData.length > 0 + && originalData[0] != null) { for (int i = 0; i < outData.length; i++) { - // if they don't have a parent set already then we set one - if (outData[i] != null && outData[i].getMetadata().get(DataProperty.PARENT) == null) { - outData[i].getMetadata().put(DataProperty.PARENT, originalData[0]); + // If they don't have a parent set already then we set one + if (outData[i] != null + && outData[i].getMetadata().get(DataProperty.PARENT) == null) { + outData[i].getMetadata().put( + DataProperty.PARENT, originalData[0]); } } } @@ -458,31 +518,36 @@ } private LogService getLogService() { - ServiceReference serviceReference = bContext.getServiceReference(DataManagerService.class.getName()); + ServiceReference serviceReference = + bContext.getServiceReference(DataManagerService.class.getName()); LogService log = null; if (serviceReference != null) { - log = (LogService) bContext.getService(bContext.getServiceReference(LogService.class.getName())); + log = (LogService) bContext.getService( + bContext.getServiceReference(LogService.class.getName())); } return log; } private ConfigurationAdmin getConfigurationAdmin() { - ServiceReference serviceReference = bContext.getServiceReference(ConfigurationAdmin.class.getName()); + ServiceReference serviceReference = + bContext.getServiceReference(ConfigurationAdmin.class.getName()); ConfigurationAdmin ca = null; if (serviceReference != null) { - ca = (ConfigurationAdmin) bContext.getService(bContext.getServiceReference(ConfigurationAdmin.class - .getName())); + ca = (ConfigurationAdmin) bContext.getService( + bContext.getServiceReference( + ConfigurationAdmin.class.getName())); } return ca; } private void logNullOCDWarning(String pid, String metatype_pid) { - this.log(LogService.LOG_WARNING, "Warning: could not get object class definition '" + metatype_pid - + "' from the algorithm '" + pid + "'"); + this.log(LogService.LOG_WARNING, + "Warning: could not get object class definition '" + metatype_pid + + "' from the algorithm '" + pid + "'"); } public ProgressMonitor getProgressMonitor() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-18 20:38:57
|
Revision: 1124 http://cishell.svn.sourceforge.net/cishell/?rev=1124&view=rev Author: pataphil Date: 2010-08-18 20:38:51 +0000 (Wed, 18 Aug 2010) Log Message: ----------- * Added handling for AlgorithmCanceledException, so Algorithms can (optionally) cancel out without the user seeing an awful error message box. * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2010-08-12 16:14:56 UTC (rev 1123) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-18 20:38:51 UTC (rev 1124) @@ -25,6 +25,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmCanceledException; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; @@ -236,19 +237,30 @@ protected Data[] tryExecutingAlgorithm(Algorithm algorithm) { Data[] outData = null; + final String algorithmName = + (String) serviceReference.getProperty(AlgorithmProperty.LABEL); + try { outData = algorithm.execute(); + } catch (AlgorithmCanceledException e) { + String logMessage = String.format( + "The algorithm: \"%s\" was canceled by the user. (Reason: %s)", + algorithmName, + e.getMessage()); + log(LogService.LOG_WARNING, logMessage, e); } catch (AlgorithmExecutionException e) { - log(LogService.LOG_ERROR, "The Algorithm: \"" - + serviceReference.getProperty(AlgorithmProperty.LABEL) - + "\" had an error while executing: " + e.getMessage(), e); + String logMessage = String.format( + "The algorithm: \"%s\" had an error while executing: %s", + algorithmName, + e.getMessage()); + log(LogService.LOG_ERROR, logMessage, e); } catch (RuntimeException e) { - GUIBuilderService builder = (GUIBuilderService) - ciShellContext.getService(GUIBuilderService.class.getName()); - - builder.showError("Error!", - "An unexpected exception occurred while " + "executing \"" - + serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\"", e); + GUIBuilderService builder = + (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); + String errorMessage = String.format( + "An unxpected error occurred while executing the algorithm \"%s\".", + algorithmName); + builder.showError("Error!", errorMessage, e); } return outData; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-19 17:08:19
|
Revision: 1126 http://cishell.svn.sourceforge.net/cishell/?rev=1126&view=rev Author: pataphil Date: 2010-08-19 17:08:12 +0000 (Thu, 19 Aug 2010) Log Message: ----------- * AlgorithmFactories can now gracefully fail in mutateParameters() and gracefully cancel/fail in createAlgorithm(). * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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 2010-08-18 20:39:52 UTC (rev 1125) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-19 17:08:12 UTC (rev 1126) @@ -26,6 +26,8 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmCanceledException; +import org.cishell.framework.algorithm.AlgorithmCreationCanceledException; +import org.cishell.framework.algorithm.AlgorithmCreationFailedException; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; @@ -100,7 +102,7 @@ } boolean inputIsValid = testDataValidityIfPossible(factory, data); - + if (!inputIsValid) { return null; } @@ -108,13 +110,28 @@ // Create algorithm parameters. String metatypePID = getMetaTypeID(serviceReference); - MetaTypeProvider provider = - getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory); + // TODO: Refactor this. + MetaTypeProvider provider = null; + + try { + provider = getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory); + } catch (AlgorithmCreationFailedException e) { + String format = + "An error occurred when creating the algorithm \"%s\" with the data you " + + "provided. (Reason: %s)"; + String logMessage = String.format( + format, + serviceReference.getProperty(AlgorithmProperty.LABEL), + e.getMessage()); + log(LogService.LOG_WARNING, logMessage, e); + + return null; + } Dictionary<String, Object> parameters = getUserEnteredParameters(metatypePID, provider); - // Check to see if the user cancelled the operation. + // Check to see if the user canceled the operation. if (parameters == null) { return null; } @@ -184,13 +201,31 @@ Data[] data, Dictionary<String, Object> parameters, CIShellContext ciContext) { + final String algorithmName = + (String) serviceReference.getProperty(AlgorithmProperty.LABEL); // TODO: Call on algorithm invocation service here. try { return factory.createAlgorithm(data, parameters, ciContext); + } catch (AlgorithmCreationCanceledException e) { + String logMessage = String.format( + "The algorithm \"%s\" was canceled by the user.", + algorithmName, + e.getMessage()); + log(LogService.LOG_WARNING, logMessage, e); + + return null; + } catch (AlgorithmCreationFailedException e) { + String format = "An error occurred when creating algorithm \"%s\". (Reason: %s)"; + String errorMessage = String.format(format, algorithmName, e.getMessage()); + GUIBuilderService builder = + (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); + + return null; } catch (Exception e) { - String errorMessage = - "Unexpected error occurred while creating algorithm " + " \"" + - serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\""; + String errorMessage = String.format( + "Unexpected error occurred while creating algorithm \"%s\".", algorithmName); GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); // TODO: This is where uncaught exceptions are displayed. @@ -244,7 +279,7 @@ outData = algorithm.execute(); } catch (AlgorithmCanceledException e) { String logMessage = String.format( - "The algorithm: \"%s\" was canceled by the user. (Reason: %s)", + "The algorithm: \"%s\" was canceled by the user.", algorithmName, e.getMessage()); log(LogService.LOG_WARNING, logMessage, e); @@ -327,7 +362,8 @@ } protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider( - String metatypePID, String pid, AlgorithmFactory factory) { + String metatypePID, String pid, AlgorithmFactory factory) + throws AlgorithmCreationFailedException { MetaTypeProvider provider = null; MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); @@ -335,18 +371,21 @@ provider = metaTypeService.getMetaTypeInformation(serviceReference.getBundle()); } - if (factory instanceof ParameterMutator && provider != null) { + if ((factory instanceof ParameterMutator) && (provider != null)) { try { - ObjectClassDefinition ocd = - provider.getObjectClassDefinition(metatypePID, null); - if (ocd == null) logNullOCDWarning(pid, metatypePID); + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); + + if (ocd == null) { + logNullOCDWarning(pid, metatypePID); + } + ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + if (ocd != null) { provider = new BasicMetaTypeProvider(ocd); } } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " - + metatypePID, e); + log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-03-04 16:27:51
|
Revision: 1234 http://cishell.svn.sourceforge.net/cishell/?rev=1234&view=rev Author: pataphil Date: 2011-03-04 16:27:45 +0000 (Fri, 04 Mar 2011) Log Message: ----------- * Very minor log message printing cleanup. * Not reviewed (but doesn't need to be). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 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-03-02 21:54:21 UTC (rev 1233) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2011-03-04 16:27:45 UTC (rev 1234) @@ -324,9 +324,12 @@ try { data[i] = converters[i][0].convert(data[i]); } catch (ConversionException e) { - log(LogService.LOG_ERROR, - "Error: Unable to convert data for use by the " - + "algorithm:\n " + e.getMessage(), e); + String logMessage = String.format( + "Error: Unable to convert data for use by the algorithm:%n %s", + e.getMessage()); + log(LogService.LOG_ERROR, logMessage, e); + e.printStackTrace(); + return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |