Source Code Cross Referenced for ResourceGenerator.java in  » EJB-Server-resin-3.1.5 » resin » com » caucho » config » j2ee » 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 resin 3.1.5 » resin » com.caucho.config.j2ee 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * Resin Open Source is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
018:         * details.
019:         *
020:         * You should have received a copy of the GNU General Public License
021:         * along with Resin Open Source; if not, write to the
022:         *
023:         *   Free Software Foundation, Inc.
024:         *   59 Temple Place, Suite 330
025:         *   Boston, MA 02111-1307  USA
026:         *
027:         * @author Scott Ferguson
028:         */
029:
030:        package com.caucho.config.j2ee;
031:
032:        import com.caucho.config.program.ValueGenerator;
033:        import com.caucho.config.program.ConfigProgram;
034:        import com.caucho.config.ConfigException;
035:        import com.caucho.config.ConfigContext;
036:        import com.caucho.naming.*;
037:        import com.caucho.util.L10N;
038:        import com.caucho.webbeans.component.ComponentImpl;
039:        import com.caucho.webbeans.manager.WebBeansContainer;
040:
041:        import javax.naming.*;
042:        import javax.persistence.*;
043:        import java.lang.reflect.AccessibleObject;
044:        import java.lang.reflect.Field;
045:        import java.lang.reflect.Method;
046:        import javax.rmi.*;
047:        import java.util.*;
048:        import java.util.logging.Level;
049:        import java.util.logging.Logger;
050:
051:        /**
052:         * Generator for the @Resource tag.
053:         */
054:        public class ResourceGenerator extends ValueGenerator {
055:            private static final Logger log = Logger
056:                    .getLogger(ResourceGenerator.class.getName());
057:            private static final L10N L = new L10N(ResourceGenerator.class);
058:
059:            private final Class _type;
060:            private final String _mappedName;
061:
062:            private final String _jndiName;
063:
064:            private final String _location;
065:
066:            private ComponentImpl _component;
067:            private boolean _isBound;
068:
069:            ResourceGenerator(Class type, String mappedName, String jndiName,
070:                    String location) {
071:                _type = type;
072:                _mappedName = mappedName;
073:
074:                _jndiName = jndiName;
075:
076:                _location = location;
077:            }
078:
079:            /**
080:             * Returns the expected type
081:             */
082:            @Override
083:            public Class getType() {
084:                return _type;
085:            }
086:
087:            /**
088:             * Creates the value.
089:             */
090:            public Object create() {
091:                if (_component == null && !_isBound) {
092:                    _isBound = false;
093:
094:                    WebBeansContainer webBeans = WebBeansContainer.create();
095:
096:                    if (_mappedName != null && !"".equals(_mappedName)) {
097:                        _component = webBeans.bind(_location, _type,
098:                                _mappedName);
099:
100:                        if (_component == null) {
101:                            Object value = getJndiValue(_type);
102:
103:                            if (value != null)
104:                                return value;
105:
106:                            throw new ConfigException(
107:                                    _location
108:                                            + L
109:                                                    .l(
110:                                                            "'{0}' with mappedName='{1}' is an unknown @EJB",
111:                                                            _type.getName(),
112:                                                            _mappedName));
113:                        }
114:                    } else if (_jndiName != null && !"".equals(_jndiName)) {
115:                        _component = webBeans.bind(_location, _type, _jndiName);
116:
117:                        if (_component == null) {
118:                            Object value = getJndiValue(_type);
119:
120:                            if (value != null)
121:                                return value;
122:                        }
123:                    }
124:
125:                    if (_component == null) {
126:                        _component = webBeans.bind(_location, _type);
127:
128:                        if (_component == null) {
129:                            Object value = getJndiValue(_type);
130:
131:                            if (value != null)
132:                                return value;
133:
134:                            throw new ConfigException(_location
135:                                    + L.l("'{0}'  is an unknown @Resource",
136:                                            _type.getName()));
137:                        }
138:                    }
139:
140:                    if (_component != null && _jndiName != null
141:                            && !"".equals(_jndiName)) {
142:                        try {
143:                            Jndi.bindDeepShort(_jndiName, _component);
144:                        } catch (NamingException e) {
145:                            throw ConfigException.create(e);
146:                        }
147:                    }
148:                }
149:
150:                if (_component != null)
151:                    return _component.get();
152:                else
153:                    return getJndiValue(_type);
154:            }
155:
156:            private Object getJndiValue(Class type) {
157:                if (_jndiName == null || "".equals(_jndiName))
158:                    return null;
159:
160:                try {
161:                    Object value = Jndi.lookup(_jndiName);
162:
163:                    if (value != null)
164:                        return PortableRemoteObject.narrow(value, type);
165:                    else
166:                        return null;
167:                } catch (Exception e) {
168:                    log.log(Level.FINE, e.toString(), e);
169:
170:                    return null;
171:                }
172:            }
173:
174:            @Override
175:            public String toString() {
176:                StringBuilder sb = new StringBuilder();
177:
178:                sb.append(getClass().getSimpleName());
179:                sb.append("[");
180:                sb.append(_type.getName());
181:
182:                if (_mappedName != null) {
183:                    sb.append(", mappedName=");
184:                    sb.append(_mappedName);
185:                }
186:
187:                if (_jndiName != null) {
188:                    sb.append(", jndiName=");
189:                    sb.append(_jndiName);
190:                }
191:
192:                sb.append("]");
193:
194:                return sb.toString();
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.