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: */
039: public NoChildren(final GPathResult parent, final String name,
040: 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(
064: "parents() not implemented yet");
065: }
066:
067: /* (non-Javadoc)
068: * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#childNodes()
069: */
070: public Iterator childNodes() {
071: return iterator();
072: }
073:
074: /* (non-Javadoc)
075: * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#iterator()
076: */
077: public Iterator iterator() {
078: return new Iterator() {
079: public boolean hasNext() {
080: return false;
081: }
082:
083: public Object next() {
084: return null;
085: }
086:
087: public void remove() {
088: throw new UnsupportedOperationException();
089: }
090: };
091: }
092:
093: /* (non-Javadoc)
094: * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#find(groovy.lang.Closure)
095: */
096: public GPathResult find(final Closure closure) {
097: return this ;
098: }
099:
100: /* (non-Javadoc)
101: * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#findAll(groovy.lang.Closure)
102: */
103: public GPathResult findAll(final Closure closure) {
104: return this ;
105: }
106:
107: /* (non-Javadoc)
108: * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#nodeIterator()
109: */
110: public Iterator nodeIterator() {
111: return iterator();
112: }
113:
114: /* (non-Javadoc)
115: * @see groovy.lang.Writable#writeTo(java.io.Writer)
116: */
117: public Writer writeTo(final Writer out) throws IOException {
118: return out;
119: }
120:
121: /* (non-Javadoc)
122: * @see org.codehaus.groovy.sandbox.markup.Buildable#build(groovy.lang.GroovyObject)
123: */
124: public void build(final GroovyObject builder) {
125: }
126:
127: protected void replaceNode(final Closure newValue) {
128: // No elements match GPath expression - do nothing
129: }
130:
131: protected void replaceBody(final Object newValue) {
132: // No elements match GPath expression - do nothing
133: }
134:
135: protected void appendNode(final Object newValue) {
136: // TODO consider creating an element for this
137: }
138: }
|