You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by si...@apache.org on 2013/02/02 21:09:14 UTC

svn commit: r1441802 - /incubator/onami/sandbox/validation/src/site/apt/index.apt.vm

Author: simonetripodi
Date: Sat Feb  2 20:09:14 2013
New Revision: 1441802

URL: http://svn.apache.org/viewvc?rev=1441802&view=rev
Log:
[ONAMI-74] #comment added a sample to demonstrate how to use @Validate#rethrowExceptionsAs() and @Validate#exceptionMessage()

Modified:
    incubator/onami/sandbox/validation/src/site/apt/index.apt.vm

Modified: incubator/onami/sandbox/validation/src/site/apt/index.apt.vm
URL: http://svn.apache.org/viewvc/incubator/onami/sandbox/validation/src/site/apt/index.apt.vm?rev=1441802&r1=1441801&r2=1441802&view=diff
==============================================================================
--- incubator/onami/sandbox/validation/src/site/apt/index.apt.vm (original)
+++ incubator/onami/sandbox/validation/src/site/apt/index.apt.vm Sat Feb  2 20:09:14 2013
@@ -180,3 +180,63 @@ public class MyService
 
   <<<exceptionMessage>>> supports <<<java.util.Formatter>>> place holders, intercepted method arguments will be used as
   message format arguments.
+
+  For example, given a generic exception:
+
++--------------------------------------+
+class DummyException
+    extends Exception
+{
+
+    public DummyException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public DummyException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}
++--------------------------------------+
+
+  Users can annotate service methods as below:
+
++--------------------------------------+
+import javax.validation.constraints.NotNull;
+
+import org.apache.onami.validation.Validate;
+
+public class MyService
+{
+
+    @Validate( rethrowExceptionsAs = DummyException.class )
+    public Country retrieve( @NotNull String name )
+    {
+        return ...;
+    }
+
+}
++--------------------------------------+
+
+  adopting that approach, the <<<DummyException( Throwable )>>> constructor will be used; otherwise:
+
++--------------------------------------+
+import javax.validation.constraints.NotNull;
+
+import org.apache.onami.validation.Validate;
+
+public class MyService
+{
+
+    @Validate( exceptionMessage = "This is just a dummy message %s", rethrowExceptionsAs = DummyException.class )
+    public Country retrieve( @NotNull String name )
+    {
+        return ...;
+    }
+
+}
++--------------------------------------+
+
+  the <<<DummyException>>> will be thrown using the <<<DummyException( String, Throwable )>>> constructor.