Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl » [javadoc | source]

    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;
   18   
   19   import java.util.Hashtable;
   20   
   21   import javax.management.ObjectName;
   22   
   23   import org.apache.geronimo.gbean.AbstractName;
   24   import org.apache.geronimo.gbean.GBeanData;
   25   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   26   import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
   27   import org.apache.geronimo.kernel.GBeanNotFoundException;
   28   import org.apache.geronimo.kernel.Kernel;
   29   import org.apache.geronimo.kernel.KernelException;
   30   import org.apache.geronimo.kernel.ObjectNameUtil;
   31   import org.apache.geronimo.kernel.management.State;
   32   
   33   public class GBeanBuilder {
   34       
   35       protected Kernel kernel;
   36       protected ClassLoader classLoader;
   37   
   38       public GBeanBuilder(Kernel kernel, ClassLoader classLoader) {
   39           this.kernel = kernel;
   40           this.classLoader = classLoader;        
   41       }
   42       
   43       /* in memory */
   44       protected void addGBeanKernel(AbstractName gbeanName, GBeanData threadData) throws KernelException {
   45           kernel.loadGBean(threadData, this.classLoader);           
   46           kernel.startRecursiveGBean(gbeanName);
   47       }
   48       
   49       /* in memory */
   50       protected void removeGBeanKernel(AbstractName gbeanName) {
   51           try {
   52               if (kernel.getGBeanState(gbeanName) == State.RUNNING_INDEX) {
   53                   kernel.stopGBean(gbeanName);
   54               }
   55               kernel.unloadGBean(gbeanName);
   56           } catch (GBeanNotFoundException e) {
   57               // Bean is no longer loaded
   58           }
   59       }
   60       
   61       /**
   62        * ObjectName must match this pattern: 
   63        * domain:j2eeType=<j2eeType>,name=MyName,J2EEServer=MyServer
   64        */
   65       public static void verifyObjectName(String objectNameStr, String j2eeType, String name) {
   66           ObjectName objectName = ObjectNameUtil.getObjectName(objectNameStr);
   67           if (objectName.isPattern()) {
   68               throw new InvalidObjectNameException(
   69                       "ObjectName can not be a pattern", objectName);
   70           }
   71           Hashtable keyPropertyList = objectName.getKeyPropertyList();
   72           if (!j2eeType.equals(keyPropertyList.get("j2eeType"))) {
   73               throw new InvalidObjectNameException(
   74                       name + " object name j2eeType property must be '" + j2eeType + "'",
   75                       objectName);
   76           }
   77           if (!keyPropertyList.containsKey(NameFactory.J2EE_NAME)) {
   78               throw new InvalidObjectNameException(
   79                       name + " object must contain a name property", 
   80                       objectName);
   81           }
   82           if (!keyPropertyList.containsKey(NameFactory.J2EE_SERVER)) {
   83               throw new InvalidObjectNameException(
   84                       name + " object name must contain a J2EEServer property",
   85                       objectName);
   86           }
   87           if (keyPropertyList.size() != 3) {
   88               throw new InvalidObjectNameException(
   89                       name + " object name can only have j2eeType, name, and J2EEServer properties",
   90                       objectName);
   91           }
   92       }
   93   }

Home » geronimo-2.2-source-release » org.apache.geronimo.concurrent.impl » [javadoc | source]