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 java.util.Map;
11  
12  import javax.wsdl.Definition;
13  import javax.wsdl.WSDLException;
14  import javax.wsdl.extensions.ExtensibilityElement;
15  import javax.wsdl.extensions.ExtensionRegistry;
16  import javax.xml.namespace.QName;
17  
18  import org.w3c.dom.Element;
19  
20  import com.ibm.wsdl.util.xml.DOMUtils;
21  import com.ibm.wsdl.util.xml.QNameUtils;
22  
23  /**
24   * Deserializer for the Address extesions configurations.
25   * 
26   * @author rchen
27   */
28  public class Jbi4CorbaExtPreprocessDeserializer extends
29          Jbi4CorbaAddressDeserializer {
30  
31      /** serialVersionUID. */
32      private static final long serialVersionUID = -3031218478097036537L;
33  
34      private static final String APPVAR_TYPE_STRING = "STRING";
35  
36      // default constructor
37      public Jbi4CorbaExtPreprocessDeserializer() {
38          super();
39      }
40  
41      /** Creates a new instance of Jbi4CorbaExtPreprocessDeserializer */
42      public Jbi4CorbaExtPreprocessDeserializer(
43              Map<String, String[]> envVariableMap) {
44          super(envVariableMap);
45      }
46  
47      @SuppressWarnings("unchecked")
48      public javax.wsdl.extensions.ExtensibilityElement unmarshall(
49              Class parentType, QName elementType, Element el, Definition def,
50              ExtensionRegistry extReg) throws javax.wsdl.WSDLException {
51          ExtensibilityElement returnValue = null;
52          if (Jbi4CorbaExtension.ADDRESS_ELEMENT.equals(elementType)) {
53  
54              Jbi4CorbaAddress jbi4Address = new Jbi4CorbaAddress();
55  
56              collectEnvVars(el, Jbi4CorbaExtension.NAME_ATTRIBUTE,
57                      APPVAR_TYPE_STRING);
58  
59              collectEnvVars(el, Jbi4CorbaExtension.LOCALIZATION_TYPE_ATTRIBUTE,
60                      APPVAR_TYPE_STRING);
61  
62              // Reads the ORB element
63              Element tempEl = DOMUtils.getFirstChildElement(el);
64              while (tempEl != null) {
65                  // ORB element
66                  if (QNameUtils.matches(Jbi4CorbaExtension.Q_ELEM_JBI4CORBA_ORB,
67                          tempEl)) {
68  
69                      Element propertyElement = DOMUtils
70                              .getFirstChildElement(tempEl);
71  
72                      while (propertyElement != null) {
73                          String propertyName = DOMUtils.getAttribute(
74                                  propertyElement,
75                                  Jbi4CorbaExtension.NAME_ATTRIBUTE);
76  
77                          collectEnvVars(propertyElement,
78                                  Jbi4CorbaExtension.VALUE_ATTRIBUTE,
79                                  APPVAR_TYPE_STRING);
80                      }
81  
82                  }
83                  tempEl = DOMUtils.getNextSiblingElement(tempEl);
84              }
85  
86              returnValue = jbi4Address;
87          }
88  
89          return returnValue;
90      }
91  
92      protected void collectEnvVars(Element el, String attrName, String type)
93              throws WSDLException {
94          String s = DOMUtils.getAttribute(el, attrName);
95          if (s != null) {
96              try {
97                  if (hasMigrationEnvVarRef(s)) {
98                      Object[] envVariableNames = getEnvVariableNames(attrName, s);
99                      if (envVariableNames != null) {
100                         for (Object envVariableName : envVariableNames) {
101                             String name = envVariableName.toString();
102                             if (!mEnvVariableMap.containsKey(name)) {
103                                 mEnvVariableMap.put(name, new String[] { "",
104                                         type });
105                             }
106                         }
107                     }
108                 }
109             } catch (Exception e) {
110                 throw new WSDLException("INVALID_WSDL", e.getMessage());
111             }
112         }
113     }
114 }