1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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.geronimo.concurrent.impl.context; 18 19 import java.util.List; 20 21 import org.apache.geronimo.concurrent.ManagedContextHandler; 22 import org.apache.geronimo.concurrent.ManagedContextHandlerChain; 23 import org.apache.geronimo.concurrent.context.BasicContextService; 24 import org.apache.geronimo.concurrent.impl.ContextHandlerUtils; 25 import org.apache.geronimo.concurrent.naming.ModuleAwareResourceSource; 26 import org.apache.geronimo.gbean.AbstractName; 27 import org.apache.geronimo.gbean.GBeanInfo; 28 import org.apache.geronimo.gbean.GBeanInfoBuilder; 29 import org.apache.geronimo.kernel.Kernel; 30 31 public class ContextServiceGBean implements ModuleAwareResourceSource { 32 33 public static final GBeanInfo GBEAN_INFO; 34 35 private ManagedContextHandlerChain mainContextHandler; 36 private BasicContextService contextService; 37 38 public ContextServiceGBean(Kernel kernel, 39 ClassLoader classLoader, 40 AbstractName name, 41 String[] contextHandlerClasses) { 42 List<ManagedContextHandler> handlers = 43 ContextHandlerUtils.loadHandlers(classLoader, contextHandlerClasses); 44 this.mainContextHandler = new ManagedContextHandlerChain(handlers); 45 } 46 47 private synchronized BasicContextService getContextService() { 48 if (this.contextService == null) { 49 this.contextService = new BasicContextService(this.mainContextHandler); 50 } 51 return this.contextService; 52 } 53 54 public Object $getResource(AbstractName moduleID) { 55 return new ContextServiceModuleFacade(getContextService(), moduleID); 56 } 57 58 static { 59 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ContextServiceGBean.class, "ContextService"); 60 61 infoFactory.addAttribute("classLoader", ClassLoader.class, false, false); 62 infoFactory.addAttribute("abstractName", AbstractName.class, false, false); 63 infoFactory.addAttribute("kernel", Kernel.class, false, false); 64 65 infoFactory.addAttribute("contextHandlers", String[].class, true); 66 67 infoFactory.setConstructor(new String[] {"kernel", 68 "classLoader", 69 "abstractName", 70 "contextHandlers"} ); 71 72 GBEAN_INFO = infoFactory.getBeanInfo(); 73 } 74 75 public static GBeanInfo getGBeanInfo() { 76 return GBEAN_INFO; 77 } 78 79 }