Home » synapse-1.2-src » org.apache.synapse.util.xpath » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   
   20   package org.apache.synapse.util.xpath;
   21   
   22   import org.apache.synapse.MessageContext;
   23   import org.apache.synapse.mediators.GetPropertyFunction;
   24   import org.jaxen.Function;
   25   import org.jaxen.FunctionContext;
   26   import org.jaxen.UnresolvableException;
   27   
   28   /**
   29    * <p>XPath function context to be used when resolving XPath functions when using the
   30    * <code>SynapseXPath</code> and this resolves one function except for the standard XPath functions
   31    * and Jaxen extension functions.</p>
   32    *
   33    * <p>The function that has been resolved by this FunctionContext is; <tt>get-property(String)</tt>
   34    * which is used to retrieve message context properties</p>
   35    *
   36    * @see org.jaxen.XPathFunctionContext
   37    * @see org.apache.synapse.util.xpath.SynapseXPath
   38    */
   39   public class SynapseXPathFunctionContext implements FunctionContext {
   40       /** Parent function context */
   41       private final FunctionContext parent;
   42       
   43       /** MessageContext to be used by the function resolver */
   44       private final MessageContext synCtx;
   45   
   46       /**
   47        * <p>Initialises the function context</p>
   48        *
   49        * @param parent the parent function context
   50        * @param synCtx message to be used for the function initialization
   51        *
   52        * @see org.jaxen.XPathFunctionContext
   53        */
   54       public SynapseXPathFunctionContext(FunctionContext parent, MessageContext synCtx) {
   55           this.parent = parent;
   56           this.synCtx = synCtx;
   57       }
   58   
   59       /**
   60        * Get the function with a given namespace and name.
   61        * <p>
   62        * Only the <tt>get-property</tt> function is recognized by this class. Any other
   63        * function will be resolved using the parent function context.
   64        * 
   65        * @param namespaceURI namespace of the function to be resolved
   66        * @param prefix string prefix to be resolved
   67        * @param localName string local name of the function
   68        * @return resolved function
   69        * @throws UnresolvableException if the function specified does not found
   70        */
   71       public Function getFunction(String namespaceURI, String prefix, String localName)
   72           throws UnresolvableException {
   73   
   74           if (localName != null && SynapseXPathConstants.GET_PROPERTY_FUNCTION.equals(localName)) {
   75               
   76               // create an instance of a synapse:get-property()
   77               // function and set it to the xpath
   78               GetPropertyFunction getPropertyFunc = new GetPropertyFunction();
   79               getPropertyFunc.setSynCtx(synCtx);
   80   
   81               return getPropertyFunc;
   82           }
   83   
   84           // if not the get-property function then try to get it from the parent context
   85           return parent.getFunction(namespaceURI, prefix, localName);
   86       }
   87   }

Home » synapse-1.2-src » org.apache.synapse.util.xpath » [javadoc | source]