View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    ******************************************************************************/
8   
9   
10  package it.imolinfo.jbi4cics.jbi.wsdl;
11  
12  
13  import javax.wsdl.Definition;
14  import javax.wsdl.WSDLException;
15  import javax.wsdl.extensions.ExtensibilityElement;
16  import javax.wsdl.extensions.ExtensionRegistry;
17  import javax.wsdl.extensions.ExtensionSerializer;
18  import javax.xml.namespace.QName;
19  import com.ibm.wsdl.util.xml.DOMUtils;
20  import it.imolinfo.jbi4cics.Logger;
21  import it.imolinfo.jbi4cics.LoggerFactory;
22  import it.imolinfo.jbi4cics.jbi.Messages;
23  
24  
25  /**
26   * Deserializer for the Jbi4Cics WSDL Extension (addess element), according 
27   * with JWSDL specs.
28   * See JSR 110.
29   * 
30   * @author amedeocannone, marcopiraccini
31   */
32  
33  public class Jbi4CicsAddressSerializer implements ExtensionSerializer {
34  
35      /**
36       * The logger for this class and its instances.
37       */
38      private static final Logger LOG
39              = LoggerFactory.getLogger(Jbi4CicsAddressSerializer.class);
40  
41      /**
42       * The responsible to translate localized messages.
43       */
44      private static final Messages MESSAGES
45              = Messages.getMessages(Jbi4CicsAddressSerializer.class);
46      
47      /**
48  	 * void constructor.
49  	 */
50  	  public Jbi4CicsAddressSerializer(){
51  		  super();
52  	  }
53      
54      /*
55       * (non-Javadoc)
56       * 
57       * @see javax.wsdl.extensions.ExtensionDeserializer#unmarshall(
58       *      java.lang.Class,javax.xml.namespace.QName, org.w3c.dom.Element,
59       *      javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
60       */
61  
62      public void marshall(Class parentType, QName elementType,
63              ExtensibilityElement extension, java.io.PrintWriter pw, 
64              Definition def, ExtensionRegistry extReg)           
65      throws WSDLException {
66  
67           // Gets the QN prefix
68          String prefix = null;
69  
70          try {
71              prefix = DOMUtils.getPrefix(Jbi4CicsExtension.NS_URI_JBI4CICS, 
72                  def);
73          } catch (WSDLException ex) {
74              LOG.warn("CIC001300_Jbi4cics_namespace_not_found", Jbi4CicsExtension.NS_URI_JBI4CICS);
75          }
76  
77          // If prefix is null, adds it
78          if (prefix == null) {
79              prefix = Jbi4CicsExtension.DEFAULT_PREFIX;
80  
81              // Adds the namespace
82              def.addNamespace(Jbi4CicsExtension.DEFAULT_PREFIX, 
83                      Jbi4CicsExtension.NS_URI_JBI4CICS);
84          }     
85  
86          prefix += ":";         
87          LOG.debug("prefix found: " + prefix);
88          
89          if (extension instanceof Jbi4CicsAddress) {
90              Jbi4CicsAddress jbi4CicsAddress = (Jbi4CicsAddress) extension;            
91              pw.print("<" + prefix + Jbi4CicsExtension.ADDRESS_ELEMENT);            
92        
93              // username            
94              if (jbi4CicsAddress.getUsername() != null) {
95                  DOMUtils.printAttribute(
96                          Jbi4CicsExtension.USERNAME_ATTRIBUTE, 
97                          jbi4CicsAddress.getUsername(), pw);
98              } else {
99              LOG.error("CIC001301_Invalid_username");      
100             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001301_Invalid_username"));
101             }                                    
102 
103             // password            
104             if (jbi4CicsAddress.getPassword() != null) {
105                 DOMUtils.printAttribute(
106                         Jbi4CicsExtension.PASSWORD_ATTRIBUTE, 
107                         jbi4CicsAddress.getPassword(), pw);
108             } else {
109             LOG.error("CIC001302_Invalid_password");      
110             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001302_Invalid_password"));
111             }                                    
112 
113             // connectionType            
114             if ((jbi4CicsAddress.getConnectionType().equals("CICS")) || 
115                     (jbi4CicsAddress.getConnectionType().equals("DUMMY"))) {
116                 DOMUtils.printAttribute(
117                         Jbi4CicsExtension.CONNECTION_TYPE_ATTRIBUTE, 
118                         jbi4CicsAddress.getConnectionType(), pw);
119             } else {
120             LOG.error("CIC001303_Invalid_connection_type");      
121             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001303_Invalid_connection_type"));
122             }                                    
123 
124             // JNDIConnectionName            
125             if (jbi4CicsAddress.getJNDIConnectionName() != null) {
126                 DOMUtils.printAttribute(
127                         Jbi4CicsExtension.JNDI_CONNECTION_NAME_ATTRIBUTE, 
128                         jbi4CicsAddress.getJNDIConnectionName(), pw);
129             } else {
130             LOG.error("CIC001304_Invalid_jndi_connection_name");      
131             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001304_Invalid_jndi_connection_name"));
132             }                                    
133 
134             // programName            
135             if (jbi4CicsAddress.getProgramName() != null) {
136                 DOMUtils.printAttribute(
137                         Jbi4CicsExtension.PROGRAM_NAME_ATTRIBUTE, 
138                         jbi4CicsAddress.getProgramName(), pw);
139             } else {
140             LOG.error("CIC001305_Invalid_program_name");      
141             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001305_Invalid_program_name"));
142             }                                    
143             // transactionName            
144             if (jbi4CicsAddress.getTransactionName() != null) {
145                 DOMUtils.printAttribute(
146                         Jbi4CicsExtension.TRANSACTION_NAME_ATTRIBUTE, 
147                         jbi4CicsAddress.getTransactionName(), pw);
148             } else {
149             LOG.error("CIC001306_Invalid_transaction_name");      
150             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001306_Invalid_transaction_name"));
151             }                                    
152 
153             // tpn            
154             if ((jbi4CicsAddress.getTpn().toString().equals("true")) || 
155                     (jbi4CicsAddress.getTpn().toString().equals("false"))) {
156                 DOMUtils.printAttribute(
157                         Jbi4CicsExtension.TPN_ATTRIBUTE, 
158                         jbi4CicsAddress.getTpn().toString(), pw);
159             } else {
160             LOG.error("CIC001307_Invalid_tpn");      
161             throw new WSDLException(WSDLException.INVALID_WSDL, MESSAGES.getString("CIC001307_Invalid_tpn"));
162             }                                    
163 
164             pw.print(">\n");       
165             pw.print("</" + prefix + Jbi4CicsExtension.ADDRESS_ELEMENT+">\n");         
166         } else {
167             LOG.warn("CIC001308_Invalid_extension_element", Jbi4CicsExtension.ADDRESS_ELEMENT);            
168         }       
169     }
170 
171 }