/[classpath]/classpath/gnu/xml/transform/ParameterNode.java
ViewVC logotype

Diff of /classpath/gnu/xml/transform/ParameterNode.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mark, Sat Jul 2 20:32:16 2005 UTC revision 1.4 by dog, Sat Jul 9 20:38:35 2005 UTC
# Line 53  import gnu.xml.xpath.Expr; Line 53  import gnu.xml.xpath.Expr;
53   */   */
54  final class ParameterNode  final class ParameterNode
55    extends TemplateNode    extends TemplateNode
56      implements Comparable
57  {  {
58    
59    final String name;    final QName name;
60    final Expr select;    final Expr select;
61    final boolean global;    final int type;
62    
63    ParameterNode(String name, Expr select, boolean global)    ParameterNode(QName name, Expr select, int type)
64    {    {
65      this.name = name;      this.name = name;
66      this.select = select;      this.select = select;
67      this.global = global;      this.type = type;
68    }    }
69    
70    TemplateNode clone(Stylesheet stylesheet)    TemplateNode clone(Stylesheet stylesheet)
71    {    {
72      TemplateNode ret = new ParameterNode(name,      TemplateNode ret = new ParameterNode(name,
73                                           select.clone(stylesheet),                                           select.clone(stylesheet),
74                                           global);                                           type);
75      if (children != null)      if (children != null)
76        {        {
77          ret.children = children.clone(stylesheet);          ret.children = children.clone(stylesheet);
# Line 83  final class ParameterNode Line 84  final class ParameterNode
84    }    }
85    
86    void doApply(Stylesheet stylesheet, QName mode,    void doApply(Stylesheet stylesheet, QName mode,
87               Node context, int pos, int len,                 Node context, int pos, int len,
88               Node parent, Node nextSibling)                 Node parent, Node nextSibling)
89      throws TransformerException      throws TransformerException
90    {    {
91      boolean apply = global || !stylesheet.bindings.containsKey(name, global);      // push the variable context
92      if (apply)      stylesheet.bindings.push(type);
93        // set the variable
94        Object value = getValue(stylesheet, mode, context, pos, len);
95        if (value != null)
96        {        {
97          // push the variable context          stylesheet.bindings.set(name, value, type);
98          stylesheet.bindings.push(global);          if (stylesheet.debug)
         // set the variable  
         Object value = getValue(stylesheet, mode, context, pos, len);  
         if (value != null)  
99            {            {
100              stylesheet.bindings.set(name, value, global);              System.err.println(this + ": set to " + value);
101            }            }
102        }        }
103      // variable and param don't process children as such      // variable and param don't process children as such
# Line 107  final class ParameterNode Line 108  final class ParameterNode
108                     context, pos, len,                     context, pos, len,
109                     parent, nextSibling);                     parent, nextSibling);
110        }        }
111      if (apply)      // pop the variable context
112        {      stylesheet.bindings.pop(type);
         // pop the variable context  
         stylesheet.bindings.pop(global);  
       }  
113    }    }
114        
115    Object getValue(Stylesheet stylesheet, QName mode,    Object getValue(Stylesheet stylesheet, QName mode,
# Line 136  final class ParameterNode Line 134  final class ParameterNode
134        }        }
135    }    }
136        
137      public boolean references(QName var)
138      {
139        if (select != null && select.references(var))
140          {
141            return true;
142          }
143        return super.references(var);
144      }
145    
146      public int compareTo(Object other)
147      {
148        if (other instanceof ParameterNode)
149          {
150            ParameterNode pn = (ParameterNode) other;
151            boolean r1 = references(pn.name);
152            boolean r2 = pn.references(name);
153            if (r1 && r2)
154              {
155                throw new IllegalArgumentException("circular definitions");
156              }
157            if (r1)
158              {
159                return 1;
160              }
161            if (r2)
162              {
163                return -1;
164              }
165          }
166        return 0;
167      }
168      
169    public String toString()    public String toString()
170    {    {
171      StringBuffer buf = new StringBuffer(getClass().getName());      StringBuffer buf = new StringBuffer(getClass().getName());
# Line 147  final class ParameterNode Line 177  final class ParameterNode
177          buf.append(",select=");          buf.append(",select=");
178          buf.append(select);          buf.append(select);
179        }        }
180      if (global)      buf.append(",type=");
181        switch (type)
182        {        {
183          buf.append(",global");        case Bindings.VARIABLE:
184            buf.append("variable");
185            break;
186          case Bindings.PARAM:
187            buf.append("param");
188            break;
189          case Bindings.WITH_PARAM:
190            buf.append("with-param");
191            break;
192        }        }
193      buf.append(']');      buf.append(']');
194      return buf.toString();      return buf.toString();

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26