Java tutorial
/* * Copyright (c) 2012 NTT DATA Corporation * * 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. */ package jp.terasoluna.fw.beans.jxpath; import java.lang.reflect.Field; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Map; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * commons-JXPath??(JXPATH-152)?? * <p> * ??? JXPathIntrospector??????private static(byClass, byInterface)?HashMap ?( * {@link HashMapForJXPathIntrospector})???<br> * </p> * <p> * ???????????(??????????)???<br> * applicationContext.xml??????????? <fieldset> <legend>applicationContext.xml</legend> <bean * id="jxpathPatchActivator" class="jp.terasoluna.fw.beans.jxpath.JXPATH152PatchActivator"/> </fieldset> * </p> * <p> * <br> * ????JXPathIntrospector?private static????? ???????? * private??(java.lang.reflect.ReflectPermission?suppressAccessChecks)????<br> * ???private???(??????????????????)??? ??????????? * ???jar??????private????? <fieldset> <legend>??(Tomcat?)</legend> * * <pre> * grant codeBase "file:${catalina.home}/webapps/ContextRoot/WEB-INF/lib/???jar??" { * permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; * }; * </pre> * * </fieldset> (???????codeBase "file:"????)<br> * ????????????????? commons-JXPath-1.3??JXPathIntrospector?????commons-JXPath????? * ????????????FATAL?<br> * ????Error???????????????????<br> * ??????Error?????????????????????????? * </p> * @see HashMapForJXPathIntrospector */ public class JXPATH152PatchActivator { /** * */ private static final Log log = LogFactory.getLog(JXPATH152PatchActivator.class); static { // ?? // (??????????????????) AccessController.doPrivileged(new PrivilegedAction<Void>() { @Override public Void run() { activate(); return null; } }); } /** * ?? */ private static void activate() { try { // ?????Map? Field byClassField = JXPathIntrospector.class.getDeclaredField("byClass"); byClassField.setAccessible(true); Map<?, ?> byClass = (Map<?, ?>) byClassField.get(null); Field byInterfaceField = JXPathIntrospector.class.getDeclaredField("byInterface"); byInterfaceField.setAccessible(true); Map<?, ?> byInterface = (Map<?, ?>) byInterfaceField.get(null); // Map?? byClassField.set(null, new HashMapForJXPathIntrospector<Object, Object>(byClass)); byInterfaceField.set(null, new HashMapForJXPathIntrospector<Object, Object>(byInterface)); log.info("JXPATH-152 Patch activation succeeded."); } catch (Exception e) { // ????? // ???????commons-JXPath????? log.fatal("JXPATH-152 Patch activation failed.", e); } } }