Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MockApplicationFactory |
|
| 5.0;5 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.shale.test.mock; | |
19 | ||
20 | import javax.faces.FacesException; | |
21 | import javax.faces.application.Application; | |
22 | import javax.faces.application.ApplicationFactory; | |
23 | ||
24 | /** | |
25 | * <p>Mock implementation of <code>ApplicationFactory</code>.</p> | |
26 | * | |
27 | * $Id$ | |
28 | */ | |
29 | ||
30 | public class MockApplicationFactory extends ApplicationFactory { | |
31 | ||
32 | ||
33 | // ------------------------------------------------------------ Constructors | |
34 | ||
35 | ||
36 | /** | |
37 | * <p>Construct a default instance.</p> | |
38 | */ | |
39 | 18 | public MockApplicationFactory() { |
40 | ||
41 | 18 | } |
42 | ||
43 | ||
44 | // ----------------------------------------------------- Mock Object Methods | |
45 | ||
46 | ||
47 | // ------------------------------------------------------ Instance Variables | |
48 | ||
49 | ||
50 | /** | |
51 | * <p>The <code>Application</code> instance to be returned by | |
52 | * this factory.</p> | |
53 | */ | |
54 | 18 | private Application application = null; |
55 | ||
56 | ||
57 | // --------------------------------------------- AppolicationFactory Methods | |
58 | ||
59 | ||
60 | /** {@inheritDoc} */ | |
61 | public Application getApplication() { | |
62 | ||
63 | 20 | if (this.application == null) { |
64 | 18 | Class clazz = null; |
65 | try { | |
66 | 18 | clazz = this.getClass().getClassLoader().loadClass |
67 | ("org.apache.shale.test.mock.MockApplication12"); | |
68 | 18 | this.application = (MockApplication) clazz.newInstance(); |
69 | } catch (NoClassDefFoundError e) { | |
70 | clazz = null; // We are not running in a JSF 1.2 environment | |
71 | } catch (ClassNotFoundException e) { | |
72 | clazz = null; // Same as above | |
73 | } catch (RuntimeException e) { | |
74 | throw e; | |
75 | } catch (Exception e) { | |
76 | throw new FacesException(e); | |
77 | 18 | } |
78 | 18 | if (clazz == null) { |
79 | try { | |
80 | clazz = this.getClass().getClassLoader().loadClass | |
81 | ("org.apache.shale.test.mock.MockApplication"); | |
82 | this.application = (MockApplication) clazz.newInstance(); | |
83 | } catch (RuntimeException e) { | |
84 | throw e; | |
85 | } catch (Exception e) { | |
86 | throw new FacesException(e); | |
87 | } | |
88 | } | |
89 | } | |
90 | 20 | return this.application; |
91 | ||
92 | } | |
93 | ||
94 | ||
95 | /** {@inheritDoc} */ | |
96 | public void setApplication(Application application) { | |
97 | ||
98 | this.application = application; | |
99 | ||
100 | } | |
101 | ||
102 | ||
103 | } |