aboutsummaryrefslogtreecommitdiffstats
path: root/api/src/main/java/org/osjava/jardiff/DOMDiffHandler.java
blob: 1c5b0165f2712acc3d649ee020dfa55effee4d1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*
 * org.osjava.jardiff.DOMDiffHandler
 *
 * $Id: IOThread.java 1952 2005-08-28 18:03:41Z cybertiger $
 * $URL: https://svn.osjava.org/svn/osjava/trunk/jardiff/src/ava/org/osjava/jardiff/DOMDiffHandler.java $
 * $Rev: 1952 $
 * $Date: 2005-08-28 18:03:41 +0000 (Sun, 28 Aug 2005) $
 * $Author: cybertiger $
 *
 * Copyright (c) 2005, Antony Riley
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * + Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *
 * + Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * + Neither the name JarDiff nor the names of its contributors may
 *   be used to endorse or promote products derived from this software without
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package org.osjava.jardiff;

/* Not in 1.4.2 
import javax.xml.XMLConstants;
*/
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.Result;
import org.w3c.dom.*;

import org.objectweb.asm.Type;

/**
 * A specific type of DiffHandler which uses DOM to create an XML document
 * describing the changes in the diff.
 *
 * @author <a href="mailto:antony@cyberiantiger.org">Antony Riley</a>
 */
public class DOMDiffHandler implements DiffHandler
{
    /**
     * The XML namespace used.
     */
    public static final String XML_URI = "http://www.osjava.org/jardiff/0.1";

    /**
     * The javax.xml.transform.sax.Transformer used to convert
     * the DOM to text.
     */
    private final Transformer transformer;

    /**
     * Where we write the result to.
     */
    private final Result result;

    /**
     * The document object we're building
     */
    private final Document doc;

    /**
     * The current Node.
     */
    private Node currentNode;
    
    /**
     * Create a new DOMDiffHandler which writes to System.out
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public DOMDiffHandler() throws DiffException {
        try {
            TransformerFactory tf = TransformerFactory.newInstance();
            this.transformer = tf.newTransformer();
            this.result = new StreamResult(System.out);
            this.currentNode = null;
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            this.doc = db.newDocument();
        } catch (TransformerConfigurationException tce) {
            throw new DiffException(tce);
        } catch (ParserConfigurationException pce) {
            throw new DiffException(pce);
        }
    }
    
    /**
     * Create a new DOMDiffHandler with the specified Transformer and Result.
     * This method allows the user to choose what they are going to do with
     * the output in a flexible manner, allowing a stylesheet to be specified
     * and some result object.
     *
     * @param transformer The transformer to transform the output with.
     * @param result Where to put the result.
     */
    public DOMDiffHandler(Transformer transformer, Result result) 
        throws DiffException
    {
        try {
            this.transformer = transformer;
            this.result = result;
            this.currentNode = null;
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            this.doc = db.newDocument();
        } catch (ParserConfigurationException pce) {
            throw new DiffException(pce);
        }
    }
    
