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.transform.requests.query;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
19  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetFromDocumentQuery;
20  
21  import static org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter.DOC_ENTRY_UNIQUE_ID;
22  import static org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter.DOC_ENTRY_UUID;
23  
24  /**
25   * Base class for transformers based on {@link GetFromDocumentQuery}.
26   * @param <T>
27   *          the actual query type that is transformed by an extending subclass.
28   * @author Jens Riemschneider
29   */
30  public abstract class GetFromDocumentQueryTransformer<T extends GetFromDocumentQuery> extends AbstractStoredQueryTransformer<T> {
31      /**
32       * Transforms the query into its ebXML representation.
33       * <p>
34       * Does not perform any transformation if one of the parameters is <code>null</code>. 
35       * @param query
36       *          the query. Can be <code>null</code>.
37       * @param ebXML
38       *          the ebXML representation. Can be <code>null</code>.
39       */
40      public void toEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
41          if (query == null || ebXML == null) {
42              return;
43          }
44  
45          super.toEbXML(query, ebXML);
46  
47          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
48          slots.fromString(DOC_ENTRY_UUID, query.getUuid());
49          slots.fromString(DOC_ENTRY_UNIQUE_ID, query.getUniqueId());
50      }
51  
52      /**
53       * Transforms the ebXML representation of a query into a query object.
54       * <p>
55       * Does not perform any transformation if one of the parameters is <code>null</code>. 
56       * @param query
57       *          the query. Can be <code>null</code>.
58       * @param ebXML
59       *          the ebXML representation. Can be <code>null</code>.
60       */
61      public void fromEbXML(T query, EbXMLAdhocQueryRequest ebXML) {
62          if (query == null || ebXML == null) {
63              return;
64          }
65  
66          super.fromEbXML(query, ebXML);
67  
68          QuerySlotHelper slots = new QuerySlotHelper(ebXML);
69          
70          query.setUniqueId(slots.toString(DOC_ENTRY_UNIQUE_ID));
71          query.setUuid(slots.toString(DOC_ENTRY_UUID));
72      }
73  
74  }