View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.validate.query;
17  
18  import static org.apache.commons.lang3.Validate.notNull;
19  
20  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
21  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
22  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.QuerySlotHelper;
23  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValueValidator;
24  import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
25  
26  /**
27   * Query parameter validation for parameters that are Number-based.
28   * @author Jens Riemschneider
29   */
30  public class NumberValidation implements QueryParameterValidation {
31      private final QueryParameter param;
32      private final ValueValidator validator;
33  
34      /**
35       * Constructs a validation object.
36       * @param param
37       *          parameter to validate.
38       * @param validator
39       *          validator to use on the parameter value.
40       */
41      public NumberValidation(QueryParameter param, ValueValidator validator) {
42          notNull(param, "param cannot be null");
43          notNull(validator, "validator cannot be null");
44          
45          this.param = param;
46          this.validator = validator;
47      }
48  
49      @Override
50      public void validate(EbXMLAdhocQueryRequest request) throws XDSMetaDataException {
51          QuerySlotHelper slots = new QuerySlotHelper(request);
52          String value = slots.toNumber(param);
53          if (value != null) {
54              validator.validate(value);
55          }
56      }
57  }