View Javadoc

1   package org.apache.maven.continuum.web.interceptor;
2   
3   /*
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
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import com.opensymphony.xwork2.ActionInvocation;
23  import com.opensymphony.xwork2.interceptor.Interceptor;
24  import org.apache.maven.continuum.Continuum;
25  import org.apache.maven.continuum.configuration.ConfigurationService;
26  
27  /**
28   * ForceContinuumConfigurationInterceptor:
29   *
30   * @author: Jesse McConnell <jmcconnell@apache.org>
31   * @version: $Id: ForceContinuumConfigurationInterceptor.java 729932 2008-12-29 16:32:22Z evenisse $
32   * @plexus.component role="com.opensymphony.xwork2.interceptor.Interceptor"
33   * role-hint="forceContinuumConfigurationInterceptor"
34   */
35  public class ForceContinuumConfigurationInterceptor
36      implements Interceptor
37  {
38      private static boolean checked = false;
39  
40      /**
41       * @plexus.requirement
42       */
43      private Continuum continuum;
44  
45      public void destroy()
46      {
47          // no-op
48      }
49  
50      public void init()
51      {
52  
53      }
54  
55      /**
56       * 1) check to see if this interceptor has been successfully executed
57       * 2) check if the configuration service is initialized
58       * 3) load the configuration and see if that is initialized (addresses restore on empty db)
59       * 4) force the configuration screen
60       *
61       * @param invocation
62       * @return
63       * @throws Exception
64       */
65      public String intercept( ActionInvocation invocation )
66          throws Exception
67      {
68          if ( checked )
69          {
70              return invocation.invoke();
71          }
72  
73          ConfigurationService configuration = continuum.getConfiguration();
74  
75          if ( configuration.isInitialized() )
76          {
77              checked = true;
78              return invocation.invoke();
79          }
80  
81          configuration.reload();
82  
83          if ( configuration.isInitialized() )
84          {
85              checked = true;
86              return invocation.invoke();
87          }
88          else
89          {
90              return "continuum-configuration-required";
91          }
92  
93      }
94  }