|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ExtensionLookupFactory.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.services.impl;
|
|
16 |
|
|
17 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
18 |
import org.apache.hivemind.ServiceImplementationFactory;
|
|
19 |
import org.apache.hivemind.ServiceImplementationFactoryParameters;
|
|
20 |
import org.apache.hivemind.lib.DefaultImplementationBuilder;
|
|
21 |
import org.apache.tapestry.spec.IApplicationSpecification;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* An implementation of {@link org.apache.hivemind.ServiceImplementationFactory}that looks for a
|
|
25 |
* service implementation provided as an
|
|
26 |
* {@link org.apache.tapestry.spec.ILibrarySpecification#getExtension(String) application
|
|
27 |
* extension}. If no such extension exists, then a
|
|
28 |
* {@link org.apache.hivemind.lib.DefaultImplementationBuilder default implementation}is
|
|
29 |
* constructed and returned instead. This allows compatibility with Tapestry 3.0 and earlier
|
|
30 |
* application extensions (though those will be phased out in the future).
|
|
31 |
*
|
|
32 |
* @author Howard Lewis Ship
|
|
33 |
* @since 4.0
|
|
34 |
*/
|
|
35 |
public class ExtensionLookupFactory implements ServiceImplementationFactory |
|
36 |
{ |
|
37 |
private IApplicationSpecification _specification;
|
|
38 |
|
|
39 |
private DefaultImplementationBuilder _defaultBuilder;
|
|
40 |
|
|
41 | 95 |
public Object createCoreServiceImplementation(
|
42 |
ServiceImplementationFactoryParameters factorParameters) |
|
43 |
{ |
|
44 | 95 |
ExtensionLookupParameter p = (ExtensionLookupParameter) factorParameters.getParameters() |
45 |
.get(0); |
|
46 |
|
|
47 | 95 |
String extensionName = p.getExtensionName(); |
48 |
|
|
49 | 95 |
Class serviceInterface = factorParameters.getServiceInterface(); |
50 |
|
|
51 | 95 |
try
|
52 |
{ |
|
53 | 95 |
if (_specification.checkExtension(extensionName))
|
54 | 1 |
return _specification.getExtension(extensionName, serviceInterface);
|
55 |
|
|
56 | 93 |
if (p.getDefault() != null) |
57 | 46 |
return p.getDefault();
|
58 |
|
|
59 | 47 |
return _defaultBuilder.buildDefaultImplementation(serviceInterface);
|
60 |
} |
|
61 |
catch (Exception ex)
|
|
62 |
{ |
|
63 | 1 |
throw new ApplicationRuntimeException(ex.getMessage(), p.getLocation(), ex); |
64 |
} |
|
65 |
} |
|
66 |
|
|
67 | 46 |
public void setDefaultBuilder(DefaultImplementationBuilder builder) |
68 |
{ |
|
69 | 46 |
_defaultBuilder = builder; |
70 |
} |
|
71 |
|
|
72 | 48 |
public void setSpecification(IApplicationSpecification specification) |
73 |
{ |
|
74 | 48 |
_specification = specification; |
75 |
} |
|
76 |
|
|
77 |
} |
|