View Javadoc

1   /****************************************************************************
2    * Copyright (c) 2005, 2006, 2007, 2008, 2009 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   package it.imolinfo.jbi4corba.jbi.wsdl;
10  
11  import it.imolinfo.jbi4corba.Logger;
12  import it.imolinfo.jbi4corba.LoggerFactory;
13  
14  import javax.wsdl.Definition;
15  import javax.wsdl.WSDLException;
16  import javax.wsdl.extensions.ExtensibilityElement;
17  import javax.wsdl.extensions.ExtensionRegistry;
18  import javax.wsdl.extensions.ExtensionSerializer;
19  import javax.xml.namespace.QName;
20  
21  import com.ibm.wsdl.util.xml.DOMUtils;
22  
23  /**
24   * Serializer for the Jbi4Corba WSDL Extension (addess element), according with
25   * JWSDL specs. See JSR 110.
26   * 
27   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>ss
28   */
29  public class Jbi4CorbaBindingSerializer implements ExtensionSerializer {
30  
31      /**
32       * The logger for this class and its instances.
33       */
34      private static final Logger LOG = LoggerFactory
35              .getLogger(Jbi4CorbaBindingSerializer.class);
36  
37      /**
38       * Default constructor.
39       */
40      public Jbi4CorbaBindingSerializer() {
41      }
42  
43      /*
44       * (non-Javadoc)
45       * 
46       * @see
47       * javax.wsdl.extensions.ExtensionDeserializer#unmarshall(java.lang.Class,
48       * javax.xml.namespace.QName, org.w3c.dom.Element, javax.wsdl.Definition,
49       * javax.wsdl.extensions.ExtensionRegistry)
50       */
51  
52      /**
53       * @param parentType
54       *            The parent type
55       * @param elementType
56       *            The element type
57       * @param extension
58       *            The extension
59       * @param pw
60       *            The io print writer
61       * @param def
62       *            The definition
63       * @param extReg
64       *            The extension registry
65       * @throws WSDLException
66       *             The WSDL exception
67       */
68      @SuppressWarnings("unchecked")
69      public void marshall(Class parentType, QName elementType,
70              ExtensibilityElement extension, java.io.PrintWriter pw,
71              Definition def, ExtensionRegistry extReg) throws WSDLException {
72  
73          // Gets the QN prefix
74          String prefix = DOMUtils.getPrefix(Jbi4CorbaExtension.NS_URI_JBI4CORBA,
75                  def);
76  
77          // If prefix is null, adds it
78          if (prefix == null) {
79              prefix = Jbi4CorbaExtension.DEFAULT_PREFIX;
80              // Adds the namespace
81              def.addNamespace(Jbi4CorbaExtension.DEFAULT_PREFIX,
82                      Jbi4CorbaExtension.NS_URI_JBI4CORBA);
83          }
84  
85          prefix += ":";
86  
87          LOG.debug("prefix found: " + prefix);
88  
89          if (extension instanceof Jbi4CorbaBinding) {
90              Jbi4CorbaBinding jbi4CorbaBinding = (Jbi4CorbaBinding) extension;
91              pw.print("<" + prefix + Jbi4CorbaExtension.BINDING_ELEMENT);
92              pw.print(">\n");
93  
94              // IDL
95              printIDLElement(jbi4CorbaBinding, pw, prefix);
96  
97              pw
98                      .print("</" + prefix + Jbi4CorbaExtension.BINDING_ELEMENT
99                              + ">\n");
100 
101         } else {
102             LOG.warn("CRB000300_The_extension_element_is_not_a",
103                     Jbi4CorbaExtension.BINDING_ELEMENT);
104         }
105 
106     }
107 
108     /**
109      * Prints the IDL element.
110      * 
111      * @param jbi4CorbaBinding
112      *            The jbi4Corba binding
113      * @param pw
114      *            The print writer
115      * @param prefix
116      *            The prefix
117      */
118     private void printIDLElement(Jbi4CorbaBinding jbi4CorbaBinding,
119             java.io.PrintWriter pw, String prefix) {
120         for (Jbi4CorbaIDLEntry jbi4CorbaIDLEntry:jbi4CorbaBinding.getJbi4CorbaDLEntryList()) {
121             if (jbi4CorbaIDLEntry.isDefault()){
122                 pw.print("<" + prefix + Jbi4CorbaExtension.IDL_ENTRY + ">");
123             } else {
124                 pw.print("<" + prefix + Jbi4CorbaExtension.IDL_ENTRY + " "+Jbi4CorbaExtension.ROOT+"=\""+jbi4CorbaIDLEntry.isRoot()+"\" "+Jbi4CorbaExtension.FILENAME+"=\""+jbi4CorbaIDLEntry.getIdlFilename()+"\" "+Jbi4CorbaExtension.RELATIVE_PATH+"=\""+jbi4CorbaIDLEntry.getRelativePath()+"\">");
125             }
126             pw.print(DOMUtils.cleanString(jbi4CorbaIDLEntry.getIDL()));
127             pw.print("</" + prefix + Jbi4CorbaExtension.IDL_ENTRY + ">\n");
128         }
129     }
130 
131 }