KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > soap > server > DeploymentDescriptor


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "SOAP" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2000, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.soap.server;
59
60 import java.io.*;
61 import java.util.*;
62 import javax.xml.parsers.*;
63 import org.w3c.dom.*;
64 import org.xml.sax.*;
65 import org.apache.soap.Constants;
66 import org.apache.soap.encoding.*;
67 import org.apache.soap.rpc.*;
68 import org.apache.soap.server.http.*;
69 import org.apache.soap.util.xml.*;
70
71 /**
72  * This class represents the deployment information about a SOAP service.
73  *
74  * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
75  * @author Matthew J. Duftler (duftler@us.ibm.com)
76  */

77 public class DeploymentDescriptor implements Serializable {
78   // types of services
79
public static final int SERVICE_TYPE_RPC = 0;
80   public static final int SERVICE_TYPE_MESSAGE = 1;
81
82   // scopes for the lifecycles of the provider class
83
public static final int SCOPE_REQUEST = 0;
84   public static final int SCOPE_SESSION = 1;
85   public static final int SCOPE_APPLICATION = 2;
86
87   // types of providers
88
public static final byte PROVIDER_JAVA = (byte) 0;
89   public static final byte PROVIDER_SCRIPT_FILE = (byte) 1;
90   public static final byte PROVIDER_SCRIPT_STRING = (byte) 2;
91   public static final byte PROVIDER_USER_DEFINED = (byte) 3;
92
93   protected String JavaDoc id;
94   protected int serviceType = SERVICE_TYPE_RPC;
95   protected int scope;
96   protected byte providerType = -1;
97   protected String JavaDoc providerClass;
98
99   protected String JavaDoc serviceClass; // For user-defined providers
100
protected Hashtable props ;
101
102   protected boolean isStatic;
103   protected String JavaDoc scriptFilenameOrString;
104   protected String JavaDoc scriptLanguage;
105   protected String JavaDoc[] methods;
106   protected TypeMapping[] mappings;
107   transient SOAPMappingRegistry cachedSMR;
108   protected String JavaDoc[] faultListener;
109   private transient SOAPFaultRouter fr;
110
111   // Should I throw a mustUnderstand fault if I get
112
// any mustUnderstand headers? If you deploy a
113
// service that doesn't process headers at all,
114
// this option should technically be set to be
115
// a good SOAP citizen.
116
protected boolean checkMustUnderstands = false;
117
118   private String JavaDoc defaultSMRClass = null;
119   /**
120    * Constructor.
121    *
122    * @param id the name of the service. Should be of valid URI syntax.
123    */

124   public DeploymentDescriptor () {
125   }
126
127   /**
128    * ID of this service.
129    */

130
131   public void setID (String JavaDoc id) {
132     this.id = id;
133   }
134
135   public String JavaDoc getID () {
136     return id;
137   }
138
139   public boolean getCheckMustUnderstands()
140   {
141       return checkMustUnderstands;
142   }
143   
144   public void setCheckMustUnderstands(boolean doIt)
145   {
146       checkMustUnderstands = doIt;
147   }
148   
149   /**
150    * Type of the service: message or procedural service. Defaults to being
151    * a procedural service. The difference is that if its procedural then
152    * the methods are invoked by decoding the children of the first body
153    * element as being parameters of the method call. If its message-oriented,
154    * then no decoding is done and the method is invoked giving the envelope
155    * as an argument.
156    */

157   public void setServiceType (int serviceType) {
158     this.serviceType = serviceType;
159   }
160
161   public int getServiceType () {
162     return serviceType;
163   }
164
165   /**
166    * Lifecyle of the object providing the service.
167    */

168   public void setScope (int scope) {
169     this.scope = scope;
170   }
171
172   public int getScope () {
173     return scope;
174   }
175
176   public void setDefaultSMRClass(String JavaDoc _defaultSMRClass) {
177     defaultSMRClass = _defaultSMRClass;
178   }
179
180   public String JavaDoc getDefaultSMRClass() {
181     return defaultSMRClass;
182   }
183
184   /**
185    * Methods provided by the service.
186    */

187   public void setMethods (String JavaDoc[] methods) {
188     this.methods = methods;
189   }
190
191   public String JavaDoc[] getMethods () {
192     return methods;
193   }
194
195   /**
196    * Type of provider.
197    */

198   public void setProviderType (byte providerType) {
199     this.providerType = providerType;
200   }
201
202   public byte getProviderType () {
203     return providerType;
204   }
205
206   /**
207    * Classname used to load provider/service
208    */

209   public void setServiceClass (String JavaDoc serviceClass) {
210     this.serviceClass = serviceClass;
211   }
212
213   public String JavaDoc getServiceClass () {
214     return serviceClass;
215   }
216
217   public Hashtable getProps() {
218     return props ;
219   }
220
221   public void setProps(Hashtable props) {
222     this.props = props ;
223   }
224
225   /**
226    * For Java providers, the class providing the service.
227    */

228   public void setProviderClass (String JavaDoc providerClass) {
229     this.providerClass = providerClass;
230   }
231
232   public String JavaDoc getProviderClass () {
233     return providerClass;
234   }
235
236   /**
237    * For Java providers, is it static or not.
238    */

239   public void setIsStatic (boolean isStatic) {
240     this.isStatic = isStatic;
241   }
242
243   public boolean getIsStatic () {
244     return isStatic;
245   }
246
247   public void setScriptLanguage (String JavaDoc scriptLanguage) {
248     this.scriptLanguage = scriptLanguage;
249   }
250
251   public String JavaDoc getScriptLanguage () {
252     return scriptLanguage;
253   }
254
255   public void setScriptFilenameOrString (String JavaDoc scriptFilenameOrString) {
256     this.scriptFilenameOrString = scriptFilenameOrString;
257   }
258
259   public String JavaDoc getScriptFilenameOrString () {
260     return scriptFilenameOrString;
261   }
262
263   /**
264    * Type mappings between XML types of certain encodings and
265    * Java types.
266    *
267    * @param map the structure containing the mapping info
268    */

269   public void setMappings (TypeMapping[] mappings) {
270     this.mappings = mappings;
271   }
272
273   /**
274    * Return the registered mappings.
275    */

276   public TypeMapping[] getMappings () {
277     return mappings;
278   }
279
280   /**
281    * Cache the SOAP serialization registry for this descriptor; used only
282    * by me.
283    */

284   private void setCachedSMR (SOAPMappingRegistry cachedSMR) {
285     this.cachedSMR = cachedSMR;
286   }
287
288   private SOAPMappingRegistry getCachedSMR () {
289     return cachedSMR;
290   }
291
292
293   public String JavaDoc[] getFaultListener() {return faultListener;}
294
295   public void setFaultListener(String JavaDoc[] _faultListener) {faultListener = _faultListener;}
296
297
298   public SOAPFaultRouter buildFaultRouter(SOAPContext ctxt) {
299         if (fr != null) return fr;
300
301         fr = new SOAPFaultRouter();
302
303         if (faultListener == null) return fr;
304
305
306         SOAPFaultListener[] lis = new SOAPFaultListener[faultListener.length];
307         try {
308           for (int i = 0; i < faultListener.length; i++) {
309             Class JavaDoc c = ctxt.loadClass( faultListener[i] );
310             lis[i] = (SOAPFaultListener)c.newInstance();
311           }
312         }
313         catch (Exception JavaDoc e) {}
314
315         fr.setFaultListener(lis);
316         return fr;
317   }
318   /**
319    * Write out the deployment descriptor according to the
320    * the deployment descriptor DTD.
321    */

322   public void toXML(Writer pr) {
323     PrintWriter pw = new PrintWriter (pr);
324
325     pw.println ("<isd:service xmlns:isd=\"" +
326                 Constants.NS_URI_XML_SOAP_DEPLOYMENT + "\" id=\"" + id + "\"" +
327                 (serviceType != SERVICE_TYPE_RPC ? " type=\"message\"" : "") +
328                 " checkMustUnderstands=\"" + (checkMustUnderstands ? "true" :
329                                                                     "false") +
330                                              "\"" +
331                 ">");
332
333     byte pt = providerType;
334     String JavaDoc[] scopes = {"Request", "Session", "Application"};
335     String JavaDoc providerString = null ;
336
337     if ( pt == DeploymentDescriptor.PROVIDER_JAVA )
338       providerString = "java" ;
339     else if ( pt == DeploymentDescriptor.PROVIDER_USER_DEFINED )
340       providerString = serviceClass ;
341     else
342       providerString = "script" ;
343
344     pw.print (" <isd:provider type=\"" + providerString +
345               "\" scope=\"" + scopes[scope] + "\" methods=\"");
346     for (int i = 0; i < methods.length; i++) {
347       pw.print (methods[i]);
348       if (i < methods.length-1) {
349         pw.print (" ");
350       }
351     }
352     pw.println ("\">");
353     if (pt == DeploymentDescriptor.PROVIDER_JAVA) {
354       pw.println (" <isd:java class=\"" + providerClass +
355                   "\" static=\"" + (isStatic ? "true" : "false") + "\"/>");
356     } else if (pt == DeploymentDescriptor.PROVIDER_SCRIPT_FILE ||
357                pt == DeploymentDescriptor.PROVIDER_SCRIPT_STRING ) {
358       pw.print (" <isd:script language=\"" + scriptLanguage + "\"");
359       if (pt == DeploymentDescriptor.PROVIDER_SCRIPT_FILE) {
360         pw.println (" source=\"" + scriptFilenameOrString + "\"/>");
361       } else {
362         pw.println (">");
363         pw.println (" <![CDATA[");
364         pw.println (scriptFilenameOrString);
365         pw.println (" ]]>");
366         pw.println (" </isd:script>");
367       }
368     }
369     else if ( pt == DeploymentDescriptor.PROVIDER_USER_DEFINED &&
370               providerClass != null ) {
371       pw.println (" <isd:java class=\"" + providerClass +
372                   "\" static=\"" + (isStatic ? "true" : "false") + "\"/>");
373     }
374
375     if ( props != null )
376         for ( Enumeration e = props.keys() ; e.hasMoreElements(); ) {
377             String JavaDoc key = (String JavaDoc) e.nextElement() ;
378             String JavaDoc value = (String JavaDoc) props.get(key);
379             pw.println(" <isd:option key=\"" + key + "\" value=\"" +
380                        value + "\" />" );
381         }
382
383     pw.println (" </isd:provider>");
384
385         if (faultListener != null) {
386                 for (int i = 0; i < faultListener.length; i++) {
387                         pw.println(" <isd:faultListener>" +
388                                    faultListener[i] +
389                                    "</isd:faultListener>");
390                 }
391         }
392
393     if (mappings != null) {
394       pw.print(" <isd:mappings");
395       if (defaultSMRClass != null) {
396         pw.println(" defaultRegistryClass=\"" + defaultSMRClass + "\">");
397       } else {
398         pw.println(">");
399       }
400
401       for (int i = 0; i < mappings.length; i++) {
402         TypeMapping tm = mappings[i];
403
404         pw.print (" <isd:map");
405
406         if (tm.encodingStyle != null) {
407           pw.print (" encodingStyle=\"" + tm.encodingStyle +"\"");
408         }
409
410         if (tm.elementType != null) {
411           pw.print (" xmlns:x=\"" + tm.elementType.getNamespaceURI () +
412                     "\" qname=\"x:" + tm.elementType.getLocalPart () + "\"");
413         }
414
415         if (tm.javaType != null) {
416           pw.print (" javaType=\"" + tm.javaType + "\"");
417         }
418
419         if (tm.xml2JavaClassName != null) {
420           pw.print (" xml2JavaClassName=\"" + tm.xml2JavaClassName + "\"");
421         }
422
423         if (tm.java2XMLClassName != null) {
424           pw.print (" java2XMLClassName=\"" + tm.java2XMLClassName + "\"");
425         }
426
427         pw.println ("/>");
428       }
429
430       pw.println (" </isd:mappings>");
431     }
432
433     pw.println ("</isd:service>");
434     pw.flush ();
435   }
436
437   public static DeploymentDescriptor fromXML(Reader rd)
438     throws IllegalArgumentException JavaDoc {
439     if (rd == null) {
440       throw new IllegalArgumentException JavaDoc("Reader passed to " +
441                                          "DeploymentDescriptor.fromXML(...) " +
442                                          "must not be null.");
443     }
444
445     try {
446       DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
447       Document doc = xdb.parse(new InputSource(rd));
448
449       if (doc != null) {
450         Element root = doc.getDocumentElement();
451
452         return fromXML(root);
453       } else {
454         throw new Exception JavaDoc("Document came back null.");
455       }
456     } catch (Exception JavaDoc e) {
457         throw new IllegalArgumentException JavaDoc("Problem parsing " +
458                                            "deployment descriptor: " +
459                                            e);
460     }
461   }
462
463   /**
464    * Build a deployment descriptor from a document corresponding to
465    * the deployment descriptor DTD.
466    */

467   public static DeploymentDescriptor fromXML(Element root)
468     throws IllegalArgumentException JavaDoc {
469     if ((root == null) ||
470         !root.getNamespaceURI().equals (Constants.NS_URI_XML_SOAP_DEPLOYMENT) ||
471         !root.getLocalName().equals ("service")) {
472       throw new IllegalArgumentException JavaDoc ("root is null or document element " +
473                                           "is not {" +
474                                           Constants.NS_URI_XML_SOAP_DEPLOYMENT +
475                                           "}service");
476     }
477
478     DeploymentDescriptor dd = new DeploymentDescriptor ();
479     NodeList nl;
480     Element e;
481
482     String JavaDoc id = DOMUtils.getAttribute (root, "id");
483     if (id == null) {
484       throw new IllegalArgumentException JavaDoc ("required 'id' attribute " +
485                                           "missing in deployment descriptor");
486     }
487     dd.setID (id);
488     
489     // If we've been marked as checking mustUnderstands, do it.
490
String JavaDoc checkMustUnderstands = DOMUtils.getAttribute(root, "checkMustUnderstands");
491     if (checkMustUnderstands != null) {
492       if (checkMustUnderstands.equals("true"))
493         dd.checkMustUnderstands = true;
494     }
495
496     // check type of service
497
String JavaDoc serviceTypeStr = DOMUtils.getAttribute (root, "type");
498     if (serviceTypeStr != null) {
499       if (serviceTypeStr.equals ("message")) {
500         dd.setServiceType (SERVICE_TYPE_MESSAGE);
501       } else {
502         throw new IllegalArgumentException JavaDoc ("unknown value for 'type' " +
503                                             "attribute: '" + serviceTypeStr +
504                                             "': bad deployment descriptor");
505       }
506     }
507
508     nl = root.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
509                                       "provider");
510     if ((nl == null) || nl.getLength () != 1) {
511       throw new IllegalArgumentException JavaDoc ("exactly one 'provider' element " +
512                                           "missing in deployment descriptor");
513     }
514     e = (Element) nl.item (0);
515     String JavaDoc typeStr = DOMUtils.getAttribute (e, "type");
516     String JavaDoc scopeStr = DOMUtils.getAttribute (e, "scope");
517     String JavaDoc methodsStr = DOMUtils.getAttribute (e, "methods");
518     if ((typeStr == null) ||
519         // (!typeStr.equals ("java") && !typeStr.equals ("script")) ||
520
(scopeStr == null) ||
521         (!scopeStr.equals ("Request") &&
522          !scopeStr.equals ("Session") && !scopeStr.equals ("Application")) ||
523         (methodsStr == null) || methodsStr.equals ("")) {
524       throw new IllegalArgumentException JavaDoc ("invalid value for type or scope " +
525                                           "or methods attribute in provider " +
526                                           "element of deployment descriptor");
527     }
528
529     int scope = -1;
530     String JavaDoc[] methods;
531
532     Element saved_E = e ;
533     nl = e.getElementsByTagNameNS(Constants.NS_URI_XML_SOAP_DEPLOYMENT,
534                                   "option" );
535     for ( int i = 0 ; nl != null && i < nl.getLength() ; i++ ) {
536       String JavaDoc key, value ;
537
538       e = (Element) nl.item(i);
539       key = DOMUtils.getAttribute( e, "key" );
540       value = DOMUtils.getAttribute( e, "value" );
541
542       if ( key == null || key.equals("") )
543         throw new IllegalArgumentException JavaDoc("Missing 'key' attribute on " +
544                                            "'option' element in deployment " +
545                                            "desriptor" );
546       if ( dd.props == null ) dd.props = new Hashtable();
547       dd.props.put( key, value );
548     }
549     e = saved_E ;
550
551     if (typeStr.equals ("java")) {
552       dd.setProviderType (DeploymentDescriptor.PROVIDER_JAVA);
553       nl = e.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
554                                      "java");
555       if ((nl == null) || nl.getLength () != 1) {
556         throw new IllegalArgumentException JavaDoc ("exactly one 'java' element " +
557                                             "missing in deployment " +
558                                             "descriptor");
559       }
560       e = (Element) nl.item (0);
561       String JavaDoc className = DOMUtils.getAttribute (e, "class");
562       if (className == null) {
563         throw new IllegalArgumentException JavaDoc ("<java> element requires " +
564                                             "'class' attribute");
565       }
566       dd.setProviderClass (className);
567       String JavaDoc isStatic = DOMUtils.getAttribute (e, "static");
568       boolean isStaticBool = false;
569       if (isStatic != null) {
570         if (isStatic.equals ("false")) {
571           isStaticBool = false;
572         } else if (isStatic.equals ("true")) {
573           isStaticBool = true;
574         } else {
575           throw new IllegalArgumentException JavaDoc ("'static' attribute of " +
576                                               "<java> element must be " +
577                                               "true or false");
578         }
579       }
580       dd.setIsStatic (isStaticBool);
581
582     } else if (typeStr.equals ("script")) {
583       nl = e.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
584                                      "script");
585       if ((nl == null) || nl.getLength () != 1) {
586         throw new IllegalArgumentException JavaDoc ("exactly one 'script' element " +
587                                             "missing in deployment " +
588                                             "descriptor");
589       }
590       e = (Element) nl.item (0);
591       dd.setScriptLanguage (DOMUtils.getAttribute (e, "language"));
592       String JavaDoc source = DOMUtils.getAttribute (e, "source");
593       if (source != null) {
594         dd.setProviderType (DeploymentDescriptor.PROVIDER_SCRIPT_FILE);
595         dd.setScriptFilenameOrString (source);
596       } else {
597         dd.setProviderType (DeploymentDescriptor.PROVIDER_SCRIPT_STRING);
598         dd.setScriptFilenameOrString (DOMUtils.getChildCharacterData (e));
599       }
600     } else {
601       // "type" element isn't one of the predefined ones so assume it's the
602
// class name of a specific provider loader
603
dd.setProviderType (DeploymentDescriptor.PROVIDER_USER_DEFINED);
604       dd.setServiceClass (typeStr);
605
606       // Support old 'java' tag
607
nl = e.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
608                                      "java");
609       if ( nl != null ) {
610         if ( nl.getLength () > 1) {
611           throw new IllegalArgumentException JavaDoc ("exactly one 'java' element " +
612                                               "missing in deployment " +
613                                               "descriptor");
614         }
615         if ( nl.getLength() != 0 ) {
616           e = (Element) nl.item (0);
617           String JavaDoc className = DOMUtils.getAttribute (e, "class");
618           if (className == null) {
619             throw new IllegalArgumentException JavaDoc ("<java> element requires " +
620                                                 "'class' attribute");
621           }
622           dd.setProviderClass (className);
623           String JavaDoc isStatic = DOMUtils.getAttribute (e, "static");
624           boolean isStaticBool = false;
625           if (isStatic != null) {
626             if (isStatic.equals ("false")) {
627               isStaticBool = false;
628             } else if (isStatic.equals ("true")) {
629               isStaticBool = true;
630             } else {
631               throw new IllegalArgumentException JavaDoc ("'static' attribute of " +
632                                                   "<java> element must be " +
633                                                   "true or false");
634             }
635           }
636           dd.setIsStatic (isStaticBool);
637           // End of old 'java' tag
638
}
639       }
640     }
641
642     if (scopeStr.equals ("Request")) {
643       scope = DeploymentDescriptor.SCOPE_REQUEST;
644     } else if (scopeStr.equals ("Session")) {
645       scope = DeploymentDescriptor.SCOPE_SESSION;
646     } else { // scopeStr.equals ("Application")
647
scope = DeploymentDescriptor.SCOPE_APPLICATION;
648     }
649     dd.setScope (scope);
650
651     StringTokenizer st = new StringTokenizer (methodsStr);
652     int nTokens = st.countTokens ();
653     methods = new String JavaDoc[nTokens];
654     for (int i = 0; i < nTokens; i++) {
655       methods[i] = st.nextToken ();
656     }
657     dd.setMethods (methods);
658     
659     //read the fault listeners
660
nl = root.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
661                                       "faultListener");
662     String JavaDoc[] lis = new String JavaDoc[nl.getLength()];
663
664     try {
665       for (int i = 0; i < nl.getLength(); i++) {
666         // Class.forName(DOMUtils.getChildCharacterData((Element)nl.item(i))).newInstance();
667
lis[i] = DOMUtils.getChildCharacterData((Element)nl.item(i));
668       }
669     }
670     catch (Exception JavaDoc ex) {
671       throw new IllegalArgumentException JavaDoc(ex.getMessage());
672     }
673
674     dd.setFaultListener(lis);
675
676     // read the type mappings
677
nl = root.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
678                                       "mappings");
679     if ((nl == null) || nl.getLength () > 1) {
680       throw new IllegalArgumentException JavaDoc ("at most one 'mappings' element " +
681                                           "allowed in deployment descriptor");
682     }
683     if (nl.getLength () == 1) {
684       e = (Element) nl.item (0);
685
686       String JavaDoc className = DOMUtils.getAttribute(e, "defaultRegistryClass");
687
688       if (className != null) {
689         dd.setDefaultSMRClass(className);
690       }
691
692       nl = e.getElementsByTagNameNS (Constants.NS_URI_XML_SOAP_DEPLOYMENT,
693                                      "map");
694       int nmaps = nl.getLength ();
695       if (nmaps > 0) {
696         TypeMapping[] tms = new TypeMapping[nmaps];
697         dd.setMappings (tms);
698         for (int i = 0; i < nmaps; i++) {
699           e = (Element) nl.item (i);
700           QName qname = DOMUtils.getQualifiedAttributeValue(e, "qname");
701           tms[i] =
702             new TypeMapping (DOMUtils.getAttribute (e, "encodingStyle"),
703                              qname,
704                              DOMUtils.getAttribute (e, "javaType"),
705                              DOMUtils.getAttribute (e, "java2XMLClassName"),
706                              DOMUtils.getAttribute (e, "xml2JavaClassName"));
707         }
708       }
709     }
710
711     return dd;
712   }
713
714   /**
715    * What do u think this does?
716    */

