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