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.spring.common.web;
18:
19: import org.apache.wicket.spring.SpringWebApplication;
20: import org.apache.wicket.spring.common.ContactDao;
21: import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
22:
23: /**
24: * Application class for our examples
25: *
26: * @author Igor Vaynberg (ivaynberg)
27: *
28: */
29: public class ExampleApplication extends SpringWebApplication {
30:
31: /**
32: * this field holds a contact dao proxy that is safe to use in wicket
33: * components
34: */
35: private ContactDao contactDaoProxy;
36:
37: /**
38: * this field holds the actual contact dao retrieved from spring context.
39: * this object should never be serialized because it will take the container
40: * with it, so BE CAREFUL when using this.
41: */
42: private ContactDao contactDao;
43:
44: @Override
45: protected void init() {
46: // THIS LINE IS IMPORTANT - IT INSTALLS THE COMPONENT INJECTOR THAT WILL
47: // INJECT NEWLY CREATED COMPONENTS WITH THEIR SPRING DEPENDENCIES
48: addComponentInstantiationListener(new SpringComponentInjector(
49: this ));
50: }
51:
52: /**
53: * Retrieves contact dao bean. This bean should not be serialized so BE
54: * CAREFUL when using it.
55: *
56: * @return contact dao bean
57: */
58: public ContactDao getContactDao() {
59: if (contactDao == null) {
60: synchronized (this ) {
61: if (contactDao == null) {
62: contactDao = (ContactDao) internalGetApplicationContext()
63: .getBean("contactDao", ContactDao.class);
64: }
65: }
66: }
67: return contactDao;
68: }
69:
70: /**
71: * Returns a lazy init proxy for the dao bean. This proxy is safe to
72: * serialize and will take up very little space when serialized.
73: *
74: * @return a lazy init proxy for the dao bean
75: */
76: public ContactDao getContactDaoProxy() {
77: if (contactDaoProxy == null) {
78: synchronized (this ) {
79: if (contactDaoProxy == null) {
80: contactDaoProxy = (ContactDao) createSpringBeanProxy(
81: ContactDao.class, "contactDao");
82: }
83: }
84: }
85: return contactDaoProxy;
86: }
87:
88: public Class getHomePage() {
89: return HomePage.class;
90: }
91:
92: }
|