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   package it.imolinfo.jbi4ejb.jbi.wsdl;
9   
10  import it.imolinfo.jbi4ejb.Logger;
11  import it.imolinfo.jbi4ejb.LoggerFactory;
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  
20  import com.ibm.wsdl.util.xml.DOMUtils;
21  
22  
23  /**
24   * Serializer for the Jbi4Ejb WSDL Extension (addess element), according with
25   * JWSDL specs.
26   * See JSR 110.
27   *
28   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
29   */
30  public class Jbi4EjbAddressSerializer implements ExtensionSerializer {
31  
32      /**
33       * The logger for this class and its instances.
34       */
35      private static final Logger LOG
36      = LoggerFactory.getLogger(Jbi4EjbAddressSerializer.class);
37      
38      /**
39       * Instantiates a new jbi4 ejb address serializer.
40       */
41      public Jbi4EjbAddressSerializer() {}
42  
43      /* (non-Javadoc)
44       * @see javax.wsdl.extensions.ExtensionSerializer#marshall(java.lang.Class, javax.xml.namespace.QName, javax.wsdl.extensions.ExtensibilityElement, java.io.PrintWriter, javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
45       */
46      
47      /**
48       * Creates the WSDL fragment for the jbi4ejb address.
49       * 
50       * @param parentType the parent type
51       * @param elementType the element type
52       * @param extension the extension
53       * @param pw the writer 
54       * @param def the WSDL definition
55       * @param extReg the extension registry
56       * 
57       * @throws WSDLException if some problem occurs in marshalling
58       */
59      @SuppressWarnings("unchecked")
60      public void marshall(Class parentType, QName elementType,
61              ExtensibilityElement extension, java.io.PrintWriter pw, Definition def, ExtensionRegistry extReg)
62      throws WSDLException {
63  
64          // Gets the QN prefix
65          String prefix = DOMUtils.getPrefix(Jbi4EjbExtension.NS_URI_JBI4EJB, def);
66          prefix += ":";
67          LOG.debug("prefix found: " + prefix);
68  
69          // If prefix is null, adds it
70          if (prefix == null) {
71              prefix = Jbi4EjbExtension.DEFAULT_PREFIX;
72              // Adds the namespace
73              def.addNamespace(Jbi4EjbExtension.DEFAULT_PREFIX, Jbi4EjbExtension.NS_URI_JBI4EJB);
74          }
75  
76          if (extension instanceof Jbi4EjbAddress) {
77              Jbi4EjbAddress jbi4EjbAddress = (Jbi4EjbAddress) extension;
78              pw.print("<" + prefix + Jbi4EjbExtension.ADDRESS_ELEMENT);
79              DOMUtils.printAttribute(Jbi4EjbExtension.NAME_ATTRIBUTE,jbi4EjbAddress.getName(), pw);
80              DOMUtils.printAttribute(Jbi4EjbExtension.LOCALIZATION_TYPE_ATTRIBUTE,jbi4EjbAddress.getLocalizationType(), pw);
81              pw.print("/>");
82          } else {
83          	LOG.warn("EJB000401_Error_in_extension_element", new Object[]{Jbi4EjbExtension.ADDRESS_ELEMENT});
84          }
85      }
86  }