View Javadoc

1   package com.atlassian.johnson.config;
2   
3   import com.atlassian.johnson.event.*;
4   import com.atlassian.johnson.setup.ContainerFactory;
5   import com.atlassian.johnson.setup.DefaultContainerFactory;
6   import com.atlassian.johnson.setup.DefaultSetupConfig;
7   import com.atlassian.johnson.setup.SetupConfig;
8   
9   import java.util.Collections;
10  import java.util.List;
11  import java.util.Map;
12  
13  /**
14   * A default implementation of {@link JohnsonConfig} which may be used as a failsafe when no other configuration is
15   * available.
16   * <p/>
17   * All URIs are {@link #isIgnoredPath(String) ignored} by this implementation. All collection-returning properties are
18   * implemented to return empty, immutable collections. All other methods generally return {@code null}, except for:
19   * <ul>
20   *     <li>{@link SetupConfig} is provided by {@link DefaultSetupConfig}</li>
21   *     <li>{@link ContainerFactory} is provided by {@link DefaultContainerFactory}</li>
22   * </ul>
23   * This class cannot be instantiated. A single, immutable instance is available via {@link #getInstance()}.
24   *
25   * @since 2.0
26   */
27  public final class DefaultJohnsonConfig implements JohnsonConfig
28  {
29      private static final DefaultJohnsonConfig instance = new DefaultJohnsonConfig();
30  
31      private final ContainerFactory containerFactory;
32      private final SetupConfig setupConfig;
33  
34      private DefaultJohnsonConfig()
35      {
36          containerFactory = new DefaultContainerFactory();
37          setupConfig = new DefaultSetupConfig();
38      }
39  
40      /**
41       * Retrieves the immutable singleton instance of the default configuration.
42       * 
43       * @return the default configuration singleton
44       */
45      public static JohnsonConfig getInstance()
46      {
47          return instance;
48      }
49  
50      /**
51       * Always empty but non-{@code null}.
52       * 
53       * @return an empty list
54       */
55      @Override
56      public List<ApplicationEventCheck> getApplicationEventChecks()
57      {
58          return Collections.emptyList();
59      }
60  
61      /**
62       * Always an instance of {@link DefaultContainerFactory}.
63       * 
64       * @return a default container factory
65       */
66      @Override
67      public ContainerFactory getContainerFactory()
68      {
69          return containerFactory;
70      }
71  
72      /**
73       * Always {@code null}.
74       * 
75       * @return {@code null}
76       */
77      @Override
78      public String getErrorPath()
79      {
80          return null;
81      }
82  
83      /**
84       * Always {@code null}.
85       * 
86       * @param id ignored
87       * @return {@code null}
88       */
89      @Override
90      public EventCheck getEventCheck(int id)
91      {
92          return null;
93      }
94  
95      /**
96       * Always empty but non-{@code null}.
97       * 
98       * @return an empty list
99       */
100     @Override
101     public List<EventCheck> getEventChecks()
102     {
103         return Collections.emptyList();
104     }
105 
106     /**
107      * Always {@code null}.
108      * 
109      * @param level ignored
110      * @return {@code null}
111      */
112     @Override
113     public EventLevel getEventLevel(String level)
114     {
115         return null;
116     }
117 
118     /**
119      * Always {@code null}.
120      *
121      * @param type ignored
122      * @return {@code null}
123      */
124     @Override
125     public EventType getEventType(String type)
126     {
127         return null;
128     }
129 
130     /**
131      * Always empty but non-{@code null}.
132      * 
133      * @return an empty list
134      */
135     @Override
136     public List<String> getIgnorePaths()
137     {
138         return Collections.emptyList();
139     }
140 
141     /**
142      * Always empty but non-{@code null}.
143      * 
144      * @return an empty map
145      */
146     @Override
147     public Map<String, String> getParams()
148     {
149         return Collections.emptyMap();
150     }
151 
152     /**
153      * Always empty but non-{@code null}.
154      * 
155      * @return an empty list
156      */
157     @Override
158     public List<RequestEventCheck> getRequestEventChecks()
159     {
160         return Collections.emptyList();
161     }
162 
163     /**
164      * Always an instance of {@link DefaultSetupConfig}.
165      */
166     @Override
167     public SetupConfig getSetupConfig()
168     {
169         return setupConfig;
170     }
171 
172     /**
173      * Always {@code null}.
174      *
175      * @return {@code null}
176      */
177     @Override
178     public String getSetupPath()
179     {
180         return null;
181     }
182 
183     /**
184      * Always {@code true}. This has the net effect of disabling Johnson, because all URIs included for filtering will
185      * be ignored and events will not be processed for them.
186      *
187      * @param uri ignored
188      * @return {@code true}
189      */
190     @Override
191     public boolean isIgnoredPath(String uri)
192     {
193         return true;
194     }
195 }