|
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.
|