Author: pamarcelot
Date: Wed Jan 2 02:02:38 2008
New Revision: 608069
URL: http://svn.apache.org/viewvc?rev=608069&view=rev
Log:
o Fixed a bug when creating a project file. An exception was raised when trying to access
the bundled schema files.
o Improved error reporting.
Modified:
directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java?rev=608069&r1=608068&r2=608069&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/PluginUtils.java
Wed Jan 2 02:02:38 2008
@@ -25,7 +25,6 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.URISyntaxException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -163,12 +162,14 @@
}
catch ( ProjectsImportException e )
{
- handleErrorWhileLoadingProjects( projectsFile, e );
+ reportError( "An error occured when loading the projects.", e, "Projects
Loading Error",
+ "An error occured when loading the projects." );
return;
}
catch ( FileNotFoundException e )
{
- handleErrorWhileLoadingProjects( projectsFile, e );
+ reportError( "An error occured when loading the projects.", e, "Projects
Loading Error",
+ "An error occured when loading the projects." );
return;
}
@@ -181,21 +182,6 @@
/**
- * This method is called when an exception is raised when trying to load the Projects
file.
- *
- * @param projectsFile
- * the Projects file
- * @param e
- * the exception raised
- */
- private static void handleErrorWhileLoadingProjects( File projectsFile, Exception e )
- {
- PluginUtils.logError( "An error occured when loading the projects.", e );
- ViewUtils.displayErrorMessageBox( "Projects Loading Error", "An error occured when
loading the projects." );
- }
-
-
- /**
* Saves the projects in the Projects File.
*/
public static void saveProjects()
@@ -211,8 +197,8 @@
}
catch ( IOException e )
{
- PluginUtils.logError( "An error occured when saving the projects.", e );
- ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when saving the projects." );
+ reportError( "An error occured when saving the projects.", e, "Projects Saving
Error",
+ "An error occured when saving the projects." );
}
}
@@ -286,36 +272,59 @@
if ( url == null )
{
- PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", null );
- ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
- + schemaName + "." );
+ reportError( "An error occured when loading the schema " + schemaName + ".",
null,
+ "Projects Loafing Error", "An error occured when loading the schema "
+ schemaName + "." );
}
else
{
- schema = XMLSchemaFileImporter.getSchema( new FileInputStream( new File(
url.toURI() ) ), url
- .toString() );
+ schema = XMLSchemaFileImporter.getSchema( url.openStream(), url.toString()
);
}
}
catch ( XMLSchemaFileImportException e )
{
- PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", e );
- ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
- + schemaName + "." );
+ reportError( "An error occured when loading the schema " + schemaName + ".",
e, "Projects Loafing Error",
+ "An error occured when loading the schema " + schemaName + "." );
}
catch ( FileNotFoundException e )
{
- PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", e );
- ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
- + schemaName + "." );
+ reportError( "An error occured when loading the schema " + schemaName + ".",
e, "Projects Loafing Error",
+ "An error occured when loading the schema " + schemaName + "." );
}
- catch ( URISyntaxException e )
+ catch ( IOException e )
{
- PluginUtils.logError( "An error occured when loading the schema " + schemaName
+ ".", e );
- ViewUtils.displayErrorMessageBox( "Projects Saving Error", "An error occured
when loading the schema "
- + schemaName + "." );
+ reportError( "An error occured when loading the schema " + schemaName + ".",
e, "Projects Loafing Error",
+ "An error occured when loading the schema " + schemaName + "." );
}
return schema;
+ }
+
+
+ /**
+ * Reports an error.
+ * <p>
+ * Logs a message and an exception, and displays a Error Dialog with title and message.
+ *
+ * @param loggerMessage
+ * the message for the logger
+ * @param e
+ * the exception to log
+ * @param dialogTitle
+ * the title of the Error Dialog (empty string used if <code>null</code>)
+ * @param dialogMessage
+ * the message to display in the Error Dialog
+ */
+ private static void reportError( String loggerMessage, Exception e, String dialogTitle,
String dialogMessage )
+ {
+ if ( ( loggerMessage != null ) || ( e != null ) )
+ {
+ PluginUtils.logError( loggerMessage, e );
+ }
+
+ if ( dialogMessage != null )
+ {
+ ViewUtils.displayErrorMessageBox( ( ( dialogTitle == null ) ? "" : dialogTitle
), dialogMessage );
+ }
}
|