View Javadoc

1   /*
2    * Copyright 2005 John G. Wilson
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package groovy.util.slurpersupport;
19  
20  import groovy.lang.Closure;
21  import groovy.lang.GroovyObject;
22  import groovy.lang.GroovyRuntimeException;
23  
24  import java.io.IOException;
25  import java.io.Writer;
26  import java.util.Iterator;
27  import java.util.Map;
28  
29  /***
30   * @author John Wilson
31   *
32   */
33  
34  public class NoChildren extends GPathResult {
35    /***
36     * @param parent
37     * @param name
38     * @param namespacePrefix
39     */
40    public NoChildren(final GPathResult parent, final String name, final Map namespaceTagHints) {
41      super(parent, name, "*", namespaceTagHints);
42    }
43  
44    /* (non-Javadoc)
45     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#size()
46     */
47    public int size() {
48      return 0;
49    }
50  
51    /* (non-Javadoc)
52     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#text()
53     */
54    public String text() {
55      return "";
56    }
57  
58    /* (non-Javadoc)
59     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#parents()
60     */
61    public GPathResult parents() {
62      // TODO Auto-generated method stub
63      throw new GroovyRuntimeException("parents() not implemented yet");
64    }
65  
66    /* (non-Javadoc)
67     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#childNodes()
68     */
69    public Iterator childNodes() {
70      return iterator();
71    }
72  
73    /* (non-Javadoc)
74     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#iterator()
75     */
76    public Iterator iterator() {
77      return new Iterator() {
78        public boolean hasNext() {
79          return false;
80        }
81        
82        public Object next() {
83          return null;
84        }
85        
86        public void remove() {
87          throw new UnsupportedOperationException();
88        }
89      };
90    }
91  
92    /* (non-Javadoc)
93     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#find(groovy.lang.Closure)
94     */
95    public GPathResult find(final Closure closure) {
96      return this;
97    }
98  
99    /* (non-Javadoc)
100    * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#findAll(groovy.lang.Closure)
101    */
102   public GPathResult findAll(final Closure closure) {
103     return this;
104   }
105 
106   /* (non-Javadoc)
107    * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#nodeIterator()
108    */
109   public Iterator nodeIterator() {
110     return iterator();
111   }
112 
113   /* (non-Javadoc)
114    * @see groovy.lang.Writable#writeTo(java.io.Writer)
115    */
116   public Writer writeTo(final Writer out) throws IOException {
117     return out;
118   }
119 
120   /* (non-Javadoc)
121    * @see org.codehaus.groovy.sandbox.markup.Buildable#build(groovy.lang.GroovyObject)
122    */
123   public void build(final GroovyObject builder) {
124   }
125 
126 }