Author: bobtarling Date: 2008-05-08 09:40:36-0700 New Revision: 14667 Modified: trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java
Log: Detect exceptions earlier rather than later. Chain exceptions when applicable. Modified: trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java?view=diff&rev=14667&p1=trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java&p2=trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java&r1=14666&r2=14667 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java (original) +++ trunk/src/argouml-app/src/org/argouml/profile/FileModelLoader.java 2008-05-08 09:40:36-0700 @@ -48,7 +48,7 @@ URL url = modelFile.toURI().toURL(); return super.loadModel(url, reference.getPublicReference()); } catch (MalformedURLException e) { - throw new ProfileException("Model file not found!"); + throw new ProfileException("Model file not found!", e); } } Modified: trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java?view=diff&rev=14667&p1=trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java&p2=trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java&r1=14666&r2=14667 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java (original) +++ trunk/src/argouml-app/src/org/argouml/profile/ReaderModelLoader.java 2008-05-08 09:40:36-0700 @@ -62,21 +62,23 @@ */ public Collection loadModel(ProfileReference reference) throws ProfileException { - if (reader != null) { - try { - XmiReader xmiReader = Model.getXmiReader(); - InputSource inputSource = new InputSource(reader); - inputSource.setSystemId(reference.getPath()); - inputSource.setPublicId( - reference.getPublicReference().toString()); - Collection elements = xmiReader.parse(inputSource, true); - return elements; - } catch (UmlException e) { - throw new ProfileException("Invalid XMI data!", e); - } + + if (reader == null) { + LOG.error("Profile not found"); + throw new ProfileException("Profile not found!"); + } + + try { + XmiReader xmiReader = Model.getXmiReader(); + InputSource inputSource = new InputSource(reader); + inputSource.setSystemId(reference.getPath()); + inputSource.setPublicId( + reference.getPublicReference().toString()); + Collection elements = xmiReader.parse(inputSource, true); + return elements; + } catch (UmlException e) { + throw new ProfileException("Invalid XMI data!", e); } - LOG.error("Profile not found"); - throw new ProfileException("Profile not found!"); } } Modified: trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java?view=diff&rev=14667&p1=trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java&p2=trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java&r1=14666&r2=14667 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java (original) +++ trunk/src/argouml-app/src/org/argouml/profile/StreamModelLoader.java 2008-05-08 09:40:36-0700 @@ -55,19 +55,19 @@ public Collection loadModel(InputStream inputStream, URL publicReference) throws ProfileException { - if (inputStream != null) { - try { - XmiReader xmiReader = Model.getXmiReader(); - InputSource inputSource = new InputSource(inputStream); - inputSource.setPublicId(publicReference.toString()); - Collection elements = xmiReader.parse(inputSource, true); - return elements; - } catch (UmlException e) { - LOG.error("Exception while loading profile ", e); - throw new ProfileException("Invalid XMI data!"); - } + if (inputStream == null) { + LOG.error("Profile not found"); + throw new ProfileException("Profile not found!"); + } + + try { + XmiReader xmiReader = Model.getXmiReader(); + InputSource inputSource = new InputSource(inputStream); + inputSource.setPublicId(publicReference.toString()); + Collection elements = xmiReader.parse(inputSource, true); + return elements; + } catch (UmlException e) { + throw new ProfileException("Invalid XMI data!", e); } - LOG.error("Profile not found"); - throw new ProfileException("Profile not found!"); } } Modified: trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java?view=diff&rev=14667&p1=trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java&p2=trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java&r1=14666&r2=14667 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java (original) +++ trunk/src/argouml-app/src/org/argouml/profile/URLModelLoader.java 2008-05-08 09:40:36-0700 @@ -61,8 +61,7 @@ Collection elements = xmiReader.parse(inputSource, true); return elements; } catch (UmlException e) { - LOG.error("Exception while loading profile ", e); - throw new ProfileException("Invalid XMI data!"); + throw new ProfileException("Invalid XMI data!", e); } } } Modified: trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java?view=diff&rev=14667&p1=trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java&p2=trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java&r1=14666&r2=14667 ============================================================================== --- trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java (original) +++ trunk/src/argouml-app/src/org/argouml/profile/ZipModelLoader.java 2008-05-08 09:40:36-0700 @@ -48,40 +48,42 @@ public Collection loadModel(ProfileReference reference) throws ProfileException { LOG.info("Loading profile from ZIP '" + reference.getPath() + "'"); + + if (!reference.getPath().endsWith("zip")) { + throw new ProfileException("Profile could not be loaded!"); + } InputStream is = null; File modelFile = new File(reference.getPath()); // TODO: This is in the wrong place. It's not profile specific. // It needs to be moved to main XMI reading code. - tfm 20060326 - if (reference.getPath().endsWith("zip")) { - String filename = modelFile.getName(); - String extension = filename.substring(filename.indexOf('.'), - filename.lastIndexOf('.')); - String path = modelFile.getParent(); - // Add the path of the model to the search path, so we can - // read dependent models - if (path != null) { - System.setProperty("org.argouml.model.modules_search_path", - path); - } - try { - is = openZipStreamAt(modelFile.toURI().toURL(), extension); - } catch (MalformedURLException e) { - LOG.error("Exception while loading profile '" - + reference.getPath() + "'", e); - throw new ProfileException(e); - } catch (IOException e) { - LOG.error("Exception while loading profile '" - + reference.getPath() + "'", e); - throw new ProfileException(e); - } - - if (is != null) { - return super.loadModel(is, reference.getPublicReference()); - } + String filename = modelFile.getName(); + String extension = filename.substring(filename.indexOf('.'), + filename.lastIndexOf('.')); + String path = modelFile.getParent(); + // Add the path of the model to the search path, so we can + // read dependent models + if (path != null) { + System.setProperty("org.argouml.model.modules_search_path", + path); + } + try { + is = openZipStreamAt(modelFile.toURI().toURL(), extension); + } catch (MalformedURLException e) { + LOG.error("Exception while loading profile '" + + reference.getPath() + "'", e); + throw new ProfileException(e); + } catch (IOException e) { + LOG.error("Exception while loading profile '" + + reference.getPath() + "'", e); + throw new ProfileException(e); + } + + if (is == null) { + throw new ProfileException("Profile could not be loaded!"); } - throw new ProfileException("Profile could not be loaded!"); + return super.loadModel(is, reference.getPublicReference()); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
