Home | History | Annotate | Download | only in webapp
      1 //
      2 //  ========================================================================
      3 //  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
      4 //  ------------------------------------------------------------------------
      5 //  All rights reserved. This program and the accompanying materials
      6 //  are made available under the terms of the Eclipse Public License v1.0
      7 //  and Apache License v2.0 which accompanies this distribution.
      8 //
      9 //      The Eclipse Public License is available at
     10 //      http://www.eclipse.org/legal/epl-v10.html
     11 //
     12 //      The Apache License v2.0 is available at
     13 //      http://www.opensource.org/licenses/apache2.0.php
     14 //
     15 //  You may elect to redistribute this code under either of these licenses.
     16 //  ========================================================================
     17 //
     18 
     19 package org.eclipse.jetty.webapp;
     20 
     21 import java.net.URL;
     22 
     23 import org.eclipse.jetty.util.resource.Resource;
     24 import org.eclipse.jetty.xml.XmlParser;
     25 
     26 public abstract class Descriptor
     27 {
     28     protected Resource _xml;
     29     protected XmlParser.Node _root;
     30     protected XmlParser _parser;
     31     protected boolean _validating;
     32 
     33     public Descriptor (Resource xml)
     34     {
     35         _xml = xml;
     36     }
     37 
     38     public abstract XmlParser newParser()
     39     throws ClassNotFoundException;
     40 
     41     public abstract void ensureParser()
     42     throws ClassNotFoundException;
     43 
     44     protected void redirect(XmlParser parser, String resource, URL source)
     45     {
     46         if (source != null) parser.redirectEntity(resource, source);
     47     }
     48 
     49 
     50     public void setValidating (boolean validating)
     51     {
     52        _validating = validating;
     53     }
     54 
     55     public void parse ()
     56     throws Exception
     57     {
     58         if (_parser == null)
     59            ensureParser();
     60 
     61         if (_root == null)
     62         {
     63             try
     64             {
     65                 _root = _parser.parse(_xml.getInputStream());
     66             }
     67             finally
     68             {
     69                 _xml.release();
     70             }
     71         }
     72     }
     73 
     74     public Resource getResource ()
     75     {
     76         return _xml;
     77     }
     78 
     79     public XmlParser.Node getRoot ()
     80     {
     81         return _root;
     82     }
     83 
     84     public String toString()
     85     {
     86         return this.getClass().getSimpleName()+"("+_xml+")";
     87     }
     88 }
     89