01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.service.invoker;
19:
20: import java.util.ResourceBundle;
21:
22: import org.apache.cxf.common.i18n.BundleUtils;
23: import org.apache.cxf.common.i18n.Message;
24: import org.apache.cxf.common.util.factory.Factory;
25: import org.apache.cxf.interceptor.Fault;
26: import org.apache.cxf.message.Exchange;
27:
28: /**
29: * This invoker implementation calls a Factory to create the service object and
30: * then applies a scope policy for caching.
31: *
32: * @author Ben Yu Feb 2, 2006 12:55:59 PM
33: */
34: public class FactoryInvoker extends AbstractInvoker {
35: private static final ResourceBundle BUNDLE = BundleUtils
36: .getBundle(FactoryInvoker.class);
37:
38: private final Factory factory;
39: private final ScopePolicy scope;
40:
41: /**
42: * Create a FactoryInvoker object.
43: *
44: * @param factory the factory used to create service object.
45: * @param scope the scope policy. Null for default.
46: */
47: public FactoryInvoker(Factory factory, ScopePolicy scope) {
48: this .factory = factory;
49: this .scope = scope == null ? new ApplicationScopePolicy()
50: : scope;
51: }
52:
53: public Object getServiceObject(Exchange ex) {
54: try {
55: return getScopedFactory(ex).create();
56: } catch (Throwable e) {
57: throw new Fault(new Message("CREATE_SERVICE_OBJECT_EXC",
58: BUNDLE), e);
59: }
60: }
61:
62: private Factory getScopedFactory(Exchange ex) {
63: return scope.applyScope(factory, ex);
64: }
65: }
|