KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > xml > SortNodes


1 // Copyright (c) 2003 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.xml;
5 import gnu.bytecode.*;
6 import gnu.mapping.*;
7 import gnu.expr.*;
8
9 /** Sort argument nodes in document order.
10  * Uses the SortedNodes class to do the actual work. */

11
12 public class SortNodes extends Procedure1 implements Inlineable
13 {
14   public static final SortNodes sortNodes = new SortNodes();
15
16   public Object JavaDoc apply1 (Object JavaDoc values)
17   {
18     SortedNodes nodes = new SortedNodes();
19     Values.writeValues(values, nodes);
20     if (nodes.count > 1)
21       return nodes;
22     else if (nodes.count == 0)
23       return Values.empty;
24     else
25       return nodes.get(0);
26   }
27
28   public void compile (ApplyExp exp, Compilation comp, Target target)
29   {
30     Expression[] args = exp.getArgs();
31     if (args.length != 1 || ! comp.mustCompile)
32       ApplyExp.compile(exp, comp, target);
33     else
34       {
35         Method resultMethod;
36         if (target instanceof ConsumerTarget
37             || (target instanceof StackTarget
38                 && target.getType().isSubtype(Compilation.typeValues)))
39           resultMethod = null;
40         else
41           resultMethod = canonicalizeMethod;
42         ConsumerTarget.compileUsingConsumer(args[0], comp, target,
43                                             makeSortedNodesMethod,
44                                             resultMethod);
45       }
46   }
47
48   public Type getReturnType (Expression[] args)
49   {
50     return Compilation.typeObject;
51   }
52
53   public static final ClassType typeSortedNodes
54     = ClassType.make("gnu.kawa.xml.SortedNodes");
55   public static final Method makeSortedNodesMethod
56     = typeSortedNodes.getDeclaredMethod("<init>", 0);
57   public static final Method canonicalizeMethod
58     = Compilation.typeValues.getDeclaredMethod("canonicalize", 0);
59 }
60
Popular Tags