public static ExternalReference copyExternalRef( final ExternalReference reference ) { return new ExternalReference( reference.getName(), reference.getExternalRef(), reference.isRequired() ); }
/** * Copies the specified result config. * * @param config The config to copy. * @return the copy. */ public static ResultConfig copyResultConfig( final ResultConfig config ) { return new ResultConfig( config.getName(), config.getClassName(), copyParams( config.getParams() ) ); }
private void copyPackageDetails( PackageConfig sourcePackage, PackageConfig targetPackage ) throws ConveyorException { try { String name = targetPackage.getName(); copyMapValues( sourcePackage.getResultTypeConfigs(), targetPackage.getResultTypeConfigs(), "Result Type Config", name ); copyMapValues( sourcePackage.getInterceptorConfigs(), targetPackage.getInterceptorConfigs(), "Interceptor Config", name ); copyMapValues( sourcePackage.getGlobalResultConfigs(), targetPackage.getGlobalResultConfigs(), "Global Result Config", name ); copyMapValues( sourcePackage.getActionConfigs(), targetPackage.getActionConfigs(), "Action Config", name ); } catch ( ConveyorException e ) { revertPackage( sourcePackage, targetPackage ); throw e; } }
public TransientActionConfig( String originalActionName, ActionConfig originalAction, Plugin defaultPlugin ) { super( originalAction.getMethodName(), originalAction.getClassName(), cloneMap( originalAction.getParams() ), cloneMap( originalAction.getResults() ), cloneList( originalAction.getInterceptors() ), cloneList( originalAction.getExternalRefs() ), originalAction.getPackageName(), findPlugin( originalAction, defaultPlugin ) ); this.originalActionName = originalActionName; plugin = super.getPlugin(); }
public OverriddenPackageConfig( PackageConfig originalPackage ) throws ConveyorException { super( originalPackage.getName(), originalPackage.getNamespace(), originalPackage.isAbstract(), originalPackage.getExternalRefResolver(), cloneList( originalPackage.getParents() ) ); this.originalPackage = originalPackage; setDefaultResultType( originalPackage.getDefaultResultType() ); setDefaultInterceptorRef( originalPackage.getDefaultInterceptorRef() ); overridingPackageConfigs = new HashSet<OverridingPackageConfig>(); overriddenActionConfigs = new HashMap<String, OverriddenActionConfig>(); aliases = new HashMap<String, Set<String>>(); }
private static Map<String, ResultConfig> defaultResults() { Map<String, ResultConfig> results = new HashMap<String, ResultConfig>(); // SUCCESS results in a chaining to another action, as defined by the 'targetAction' field of the OverriddenAction. ResultConfig success = new ResultConfig(); success.setName( OverriddenAction.SUCCESS ); success.setClassName( ActionChainResult.class.getName() ); success.addParam( ActionChainResult.DEFAULT_PARAM, OverriddenAction.SUCCESS_DEFAULT_PARAM ); // ERROR results in a redirect to the 'errors.jsp', although it shouldn't actually get called anyway... ResultConfig error = new ResultConfig(); error.setName( OverriddenAction.ERROR ); error.setClassName( VelocityResult.class.getName() ); error.addParam( VelocityResult.DEFAULT_PARAM, OverriddenAction.ERROR_DEFAULT_PARAM ); results.put( OverriddenAction.SUCCESS, success ); results.put( OverriddenAction.ERROR, error ); return results; }
private void setOverriddenInterceptor( InterceptorConfig overriddenInterceptor, boolean copySettings ) { this.overriddenInterceptor = overriddenInterceptor; if ( copySettings ) { if ( this.getClassName() == null ) { setClassName( overriddenInterceptor.getClassName() ); } // Copy the new params over the old params. Map<String, String> oldParams = ConveyorConfigurationProvider.copyParams( overriddenInterceptor .getParams() ); if ( oldParams != null ) { Map<String, String> params = getParams(); if ( params != null ) oldParams.putAll( params ); setParams( oldParams ); } } }
public static ResultConfig getResultConfig(String namespace, String actionName, String resultName) { ResultConfig result = null; ActionConfig actionConfig = getActionConfig(namespace, actionName); if (actionConfig != null) { Map resultMap = actionConfig.getResults(); result = (ResultConfig) resultMap.get(resultName); } return result; }
private void removeActionConfig( PackageConfig packageConfig, String actionName ) { packageConfig.getActionConfigs().remove( actionName ); if ( packageConfig instanceof OverriddenPackageConfig ) { removeActionAliases( (OverriddenPackageConfig) packageConfig, actionName ); } }
@Override protected void addResultTypes( PackageConfig packageContext, Element element ) { NodeList resultTypeList = element.getElementsByTagName( "result-type" ); for ( int i = 0; i < resultTypeList.getLength(); i++ ) { Element resultTypeElement = (Element) resultTypeList.item( i ); String name = resultTypeElement.getAttribute( "name" ); String className = resultTypeElement.getAttribute( "class" ); String def = resultTypeElement.getAttribute( "default" ); try { Class<?> clazz = ClassLoaderUtil.loadClass( className, getClass() ); ResultTypeConfig resultType = new ResultTypeConfig( name, clazz ); packageContext.addResultTypeConfig( resultType ); // set the default result type if ( "true".equals( def ) ) { packageContext.setDefaultResultType( name ); } } catch ( ClassNotFoundException e ) { LOG.error( "Result class [" + className + "] doesn't exist, ignoring" ); } } }
/** * Retrieves the 'real' {@link ActionConfig) for the current context. This is different * to what is available in via the {@link com.opensymphony.xwork.ActionContext#getContext()} * method because that come from the 'runtime' configuration which has been generated separately. * * @return The original {@link ActionConfig} for the current context. */ public ActionConfig getCurrentActionConfig() { if ( ActionContext.getContext() != null && ActionContext.getContext().getActionInvocation() != null && ActionContext.getContext().getActionInvocation().getProxy() != null ) { ActionConfig currentAction = ActionContext.getContext().getActionInvocation().getProxy().getConfig(); ActionRequest request = null; try { request = ActionRequest.parse( ActionContext.getContext().getName() ); PackageConfig packageConfig = ConfigurationManager.getConfiguration().getPackageConfig( currentAction.getPackageName() ); if ( packageConfig != null ) return (ActionConfig) packageConfig.getActionConfigs().get( request.getActionName() ); } catch ( ConveyorException e ) { } } return null; }
private String findResultFromExceptionMappings( List exceptionMappings, Throwable t ) { String result = null; // Check for specific exception mappings. if ( exceptionMappings != null ) { int deepest = Integer.MAX_VALUE; for ( Iterator iter = exceptionMappings.iterator(); iter.hasNext(); ) { ExceptionMappingConfig exceptionMappingConfig = (ExceptionMappingConfig) iter.next(); int depth = getDepth( exceptionMappingConfig.getExceptionClassName(), t ); if ( depth >= 0 && depth < deepest ) { deepest = depth; result = exceptionMappingConfig.getResult(); } } } return result; }
public static File getViewFile(String namespace, String actionName, String resultName) { ResultConfig result = getResultConfig(namespace, actionName, resultName); String location = (String) result.getParams().get("location"); for (int i = 0; i < views.length; i++) { String viewRoot = views[i]; File viewFile = getViewFileInternal(viewRoot, location, namespace); if (viewFile != null) { return viewFile; } } return null; }
public OverriddenResultConfig( ResultConfig originalResult ) { super( originalResult.getName(), OverriddenResult.class ); setOriginalResult( originalResult ); setOverridingResults( new ArrayList<OverridingResultConfig>() ); }
private PackageConfig findPackageConfig( String name, String namespace ) throws ConveyorException { PackageConfig packageConfig = ConfigurationManager.getConfiguration().getPackageConfig( name ); if ( packageConfig == null ) { throw new ConveyorException( "Unable to find the package being overridden named '" + name + "'." ); } if ( !StringUtils.equals( namespace, packageConfig.getNamespace() ) ) { throw new ConveyorException( "The namespace for the '" + name + "' package is '" + packageConfig.getNamespace() + "' but the override specified '" + namespace + "'" ); } return packageConfig; }
public Method extractMethod(ActionInvocation invocation) throws NoSuchMethodException { return invocation.getProxy().getConfig().getMethod(); } }
public CreatePackageReceipt createPackage( PackageConfig packageConfig ) throws ConveyorException { String name = packageConfig.getName(); Configuration configuration = ConfigurationManager.getConfiguration(); if ( configuration.getPackageConfig( name ) != null ) throw new ConveyorException( "Unable to add a package named '" + name + "' because one already exists with the same name." ); configuration.addPackageConfig( name, packageConfig ); return keepReceipt( new CreatePackageReceipt( name, this ) ); }
private void revertPackage( PackageConfig sourcePackage, PackageConfig targetPackage ) { removeMapValues( sourcePackage.getResultTypeConfigs(), targetPackage.getResultTypeConfigs() ); removeMapValues( sourcePackage.getInterceptorConfigs(), targetPackage.getInterceptorConfigs() ); removeMapValues( sourcePackage.getGlobalResultConfigs(), targetPackage.getGlobalResultConfigs() ); Map<String, ActionConfig> actionConfigs = sourcePackage.getActionConfigs(); for ( Map.Entry<String, ActionConfig> entry : actionConfigs.entrySet() ) { removeActionConfig( targetPackage, entry.getKey() ); } }
private static String findActionAlias( PackageConfig packageConfig, String actionName ) { Map<String, ActionConfig> actionConfigs = packageConfig.getActionConfigs(); int i = 1; while ( actionConfigs.containsKey( getAlias( actionName, i ) ) ) i++; return getAlias( actionName, i ); }
protected void checkPackage( List violations, XworkPackageConfig expectedPackage, Configuration xwConfig ) { PackageConfig xwPackageConfig = findPackageNamespace( xwConfig, expectedPackage.name ); if ( xwPackageConfig != null ) { Map xwActionMap = xwPackageConfig.getActionConfigs(); Iterator it = expectedPackage.actions.iterator(); while ( it.hasNext() ) { XworkActionConfig expectedAction = (XworkActionConfig) it.next(); checkAction( violations, expectedPackage, expectedAction, xwActionMap ); } } else { violations.add( "Missing " + quote( expectedPackage.name ) + " package namespace in xwork.xml" ); } }