alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (XPathFactoryImpl.java)

This example Java source code file (XPathFactoryImpl.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

boolean, class_name, featuremanager, illegalargumentexception, nullpointerexception, object, string, xml, xpath, xpathfactoryconfigurationexception, xpathfactoryimpl, xpathfunctionresolver, xpathvariableresolver

The XPathFactoryImpl.java Java example source code

/*
 * reserved comment block
 * DO NOT REMOVE OR ALTER!
 */
/*
 * Copyright 1999-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// $Id: XPathFactoryImpl.java,v 1.2 2005/08/16 22:41:13 jeffsuttor Exp $

package com.sun.org.apache.xpath.internal.jaxp;

import com.sun.org.apache.xalan.internal.XalanConstants;
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
import com.sun.org.apache.xalan.internal.res.XSLMessages;
import com.sun.org.apache.xalan.internal.utils.FeatureManager;
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase;

import javax.xml.XMLConstants;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import javax.xml.xpath.XPathFunctionResolver;
import javax.xml.xpath.XPathVariableResolver;

/**
 * The XPathFactory builds XPaths.
 *
 * @version $Revision: 1.11 $
 * @author  Ramesh Mandava
 */
public  class XPathFactoryImpl extends XPathFactory {

        /**
         * <p>Name of class as a constant to use for debugging.

*/ private static final String CLASS_NAME = "XPathFactoryImpl"; /** *<p>XPathFunctionResolver for this XPathFactory and created XPaths.

*/ private XPathFunctionResolver xPathFunctionResolver = null; /** * <p>XPathVariableResolver for this XPathFactory and created XPaths

*/ private XPathVariableResolver xPathVariableResolver = null; /** * <p>State of secure processing feature.

*/ private boolean _isNotSecureProcessing = true; /** * <p>State of secure mode.

*/ private boolean _isSecureMode = false; /** * javax.xml.xpath.XPathFactory implementation. */ private boolean _useServicesMechanism = true; private final FeatureManager _featureManager; public XPathFactoryImpl() { this(true); } public static XPathFactory newXPathFactoryNoServiceLoader() { return new XPathFactoryImpl(false); } public XPathFactoryImpl(boolean useServicesMechanism) { _featureManager = new FeatureManager(); if (System.getSecurityManager() != null) { _isSecureMode = true; _isNotSecureProcessing = false; _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE); } this._useServicesMechanism = useServicesMechanism; } /** * <p>Is specified object model supported by this * <code>XPathFactory?

* * @param objectModel Specifies the object model which the returned * <code>XPathFactory will understand. * * @return <code>true if XPathFactory supports * <code>objectModel, else false. * * @throws NullPointerException If <code>objectModel is null. * @throws IllegalArgumentException If <code>objectModel.length() == 0. */ public boolean isObjectModelSupported(String objectModel) { if (objectModel == null) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_OBJECT_MODEL_NULL, new Object[] { this.getClass().getName() } ); throw new NullPointerException( fmsg ); } if (objectModel.length() == 0) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_OBJECT_MODEL_EMPTY, new Object[] { this.getClass().getName() } ); throw new IllegalArgumentException( fmsg ); } // know how to support default object model, W3C DOM if (objectModel.equals(XPathFactory.DEFAULT_OBJECT_MODEL_URI)) { return true; } // don't know how to support anything else return false; } /** * <p>Returns a new XPath object using the underlying * object model determined when the factory was instantiated.</p> * * @return New <code>XPath */ public javax.xml.xpath.XPath newXPath() { return new com.sun.org.apache.xpath.internal.jaxp.XPathImpl( xPathVariableResolver, xPathFunctionResolver, !_isNotSecureProcessing, _useServicesMechanism, _featureManager ); } /** * <p>Set a feature for this XPathFactory and * <code>XPaths created by this factory.

* * <p> * Feature names are fully qualified {@link java.net.URI}s. * Implementations may define their own features. * An {@link XPathFactoryConfigurationException} is thrown if this * <code>XPathFactory or the XPaths * it creates cannot support the feature. * It is possible for an <code>XPathFactory to expose a feature * value but be unable to change its state. * </p> * * <p>See {@link javax.xml.xpath.XPathFactory} for full documentation * of specific features.</p> * * @param name Feature name. * @param value Is feature state <code>true or false. * * @throws XPathFactoryConfigurationException if this * <code>XPathFactory or the XPaths * it creates cannot support this feature. * @throws NullPointerException if <code>name is * <code>null. */ public void setFeature(String name, boolean value) throws XPathFactoryConfigurationException { // feature name cannot be null if (name == null) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_FEATURE_NAME_NULL, new Object[] { CLASS_NAME, new Boolean( value) } ); throw new NullPointerException( fmsg ); } // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { if ((_isSecureMode) && (!value)) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_SECUREPROCESSING_FEATURE, new Object[] { name, CLASS_NAME, new Boolean(value) } ); throw new XPathFactoryConfigurationException( fmsg ); } _isNotSecureProcessing = !value; if (value && _featureManager != null) { _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE); } // all done processing feature return; } if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { //in secure mode, let _useServicesMechanism be determined by the constructor if (!_isSecureMode) _useServicesMechanism = value; return; } if (_featureManager != null && _featureManager.setValue(name, FeaturePropertyBase.State.APIPROPERTY, value)) { return; } // unknown feature String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_FEATURE_UNKNOWN, new Object[] { name, CLASS_NAME, new Boolean(value) } ); throw new XPathFactoryConfigurationException( fmsg ); } /** * <p>Get the state of the named feature.

* * <p> * Feature names are fully qualified {@link java.net.URI}s. * Implementations may define their own features. * An {@link XPathFactoryConfigurationException} is thrown if this * <code>XPathFactory or the XPaths * it creates cannot support the feature. * It is possible for an <code>XPathFactory to expose a feature * value but be unable to change its state. * </p> * * @param name Feature name. * * @return State of the named feature. * * @throws XPathFactoryConfigurationException if this * <code>XPathFactory or the XPaths * it creates cannot support this feature. * @throws NullPointerException if <code>name is * <code>null. */ public boolean getFeature(String name) throws XPathFactoryConfigurationException { // feature name cannot be null if (name == null) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_GETTING_NULL_FEATURE, new Object[] { CLASS_NAME } ); throw new NullPointerException( fmsg ); } // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { return !_isNotSecureProcessing; } if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { return _useServicesMechanism; } /** Check to see if the property is managed by the security manager **/ String propertyValue = (_featureManager != null) ? _featureManager.getValueAsString(name) : null; if (propertyValue != null) { return _featureManager.isFeatureEnabled(name); } // unknown feature String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_GETTING_UNKNOWN_FEATURE, new Object[] { name, CLASS_NAME } ); throw new XPathFactoryConfigurationException( fmsg ); } /** * <p>Establish a default function resolver.

* * <p>Any XPath objects constructed from this factory will use * the specified resolver by default.</p> * * <p>A NullPointerException is thrown if * <code>resolver is null.

* * @param resolver XPath function resolver. * * @throws NullPointerException If <code>resolver is * <code>null. */ public void setXPathFunctionResolver(XPathFunctionResolver resolver) { // resolver cannot be null if (resolver == null) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_NULL_XPATH_FUNCTION_RESOLVER, new Object[] { CLASS_NAME } ); throw new NullPointerException( fmsg ); } xPathFunctionResolver = resolver; } /** * <p>Establish a default variable resolver.

* * <p>Any XPath objects constructed from this factory will use * the specified resolver by default.</p> * * <p>A NullPointerException is thrown if resolver is null.

* * @param resolver Variable resolver. * * @throws NullPointerException If <code>resolver is * <code>null. */ public void setXPathVariableResolver(XPathVariableResolver resolver) { // resolver cannot be null if (resolver == null) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_NULL_XPATH_VARIABLE_RESOLVER, new Object[] { CLASS_NAME } ); throw new NullPointerException( fmsg ); } xPathVariableResolver = resolver; } }

Other Java examples (source code examples)

Here is a short list of links related to this Java XPathFactoryImpl.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.