717   public String JavaDoc toString () {
718     StringBuffer JavaDoc methodsStrbuf = new StringBuffer JavaDoc ("[");
719     for (int i = 0; i < methods.length; i++) {
720       methodsStrbuf.append (methods[i]);
721       if (i < methods.length-1) {
722         methodsStrbuf.append (",");
723       }
724     }
725     methodsStrbuf.append ("]");
726     String JavaDoc header = "[DeploymentDescriptor id='" + id + "', " +
727       ((serviceType != SERVICE_TYPE_RPC) ? "type='message', " : "") +
728       "scope='" + scope + "', ";
729     String JavaDoc body = null;
730     if (providerType == PROVIDER_JAVA) {
731       body = "class='" + providerClass + "', static='" + isStatic + "', ";
732     } else if (providerType == PROVIDER_SCRIPT_FILE) {
733       body = "source='" + scriptFilenameOrString + "', ";
734       body += "language='" + scriptLanguage + "', ";
735     } else if (providerType == PROVIDER_USER_DEFINED) {
736       body = "type='" + serviceClass + "', class='" + providerClass ;
737       body += "', static='" + isStatic + "', ";
738     }
739
740     StringBuffer JavaDoc lis = new StringBuffer JavaDoc("[");
741     if (faultListener != null)
742       for (int i = 0; i < faultListener.length;
743         lis.append(faultListener[i]), lis.append(" "), i++);
744     lis.append("]");
745
746     StringBuffer JavaDoc opts = new StringBuffer JavaDoc();
747     if (props != null)
748       opts.append( props.toString() );
749
750     return header + body + "methods='" + methodsStrbuf + "', " +
751       "faultListener='" + lis + "', " + "mappings='" +
752       mappingsToString(mappings) + "'], " +
753       "opts='" + opts ;
754   }
755
756   private static String JavaDoc mappingsToString(TypeMapping[] mappings) {
757     if (mappings != null) {
758       StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc();
759
760       for (int i = 0; i < mappings.length; i++) {
761         strBuf.append((i > 0 ? " " : "") + mappings[i]);
762       }
763
764       return strBuf.toString();
765     } else {
766       return null;
767     }
768   }
769
770   /**
771    * Utility to generate an XML serialization registry from all the
772    * type mappings registered into a deployment descriptor.
773    *
774    * @param dd the deployment descriptor
775    * @return the xml serialization registry
776    */

