001: /*
002: * Copyright 2005 jWic group (http://www.jwic.de)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: * de.jwic.spring.JWicRuntimeFactoryBean
017: * Created on 20.05.2005
018: * $Id: JWicRuntimeFactoryBean.java,v 1.1 2006/01/16 08:31:13 lordsam Exp $
019: */
020: package de.jwic.spring;
021:
022: import java.io.InputStream;
023:
024: import javax.servlet.ServletException;
025:
026: import org.springframework.beans.BeansException;
027: import org.springframework.beans.factory.FactoryBean;
028: import org.springframework.beans.factory.InitializingBean;
029: import org.springframework.context.ApplicationContext;
030: import org.springframework.context.ApplicationContextAware;
031: import org.springframework.core.io.Resource;
032:
033: import de.jwic.base.JWicRuntime;
034:
035: /**
036: * Spring FactoryBean wrapper for a JWicRuntime singleton.
037: *
038: * @version $Revision: 1.1 $
039: * @author Christian Jaeckel
040: * @since Nov 25, 2004
041: */
042: public class JWicRuntimeFactoryBean implements ApplicationContextAware,
043: FactoryBean, InitializingBean {
044: private String savePath;
045: private String webRootProperty = "";
046: private ApplicationContext context = null;
047:
048: /* (non-Javadoc)
049: * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
050: */
051: public void afterPropertiesSet() throws Exception {
052: JWicRuntime jr = JWicRuntime.getJWicRuntime();
053:
054: if (savePath != null)
055: jr.setSavePath(savePath);
056:
057: Resource res = context.getResource("/WEB-INF/jwic-setup.xml");
058: if (res.exists()) {
059: InputStream in = res.getInputStream();
060: if (in != null) {
061: jr.setupRuntime(in);
062: } else {
063: throw new ServletException(
064: "WEB-INF/jwic-setup.xml not found.");
065: }
066: }
067:
068: }
069:
070: /* (non-Javadoc)
071: * @see org.springframework.beans.factory.FactoryBean#getObject()
072: */
073: public Object getObject() throws Exception {
074: return JWicRuntime.getJWicRuntime();
075: }
076:
077: /* (non-Javadoc)
078: * @see org.springframework.beans.factory.FactoryBean#getObjectType()
079: */
080: public Class getObjectType() {
081: return JWicRuntime.class;
082: }
083:
084: /* (non-Javadoc)
085: * @see org.springframework.beans.factory.FactoryBean#isSingleton()
086: */
087: public boolean isSingleton() {
088: return true;
089: }
090:
091: /**
092: * @return Returns the webRootDir.
093: */
094: public String getWebRootProperty() {
095: return webRootProperty;
096: }
097:
098: /**
099: * @param webRootDir The webRootDir to set.
100: */
101: public void setWebRootProperty(String webRootProperty) {
102: this .webRootProperty = webRootProperty;
103: }
104:
105: /* (non-Javadoc)
106: * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
107: */
108: public void setApplicationContext(ApplicationContext context)
109: throws BeansException {
110: this.context = context;
111: ApplicationContextUtil.setApplicationContext(context);
112: }
113: }
|