⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 methodconfigurationprovider.java

📁 struts 2 核心包 的源码 有错误是难免的
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   MethodConfigurationProvider.java

package org.apache.struts2.config;

import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.config.*;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import java.lang.reflect.Method;
import java.util.*;

public class MethodConfigurationProvider
	implements ConfigurationProvider
{

	private Configuration configuration;
	boolean reload;
	ObjectFactory factory;

	public MethodConfigurationProvider()
	{
	}

	public void setConfiguration(Configuration configuration)
	{
		this.configuration = configuration;
	}

	public void destroy()
	{
	}

	public void init(Configuration configuration)
		throws ConfigurationException
	{
		setConfiguration(configuration);
		configuration.rebuildRuntimeConfiguration();
	}

	public void register(ContainerBuilder containerbuilder, LocatableProperties locatableproperties)
		throws ConfigurationException
	{
	}

	public void loadPackages()
		throws ConfigurationException
	{
		Set namespaces = Collections.EMPTY_SET;
		RuntimeConfiguration rc = configuration.getRuntimeConfiguration();
		Map allActionConfigs = rc.getActionConfigs();
		if (allActionConfigs != null)
			namespaces = allActionConfigs.keySet();
		if (namespaces.size() == 0)
			throw new ConfigurationException("MethodConfigurationProvider.loadPackages: namespaces.size == 0");
		boolean added = false;
		for (Iterator i$ = namespaces.iterator(); i$.hasNext();)
		{
			Object namespace = i$.next();
			Map actions = (Map)allActionConfigs.get(namespace);
			Set actionNames = actions.keySet();
			Iterator i$ = actionNames.iterator();
			while (i$.hasNext()) 
			{
				Object actionName = i$.next();
				ActionConfig actionConfig = (ActionConfig)actions.get(actionName);
				added |= addDynamicMethods(actions, (String)actionName, actionConfig);
			}
		}

		reload = added;
	}

	public boolean needsReload()
	{
		return reload;
	}

	public void setObjectFactory(ObjectFactory factory)
	{
		this.factory = factory;
	}

	private ObjectFactory getObjectFactory()
		throws ConfigurationException
	{
		if (factory == null)
		{
			factory = ObjectFactory.getObjectFactory();
			if (factory == null)
				throw new ConfigurationException("MethodConfigurationProvider.getObjectFactory: ObjectFactory==null");
		}
		return factory;
	}

	private boolean upperAt(int pos, String string)
	{
		int len = string.length();
		if (len < pos)
		{
			return false;
		} else
		{
			String ch = string.substring(pos, pos + 1);
			return ch.equals(ch.toUpperCase());
		}
	}

	protected boolean addDynamicMethods(Map actions, String actionName, ActionConfig actionConfig)
		throws ConfigurationException
	{
		String configMethod = actionConfig.getMethodName();
		boolean hasMethod = configMethod != null && configMethod.length() > 0;
		if (hasMethod)
			return false;
		String className = actionConfig.getClassName();
		Set actionMethods = new HashSet();
		ObjectFactory factory = getObjectFactory();
		Class actionClass;
		try
		{
			actionClass = factory.getClassInstance(className);
		}
		catch (ClassNotFoundException e)
		{
			throw new ConfigurationException(e);
		}
		Method methods[] = actionClass.getMethods();
		Method arr$[] = methods;
		int len$ = arr$.length;
		for (int i$ = 0; i$ < len$; i$++)
		{
			Method method = arr$[i$];
			String returnString = method.getReturnType().getName();
			boolean isString = "java.lang.String".equals(returnString);
			if (!isString)
				continue;
			Class parameterTypes[] = method.getParameterTypes();
			boolean noParameters = parameterTypes.length == 0;
			String methodString = method.getName();
			boolean notGetMethod = !methodString.startsWith("get") || !upperAt(3, methodString);
			boolean notIsMethod = !methodString.startsWith("is") || !upperAt(2, methodString);
			boolean notToString = !"toString".equals(methodString);
			boolean notExecute = !"execute".equals(methodString);
			boolean qualifies = noParameters && notGetMethod && notIsMethod && notToString && notExecute;
			if (qualifies)
				actionMethods.add(methodString);
		}

		Iterator i$ = actionMethods.iterator();
		do
		{
			if (!i$.hasNext())
				break;
			Object actionMethod = i$.next();
			String methodName = (String)actionMethod;
			StringBuilder sb = new StringBuilder();
			sb.append(actionName);
			sb.append("!");
			sb.append(methodName);
			String newActionName = sb.toString();
			boolean haveAction = actions.containsKey(newActionName);
			if (!haveAction)
			{
				ActionConfig newActionConfig = new ActionConfig(newActionName, actionConfig.getClassName(), actionConfig.getParams(), actionConfig.getResults(), actionConfig.getInterceptors(), actionConfig.getExceptionMappings());
				newActionConfig.setMethodName(methodName);
				String packageName = actionConfig.getPackageName();
				newActionConfig.setPackageName(packageName);
				PackageConfig packageConfig = configuration.getPackageConfig(packageName);
				packageConfig.addActionConfig(newActionName, actionConfig);
			}
		} while (true);
		return actionMethods.size() > 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -