01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.wicket.injection;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.application.IComponentInstantiationListener;
21: import org.apache.wicket.injection.web.InjectorHolder;
22:
23: /**
24: * Enables your application to do Spring dependency injection. To use, register
25: * the injector as a {@link org.apache.wicket.application.IComponentInstantiationListener}
26: * like this:
27: *
28: * <pre>
29: * ... (in your application's constructor or init method)
30: * addComponentInstantiationListener(new ComponentInjector());
31: * ...
32: * </pre>
33: *
34: * @see org.apache.wicket.application.IComponentInstantiationListener
35: * @see org.apache.wicket.Application#addComponentInstantiationListener(org.apache.wicket.application.IComponentInstantiationListener)
36: * @author Eelco Hillenius
37: */
38: public class ComponentInjector implements
39: IComponentInstantiationListener {
40:
41: /**
42: * Construct.
43: */
44: public ComponentInjector() {
45: }
46:
47: /**
48: * @see org.apache.wicket.application.IComponentInstantiationListener#onInstantiation(org.apache.wicket.Component)
49: */
50: public void onInstantiation(Component component) {
51: getInjector().inject(component);
52: }
53:
54: private ConfigurableInjector getInjector() {
55: ConfigurableInjector injector = InjectorHolder.getInjector();
56: if (injector == null) {
57: throw new RuntimeException(
58: "injector not set in InjectorHolder");
59: }
60: return injector;
61: }
62: }
|