777   public static SOAPMappingRegistry
778       buildSOAPMappingRegistry (DeploymentDescriptor dd, SOAPContext ctx) {
779     TypeMapping[] maps = dd.getMappings ();
780     SOAPMappingRegistry smr = dd.getCachedSMR ();
781
782     if (smr != null) {
783       return smr;
784     } else {
785       String JavaDoc defaultSMRClassName = dd.getDefaultSMRClass();
786
787       if (defaultSMRClassName != null) {
788         try {
789           Class JavaDoc defaultSMRClass = ctx.loadClass( defaultSMRClassName );
790
791           smr = (SOAPMappingRegistry)defaultSMRClass.newInstance();
792         }
793         catch (Exception JavaDoc e) {
794       // this needs to be logged somewhere
795
}
796       }
797
798       if (smr == null) {
799     SOAPMappingRegistry baseReg = SOAPMappingRegistry.getBaseRegistry (
800           Constants.NS_URI_CURRENT_SCHEMA_XSD);
801     if (maps == null) {
802       dd.setCachedSMR (baseReg);
803       return baseReg;
804     } else {
805       smr = new SOAPMappingRegistry (baseReg);
806         }
807       }
808     }
809
810     if (maps != null) {
811       for (int i = 0; i < maps.length; i++) {
812         TypeMapping tm = maps[i];
813         int step = 0;
814         try {
815           step = 0;
816           Class JavaDoc javaType = null;
817           if (tm.javaType != null)
818             javaType = ctx.loadClass( tm.javaType );
819           step = 1;
820           Serializer s = null;
821           if (tm.java2XMLClassName != null) {
822             Class JavaDoc c = ctx.loadClass( tm.java2XMLClassName );
823             s = (Serializer) c.newInstance ();
824           }
825           step = 2;
826           Deserializer d = null;
827           if (tm.xml2JavaClassName != null) {
828             Class JavaDoc c = ctx.loadClass( tm.xml2JavaClassName );
829             d = (Deserializer) c.newInstance ();
830           }
831           smr.mapTypes (tm.encodingStyle, tm.elementType, javaType, s, d);
832         } catch (Exception JavaDoc e2) {
833           String JavaDoc m = "Deployment error in SOAP service '" + dd.getID () +
834             "': ";
835           if (step == 0) {
836             m += "class name '" + tm.javaType + "' could not be resolved: ";
837           } else if (step == 1) {
838             m += "class name '" + tm.java2XMLClassName + "' could not be " +
839               "resolved as a serializer: ";
840           } else {
841             m += "class name '" + tm.xml2JavaClassName + "' could not be " +
842               "resolved as a deserializer: ";
843           }
844           throw new IllegalArgumentException JavaDoc (m + e2.getMessage ());
845         }
846       }
847     }
848     dd.setCachedSMR (smr);
849     return smr;
850   }
851 }
852
Popular Tags