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.ebxml.ebxml30;
17  
18  import static org.apache.commons.lang3.Validate.notNull;
19  
20  import java.util.Collections;
21  import java.util.List;
22  
23  import javax.xml.bind.JAXBElement;
24  
25  import lombok.experimental.Delegate;
26  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
27  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSubmitObjectsRequest;
28  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.lcm.SubmitObjectsRequest;
29  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.IdentifiableType;
30  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.RegistryObjectListType;
31  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.SlotListType;
32  
33  /**
34   * Encapsulation of {@link SubmitObjectsRequest}
35   * @author Jens Riemschneider
36   */
37  public class EbXMLSubmitObjectsRequest30 extends EbXMLObjectContainer30 implements EbXMLSubmitObjectsRequest {
38      private final SubmitObjectsRequest submitObjectsRequest;
39  
40      /**
41       * Constructs a request by wrapping the given ebXML 3.0 object.
42       * @param submitObjectsRequest
43       *          the object to wrap.
44       * @param objectLibrary
45       *          the object library to use.
46       */
47      public EbXMLSubmitObjectsRequest30(SubmitObjectsRequest submitObjectsRequest, EbXMLObjectLibrary objectLibrary) {
48          super(objectLibrary);
49          notNull(submitObjectsRequest, "submitObjectsRequest cannot be null");
50          this.submitObjectsRequest = submitObjectsRequest;
51      }
52  
53      /**
54       * Constructs a request by wrapping the given ebXML 3.0 object using a new object library.
55       * @param submitObjectsRequest
56       *          the object to wrap.
57       */
58      public EbXMLSubmitObjectsRequest30(SubmitObjectsRequest submitObjectsRequest) {
59          this(submitObjectsRequest, new EbXMLObjectLibrary());
60          fillObjectLibrary();
61      }
62  
63      @Override
64      List<JAXBElement<? extends IdentifiableType>> getContents() {
65          RegistryObjectListType list = submitObjectsRequest.getRegistryObjectList();
66          if (list == null) {
67              return Collections.emptyList();
68          }
69          return list.getIdentifiable();
70      }
71  
72      @Override
73      public SubmitObjectsRequest getInternal() {
74          return submitObjectsRequest;
75      }
76  
77      /**
78       * Implements the {@link org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlotList} interface
79       * by delegating the calls to a "proper" slot list.
80       */
81      @Delegate
82      private EbXMLSlotList30 getSlotList() {
83          if (submitObjectsRequest.getRequestSlotList() == null) {
84              submitObjectsRequest.setRequestSlotList(new SlotListType());
85          }
86          return new EbXMLSlotList30(submitObjectsRequest.getRequestSlotList().getSlot());
87      }
88  }