1 package org.apache.archiva.web.action.admin.repositories;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork2.ActionContext;
23 import com.opensymphony.xwork2.DefaultTextProvider;
24 import com.opensymphony.xwork2.ObjectFactory;
25 import com.opensymphony.xwork2.TextProvider;
26 import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
27 import com.opensymphony.xwork2.conversion.impl.DefaultObjectTypeDeterminer;
28 import com.opensymphony.xwork2.conversion.impl.XWorkBasicConverter;
29 import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
30 import com.opensymphony.xwork2.inject.Container;
31 import com.opensymphony.xwork2.inject.ContainerBuilder;
32 import com.opensymphony.xwork2.inject.Scope;
33 import com.opensymphony.xwork2.ognl.OgnlReflectionProvider;
34 import com.opensymphony.xwork2.ognl.OgnlUtil;
35 import com.opensymphony.xwork2.ognl.OgnlValueStackFactory;
36 import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
37 import com.opensymphony.xwork2.util.CompoundRoot;
38 import com.opensymphony.xwork2.util.ValueStack;
39 import com.opensymphony.xwork2.util.ValueStackFactory;
40 import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
41 import com.opensymphony.xwork2.validator.ActionValidatorManager;
42 import com.opensymphony.xwork2.validator.DefaultActionValidatorManager;
43 import com.opensymphony.xwork2.validator.DefaultValidatorFactory;
44 import com.opensymphony.xwork2.validator.DefaultValidatorFileParser;
45 import ognl.PropertyAccessor;
47 import java.util.HashMap;
50 * Factory for creating the DefaultActionValidatorManager to be used for the validation tests.
52 public class DefaultActionValidatorManagerFactory
55 // ObjectFactory.setObjectFactory(..) was removed in struts 2.1, so we have to workaround with this
56 // to make the validation tests work
57 public ActionValidatorManager createDefaultActionValidatorManager()
58 throws ClassNotFoundException
60 Container container = createBootstrapContainer();
62 ActionContext context = new ActionContext( new HashMap<String, Object>() );
63 context.setValueStack( createValueStack( container ) );
64 ActionContext.setContext( context );
66 OgnlReflectionProvider reflectionProvider = new OgnlReflectionProvider();
68 reflectionProvider.setOgnlUtil( container.getInstance( OgnlUtil.class ) );
70 ObjectFactory objectFactory = new ObjectFactory();
71 objectFactory.setReflectionProvider( reflectionProvider );
73 DefaultValidatorFileParser fileParser = new DefaultValidatorFileParser();
74 fileParser.setObjectFactory( objectFactory );
76 DefaultValidatorFactory validatorFactory = new DefaultValidatorFactory( objectFactory, fileParser );
78 DefaultActionValidatorManager defaultValidatorManager = new DefaultActionValidatorManager();
79 defaultValidatorManager.setValidatorFactory( validatorFactory );
80 defaultValidatorManager.setValidatorFileParser( fileParser );
82 return defaultValidatorManager;
85 private ValueStack createValueStack( Container container )
86 throws ClassNotFoundException
88 OgnlValueStackFactory stackFactory = new OgnlValueStackFactory();
90 stackFactory.setXWorkConverter( container.getInstance( XWorkConverter.class ) );
91 stackFactory.setContainer( container );
92 stackFactory.setTextProvider( container.getInstance( TextProvider.class ) );
94 ValueStack stack = stackFactory.createValueStack();
99 private Container createBootstrapContainer()
101 ContainerBuilder builder = new ContainerBuilder();
102 builder.factory( ObjectFactory.class, Scope.SINGLETON );
103 builder.factory( ReflectionProvider.class, OgnlReflectionProvider.class, Scope.SINGLETON );
104 builder.factory( ValueStackFactory.class, OgnlValueStackFactory.class, Scope.SINGLETON );
105 builder.factory( XWorkConverter.class, Scope.SINGLETON );
106 builder.factory( XWorkBasicConverter.class, Scope.SINGLETON );
107 builder.factory( TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON );
108 builder.factory( ObjectTypeDeterminer.class, DefaultObjectTypeDeterminer.class, Scope.SINGLETON );
109 builder.factory( PropertyAccessor.class, CompoundRoot.class.getName(), CompoundRootAccessor.class, Scope.SINGLETON );
110 builder.factory( OgnlUtil.class, Scope.SINGLETON );
111 builder.constant( "devMode", "false" );
113 return builder.create( true );