    /**
     * Start the diff.
     * This writes out the start of a &lt;diff&gt; node.
     *
     * @param oldJar ignored
     * @param newJar ignored
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startDiff(String oldJar, String newJar) throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "diff");
        tmp.setAttribute( "old", oldJar);
        tmp.setAttribute( "new", newJar);
        doc.appendChild(tmp);
        currentNode = tmp;
    }

    /**
     * Start the list of old contents.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startOldContents() throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "oldcontents");
        currentNode.appendChild(tmp);
        currentNode = tmp;
    }

    /**
     * Start the list of old contents.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startNewContents() throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "newcontents");
        currentNode.appendChild(tmp);
        currentNode = tmp;
    }

    /**
     * Add a contained class.
     *
     * @param info information about a class
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void contains(ClassInfo info) throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "class");
        tmp.setAttribute("name", info.getName());
        currentNode.appendChild(tmp);
    }

    /**
     * End the list of old contents.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endOldContents() throws DiffException {
        currentNode = currentNode.getParentNode();
    }

    /**
     * End the list of new contents.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endNewContents() throws DiffException {
        currentNode = currentNode.getParentNode();
    }
    
    /**
     * Start the removed node.
     * This writes out a &lt;removed&gt; node.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startRemoved() throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "removed");
        currentNode.appendChild(tmp);
        currentNode = tmp;
    }
    
    /**
     * Write out class info for a removed class.
     * This writes out the nodes describing a class
     *
     * @param info The info to write out.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void classRemoved(ClassInfo info) throws DiffException {
        writeClassInfo(info);
    }
    
    /**
     * End the removed section.
     * This closes the &lt;removed&gt; tag.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endRemoved() throws DiffException {
        currentNode = currentNode.getParentNode();
    }
    
    /**
     * Start the added section.
     * This opens the &lt;added&gt; tag.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startAdded() throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "added");
        currentNode.appendChild(tmp);
        currentNode = tmp;
    }
    
    /**
     * Write out the class info for an added class.
     * This writes out the nodes describing an added class.
     *
     * @param info The class info describing the added class.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void classAdded(ClassInfo info) throws DiffException {
        writeClassInfo(info);
    }
    
    /**
     * End the added section.
     * This closes the &lt;added&gt; tag.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endAdded() throws DiffException {
        currentNode = currentNode.getParentNode();
    }
    
    /**
     * Start the changed section.
     * This writes out the &lt;changed&gt; node.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startChanged() throws DiffException {
        Element tmp = doc.createElementNS(XML_URI, "changed");
        currentNode.appendChild(tmp);
        currentNode = tmp;
    }
    
    /**
     * Start a changed section for an individual class.
     * This writes out an &lt;classchanged&gt; node with the real class
     * name as the name attribute.
     *
     * @param internalName the internal name of the class that has changed.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void startClassChanged(String internalName) throws DiffException 
    {
        Element tmp = doc.createElementNS(XML_URI, "classchanged");
        tmp.setAttribute( "name", internalName);
        currentNode.appendChild(tmp);
        currentNode = tmp;
    }
    
    /**
     * Write out info about a removed field.
     * This just writes out the field info, it will be inside a start/end
     * removed section.
     *
     * @param info Info about the field that's been removed.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void fieldRemoved(FieldInfo info) throws DiffException {
        writeFieldInfo(info);
    }
    
    /**
     * Write out info about a removed method.
     * This just writes out the method info, it will be inside a start/end 
     * removed section.
     *
     * @param info Info about the method that's been removed.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void methodRemoved(MethodInfo info) throws DiffException {
        writeMethodInfo(info);
    }
    
    /**
     * Write out info about an added field.
     * This just writes out the field info, it will be inside a start/end 
     * added section.
     *
     * @param info Info about the added field.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void fieldAdded(FieldInfo info) throws DiffException {
        writeFieldInfo(info);
    }
    
    /**
     * Write out info about a added method.
     * This just writes out the method info, it will be inside a start/end
     * added section.
     *
     * @param info Info about the added method.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void methodAdded(MethodInfo info) throws DiffException {
        writeMethodInfo(info);
    }
    
    /**
     * Write out info aboout a changed class.
     * This writes out a &lt;classchange&gt; node, followed by a 
     * &lt;from&gt; node, with the old information about the class
     * followed by a &lt;to&gt; node with the new information about the
     * class.
     *
     * @param oldInfo Info about the old class.
     * @param newInfo Info about the new class.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void classChanged(ClassInfo oldInfo, ClassInfo newInfo)
        throws DiffException 
    {
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI, "classchange");
        Element from = doc.createElementNS(XML_URI, "from");
        Element to = doc.createElementNS(XML_URI, "to");
        tmp.appendChild(from);
        tmp.appendChild(to);
        currentNode.appendChild(tmp);
        this.currentNode = from;
        writeClassInfo(oldInfo);
        this.currentNode = to;
        writeClassInfo(newInfo);
        this.currentNode = currentNode;
    }
    
    /**
     * Write out info aboout a changed field.
     * This writes out a &lt;fieldchange&gt; node, followed by a 
     * &lt;from&gt; node, with the old information about the field
     * followed by a &lt;to&gt; node with the new information about the
     * field.
     *
     * @param oldInfo Info about the old field.
     * @param newInfo Info about the new field.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void fieldChanged(FieldInfo oldInfo, FieldInfo newInfo)
        throws DiffException 
    {
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI, "fieldchange");
        Element from = doc.createElementNS(XML_URI, "from");
        Element to = doc.createElementNS(XML_URI, "to");
        tmp.appendChild(from);
        tmp.appendChild(to);
        currentNode.appendChild(tmp);
        this.currentNode = from;
        writeFieldInfo(oldInfo);
        this.currentNode = to;
        writeFieldInfo(newInfo);
        this.currentNode = currentNode;
    }
    
    /**
     * Write out info aboout a changed method.
     * This writes out a &lt;methodchange&gt; node, followed by a 
     * &lt;from&gt; node, with the old information about the method
     * followed by a &lt;to&gt; node with the new information about the
     * method.
     *
     * @param oldInfo Info about the old method.
     * @param newInfo Info about the new method.
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void methodChanged(MethodInfo oldInfo, MethodInfo newInfo)
        throws DiffException
    {
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI, "methodchange");
        Element from = doc.createElementNS(XML_URI, "from");
        Element to = doc.createElementNS(XML_URI, "to");
        tmp.appendChild(from);
        tmp.appendChild(to);
        currentNode.appendChild(tmp);
        this.currentNode = from;
        writeMethodInfo(oldInfo);
        this.currentNode = to;
        writeMethodInfo(newInfo);
        this.currentNode = currentNode;
    }
    
    /**
     * End the changed section for an individual class.
     * This closes the &lt;classchanged&gt; node.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endClassChanged() throws DiffException {
        currentNode = currentNode.getParentNode();
    }
    
    /**
     * End the changed section.
     * This closes the &lt;changed&gt; node.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endChanged() throws DiffException {
        currentNode = currentNode.getParentNode();
    }
    
    /**
     * End the diff.
     * This closes the &lt;diff&gt; node.
     *
     * @throws DiffException when there is an underlying exception, e.g.
     *                       writing to a file caused an IOException
     */
    public void endDiff() throws DiffException {
        DOMSource source = new DOMSource(doc);
        try {
        transformer.transform(source, result);
        } catch (TransformerException te) {
            throw new DiffException(te);
        }
    }
    
