View Javadoc

1   /*
2    * $Id$
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.construct.builder;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.MuleContext;
15  import org.mule.api.MuleException;
16  import org.mule.api.routing.filter.Filter;
17  import org.mule.construct.Validator;
18  import org.mule.util.StringUtils;
19  
20  public class ValidatorBuilder extends
21      AbstractFlowConstructWithSingleInboundAndOutboundEndpointBuilder<ValidatorBuilder, Validator>
22  {
23      protected Filter validationFilter;
24      protected String ackExpression;
25      protected String nackExpression;
26      protected String errorExpression;
27  
28      public ValidatorBuilder validationFilter(Filter validationFilter)
29      {
30          this.validationFilter = validationFilter;
31          return this;
32      }
33  
34      public ValidatorBuilder ackExpression(String ackExpression)
35      {
36          this.ackExpression = ackExpression;
37          return this;
38      }
39  
40      public ValidatorBuilder nackExpression(String nackExpression)
41      {
42          this.nackExpression = nackExpression;
43          return this;
44      }
45  
46      public ValidatorBuilder errorExpression(String errorExpression)
47      {
48          this.errorExpression = errorExpression;
49          return this;
50      }
51  
52      @Override
53      protected MessageExchangePattern getInboundMessageExchangePattern()
54      {
55          return MessageExchangePattern.REQUEST_RESPONSE;
56      }
57  
58      @Override
59      protected MessageExchangePattern getOutboundMessageExchangePattern()
60      {
61          return hasErrorExpression()
62                                     ? MessageExchangePattern.REQUEST_RESPONSE
63                                     : MessageExchangePattern.ONE_WAY;
64      }
65  
66      @Override
67      protected Validator buildFlowConstruct(MuleContext muleContext) throws MuleException
68      {
69          return new Validator(name, muleContext, getOrBuildInboundEndpoint(muleContext),
70              getOrBuildOutboundEndpoint(muleContext), validationFilter, ackExpression, nackExpression,
71              errorExpression);
72      }
73  
74      protected boolean hasErrorExpression()
75      {
76          return StringUtils.isNotBlank(errorExpression);
77      }
78  }