001 /**
002 * GRANITE DATA SERVICES
003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004 *
005 * This file is part of the Granite Data Services Platform.
006 *
007 * Granite Data Services is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * Granite Data Services is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015 * General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020 * USA, or see <http://www.gnu.org/licenses/>.
021 */
022 package org.granite.tide.ejb;
023
024 import java.lang.annotation.Annotation;
025 import java.util.Collections;
026 import java.util.Set;
027
028 import javax.naming.InitialContext;
029 import javax.servlet.ServletContext;
030
031 import org.granite.config.ConfigProvider;
032 import org.granite.gravity.Gravity;
033 import org.granite.logging.Logger;
034 import org.granite.messaging.service.ServiceFactory;
035
036
037 public class EjbConfigProvider implements ConfigProvider {
038
039 private static final Logger log = Logger.getLogger(EjbConfigProvider.class);
040
041 private ServletContext servletContext;
042
043 public EjbConfigProvider(ServletContext servletContext) {
044 this.servletContext = servletContext;
045 }
046
047 public Boolean useTide() {
048 return true;
049 }
050
051 public String getType() {
052 return "server";
053 }
054
055 public Class<? extends ServiceFactory> getFactoryClass() {
056 return EjbServiceFactory.class;
057 }
058
059 public <T> T findInstance(Class<T> type) {
060 return null;
061 }
062
063 public <T> Set<T> findInstances(Class<T> type) {
064 return Collections.emptySet();
065 }
066
067 public Class<?>[] getTideInterfaces() {
068 return new Class<?>[] { EjbIdentity.class };
069 }
070
071 @SuppressWarnings("unchecked")
072 public Class<? extends Annotation>[] getTideAnnotations() {
073 return new Class[0];
074 }
075
076 public void initGravity(Gravity gravity) {
077 try {
078 // Set reference in EJB proxy if found
079 InitialContext ic = new InitialContext();
080 org.granite.ejb.Gravity gravityEJB = (org.granite.ejb.Gravity)ic.lookup("java:global" + servletContext.getContextPath() + "/org.granite.ejb.Gravity");
081 gravityEJB.setGravity(gravity);
082 log.info("Registered Gravity EJB");
083 }
084 catch (Exception e) {
085 log.debug(e, "Gravity EJB not found");
086 }
087 }
088
089 }