    /**
     * Write out information about a class.
     * This writes out a &lt;class&gt; node, which contains information about
     * what interfaces are implemented each in a &lt;implements&gt; node.
     *
     * @param info Info about the class to write out.
     */
    protected void writeClassInfo(ClassInfo info) {
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI, "class");
        currentNode.appendChild(tmp);
        this.currentNode = tmp;
        addAccessFlags(info);
        if (info.getName() != null)
            tmp.setAttribute( "name",
                    info.getName());
        if (info.getSignature() != null)
            tmp.setAttribute( "signature",
                    info.getSignature());
        if (info.getSupername() != null)
            tmp.setAttribute( "superclass",
                              info.getSupername());
        String[] interfaces = info.getInterfaces();
        for (int i = 0; i < interfaces.length; i++) {
            Element iface = doc.createElementNS(XML_URI, "implements");
            tmp.appendChild(iface);
            iface.setAttribute( "name", 
                    interfaces[i]);
        }
        this.currentNode = currentNode;
    }
    
    /**
     * Write out information about a method.
     * This writes out a &lt;method&gt; node which contains information about
     * the arguments, the return type, and the exceptions thrown by the 
     * method.
     *
     * @param info Info about the method.
     */
    protected void writeMethodInfo(MethodInfo info) {
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI, "method");
        currentNode.appendChild(tmp);
        this.currentNode = tmp;
        addAccessFlags(info);

        if (info.getName() != null)
            tmp.setAttribute( "name", info.getName());
        if (info.getSignature() != null)
            tmp.setAttribute( "signature", info.getSignature());
        if (info.getDesc() != null)
            addMethodNodes(info.getDesc());
        String[] exceptions = info.getExceptions();
        if (exceptions != null) {
            for (int i = 0; i < exceptions.length; i++) {
                Element excep = doc.createElementNS(XML_URI, "exception");
                excep.setAttribute( "name", exceptions[i]);
                tmp.appendChild(excep);
            }
        }
        this.currentNode = currentNode;
    }
    
    /**
     * Write out information about a field.
     * This writes out a &lt;field&gt; node with attributes describing the
     * field.
     *
     * @param info Info about the field.
     */
    protected void writeFieldInfo(FieldInfo info) {
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI, "field");
        currentNode.appendChild(tmp);
        this.currentNode = tmp;
        addAccessFlags(info);

        if (info.getName() != null)
            tmp.setAttribute( "name", 
                    info.getName());
        if (info.getSignature() != null)
            tmp.setAttribute( "signature", 
                    info.getSignature());
        if (info.getValue() != null)
            tmp.setAttribute( "value",
                    info.getValue().toString());
        if (info.getDesc() != null)
            addTypeNode(info.getDesc());
        this.currentNode = currentNode;
    }
    
    /**
     * Add attributes describing some access flags.
     * This adds the attributes to the attr field.
     *
     * @see #attr
     * @param info Info describing the access flags.
     */
    protected void addAccessFlags(AbstractInfo info) {
        Element currentNode = (Element) this.currentNode;
        currentNode.setAttribute( "access", info.getAccessType());
        if (info.isAbstract())
            currentNode.setAttribute( "abstract", "yes");
        if (info.isAnnotation())
            currentNode.setAttribute( "annotation", "yes");
        if (info.isBridge())
            currentNode.setAttribute( "bridge", "yes");
        if (info.isDeprecated())
            currentNode.setAttribute( "deprecated", "yes");
        if (info.isEnum())
            currentNode.setAttribute( "enum", "yes");
        if (info.isFinal())
            currentNode.setAttribute( "final", "yes");
        if (info.isInterface())
            currentNode.setAttribute( "interface", "yes");
        if (info.isNative())
            currentNode.setAttribute( "native", "yes");
        if (info.isStatic())
            currentNode.setAttribute( "static", "yes");
        if (info.isStrict())
            currentNode.setAttribute( "strict", "yes");
        if (info.isSuper())
            currentNode.setAttribute( "super", "yes");
        if (info.isSynchronized())
            currentNode.setAttribute( "synchronized", "yes");
        if (info.isSynthetic())
            currentNode.setAttribute( "synthetic", "yes");
        if (info.isTransient())
            currentNode.setAttribute( "transient", "yes");
        if (info.isVarargs())
            currentNode.setAttribute( "varargs", "yes");
        if (info.isVolatile())
            currentNode.setAttribute( "volatile", "yes");
    }
    
    /**
     * Add the method nodes for the method descriptor.
     * This writes out an &lt;arguments&gt; node containing the 
     * argument types for the method, followed by a &lt;return&gt; node
     * containing the return type.
     *
     * @param desc The descriptor for the method to write out.
     */
    protected void addMethodNodes(String desc) {
        Type[] args = Type.getArgumentTypes(desc);
        Type ret = Type.getReturnType(desc);
        Node currentNode = this.currentNode;
        Element tmp = doc.createElementNS(XML_URI,"arguments");
        currentNode.appendChild(tmp);
        this.currentNode = tmp;
        for (int i = 0; i < args.length; i++)
            addTypeNode(args[i]);
        tmp = doc.createElementNS(XML_URI,"return");
        currentNode.appendChild(tmp);
        this.currentNode = tmp;
        addTypeNode(ret);
        this.currentNode = currentNode;
    }
    
    /**
     * Add a type node for the specified descriptor.
     *
     * @param desc A type descriptor.
     */
    protected void addTypeNode(String desc) {
        addTypeNode(Type.getType(desc));
    }
    
    /**
     * Add a type node for the specified type.
     * This writes out a &lt;type&gt; node with attributes describing
     * the type.
     *
     * @param type The type to describe.
     */
    protected void addTypeNode(Type type) {
        Element tmp = doc.createElementNS(XML_URI, "type");
        currentNode.appendChild(tmp);
        int i = type.getSort();
        if (i == Type.ARRAY) {
            tmp.setAttribute( "array", "yes");
            tmp.setAttribute( "dimensions",
                              "" + type.getDimensions());
            type = type.getElementType();
            i = type.getSort();
        }
        switch (i) {
        case Type.BOOLEAN:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "boolean");
            break;
        case Type.BYTE:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "byte");
            break;
        case Type.CHAR:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "char");
            break;
        case Type.DOUBLE:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "double");
            break;
        case Type.FLOAT:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "float");
            break;
        case Type.INT:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "int");
            break;
        case Type.LONG:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "long");
            break;
        case Type.OBJECT:
            tmp.setAttribute( "name", type.getInternalName());
            break;
        case Type.SHORT:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "short");
            break;
        case Type.VOID:
            tmp.setAttribute( "primitive", "yes");
            tmp.setAttribute( "name", "void");
            break;
        }
    }
}