01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.ioc.internal;
16:
17: import org.apache.tapestry.ioc.ObjectCreator;
18: import org.apache.tapestry.ioc.ServiceLifecycle;
19: import org.apache.tapestry.ioc.ServiceResources;
20:
21: /**
22: * Wrapper around a lifecycle, a set of resources for a service, and an underlying
23: * {@link ObjectCreator} for a service that allows the service lifecycle to alter the way that the
24: * service is created (this is needed for the more advanced, non-singleton types of service
25: * lifecycles).
26: */
27: public class LifecycleWrappedServiceCreator implements ObjectCreator {
28: private final InternalRegistry _registry;
29:
30: private final String _serviceScope;
31:
32: private final ServiceResources _resources;
33:
34: private final ObjectCreator _creator;
35:
36: public LifecycleWrappedServiceCreator(InternalRegistry registry,
37: String serviceScope, ServiceResources resources,
38: ObjectCreator creator) {
39: _registry = registry;
40: _serviceScope = serviceScope;
41: _resources = resources;
42: _creator = creator;
43: }
44:
45: /**
46: * Passes the resources and the service creator through the
47: * {@link org.apache.tapestry.ioc.ServiceLifecycle}.
48: */
49: public Object createObject() {
50: ServiceLifecycle lifecycle = _registry
51: .getServiceLifecycle(_serviceScope);
52:
53: return lifecycle.createService(_resources, _creator);
54: }
55:
56: }
|