From: <jrb...@us...> - 2009-08-03 16:33:53
|
Revision: 912 http://cishell.svn.sourceforge.net/cishell/?rev=912&view=rev Author: jrbibers Date: 2009-08-03 16:33:43 +0000 (Mon, 03 Aug 2009) Log Message: ----------- For conversion exception handling task, NWB sprint, July 2009. Stepped through each converter algorithm and tried to clean up the exception handling in each to provide useful error messages. While at it, also updated the style of unpacking the input Data[]. I've been told we're now trying to unpack this data in the constructor rather than the execute method. Finally, updated central conversion exception handling in CIShell. I've attempted to maintain this desired behavior: When an exception occurs during a conversion, if the first and only exception occurred in the final step (of a potentially multi-stepped conversion chain), and that final converter was specifically a file handler (in the "validator, reader, writer, handler" sense: it takes data from MIME type "foo" to file extension "foo"), do not throw an error, but rather log a warning and use the "unhandled" data. Conversion should work this way whether it is for saving, for viewing, or (implicitly) for use by another algorithm. As a pleasant side effect, since adding these changes, I haven't gotten any of the ugly dialogs filled with raw/junky-looking text that would sometimes pop up when saving or viewing a file in a relatively buggy format (like Pajek .net). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java trunk/core/org.cishell.reference/.classpath trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/DataConversionServiceImpl.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2009-08-03 16:33:43 UTC (rev 912) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2sdk1.4.2_19"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> Added: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs 2009-08-03 16:33:43 UTC (rev 912) @@ -0,0 +1,12 @@ +#Tue Jul 28 13:21:05 EDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2009-08-03 16:33:43 UTC (rev 912) @@ -9,6 +9,7 @@ org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", org.cishell.reference.gui.common, + org.cishell.reference.service.conversion, org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/FileUtil.java 2009-08-03 16:33:43 UTC (rev 912) @@ -51,8 +51,10 @@ public static String extractExtension(String format) { String extension = ""; - //TODO: We should really have explicit piece of metadata that says what the extension is, - //TODO: as this method is not guaranteed to yield the correct extension + /* TODO: We should really have explicit piece of metadata that says what + * the extension is, as this method is not guaranteed to yield the + * correct extension. + */ if (format.startsWith("file:text/")) { extension = "." + format.substring("file:text/".length()); } else if (format.startsWith("file-ext:")) { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-08-03 16:33:43 UTC (rev 912) @@ -28,8 +28,10 @@ * @author Team */ public class FileSaver { - private static File currentDir; + public static final String FILE_EXTENSION_PREFIX = "file-ext:"; + private static File currentDir; + private Shell parent; private GUIBuilderService guiBuilder; @@ -87,25 +89,28 @@ * @return Whether or not the save was successful */ public boolean save(Converter converter, Data data) { - String outDataStr = (String)converter.getProperties().get(AlgorithmProperty.OUT_DATA); + String outDataStr = + (String) converter.getProperties().get(AlgorithmProperty.OUT_DATA); String ext = ""; - if (outDataStr.startsWith("file-ext:")) { - ext = outDataStr.substring(outDataStr.indexOf(':')+1); + if (outDataStr.startsWith(FILE_EXTENSION_PREFIX)) { + ext = outDataStr.substring(FILE_EXTENSION_PREFIX.length()); } - if ((""+ext).startsWith(".")) { + // Skip any initial "." if present. + if (ext.startsWith(".")) { ext = ext.substring(1); } FileDialog dialog = new FileDialog(parent, SWT.SAVE); if (currentDir == null) { - currentDir = new File(System.getProperty("user.home") + File.separator + "anything"); + currentDir = new File(System.getProperty("user.home") + File.separator + + "anything"); } dialog.setFilterPath(currentDir.getPath()); - + if (ext != null && !ext.equals("*")) { dialog.setFilterExtensions(new String[]{"*." + ext}); } @@ -128,38 +133,46 @@ String fileName = dialog.open(); if (fileName != null) { File selectedFile = new File(fileName); - if (!isSaveFileValid(selectedFile)) + if (!isSaveFileValid(selectedFile)) { continue; - if (ext != null && ext.length() != 0) - if (!selectedFile.getPath().endsWith(ext) && !ext.equals("*")) + } + + if (ext != null && ext.length() != 0) { + if (!selectedFile.getPath().endsWith(ext) && !ext.equals("*")) { selectedFile = new File(selectedFile.getPath()+'.'+ ext); + } + } + try { - Data newData = converter.convert(data); - - - copy((File)newData.getData(), selectedFile); - - if (selectedFile.isDirectory()) { - currentDir = new File(selectedFile + File.separator + "anything"); - } else { - currentDir = new File(selectedFile.getParent() + File.separator + "anything"); + Data newData = converter.convert(data); + + copy((File) newData.getData(), selectedFile); + + if (selectedFile.isDirectory()) { + currentDir = new File(selectedFile + File.separator + "anything"); + } else { + currentDir = new File(selectedFile.getParent() + File.separator + "anything"); + } + + done = true; } - - done = true; - } catch (ConversionException e1) { - this.log.log(LogService.LOG_ERROR, "Error occurred while converting data to saved format.", e1); + catch (ConversionException e) { + log.log(LogService.LOG_ERROR, "Error occurred while converting data to saved format:\n " + e.getMessage(), e); return false; } + log.log(LogService.LOG_INFO, "Saved: " + selectedFile.getPath()); } else { done = true; return false; - } + } } return true; } - - /** + + + + /** * Converter puts it into a temporary directory, this copies it over * * @param in The temp file to copy Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2009-08-03 16:33:43 UTC (rev 912) @@ -24,14 +24,13 @@ * @author bmarkine */ public class Save implements Algorithm { - Data[] data; - Dictionary parameters; - CIShellContext context; - Shell parentShell; + public static final String ANY_FILE_EXTENSION = "file-ext:*"; + public static final String SAVE_DIALOG_TITLE = "Save"; + private Data[] data; + private CIShellContext context; + private Shell parentShell; - private GUIBuilderService guiBuilder; private DataConversionService conversionManager; - private LogService log; /** * Sets up default services for the algorithm @@ -42,102 +41,66 @@ */ public Save(Data[] data, Dictionary parameters, CIShellContext context) { this.data = data; - this.parameters = parameters; this.context = context; - this.conversionManager = (DataConversionService) context.getService( - DataConversionService.class.getName()); - - this.log = (LogService) context.getService(LogService.class.getName()); - this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); + this.conversionManager = (DataConversionService) + context.getService(DataConversionService.class.getName()); } /** - * Executes the algorithm - * - * @return Null for this algorithm + * @return Null when successful */ public Data[] execute() throws AlgorithmExecutionException { - //NOTE: A "converter" here is actually a converter path - //starting with the format for the data we want to save - //and ending in a output format - Data dataToSave = data[0]; + Data outData = data[0]; + + tryToSave(outData, ANY_FILE_EXTENSION); - //first, try to save the normal way, which is using validators to validate the output. - String saveThroughValidators = "file-ext:*"; - Object firstAttemptResult = tryToSave(dataToSave, saveThroughValidators); - if (firstAttemptResult instanceof Boolean) { - boolean succeeded = ((Boolean) firstAttemptResult).booleanValue(); - if (succeeded) { - System.out.println("Success"); - return null; //FILE SAVED SUCCESSFULLY. DONE. - } else { - System.out.println("No converter"); - this.log.log(LogService.LOG_WARNING, "No converters found that can save file through a validator." + - " Attempting to save without validating."); - } - } else { //result instanceof Exception - Exception reasonForFailure = (Exception) firstAttemptResult; - this.log.log(LogService.LOG_WARNING, "Exception occurred while attempting to save" + - " file using a validator. Attempting to save without validating.", reasonForFailure); - System.out.println("Exception"); - } - - System.out.println("Trying without validators"); - - //if saving with validators didn't work, try to save it without using validators - String saveWithoutValidators = "file:*"; - Object secondAttemptResult = tryToSave(dataToSave, saveWithoutValidators); - if (secondAttemptResult instanceof Boolean) { - boolean succeeded = ((Boolean) secondAttemptResult).booleanValue(); - if (succeeded) { - return null; //FILE SAVED SUCCESSFULLY. DONE. - } else { - throw new AlgorithmExecutionException("No converters found that could save file. Save failed"); - } - } else { //result instanceof Exception - Exception reasonForFailure2 = (Exception) secondAttemptResult; - throw new AlgorithmExecutionException("Exception occurred while attempting to save", reasonForFailure2); - } + return null; } - //returns True if save was successful - //return False if there are no converter chains available to save to the given format - //return an Exception if an exception occurred while attempting to save - private Object tryToSave(final Data dataToSave, String formatToSaveTo) { - final Converter[] converters = conversionManager.findConverters(dataToSave, formatToSaveTo); - if (converters.length == 0) {return new Boolean(false);}; + private void tryToSave(final Data outData, String outFormat) + throws AlgorithmExecutionException { + final Converter[] converters = + conversionManager.findConverters(outData, outFormat); + if (converters.length == 0) { + throw new AlgorithmExecutionException( + "Error: Calculated an empty converter chain."); + } - parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); - if (parentShell.isDisposed()) {return makeParentShellDisposedException();}; + parentShell = + PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); + if (parentShell.isDisposed()) { + throw new AlgorithmExecutionException( + "Attempted to use disposed parent shell."); + } try { - guiRun(new Runnable() { - public void run() { - if (converters.length == 1){ - //only one possible choice in how to save data. Just do it. - Converter onlyConverter = converters[0]; - final FileSaver saver = new FileSaver(parentShell, context); - saver.save(onlyConverter, dataToSave); - } else { //converters.length > 1 - //multiple ways to save the data. Let user choose. - SaveDataChooser saveChooser = new SaveDataChooser(dataToSave, - parentShell, converters, "Save", context); - saveChooser.createContent(new Shell(parentShell)); - saveChooser.open(); - } - }}); + guiRun(new Runnable() { + public void run() { + if (converters.length == 1) { + // Only one possible choice in how to save data. Do it. + Converter onlyConverter = converters[0]; + final FileSaver saver = + new FileSaver(parentShell, context); + saver.save(onlyConverter, outData); + } else { + // Multiple ways to save the data. Let user choose. + SaveDataChooser saveChooser = + new SaveDataChooser(outData, + parentShell, + converters, + SAVE_DIALOG_TITLE, + context); + saveChooser.createContent(new Shell(parentShell)); + saveChooser.open(); + } + } + }); } catch (Exception e) { - return e; + throw new AlgorithmExecutionException(e.getMessage(), e); } - - return new Boolean(true); } - private AlgorithmExecutionException makeParentShellDisposedException() { - return new AlgorithmExecutionException("Attempted to use disposed parent shell"); - } - private void guiRun(Runnable run) { if (Thread.currentThread() == Display.getDefault().getThread()) { run.run(); @@ -145,29 +108,4 @@ parentShell.getDisplay().syncExec(run); } } - - private class NoConversionConverter implements Converter { - Dictionary props = new Hashtable(); - - public Data convert(Data data) { - return data; - } - - public AlgorithmFactory getAlgorithmFactory() { - return null; - } - - public ServiceReference[] getConverterChain() { - return null; - } - - public Dictionary getProperties() { - props.put(AlgorithmProperty.OUT_DATA, "file:*"); - return props; - } - } - - private Data removeExtension(Data data) { - return new BasicData(data.getMetadata(), data, ""); - } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2009-08-03 16:33:43 UTC (rev 912) @@ -308,12 +308,12 @@ * of opening the FileSaver and saving the model. * @param selectedIndex The chosen converter */ - protected void selectionMade(int selectedIndex){ + protected void selectionMade(int selectedIndex) { try { - getShell().setVisible(false); - final Converter converter = converterArray[selectedIndex]; - final FileSaver saver = new FileSaver(getShell(), context); - close(saver.save(converter, data)); + getShell().setVisible(false); + final Converter converter = converterArray[selectedIndex]; + final FileSaver saver = new FileSaver(getShell(), context); + close(saver.save(converter, data)); } catch (Exception e) { throw new RuntimeException(e); } @@ -328,34 +328,38 @@ public void createDialogButtons(Composite parent) { Button select = new Button(parent, SWT.PUSH); select.setText("Select"); - select.addSelectionListener(new SelectionAdapter() { + select.addSelectionListener( + new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int index = converterList.getSelectionIndex(); - + if (index != -1) { selectionMade(index); } } - }); + } + ); Button cancel = new Button(parent, SWT.NONE); cancel.setText("Cancel"); - cancel.addSelectionListener(new SelectionAdapter() { + cancel.addSelectionListener( + new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { close(false); } - }); + } + ); } /** * Checks for the number of file savers. If there is one - * converter then it will save directly, otherwise intialize the chooser. + * converter then it will save directly, otherwise initialize the chooser. * * @param parent The parent GUI for new dialog windows. */ public Composite createContent(Composite parent) { if (converterArray.length == 1) { - final FileSaver saver = new FileSaver((Shell)parent, context); + final FileSaver saver = new FileSaver((Shell) parent, context); close(saver.save(converterArray[0], data)); return parent; } @@ -365,31 +369,30 @@ } private class CompareAlphabetically implements Comparator { - public int compare(Object o1, Object o2) { - if (o1 instanceof Converter && o2 instanceof Converter) { - Converter c1 = (Converter) o1; - String c1Label = getLabel(c1); - - Converter c2 = (Converter) o2; - String c2Label = getLabel(c2); - - if (c1Label != null && c2Label != null) { - return c1Label.compareTo(c2Label); - } else if (c1Label == null) { - //c1 > c2 - return 1; - } else if (c2Label == null) { - //c1 < c2 - return -1; - } else { - //c1 == c2 - return 0; - } - } else { - throw new IllegalArgumentException("Can only " + - "compare Converters"); - } + if (o1 instanceof Converter && o2 instanceof Converter) { + Converter c1 = (Converter) o1; + String c1Label = getLabel(c1); + + Converter c2 = (Converter) o2; + String c2Label = getLabel(c2); + + if (c1Label != null && c2Label != null) { + return c1Label.compareTo(c2Label); + } else if (c1Label == null) { + //c1 > c2 + return 1; + } else if (c2Label == null) { + //c1 < c2 + return -1; + } else { + //c1 == c2 + return 0; + } + } else { + throw new IllegalArgumentException("Can only " + + "compare Converters"); + } } private String getLabel(Converter c) { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2009-08-03 16:33:43 UTC (rev 912) @@ -27,266 +27,269 @@ * @author Weixia(Bonnie) Huang (hu...@in...) */ public class FileView implements Algorithm { - Data[] data; - Dictionary parameters; - CIShellContext context; - DataConversionService conversionManager; - LogService logger; - Program program; - // Program programTwo; - File tempFile; - - public FileView(Data[] data, Dictionary parameters, CIShellContext context) { - this.data = data; - this.parameters = parameters; - this.context = context; - - conversionManager = (DataConversionService) context.getService( - DataConversionService.class.getName()); - - logger = (LogService)context.getService(LogService.class.getName()); - } + public static final String ANY_FILE_EXTENSION_FILTER = "file-ext:*"; + private static final String CSV_FILE_EXT = "file-ext:csv"; + private static final String CSV_MIME_TYPE = "file:text/csv"; + public static final String FILE_EXTENSION_PREFIX = "file-ext:"; + public static final String ANY_TEXT_MIME_TYPE = "file:text/"; + private Data[] data; + private CIShellContext context; + private DataConversionService conversionManager; + private LogService logger; + private Program program; + private File tempFile; + - //show the contents of a file to the user - public Data[] execute() throws AlgorithmExecutionException { - try { - boolean lastSaveSuccessful = false; - boolean isCSVFile = false; - String format; - - //tempFile = getTempFile(); TC181 - - - //for each data item we want to view... - for (int i = 0; i < data.length; i++){ - Object theData = data[i].getData(); - format = data[i].getFormat(); - String label = (String) data[i].getMetadata().get(DataProperty.LABEL); - - //if it is a text file... - if (theData instanceof File || - format.startsWith("file:text/") || - format.startsWith("file-ext:")){ - - //if it is a csv text file... - if (format.startsWith("file:text/csv") || format.startsWith("file-ext:csv")) - { - //prepare to open it like a csv file - tempFile = getTempFileCSV(); - isCSVFile = true; - - } - else //it is just a regular text file - { - //prepare to open it like a normal text file - String fileName = FileUtil.extractFileName(label); - String extension = FileUtil.extractExtension(format); - tempFile = FileUtil.getTempFile(fileName, extension, logger); - } - - //copy out data into the temp file we just created. - copy((File)data[i].getData(), tempFile); - lastSaveSuccessful = true; - - - - }else {//the data item is in an in-memory format, and must be converted to a file format before the user can see it - - final Converter[] convertersCSV = conversionManager.findConverters(data[i], "file-ext:csv"); - - //if the data item can be converted to a csv file ... do it. - if (convertersCSV.length == 1) - { - Data newDataCSV = convertersCSV[0].convert(data[i]); - tempFile = getTempFileCSV(); - isCSVFile = true; - copy((File)newDataCSV.getData(), tempFile); - lastSaveSuccessful = true; - - } - else if (convertersCSV.length > 1) - { - Data newDataCSV = convertersCSV[0].convert(data[i]); - for (int j = 1; j < convertersCSV.length; j++ ) - { - newDataCSV = convertersCSV[j].convert(newDataCSV); - } - tempFile = getTempFileCSV(); - isCSVFile = true; - copy((File)newDataCSV.getData(), tempFile); - lastSaveSuccessful = true; - } else { //it cannot be converted to a .csv - - //try to convert it to any other file format - - final Converter[] converters = conversionManager.findConverters(data[i], "file-ext:*"); - - //if it can't be converted to any file format... - if (converters.length < 1) { - //throw an error - throw new AlgorithmExecutionException("No valid converters for data type: " + - data[i].getData().getClass().getName() + - ". Please install a plugin that will save the data type to a file"); - } - else if (converters.length == 1){ //if there is only file format it can be converted to - //go ahead and convert the data item to that format - Data newData = converters[0].convert(data[i]); - - String fileName = FileUtil.extractFileName(label); - String extension = FileUtil.extractExtension(newData.getFormat()); - tempFile = FileUtil.getTempFile(fileName, extension, logger); - copy((File)newData.getData(), tempFile); - lastSaveSuccessful = true; - } - else { //there is more than one format that the data item could be converted to - - //let the user choose - - //(get some eclipse UI stuff that we need to open the data viewer) - - Display display; - IWorkbenchWindow[] windows; - final Shell parentShell; - - windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - if (windows.length == 0){ - throw new AlgorithmExecutionException("Cannot get workbench window."); - } - parentShell = windows[0].getShell(); - display = PlatformUI.getWorkbench().getDisplay(); - - //(open the data viewer, which lets the user choose which format they want to see the data item in.) - - if (!parentShell.isDisposed()) { - DataViewer dataViewer = new DataViewer(parentShell, data[i], converters); - display.syncExec(dataViewer); - lastSaveSuccessful = dataViewer.isSaved; - tempFile = dataViewer.outputFile; - } - } - } - } - - //if it's a CSV file - if (isCSVFile){//TC181 - //prepare to open the file with the default csv program - Display.getDefault().syncExec(new Runnable() { - public void run() { - program = Program.findProgram("csv"); - }}); - - }else - {//it's any other file - //prepare to open it with the standard text editor. - Display.getDefault().syncExec(new Runnable() { - public void run() { - program = Program.findProgram("txt"); - }}); - - } - - /* - Display.getDefault().syncExec(new Runnable() { - public void run() { - programTwo = Program.findProgram("doc"); - }}); - - if (programTwo == null) { - System.out.println("***\nYO!\nNo doc viewer\n"); - } else { - System.out.println("!!!\nHEY!\nDoc viewer found\n"); - - } - */ - - //if we can't find any program to open the file... - if (program == null) { - //throw an error - throw new AlgorithmExecutionException( - "No valid text viewer for the .txt file. " + - "The file is located at: "+tempFile.getAbsolutePath() + - ". Unable to open default text viewer. File is located at: "+ - tempFile.getAbsolutePath()); - } - else {//we found a program to open the file - //open it, for real. - if (lastSaveSuccessful == true) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - program.execute(tempFile.getAbsolutePath()); - }}); - } - } - } - return null; - } catch (ConversionException e1) { - throw new AlgorithmExecutionException("Error converting data to target view format.", e1); - } catch (Throwable e2){ - throw new AlgorithmExecutionException(e2); - } - } - - public File getTempFileCSV(){ //TC181 - File tempFile; - - String tempPath = System.getProperty("java.io.tmpdir"); - File tempDir = new File(tempPath+File.separator+"temp"); - if(!tempDir.exists()) - tempDir.mkdir(); - try{ - tempFile = File.createTempFile("xxx-Session-", ".csv", tempDir); - - }catch (IOException e){ - logger.log(LogService.LOG_ERROR, e.toString(), e); - tempFile = new File (tempPath+File.separator+"temp"+File.separator+"temp.csv"); + public FileView(Data[] data, Dictionary parameters, CIShellContext context) { + this.data = data; + this.context = context; - } - return tempFile; - } - - public static boolean copy(File in, File out) throws AlgorithmExecutionException{ - try { - FileInputStream fis = new FileInputStream(in); - FileOutputStream fos = new FileOutputStream(out); - - FileChannel readableChannel = fis.getChannel(); - FileChannel writableChannel = fos.getChannel(); - - writableChannel.truncate(0); - writableChannel.transferFrom(readableChannel, 0, readableChannel.size()); - fis.close(); - fos.close(); - return true; - } - catch (IOException ioe) { - throw new AlgorithmExecutionException("IOException during copy", ioe); - } - } - - final class DataViewer implements Runnable { - Shell shell; - boolean isSaved; - File outputFile; - Data theData; - Converter[] theConverters; + this.conversionManager = (DataConversionService) context + .getService(DataConversionService.class.getName()); + + this.logger = (LogService) context.getService(LogService.class.getName()); + } + + + // Show the contents of a file to the user + public Data[] execute() throws AlgorithmExecutionException { + try { + boolean lastSaveSuccessful = false; + boolean isCSVFile = false; + String format; + + // For each data item we want to view... + for (int i = 0; i < data.length; i++) { + Object theData = data[i].getData(); + format = data[i].getFormat(); + String label = (String) data[i].getMetadata().get( + DataProperty.LABEL); + + // If it is a text file... + if (theData instanceof File + || format.startsWith(ANY_TEXT_MIME_TYPE) + || format.startsWith(FILE_EXTENSION_PREFIX)) { + + // If it is a CSV text file... + if (format.startsWith(CSV_MIME_TYPE) + || format.startsWith(CSV_FILE_EXT)) { + // Prepare to open it like a CSV file + tempFile = getTempFileCSV(); + isCSVFile = true; + } else { + // Prepare to open it like a normal text file + String fileName = FileUtil.extractFileName(label); + String extension = FileUtil.extractExtension(format); + tempFile = FileUtil.getTempFile(fileName, extension, + logger); + } + + // Copy out data into the temp file we just created. + copy((File) data[i].getData(), tempFile); + lastSaveSuccessful = true; + + } else { + /* The data item is in an in-memory format, and must be + * converted to a file format before the user can see it. + */ + final Converter[] convertersCSV = + conversionManager.findConverters(data[i], CSV_FILE_EXT); + + // If the data item can be converted to a CSV file, do so. + if (convertersCSV.length == 1) { + Data newDataCSV = convertersCSV[0].convert(data[i]); + tempFile = getTempFileCSV(); + isCSVFile = true; + copy((File) newDataCSV.getData(), tempFile); + lastSaveSuccessful = true; + + } else if (convertersCSV.length > 1) { + Data newDataCSV = convertersCSV[0].convert(data[i]); + for (int j = 1; j < convertersCSV.length; j++) { + newDataCSV = convertersCSV[j].convert(newDataCSV); + } + tempFile = getTempFileCSV(); + isCSVFile = true; + copy((File) newDataCSV.getData(), tempFile); + lastSaveSuccessful = true; + } else { // it cannot be converted to a .csv + + // try to convert it to any other file format + + final Converter[] converters = + conversionManager.findConverters( + data[i], ANY_FILE_EXTENSION_FILTER); + + // if it can't be converted to any file format... + if (converters.length < 1) { + // throw an error + throw new AlgorithmExecutionException( + "No valid converters for data type: " + + data[i].getData().getClass() + .getName() + + ". Please install a plugin that will save the data type to a file"); + } else if (converters.length == 1) { // if there is only + // file format + // it can be + // converted to + // go ahead and convert the data item to that format + Data newData = converters[0].convert(data[i]); + + String fileName = FileUtil.extractFileName(label); + String extension = FileUtil + .extractExtension(newData.getFormat()); + tempFile = FileUtil.getTempFile(fileName, + extension, logger); + copy((File) newData.getData(), tempFile); + lastSaveSuccessful = true; + } else { + // there is more than one format that the data + // item could be converted to + // let the user choose + // (get some eclipse UI stuff that we need to open + // the data viewer) + + Display display; + IWorkbenchWindow[] windows; + final Shell parentShell; + + windows = PlatformUI.getWorkbench() + .getWorkbenchWindows(); + if (windows.length == 0) { + throw new AlgorithmExecutionException( + "Cannot get workbench window."); + } + parentShell = windows[0].getShell(); + display = PlatformUI.getWorkbench().getDisplay(); + + // (open the data viewer, which lets the user choose + // which format they want to see the data item in.) + + if (!parentShell.isDisposed()) { + DataViewer dataViewer = new DataViewer( + parentShell, data[i], converters); + display.syncExec(dataViewer); + lastSaveSuccessful = dataViewer.isSaved; + tempFile = dataViewer.outputFile; + } + } + } + } + + // If it's a CSV file + if (isCSVFile) {// TC181 + // prepare to open the file with the default csv program + Display.getDefault().syncExec(new Runnable() { + public void run() { + program = Program.findProgram("csv"); + } + }); + } else { + // Prepare to open it with the standard text editor. + Display.getDefault().syncExec( + new Runnable() { + public void run() { + program = Program.findProgram("txt"); + } + } + ); + } + + // If we can't find any program to open the file... + if (program == null) { + throw new AlgorithmExecutionException( + "No valid text viewer for the .txt file. " + + "The file is located at: " + + tempFile.getAbsolutePath() + + ". Unable to open default text viewer. " + + "File is located at: " + + tempFile.getAbsolutePath()); + } else { + // We found a program to open the file. Open it. + if (lastSaveSuccessful == true) { + Display.getDefault().syncExec( + new Runnable() { + public void run() { + program.execute(tempFile.getAbsolutePath()); + } + } + ); + } + } + } - DataViewer (Shell parentShell, Data data, Converter[] converters){ + return null; + } catch (ConversionException e) { + throw new AlgorithmExecutionException( + "Error: Unable to view data:\n " + e.getMessage(), e); + } catch (Throwable e) { + throw new AlgorithmExecutionException(e); + } + } + + public File getTempFileCSV() { + File tempFile; + + String tempPath = System.getProperty("java.io.tmpdir"); + File tempDir = new File(tempPath + File.separator + "temp"); + if (!tempDir.exists()) + tempDir.mkdir(); + try { + tempFile = File.createTempFile("xxx-Session-", ".csv", tempDir); + + } catch (IOException e) { + logger.log(LogService.LOG_ERROR, e.toString(), e); + tempFile = new File(tempPath + File.separator + "temp" + + File.separator + "temp.csv"); + + } + return tempFile; + } + + public static boolean copy(File in, File out) + throws AlgorithmExecutionException { + try { + FileInputStream fis = new FileInputStream(in); + FileOutputStream fos = new FileOutputStream(out); + + FileChannel readableChannel = fis.getChannel(); + FileChannel writableChannel = fos.getChannel(); + + writableChannel.truncate(0); + writableChannel.transferFrom(readableChannel, 0, readableChannel + .size()); + fis.close(); + fos.close(); + return true; + } catch (IOException ioe) { + throw new AlgorithmExecutionException("IOException during copy", + ioe); + } + } + + final class DataViewer implements Runnable { + public static final String VIEW_DIALOG_TITLE = "View"; + private Shell shell; + private boolean isSaved; + private File outputFile; + private Data data; + private Converter[] converters; + + + DataViewer(Shell parentShell, Data data, Converter[] converters) { this.shell = parentShell; - this.theData = data; - this.theConverters = converters; + this.data = data; + this.converters = converters; } + public void run() { - // lots of persisters found, return the chooser - ViewDataChooser vdc = new ViewDataChooser("View", shell, - theData, theConverters, context, logger); + // Lots of persisters found, return the chooser + ViewDataChooser vdc = new ViewDataChooser( + VIEW_DIALOG_TITLE, shell, data, converters, context, logger); vdc.open(); isSaved = vdc.isSaved(); outputFile = vdc.outputFile; } } - - - - } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2009-08-03 16:33:43 UTC (rev 912) @@ -3,10 +3,12 @@ import java.io.File; import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.persistence.FileUtil; import org.cishell.reference.gui.persistence.save.SaveDataChooser; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.eclipse.swt.widgets.Shell; import org.osgi.service.log.LogService; @@ -29,20 +31,29 @@ this.logger = logger; } - protected void selectionMade(int selectedIndex){ - try { + protected void selectionMade(int selectedIndex) { getShell().setVisible(false); final Converter converter = converterArray[selectedIndex]; - Data newData = converter.convert(theData); - String label = (String) newData.getMetadata().get(DataProperty.LABEL); - String fileName = FileUtil.extractFileName(label); - String extension = FileUtil.extractExtension(newData.getFormat()); - File tempFile = FileUtil.getTempFile(fileName, extension, logger); - isSaved = FileView.copy((File)newData.getData(), tempFile); - outputFile = tempFile; - close(true); - } catch (Exception e) { - throw new RuntimeException(e); + + try { + Data newData = converter.convert(theData); + String label = (String) newData.getMetadata().get(DataProperty.LABEL); + String fileName = FileUtil.extractFileName(label); + String extension = FileUtil.extractExtension(newData.getFormat()); + File tempFile = FileUtil.getTempFile(fileName, extension, logger); + + try { + isSaved = FileView.copy((File)newData.getData(), tempFile); + } catch (AlgorithmExecutionException e) { + logger.log(LogService.LOG_ERROR, "Error copying view for view:\n " + e.getMessage(), e); + return; + } + + outputFile = tempFile; + close(true); + } catch (ConversionException e) { + logger.log(LogService.LOG_ERROR, "Error: Unable to view data:\n " + e.getMessage(), e); + return; } } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2009-08-03 16:33:43 UTC (rev 912) @@ -107,11 +107,11 @@ //If length=1, use the unique path to save it directly //and bring the text editor. try { - Data newData = converters[0].convert(data[i]); - copy((File)newData.getData(), tempFile); - lastSaveSuccessful = true; + Data newData = converters[0].convert(data[i]); + copy((File)newData.getData(), tempFile); + lastSaveSuccessful = true; } catch (ConversionException e) { - this.logger.log(LogService.LOG_WARNING, "Error while converting to target save format. Will attempt to use other available converters.", e); + this.logger.log(LogService.LOG_WARNING, "Warning: Unable to convert to target save format (" + e.getMessage() + "). Will attempt to use other available converters.", e); } } else { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2009-08-03 16:33:43 UTC (rev 912) @@ -28,11 +28,13 @@ protected void selectionMade(int selectedIndex){ try { - getShell().setVisible(false); - final Converter converter = converterArray[selectedIndex]; - Data newData = converter.convert(theData); - isSaved = FileViewWith.copy((File)newData.getData(), tempFile); - close(true); + getShell().setVisible(false); + final Converter converter = converterArray[selectedIndex]; + Data newData = converter.convert(theData); + isSaved = FileViewWith.copy((File)newData.getData(), tempFile); + close(true); + } catch (ConversionException e) { + throw new RuntimeException("Error: Unable to view data:\n " + e.getMessage(), e); } catch (Exception e) { throw new RuntimeException(e); } Modified: trunk/core/org.cishell.reference/.classpath =================================================================== --- trunk/core/org.cishell.reference/.classpath 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/core/org.cishell.reference/.classpath 2009-08-03 16:33:43 UTC (rev 912) @@ -1,7 +1,7 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="output" path="bin"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2sdk1.4.2_19"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs (rev 0) +++ trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs 2009-08-03 16:33:43 UTC (rev 912) @@ -0,0 +1,12 @@ +#Mon Jul 27 15:45:33 EDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2009-07-31 20:40:05 UTC (rev 911) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2009-08-03 16:33:43 UTC (rev 912) @@ -29,73 +29,69 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; import org.osgi.service.metatype.MetaTypeProvider; -/** - * - * @author Bruce Herr (bh...@bh...) - */ public class ConverterImpl implements Converter, AlgorithmFactory, AlgorithmProperty { private ServiceReference[] refs; private BundleContext bContext; - private Dictionary props; + private Dictionary properties; private CIShellContext ciContext; + public ConverterImpl(BundleContext bContext, CIShellContext ciContext, ServiceReference[] refs) { this.bContext = bContext; this.ciContext = ciContext; this.refs = refs; - props = new Hashtable(); - props.put(IN_DATA, refs[0].getProperty(IN_DATA)); - props.put(OUT_DATA, refs[refs.length-1].getProperty(OUT_DATA)); - props.put(LABEL, props.get(IN_DATA) + " -> " + props.get(OUT_DATA)); + properties = new Hashtable(); + properties.put(IN_DATA, refs[0].getProperty(IN_DATA)); + properties.put(OUT_DATA, refs[refs.length-1].getProperty(OUT_DATA)); + properties.put(LABEL, properties.get(IN_DATA) + " -> " + properties.get(OUT_DATA)); + // TODO: Do the same thing for complexity String lossiness = calculateLossiness(refs); - props.put(CONVERSION, lossiness); + properties.put(CONVERSION, lossiness); } /** * @see org.cishell.service.conversion.Converter#convert(org.cishell.framework.data.Data) */ - public Data convert(Data inDM) throws ConversionException { - Data[] dm = new Data[]{inDM}; + public Data convert(Data inData) throws ConversionException { + Data[] data = new Data[]{inData}; AlgorithmFactory factory = getAlgorithmFactory(); - Algorithm alg = factory.createAlgorithm(dm, new Hashtable(), ciContext); + Algorithm algorithm = factory.createAlgorithm(data, new Hashtable(), ciContext); try { - dm = alg.execute(); - } catch (AlgorithmExecutionException aee) { - throw new ConversionException( - "Problem converting data: " + aee.getMessage(), - aee); + data = algorithm.execute(); + } catch (AlgorithmExecutionException e) { + throw new ConversionException(e.getMessage(), e); } catch (Exception e) { throw new ConversionException( - "Problem converting data: " + e.getMessage(), - e); + "Unexpected error: " + e.getMessage(), e); } Object outData = null; - if (dm != null && dm.length > 0) { - outData = dm[0].getData(); + if (data != null && data.length > 0) { + outData = data[0].getData(); } if (outData != null) { - Dictionary props = inDM.getMetadata(); - Dictionary newProps = new Hashtable(); + Dictionary properties = inData.getMetadata(); + Dictionary newProperties = new Hashtable(); - for (Enumeration e = props.keys(); e.hasMoreElements();) { - Object key = e.nextElement(); - newProps.put(key, props.get(key)); + for (Enumeration propertyKeys = properties.keys(); propertyKeys.hasMoreElements();) { + Object key = propertyKeys.nextElement(); + newProperties.put(key, properties.get(key)); } String outFormat = (String) getProperties().get(AlgorithmProperty.OUT_DATA); - return new BasicData(newProps, outData, outFormat); + return new BasicData(newProperties, outData, outFormat); } else { return null; } @@ -120,7 +116,7 @@ * @see org.cishell.service.conversion.Converter#getProperties() */ public Dictionary getProperties() { - return props; + return properties; } public Algorithm createAlgorithm(Data[] dm, @@ -186,37 +182,141 @@ } private class ConverterAlgorithm implements Algorithm { - Data[] inDM; - CIShellContext context; - Dictionary parameters; + public static final String FILE_EXTENSION_PREFIX = "file-ext:"; + public static final String MIME_TYPE_PREFIX = "file:"; + + private Data[] inData; + private Dictionary parameters; + private CIShellContext context; + private LogService log; - public ConverterAlgorithm(Data[] dm, + + public ConverterAlgorithm(Data[] inData, Dictionary parameters, CIShellContext context) { - this.inDM = dm; + this.inData = inData; this.parameters = parameters; this.context = context; + this.log = + (LogService) context.getService(LogService.class.getName()); } + public Data[] execute() throws AlgorithmExecutionException { - Data[] dm = inDM; - for (int i = 0; i < refs.length; i++) { + Data[] convertedData = inData; + + // For each converter in the converter chain (refs) + for (int ii = 0; ii < refs.length; ii++) { AlgorithmFactory factory = - (AlgorithmFactory) bContext.getService(refs[i]); + (AlgorithmFactory) bContext.getService(refs[ii]); if (factory != null) { Algorithm alg = - factory.createAlgorithm(dm, parameters, context); + factory.createAlgorithm(convertedData, parameters, context); - dm = alg.execute(); + try { + convertedData = alg.execute(); + } catch(AlgorithmExecutionException e) { + boolean isLastStep = (ii == refs.length - 1); + if (isLastStep && isHandler(refs[ii])) { + /* If the last step of the converter chain is a + * handler and it is the first (and so only) step + * to fail, just log a warning and return the + * un-handled data. + */ + String warningMessage = + "Warning: Attempting to convert data without " + + "validating the output since the validator failed " + + "with this problem:\n " + + createErrorMessage(refs[ii], e); + + log.log(LogService.LOG_WARNING, warningMessage, e); + + return convertedData; + } else { + throw new AlgorithmExecutionException( + createErrorMessage(refs[ii], e), e); + } + } } else { throw new AlgorithmExecutionException( - "Missing subconverter: " - + refs[i].getProperty(Constants.SERVICE_PID)); + "Missing subconverter: " + + refs[ii].getProperty(Constants.SERVICE_PID)); } } - return dm; + return convertedData; } + + private boolean isHandler(ServiceReference ref) { + /* For some reason, handlers are often referred to as validators, + * though strictly speaking, validators are for reading in data and + * handlers are for writing out data. + */ + String algorithmType = + (String) ref.getProperty(AlgorithmProperty.ALGORITHM_TYPE); + boolean algorithmTypeIsValidator = + AlgorithmProperty.TYPE_VALIDATOR.equals(algorithmType); + + String inDataType = + (String) ref.getProperty(AlgorithmProperty.IN_DATA); + boolean inDataTypeIsFile = inDataType.startsWith(MIME_TYPE_PREFIX); + + String outDataType = + (String) ref.getProperty(AlgorithmProperty.OUT_DATA); + boolean outDataTypeIsFileExt = + outDataType.startsWith(FILE_EXTENSION_PREFIX); + + return (algorithmTypeIsValidator + && inDataTypeIsFile + && outDataTypeIsFileExt); + } + + private String createErrorMessage(ServiceReference ref, Throwable e) { + String inType = (String) properties.get(IN_DATA); + String preProblemType = (String) ref.getProperty(IN_DATA); + String postProblemType = (String) ref.getProperty(OUT_DATA); + String outType = (String) properties.get(OUT_DATA); + + /* Only report the intermediate conversion if it is different + * from the overall conversion. + */ + if (inType.equals(preProblemType) + && outType.equals(postProblemType)) { + return "Problem converting data from " + + prettifyDataType(inType) + + " to " + prettifyDataType(outType) + + " (See the log file for more details).:\n ... [truncated message content] |