01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.gjndi.binding;
17:
18: import javax.naming.NamingException;
19:
20: import org.apache.geronimo.gbean.AbstractName;
21: import org.apache.geronimo.gbean.AbstractNameQuery;
22: import org.apache.geronimo.gbean.GBeanInfo;
23: import org.apache.geronimo.gbean.GBeanInfoBuilder;
24: import org.apache.geronimo.kernel.Kernel;
25: import org.apache.geronimo.naming.ResourceSource;
26:
27: /**
28: * @version $Rev: 615514 $ $Date: 2008-01-26 14:08:26 -0800 (Sat, 26 Jan 2008) $
29: */
30: public class ResourceBinding extends GBeanFormatBinding {
31:
32: public ResourceBinding(String format, String namePattern,
33: String nameInNamespace,
34: AbstractNameQuery abstractNameQuery, Kernel kernel)
35: throws NamingException {
36: super (format, namePattern, nameInNamespace, abstractNameQuery,
37: kernel);
38: }
39:
40: /**
41: * Preprocess the value before it is bound. This is usefult for wrapping values with reference objects.
42: * By default, this method simply return the value.
43: *
44: * @param abstractName the abstract name of the gbean to bind
45: * @param value the gbean instance
46: * @return the value to bind or null if there was a problem
47: */
48: protected Object preprocessVaue(AbstractName abstractName,
49: Object value) {
50: if (!(value instanceof ResourceSource)) {
51: log.info("value at " + abstractName
52: + " is not a ResourceSource: "
53: + value.getClass().getName());
54: return null;
55: }
56: try {
57: return ((ResourceSource) value).$getResource();
58: } catch (Throwable throwable) {
59: log.info("Could not get resource from gbean at "
60: + abstractName, throwable);
61: return null;
62: }
63: }
64:
65: public static final GBeanInfo GBEAN_INFO;
66:
67: static {
68: GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(
69: ResourceBinding.class, GBeanFormatBinding.GBEAN_INFO,
70: "Context");
71: GBEAN_INFO = builder.getBeanInfo();
72: }
73:
74: public static GBeanInfo getGBeanInfo() {
75: return GBEAN_INFO;
76: }
77: }
|