DynamicSOAPMessage.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.message.soap.dynamic;

  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. import java.util.Iterator;

  24. import javax.activation.DataHandler;
  25. import javax.xml.soap.AttachmentPart;
  26. import javax.xml.soap.MimeHeaders;
  27. import javax.xml.soap.SOAPBody;
  28. import javax.xml.soap.SOAPElement;
  29. import javax.xml.soap.SOAPException;
  30. import javax.xml.soap.SOAPHeader;
  31. import javax.xml.soap.SOAPPart;

  32. import org.openspcoop2.message.soap.AbstractOpenSPCoop2Message_saaj_impl;
  33. import org.openspcoop2.message.soap.AbstractOpenSPCoop2Message_soap_impl;

  34. /**
  35.  * DynamicSOAPMessage
  36.  *
  37.  * @author Andrea Poli (poli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class DynamicSOAPMessage<T extends AbstractOpenSPCoop2Message_saaj_impl> extends javax.xml.soap.SOAPMessage {

  42.     private AbstractOpenSPCoop2Message_soap_impl<T> wrapped;
  43.     public DynamicSOAPMessage(AbstractOpenSPCoop2Message_soap_impl<T> wrapped) {
  44.         this.wrapped = wrapped;
  45.     }

  46.     private javax.xml.soap.SOAPMessage _getSOAPMessage(){
  47.         try {
  48.             return this.wrapped.getContent().getSOAPMessage();
  49.         }catch(Exception e) {
  50.             throw new RuntimeException(e.getMessage(),e);
  51.         }
  52.     }
  53.    
  54.    

  55.     // Metodi ottimizzati per il dynamic behaviour
  56.    
  57.     private DynamicSOAPHeader<T> dynamicSoapHeader;
  58.    
  59.     @Override
  60.     public SOAPHeader getSOAPHeader() throws SOAPException {
  61.         if(this.wrapped.isSoapHeaderOptimizable()) {
  62.             if(this.dynamicSoapHeader==null) {
  63.                 this.dynamicSoapHeader = new DynamicSOAPHeader<T>(this.wrapped);
  64.             }
  65.             return this.dynamicSoapHeader;
  66.         }
  67.         return _getSOAPMessage().getSOAPHeader();
  68.     }
  69.    
  70.     private DynamicSOAPPart<T> dynamicSoapPart;
  71.    
  72.     @Override
  73.     public SOAPPart getSOAPPart() {
  74.         if(this.wrapped.isSoapHeaderOptimizable()) {
  75.             if(this.dynamicSoapPart==null) {
  76.                 this.dynamicSoapPart = new DynamicSOAPPart<T>(this.wrapped);
  77.             }
  78.             return this.dynamicSoapPart;
  79.         }
  80.         return _getSOAPMessage().getSOAPPart();
  81.     }
  82.    
  83.     public void clearDynamicResources() {
  84.         this.dynamicSoapHeader=null;
  85.        
  86.         if(this.dynamicSoapPart!=null) {
  87.             this.dynamicSoapPart.clearDynamicResources();
  88.         }
  89.         this.dynamicSoapPart=null;
  90.     }
  91.    
  92.    
  93.     // Metodi implementati in SAAJ
  94.    
  95.     @Override
  96.     public void addAttachmentPart(AttachmentPart arg0) {
  97.         _getSOAPMessage().addAttachmentPart(arg0);
  98.     }

  99.     @Override
  100.     public int countAttachments() {
  101.         return _getSOAPMessage().countAttachments();
  102.     }

  103.     @Override
  104.     public AttachmentPart createAttachmentPart() {
  105.         return _getSOAPMessage().createAttachmentPart();
  106.     }

  107.     @Override
  108.     public AttachmentPart getAttachment(SOAPElement arg0) throws SOAPException {
  109.         return _getSOAPMessage().getAttachment(arg0);
  110.     }

  111.     @Override
  112.     public Iterator<AttachmentPart> getAttachments() {
  113.         return _getSOAPMessage().getAttachments();
  114.     }

  115.     @Override
  116.     public Iterator<AttachmentPart> getAttachments(MimeHeaders arg0) {
  117.         return _getSOAPMessage().getAttachments(arg0);
  118.     }

  119.     @Override
  120.     public String getContentDescription() {
  121.         return _getSOAPMessage().getContentDescription();
  122.     }

  123.     @Override
  124.     public MimeHeaders getMimeHeaders() {
  125.         return _getSOAPMessage().getMimeHeaders();
  126.     }

  127.     @Override
  128.     public void removeAllAttachments() {
  129.         _getSOAPMessage().removeAllAttachments();
  130.     }

  131.     @Override
  132.     public void removeAttachments(MimeHeaders arg0) {
  133.         _getSOAPMessage().removeAttachments(arg0);
  134.     }

  135.     @Override
  136.     public void saveChanges() throws SOAPException {
  137.         _getSOAPMessage().saveChanges();
  138.     }

  139.     @Override
  140.     public boolean saveRequired() {
  141.         return _getSOAPMessage().saveRequired();
  142.     }

  143.     @Override
  144.     public void setContentDescription(String arg0) {
  145.         _getSOAPMessage().setContentDescription(arg0);
  146.     }

  147.     @Override
  148.     public void writeTo(OutputStream arg0) throws SOAPException, IOException {
  149.         _getSOAPMessage().writeTo(arg0);
  150.     }

  151.     @Override
  152.     public AttachmentPart createAttachmentPart(DataHandler dataHandler) {
  153.         return _getSOAPMessage().createAttachmentPart(dataHandler);
  154.     }

  155.     @Override
  156.     public AttachmentPart createAttachmentPart(Object content, String contentType) {
  157.         return _getSOAPMessage().createAttachmentPart(content, contentType);
  158.     }

  159.     @Override
  160.     public Object getProperty(String property) throws SOAPException {
  161.         return _getSOAPMessage().getProperty(property);
  162.     }

  163.     @Override
  164.     public SOAPBody getSOAPBody() throws SOAPException {
  165.         return _getSOAPMessage().getSOAPBody();
  166.     }

  167.     @Override
  168.     public void setProperty(String property, Object value) throws SOAPException {
  169.         _getSOAPMessage().setProperty(property, value);
  170.     }
  171. }