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     */
    39    public NoChildren(final GPathResult parent, final String name, final Map namespaceTagHints) {
    40      super(parent, name, "*", namespaceTagHints);
    41    }
    42
    43    /* (non-Javadoc)
    44     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#size()
    45     */
    46    public int size() {
    47      return 0;
    48    }
    49
    50    /* (non-Javadoc)
    51     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#text()
    52     */
    53    public String text() {
    54      return "";
    55    }
    56
    57    /* (non-Javadoc)
    58     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#parents()
    59     */
    60    public GPathResult parents() {
    61      // TODO Auto-generated method stub
    62      throw new GroovyRuntimeException("parents() not implemented yet");
    63    }
    64
    65    /* (non-Javadoc)
    66     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#childNodes()
    67     */
    68    public Iterator childNodes() {
    69      return iterator();
    70    }
    71
    72    /* (non-Javadoc)
    73     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#iterator()
    74     */
    75    public Iterator iterator() {
    76      return new Iterator() {
    77        public boolean hasNext() {
    78          return false;
    79        }
    80
    81        public Object next() {
    82          return null;
    83        }
    84
    85        public void remove() {
    86          throw new UnsupportedOperationException();
    87        }
    88      };
    89    }
    90
    91    /* (non-Javadoc)
    92     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#find(groovy.lang.Closure)
    93     */
    94    public GPathResult find(final Closure closure) {
    95      return this;
    96    }
    97
    98    /* (non-Javadoc)
    99     * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#findAll(groovy.lang.Closure)
    100    */
    101   public GPathResult findAll(final Closure closure) {
    102     return this;
    103   }
    104
    105   /* (non-Javadoc)
    106    * @see org.codehaus.groovy.sandbox.util.slurpersupport.GPathResult#nodeIterator()
    107    */
    108   public Iterator nodeIterator() {
    109     return iterator();
    110   }
    111
    112   /* (non-Javadoc)
    113    * @see groovy.lang.Writable#writeTo(java.io.Writer)
    114    */
    115   public Writer writeTo(final Writer out) throws IOException {
    116     return out;
    117   }
    118
    119   /* (non-Javadoc)
    120    * @see org.codehaus.groovy.sandbox.markup.Buildable#build(groovy.lang.GroovyObject)
    121    */
    122   public void build(final GroovyObject builder) {
    123   }
    124
    125   protected void replaceNode(final Closure newValue) {
    126     // No elements match GPath expression - do nothing
    127   }
    128
    129   protected void replaceBody(final Object newValue) {
    130     // No elements match GPath expression - do nothing
    131   }
    132
    133   protected void appendNode(final Object newValue) {
    134     // TODO consider creating an element for this
    135   }
    136 }