]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/channel/ServiceException.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / channel / ServiceException.java
1 package org.simantics.databoard.channel;\r
2 \r
3 import org.simantics.databoard.adapter.AdaptException;\r
4 import org.simantics.databoard.binding.Binding;\r
5 import org.simantics.databoard.binding.error.BindingException;\r
6 import org.simantics.databoard.binding.mutable.Variant;\r
7 \r
8 /**\r
9  * Service exception is a problem in processing the service request.\r
10  * It is produces by Service Handler. Service Exception is not a communication \r
11  * error.   \r
12  *\r
13  * @author Toni Kalajainen <toni.kalajainen@iki.fi>\r
14  */\r
15 public abstract class ServiceException extends Exception {\r
16 \r
17         private static final long serialVersionUID = 1L;\r
18 \r
19         Variant error;\r
20         \r
21         public ServiceException(Variant error) {\r
22                 this.error = error;\r
23         }\r
24         \r
25         public ServiceException(Binding binding, Object value) {\r
26                 error = new Variant(binding, value);\r
27         }\r
28         \r
29         public Variant getError() {\r
30                 return error;\r
31         }\r
32         \r
33         public Object getErrorType() {\r
34                 return error.type();\r
35         }\r
36         \r
37         public Object getError(Binding binding) throws BindingException {\r
38                 try {\r
39                         return error.getValue(binding);\r
40                 } catch (AdaptException e) {\r
41                         if (e.getCause()!=null && e.getCause() instanceof BindingException) throw (BindingException) e.getCause();\r
42                         throw new BindingException(e);\r
43                 }\r
44         }\r
45         \r
46 }\r