Source Code Cross Referenced for AbstractGBeanReference.java in  » EJB-Server-geronimo » kernel » org » apache » geronimo » gbean » runtime » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » kernel » org.apache.geronimo.gbean.runtime 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.gbean.runtime;
017:
018:        import org.apache.geronimo.gbean.AbstractName;
019:        import org.apache.geronimo.gbean.GReferenceInfo;
020:        import org.apache.geronimo.gbean.InvalidConfigurationException;
021:        import org.apache.geronimo.kernel.ClassLoading;
022:        import org.apache.geronimo.kernel.GBeanNotFoundException;
023:        import org.apache.geronimo.kernel.Kernel;
024:        import org.apache.geronimo.kernel.management.State;
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:
028:        import java.lang.reflect.Method;
029:        import java.lang.reflect.Modifier;
030:
031:        /**
032:         * @version $Rev: 614255 $ $Date: 2008-01-22 08:53:48 -0800 (Tue, 22 Jan 2008) $
033:         */
034:        public abstract class AbstractGBeanReference implements  GBeanReference {
035:            /**
036:             * Should we proxy references.
037:             */
038:            protected static final boolean NO_PROXY;
039:            static {
040:                Log log = LogFactory.getLog(AbstractGBeanReference.class);
041:                String no_proxy = System.getProperty(
042:                        "Xorg.apache.geronimo.gbean.NoProxy", "true");
043:                NO_PROXY = no_proxy.equalsIgnoreCase("true");
044:                if (NO_PROXY) {
045:                    log.info("GBean references are not using proxies");
046:                } else {
047:                    log.info("GBean references are using proxies");
048:                }
049:            }
050:
051:            /**
052:             * Name of this reference.
053:             */
054:            private final String name;
055:
056:            /**
057:             * Interface this GBeanInstance uses to refer to the other.
058:             */
059:            private final Class referenceType;
060:
061:            /**
062:             * Proxy type which is injected into the GBeanInstance.
063:             */
064:            private final Class proxyType;
065:
066:            /**
067:             * The GBeanInstance to which this reference belongs.
068:             */
069:            private final GBeanInstance gbeanInstance;
070:
071:            /**
072:             * The method that will be called to set the attribute value.  If null, the value will be set with
073:             * a constructor argument
074:             */
075:            private final MethodInvoker setInvoker;
076:
077:            private final boolean hasTargets;
078:
079:            /**
080:             * The metadata for this reference
081:             */
082:            private final GReferenceInfo referenceInfo;
083:
084:            /**
085:             * The kernel to which the reference is bound.
086:             */
087:            private final Kernel kernel;
088:
089:            /**
090:             * Proxy for this reference
091:             */
092:            private Object proxy;
093:
094:            public AbstractGBeanReference(GBeanInstance gbeanInstance,
095:                    GReferenceInfo referenceInfo, Kernel kernel,
096:                    boolean hasTargets) throws InvalidConfigurationException {
097:                this .gbeanInstance = gbeanInstance;
098:                this .referenceInfo = referenceInfo;
099:                this .kernel = kernel;
100:                this .hasTargets = hasTargets;
101:
102:                this .name = referenceInfo.getName();
103:                try {
104:                    this .referenceType = ClassLoading.loadClass(referenceInfo
105:                            .getReferenceType(), gbeanInstance.getType()
106:                            .getClassLoader());
107:                } catch (ClassNotFoundException e) {
108:                    throw new InvalidConfigurationException(
109:                            "Could not load Reference Type: "
110:                                    + getDescription(), e);
111:                }
112:                if (Modifier.isFinal(referenceType.getModifiers())) {
113:                    throw new IllegalArgumentException(
114:                            "Proxy interface cannot be a final class: "
115:                                    + referenceType.getName());
116:                }
117:                try {
118:                    this .proxyType = ClassLoading.loadClass(referenceInfo
119:                            .getProxyType(), gbeanInstance.getType()
120:                            .getClassLoader());
121:                } catch (ClassNotFoundException e) {
122:                    throw new InvalidConfigurationException(
123:                            "Could not load Proxy Type:" + getDescription(), e);
124:                }
125:
126:                if (referenceInfo.getSetterName() != null) {
127:                    try {
128:                        String setterName = referenceInfo.getSetterName();
129:                        Method setterMethod = gbeanInstance.getType()
130:                                .getMethod(setterName,
131:                                        new Class[] { proxyType });
132:                        if (NO_PROXY) {
133:                            setInvoker = new ReflectionMethodInvoker(
134:                                    setterMethod);
135:                        } else {
136:                            setInvoker = new FastMethodInvoker(setterMethod);
137:                        }
138:                    } catch (NoSuchMethodException e) {
139:                        throw new InvalidConfigurationException(
140:                                "Setter method not found " + getDescription(),
141:                                e);
142:                    }
143:                } else {
144:                    setInvoker = null;
145:                }
146:
147:            }
148:
149:            protected final Kernel getKernel() {
150:                return kernel;
151:            }
152:
153:            public final GBeanInstance getGBeanInstance() {
154:                return gbeanInstance;
155:            }
156:
157:            public final String getName() {
158:                return name;
159:            }
160:
161:            public final GReferenceInfo getReferenceInfo() {
162:                return referenceInfo;
163:            }
164:
165:            public final Class getReferenceType() {
166:                return referenceType;
167:            }
168:
169:            public final Class getProxyType() {
170:                return proxyType;
171:            }
172:
173:            public final Object getProxy() {
174:                return proxy;
175:            }
176:
177:            protected final void setProxy(Object proxy) {
178:                this .proxy = proxy;
179:            }
180:
181:            /**
182:             * Is the component in the Running state
183:             *
184:             * @param abstractName name of the component to check
185:             * @return true if the component is running; false otherwise
186:             */
187:            protected boolean isRunning(Kernel kernel, AbstractName abstractName) {
188:                try {
189:                    final int state = kernel.getGBeanState(abstractName);
190:                    return state == State.RUNNING_INDEX;
191:                } catch (GBeanNotFoundException e) {
192:                    // mbean is no longer registerd
193:                    return false;
194:                } catch (Exception e) {
195:                    // problem getting the attribute, mbean has most likely failed
196:                    return false;
197:                }
198:            }
199:
200:            protected final String getDescription() {
201:                return "\n    GBeanInstance: " + gbeanInstance.getName()
202:                        + "\n    Reference Name: " + getName()
203:                        + "\n    Reference Type: "
204:                        + referenceInfo.getReferenceType()
205:                        + "\n    Proxy Type: " + referenceInfo.getProxyType();
206:            }
207:
208:            public final synchronized void inject(Object target)
209:                    throws Exception {
210:                // set the proxy into the instance
211:                if (setInvoker != null && hasTargets) {
212:                    setInvoker.invoke(target, new Object[] { getProxy() });
213:                }
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.