org.openxdata.server.rpc.OxdPersistentRemoteService.java Source code

Java tutorial

Introduction

Here is the source code for org.openxdata.server.rpc.OxdPersistentRemoteService.java

Source

/*
 *  Licensed to the OpenXdata Foundation (OXDF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The OXDF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, 
 *  software distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and limitations under the License.
 *
 *  Copyright 2010 http://www.openxdata.org.
 */
package org.openxdata.server.rpc;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import net.sf.gilead.core.PersistentBeanManager;
import net.sf.gilead.core.hibernate.HibernateUtil;
import net.sf.gilead.gwt.GwtConfigurationHelper;
import net.sf.gilead.gwt.PersistentRemoteService;

import org.hibernate.SessionFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * Base class for all remote service implementations to set the PersistentBeanManager
 * as required by Gilead.
 *  
 * @author daniel
 *
 */
public class OxdPersistentRemoteService extends PersistentRemoteService {

    private static final long serialVersionUID = -3187795188510247069L;

    public OxdPersistentRemoteService() {
    }

    /**
     * Servlet initialisation
     */
    @Override
    public void init() throws ServletException {
        super.init();

        WebApplicationContext ctx = getApplicationContext();

        HibernateUtil hibernateUtil = new HibernateUtil();
        hibernateUtil.setSessionFactory((SessionFactory) ctx.getBean("sessionFactory"));
        PersistentBeanManager persistentBeanManager = GwtConfigurationHelper
                .initGwtStatelessBeanManager(hibernateUtil);
        setBeanManager(persistentBeanManager);
    }

    protected WebApplicationContext getApplicationContext() {
        ServletContext sctx = this.getServletContext();
        WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sctx);
        return ctx;
    }
}