View Javadoc
1   /*
2    * Copyright 2013 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;
17  
18  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.*;
19  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
20  import org.openehealth.ipf.commons.ihe.xds.core.requests.RemoveMetadata;
21  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.Query;
22  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryType;
23  
24  /**
25   * Transforms between a {@link RemoveMetadata} and its ebXML representation.
26   * @author Boris Stanojevic
27   */
28  public class RemoveMetadataRequestTransformer {
29      private final EbXMLFactory factory = new EbXMLFactory30();
30  
31      /**
32       * Constructs the transformer
33       */
34      public RemoveMetadataRequestTransformer() {
35      }
36  
37      /**
38       * Transforms the request into its ebXML representation.
39       * @param request
40       *          the request. Can be <code>null</code>.
41       * @return the ebXML representation. <code>null</code> if the input was <code>null</code>.
42       */
43      public EbXMLRemoveMetadataRequest toEbXML(RemoveMetadata request) {
44          if (request == null) {
45              return null;
46          }
47  
48          EbXMLRemoveMetadataRequest ebXML = factory.createRemoveMetadataRequest();
49          ebXML.setReferences(request.getReferences());
50  
51          return ebXML;
52      }
53  
54      /**
55       * Transforms the ebXML representation into a request.
56       * @param ebXML
57       *          the ebXML representation. Can be <code>null</code>.
58       * @return the request. <code>null</code> if the input was <code>null</code>.
59       */
60      public RemoveMetadata fromEbXML(EbXMLRemoveMetadataRequest ebXML) {
61          if (ebXML == null) {
62              return null;
63          }
64  
65          RemoveMetadata request = new RemoveMetadata();
66          request.getReferences().addAll(ebXML.getReferences());
67  
68          return request;
69      }
70  
71      private Query createQuery(QueryType queryType) {
72          try {
73              return queryType.getType().newInstance();
74          } catch (InstantiationException | IllegalAccessException e) {
75              throw new IllegalStateException("Invalid query class for type: " + queryType, e);
76          }
77      }
78  
79  }