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 java.util.Properties;
14  
15  import javax.wsdl.Definition;
16  import javax.wsdl.WSDLException;
17  import javax.wsdl.extensions.ExtensibilityElement;
18  import javax.wsdl.extensions.ExtensionDeserializer;
19  import javax.wsdl.extensions.ExtensionRegistry;
20  import javax.xml.namespace.QName;
21  
22  import org.w3c.dom.Element;
23  
24  import com.ibm.wsdl.util.xml.DOMUtils;
25  import com.ibm.wsdl.util.xml.QNameUtils;
26  
27  /**
28   * Deserializer for the Jbi4Ejb WSDL Extension (Binding element), according with JWSDL specs.
29   * See JSR 110.
30   *
31   * @author <a href="mailto:mpiraccini@imolinfo.it">Marco Piraccini</a>
32   */
33  public class Jbi4EjbBindingDeserializer implements ExtensionDeserializer {
34  
35      /**
36       * The logger for this class and its instances.
37       */
38      private static final Logger LOG
39              = LoggerFactory.getLogger(Jbi4EjbBindingDeserializer.class);
40  
41      
42      /**
43       * Instantiates a new jbi4 ejb binding deserializer.
44       */
45      public Jbi4EjbBindingDeserializer() {}
46      
47      /*
48       * (non-Javadoc)
49       *
50       * @see javax.wsdl.extensions.ExtensionDeserializer#unmarshall(java.lang.Class,
51       *      javax.xml.namespace.QName, org.w3c.dom.Element,
52       *      javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
53       */
54      
55      /**
56       * Unmarshall the WSDL to obtain a <code>Jbi4EjbBinding</code> element.
57       * 
58       * @param parentType the parent type
59       * @param elementType the element type
60       * @param el the element to parse
61       * @param def the WSDL definition
62       * @param extReg the ExtensionRegistry
63       * 
64       * @return the <code>jbi4EjbBinding</code> Extensibility element
65       * 
66       * @see javax.wsdl.extensions.ExtensionDeserializer#unmarshall(java.lang.Class,
67       *      javax.xml.namespace.QName, org.w3c.dom.Element,
68       *      javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
69       * 
70       * @throws WSDLException if some problem occurs in unmarshalling
71       */
72      @SuppressWarnings("unchecked")
73      public ExtensibilityElement unmarshall(Class parentType, QName elementType,
74              Element el, Definition def, ExtensionRegistry extReg)
75      throws WSDLException {
76  
77          Jbi4EjbBinding jbi4EjbBinding = (Jbi4EjbBinding) extReg
78          .createExtension(parentType, elementType);
79  
80          Element tempEl = DOMUtils.getFirstChildElement(el);
81          while (tempEl != null) {
82  
83              // ORB element
84              if (QNameUtils.matches(Jbi4EjbExtension.Q_ELEM_JBI4EJB_ORB,
85                      tempEl)) {
86  
87                  // loads the ORB properties
88                  Properties orbProperties = new Properties();
89  
90                  Element propertyElement = DOMUtils.getFirstChildElement(tempEl);
91  
92                  while (propertyElement != null) {
93                      String propertyName = DOMUtils.getAttribute(
94                              propertyElement, Jbi4EjbExtension.NAME_ATTRIBUTE);
95                      String propertyValue = DOMUtils
96                      .getAttribute(propertyElement,
97                              Jbi4EjbExtension.VALUE_ATTRIBUTE);
98                      orbProperties.put(propertyName, propertyValue);
99                      LOG.debug("Read ORB properties: [" + propertyName + "] "
100                             + " [" + propertyValue + "]");
101                     propertyElement = DOMUtils
102                     .getNextSiblingElement(propertyElement);
103                 }
104 
105                 // Todo implements
106                 LOG.debug("Read orb properties: " + orbProperties);
107                 jbi4EjbBinding.setOrbProperties(orbProperties);
108             }
109 
110             // JNDI Element
111             if (QNameUtils.matches(Jbi4EjbExtension.Q_ELEM_JBI4EJB_JNDI,
112                     tempEl)) {
113 
114                 // loads the ORB properties
115                 Properties jndiProperties = new Properties();
116 
117                 Element propertyElement = DOMUtils.getFirstChildElement(tempEl);
118 
119                 while (propertyElement != null) {
120                     String propertyName = DOMUtils.getAttribute(
121                             propertyElement, Jbi4EjbExtension.NAME_ATTRIBUTE);
122                     String propertyValue = DOMUtils
123                     .getAttribute(propertyElement,
124                             Jbi4EjbExtension.VALUE_ATTRIBUTE);
125                     jndiProperties.put(propertyName, propertyValue);
126                     LOG.debug("Read ORB properties: [" + propertyName + "] "
127                             + " [" + propertyValue + "]");
128                     propertyElement = DOMUtils
129                     .getNextSiblingElement(propertyElement);
130                 }
131 
132                 // Todo implements
133                 LOG.debug("Read jndi properties: " + jndiProperties);
134                 jbi4EjbBinding.setOrbProperties(jndiProperties);
135             }
136 
137             tempEl = DOMUtils.getNextSiblingElement(tempEl);
138         }
139 
140         return jbi4EjbBinding;
141     }
142 }