ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1144468 - in /webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters: Converter.java ConverterException.java DOMToStaxConverter.java StaxToDOMConverter.java
Date Fri, 08 Jul 2011 19:59:20 GMT
Author: veithen
Date: Fri Jul  8 19:59:19 2011
New Revision: 1144468

URL: http://svn.apache.org/viewvc?rev=1144468&view=rev
Log:
NEETHI-9: Make sure that Converter implementations throw an exception instead of returning
null.

Added:
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/ConverterException.java
  (with props)
Modified:
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/Converter.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/DOMToStaxConverter.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/StaxToDOMConverter.java

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/Converter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/Converter.java?rev=1144468&r1=1144467&r2=1144468&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/Converter.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/Converter.java
Fri Jul  8 19:59:19 2011
@@ -37,6 +37,13 @@ public interface Converter<S, T> {
     Map<QName, String> getAttributes(S s);
     Iterator<S> getChildren(S s);
 
-    
+    /**
+     * 
+     * @param s
+     * @return the result of the conversion; may not be <code>null</code>
+     * @throws ConverterException
+     *             if the conversion fails; note that to indicate a failure, the method may
throw
+     *             other unchecked exceptions specific to the APIs involved in the conversion
+     */
     T convert(S s);
 }

Added: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/ConverterException.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/ConverterException.java?rev=1144468&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/ConverterException.java
(added)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/ConverterException.java
Fri Jul  8 19:59:19 2011
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.neethi.builders.converters;
+
+/**
+ * Thrown to indicate that conversion from one XML object model to another failed.
+ */
+public class ConverterException extends RuntimeException {
+    private static final long serialVersionUID = 1156276815855954750L;
+
+    public ConverterException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ConverterException(String message) {
+        super(message);
+    }
+
+    public ConverterException(Throwable cause) {
+        super(cause);
+    }
+}

Propchange: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/ConverterException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/DOMToStaxConverter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/DOMToStaxConverter.java?rev=1144468&r1=1144467&r2=1144468&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/DOMToStaxConverter.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/DOMToStaxConverter.java
Fri Jul  8 19:59:19 2011
@@ -20,6 +20,7 @@
 package org.apache.neethi.builders.converters;
 
 import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.dom.DOMSource;
 
@@ -34,8 +35,8 @@ public class DOMToStaxConverter extends 
     public XMLStreamReader convert(Element s) {
         try {
             return XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(s));
-        } catch (Exception e) {
-            return null;
+        } catch (XMLStreamException ex) {
+            throw new ConverterException(ex);
         }
     }
 

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/StaxToDOMConverter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/StaxToDOMConverter.java?rev=1144468&r1=1144467&r2=1144468&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/StaxToDOMConverter.java
(original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/converters/StaxToDOMConverter.java
Fri Jul  8 19:59:19 2011
@@ -22,6 +22,7 @@ package org.apache.neethi.builders.conve
 import java.util.Stack;
 
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -42,8 +43,10 @@ public class StaxToDOMConverter extends 
             Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
             readDocElements(doc, doc, reader);
             return doc.getDocumentElement();
-        } catch (Exception e) {
-            return null;
+        } catch (ParserConfigurationException ex) {
+            throw new ConverterException(ex);
+        } catch (XMLStreamException ex) {
+            throw new ConverterException(ex);
         }
     }
 



Mime
View raw message