Home » geronimo-2.2-source-release » org.apache.geronimo.gjndi.binding » [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.gjndi.binding;
   18   
   19   import javax.naming.NamingException;
   20   import javax.naming.Name;
   21   
   22   import org.apache.geronimo.gbean.AbstractName;
   23   import org.apache.geronimo.gbean.AbstractNameQuery;
   24   import org.apache.geronimo.gbean.GBeanInfo;
   25   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   26   import org.apache.geronimo.kernel.Kernel;
   27   import org.apache.geronimo.naming.ResourceSource;
   28   
   29   /**
   30    * @version $Rev: 656562 $ $Date: 2008-05-15 02:13:47 -0700 (Thu, 15 May 2008) $
   31    */
   32   public class ResourceBinding extends GBeanFormatBinding {
   33   
   34       public ResourceBinding(String format, String namePattern, String nameInNamespace, AbstractNameQuery abstractNameQuery, Kernel kernel) throws NamingException {
   35           super(format, namePattern, nameInNamespace, abstractNameQuery, kernel);
   36       }
   37   
   38       /**
   39        * Preprocess the value before it is bound.  This is usefult for wrapping values with reference objects.
   40        * By default, this method simply return the value.
   41        *
   42        * @param abstractName the abstract name of the gbean to bind
   43        * @param value        the gbean instance
   44        * @return the value to bind  or null if there was a problem
   45        */
   46       @Override
   47       protected Object preprocessVaue(AbstractName abstractName, Name name, Object value) {
   48           if (!(value instanceof ResourceSource)) {
   49               log.info("value at " + abstractName + " is not a ResourceSource: " + value.getClass().getName());
   50               return null;
   51           }
   52           try {
   53               return ((ResourceSource) value).$getResource();
   54           } catch (Throwable throwable) {
   55               log.info("Could not get resource from gbean at " + abstractName,throwable);
   56               return null;
   57           }
   58       }
   59   
   60       public static final GBeanInfo GBEAN_INFO;
   61   
   62       static {
   63           GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(ResourceBinding.class, GBeanFormatBinding.GBEAN_INFO, "Context");
   64           GBEAN_INFO = builder.getBeanInfo();
   65       }
   66   
   67       public static GBeanInfo getGBeanInfo() {
   68           return GBEAN_INFO;
   69       }
   70   }

Home » geronimo-2.2-source-release » org.apache.geronimo.gjndi.binding » [javadoc | source]