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.lang.reflect.Modifier;
21: import java.util.ResourceBundle;
22:
23: import org.apache.cxf.common.i18n.BundleUtils;
24: import org.apache.cxf.common.i18n.Message;
25: import org.apache.cxf.common.util.factory.Factory;
26: import org.apache.cxf.interceptor.Fault;
27:
28: /**
29: * The XFire implementation of {@link Factory} interface.
30: * <p>
31: *
32: * @author Ben Yu Feb 10, 2006 11:31:27 PM
33: */
34: public class LocalFactory implements Factory {
35: private static final ResourceBundle BUNDLE = BundleUtils
36: .getBundle(LocalFactory.class);
37:
38: private final Class svcClass;
39:
40: public LocalFactory(final Class svcClass) {
41: super ();
42: this .svcClass = svcClass;
43: }
44:
45: public Object create() throws Fault {
46: try {
47: if (svcClass.isInterface()) {
48: throw new Fault(new Message("SVC_CLASS_IS_INTERFACE",
49: BUNDLE, svcClass.getName()));
50: }
51:
52: if (Modifier.isAbstract(svcClass.getModifiers())) {
53: throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT",
54: BUNDLE, svcClass.getName()));
55: }
56: return svcClass.newInstance();
57: } catch (InstantiationException e) {
58: throw new Fault(
59: new Message("COULD_NOT_INSTANTIATE", BUNDLE));
60: } catch (IllegalAccessException e) {
61: throw new Fault(new Message("ILLEGAL_ACCESS", BUNDLE));
62: }
63: }
64: }
|