001 /*
002 * Copyright 2005 John G. Wilson
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 */
017
018 package groovy.util.slurpersupport;
019
020 import groovy.lang.Closure;
021 import groovy.lang.GroovyObject;
022 import groovy.lang.GroovyRuntimeException;
023
024 import java.io.IOException;
025 import java.io.Writer;
026 import java.util.Iterator;
027 import java.util.Map;
028
029 /**
030 * @author John Wilson
031 *
032 */
033
034 public class NoChildren extends GPathResult {
035 /**
036 * @param parent
037 * @param name
038 * @param namespacePrefix
039 */
040 public NoChildren(final GPathResult parent, final String name, final Map namespaceTagHints) {
041 super(parent, name, "*", namespaceTagHints);
042 }
043
044 /* (non-Javadoc)
045 * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#size()
046 */
047 public int size() {
048 return 0;
049 }
050
051 /* (non-Javadoc)
052 * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#text()
053 */
054 public String text() {
055 return "";
056 }
057
058 /* (non-Javadoc)
059 * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#parents()
060 */
061 public GPathResult parents() {
062 // TODO Auto-generated method stub
063 throw new GroovyRuntimeException("parents() not implemented yet");
064 }
065
066 /* (non-Javadoc)
067 * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#childNodes()
068 */
069 public Iterator childNodes() {
070 return iterator();
071 }
072
073 /* (non-Javadoc)
074 * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#iterator()
075 */
076 public Iterator iterator() {
077 return new Iterator() {
078 public boolean hasNext() {
079 return false;
080 }
081
082 public Object next() {
083 return null;
084 }
085
086 public void remove() {
087 throw new UnsupportedOperationException();
088 }
089 };
090 }
091
092 /* (non-Javadoc)
093 * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#find(groovy.lang.Closure)
094 */
095 public GPathResult find(final Closure closure) {
096 return this;
097 }
098
099 /* (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 }