X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fchannel%2FServiceException.java;fp=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fchannel%2FServiceException.java;h=c4a8854c26c7d87020af0acfa975a1b4406913aa;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/channel/ServiceException.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/channel/ServiceException.java new file mode 100644 index 000000000..c4a8854c2 --- /dev/null +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/channel/ServiceException.java @@ -0,0 +1,46 @@ +package org.simantics.databoard.channel; + +import org.simantics.databoard.adapter.AdaptException; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.binding.mutable.Variant; + +/** + * Service exception is a problem in processing the service request. + * It is produces by Service Handler. Service Exception is not a communication + * error. + * + * @author Toni Kalajainen + */ +public abstract class ServiceException extends Exception { + + private static final long serialVersionUID = 1L; + + Variant error; + + public ServiceException(Variant error) { + this.error = error; + } + + public ServiceException(Binding binding, Object value) { + error = new Variant(binding, value); + } + + public Variant getError() { + return error; + } + + public Object getErrorType() { + return error.type(); + } + + public Object getError(Binding binding) throws BindingException { + try { + return error.getValue(binding); + } catch (AdaptException e) { + if (e.getCause()!=null && e.getCause() instanceof BindingException) throw (BindingException) e.getCause(); + throw new BindingException(e); + } + } + +}