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   package it.imolinfo.jbi4corba.jbi.wsdl;
9   
10  import it.imolinfo.jbi4corba.Logger;
11  import it.imolinfo.jbi4corba.LoggerFactory;
12  
13  import javax.wsdl.Definition;
14  import javax.wsdl.WSDLException;
15  import javax.wsdl.extensions.ExtensibilityElement;
16  import javax.wsdl.extensions.ExtensionDeserializer;
17  import javax.wsdl.extensions.ExtensionRegistry;
18  import javax.xml.namespace.QName;
19  
20  import org.w3c.dom.Element;
21  
22  import com.ibm.wsdl.util.xml.DOMUtils;
23  import com.ibm.wsdl.util.xml.QNameUtils;
24  
25  /**
26   * Deserializer for the Jbi4Corba WSDL Extension (Binding element),
27   * according with JWSDL specs.
28   * See JSR 110.
29   *
30   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
31   */
32  public class Jbi4CorbaBindingDeserializer implements ExtensionDeserializer {
33  
34      /**
35       * The logger for this class and its instances.
36       */
37      private static final Logger LOG
38              = LoggerFactory.getLogger(Jbi4CorbaBindingDeserializer.class);
39  
40      /**
41       * Default constructor.
42       */
43      public Jbi4CorbaBindingDeserializer(){
44      }
45         
46      /**
47       * Unmarshall the CorbaBinding.
48       * @param parentType      The parent type
49       * @param elementType     The element type
50       * @param el              The element
51       * @param def             The definition
52       * @param extReg          The extension registry
53       * @return                The return
54       * @throws WSDLException  The WSDL exception
55       */
56      @SuppressWarnings("unchecked")
57  	public ExtensibilityElement unmarshall(
58        Class parentType,
59        QName elementType,
60        Element el,
61        Definition def,
62        ExtensionRegistry extReg) throws WSDLException {
63  
64        Jbi4CorbaBinding jbi4CorbaBinding = (Jbi4CorbaBinding)
65          extReg.createExtension(parentType, elementType);
66              
67          // Reads the Corba IDL
68          Element tempEl = DOMUtils.getFirstChildElement(el);
69          while (tempEl != null) {
70  
71              // IDL Element
72              if (QNameUtils.matches(Jbi4CorbaExtension.Q_ELEM_JBI4CORBA_IDLENTRY,
73                      tempEl)) {
74                  // loads the IDL
75                  String idlContent = tempEl.getTextContent();
76                  tempEl.getAttributes();
77                  String location=tempEl.getAttribute(Jbi4CorbaExtension.RELATIVE_PATH);
78                  if ("".equals(location)){
79                      location=Jbi4CorbaExtension.DEFAULT_RELATIVE_PATH;
80                  }
81                  String filename=tempEl.getAttribute(Jbi4CorbaExtension.FILENAME);
82                  if ("".equals(filename)){
83                      filename=Jbi4CorbaExtension.DEFAULT_FILENAME;
84                  }
85                  String rootString=tempEl.getAttribute(Jbi4CorbaExtension.ROOT);
86                  if ("".equals(rootString)){
87                      rootString="true";
88                  }
89                  boolean root=Boolean.parseBoolean(rootString);
90                  Jbi4CorbaIDLEntry jbi4CorbaIDLEntry=new Jbi4CorbaIDLEntry();
91                  jbi4CorbaIDLEntry.setIDL(idlContent);
92                  jbi4CorbaIDLEntry.setIdlFilename(filename);
93                  jbi4CorbaIDLEntry.setRelativePath(location);
94                  jbi4CorbaIDLEntry.setRoot(root);
95                  jbi4CorbaBinding.getJbi4CorbaDLEntryList().add(jbi4CorbaIDLEntry);
96                  LOG.debug("Loaded idl entry: " + jbi4CorbaIDLEntry);
97              }
98  
99              tempEl = DOMUtils.getNextSiblingElement(tempEl);
100 
101         }
102         LOG.debug("Loaded binding: " + jbi4CorbaBinding);
103         return jbi4CorbaBinding;
104     }
105 }