View Javadoc

1   /*
2    * Copyright 2011 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.fatwire.gst.foundation.controller.action.support;
18  
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  
22  import COM.FutureTense.Interfaces.ICS;
23  
24  import com.fatwire.gst.foundation.controller.action.Action;
25  import com.fatwire.gst.foundation.controller.action.ActionLocator;
26  import com.fatwire.gst.foundation.controller.action.Factory;
27  import com.fatwire.gst.foundation.controller.action.Injector;
28  import com.fatwire.gst.foundation.controller.action.RenderPage;
29  
30  /**
31   * ActionLocator with support for Factory and a fall back ActionLocator.
32   * <p/>
33   * Objects are created via a {@link Factory}, that can be configured via the
34   * <tt>factoryClassname</tt>. That class needs to have a constructor accepting
35   * ICS.
36   * 
37   * @author Dolf Dijkstra
38   * @since Apr 27, 2011
39   */
40  public abstract class BaseActionLocator extends AbstractActionLocator {
41  
42      protected static final Log LOG = LogFactory.getLog(BaseActionLocator.class.getPackage().getName());
43  
44      private ReflectionFactoryProducer f = new ReflectionFactoryProducer();
45      private Injector i;
46  
47      public BaseActionLocator() {
48          super();
49          this.setFallbackActionLocator(new ActionLocator() {
50  
51              public Action getAction(final ICS ics, final String name) {
52                  Action action = new RenderPage();
53                  injectDependencies(ics, action);
54                  return action;
55              }
56  
57          });
58          i = new DefaultAnnotationInjector(f);
59          this.setInjector(i);
60      }
61  
62      /**
63       * @param factoryClassname the factoryClassname to set
64       */
65      public void setFactoryClassname(final String factoryClassname) {
66          f.setFactoryClassname(factoryClassname);
67      }
68  }