Source Code Cross Referenced for EjbResolver.java in  » J2EE » openejb3 » org » apache » openejb » assembler » classic » 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 » J2EE » openejb3 » org.apache.openejb.assembler.classic 
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.openejb.assembler.classic;
017:
018:        import org.apache.openejb.util.LinkResolver;
019:
020:        import java.net.URI;
021:        import java.util.List;
022:        import java.util.Map;
023:        import java.util.TreeMap;
024:        import java.util.Arrays;
025:
026:        /**
027:         * @version $Rev$ $Date$
028:         */
029:        public class EjbResolver {
030:
031:            public static interface Reference {
032:
033:                String getName();
034:
035:                Type getRefType();
036:
037:                String getHome();
038:
039:                String getInterface();
040:
041:                String getMappedName();
042:
043:                String getEjbLink();
044:            }
045:
046:            public static enum Type {
047:                UNKNOWN, LOCAL, REMOTE;
048:            }
049:
050:            public static enum Scope {
051:                GLOBAL, EAR, EJBJAR;
052:            }
053:
054:            private final Map<String, EnterpriseBeanInfo> deployments = new TreeMap<String, EnterpriseBeanInfo>();
055:            private final LinkResolver<String> resolver = new LinkResolver<String>();
056:            private final Map<Interfaces, String> remoteInterfaces = new TreeMap<Interfaces, String>();
057:            private final Map<Interfaces, String> localInterfaces = new TreeMap<Interfaces, String>();
058:
059:            private EjbResolver parent;
060:
061:            private final Scope scope;
062:
063:            public EjbResolver(EjbResolver parent, Scope scope,
064:                    EjbJarInfo... ejbJars) {
065:                this (parent, scope, Arrays.asList(ejbJars));
066:            }
067:
068:            public EjbResolver(EjbResolver parent, Scope scope,
069:                    List<EjbJarInfo> ejbJars) {
070:                this .scope = scope;
071:                this .parent = parent;
072:
073:                for (EjbJarInfo ejbJarInfo : ejbJars) {
074:                    add(ejbJarInfo);
075:                }
076:            }
077:
078:            /**
079:             * Possible syncronization issue here
080:             */
081:            public void addAll(List<EjbJarInfo> ejbJars) {
082:                for (EjbJarInfo ejbJarInfo : ejbJars) {
083:                    add(ejbJarInfo);
084:                }
085:            }
086:
087:            private void add(EjbJarInfo ejbJarInfo) {
088:                for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
089:                    index(ejbJarInfo.moduleId, bean);
090:                }
091:            }
092:
093:            private void index(String moduleId, EnterpriseBeanInfo bean) {
094:                // All deployments: deploymentId -> bean
095:                deployments.put(bean.ejbDeploymentId, bean);
096:
097:                // add to the link resolver
098:                resolver.add(moduleId, bean.ejbName, bean.ejbDeploymentId);
099:
100:                // Remote: Interfaces(home,object) -> deploymentId
101:                if (bean.remote != null) {
102:                    remoteInterfaces.put(
103:                            new Interfaces(bean.home, bean.remote),
104:                            bean.ejbDeploymentId);
105:                    remoteInterfaces.put(new Interfaces(bean.remote),
106:                            bean.ejbDeploymentId);
107:                }
108:                for (String businessRemote : bean.businessRemote) {
109:                    remoteInterfaces.put(new Interfaces(businessRemote),
110:                            bean.ejbDeploymentId);
111:                }
112:
113:                // Local: Interfaces(home,object) -> deploymentId
114:                if (bean.local != null) {
115:                    localInterfaces.put(new Interfaces(bean.localHome,
116:                            bean.local), bean.ejbDeploymentId);
117:                    localInterfaces.put(new Interfaces(bean.local),
118:                            bean.ejbDeploymentId);
119:                }
120:                for (String businessLocal : bean.businessLocal) {
121:                    localInterfaces.put(new Interfaces(businessLocal),
122:                            bean.ejbDeploymentId);
123:                }
124:            }
125:
126:            private String resolveLink(String link, URI moduleUri) {
127:                if (link == null || link.length() == 0)
128:                    return null;
129:
130:                String id = resolver.resolveLink(link, moduleUri);
131:                if (id == null && parent != null) {
132:                    id = parent.resolveLink(link, moduleUri);
133:                }
134:                return id;
135:            }
136:
137:            private String resolveInterface(Type type, String homeInterface,
138:                    String objectInterface) {
139:                Interfaces interfaces = new Interfaces(homeInterface,
140:                        objectInterface);
141:                return resolveInterface(type, interfaces);
142:            }
143:
144:            private String resolveInterface(Type type, Interfaces interfaces) {
145:                String id;
146:                switch (type) {
147:                case UNKNOWN:
148:                case REMOTE: {
149:                    id = remoteInterfaces.get(interfaces);
150:                    id = (id != null) ? id : localInterfaces.get(interfaces);
151:                }
152:                    break;
153:                case LOCAL: {
154:                    id = localInterfaces.get(interfaces);
155:                    id = (id != null) ? id : remoteInterfaces.get(interfaces);
156:                }
157:                    break;
158:                default:
159:                    id = null;
160:                }
161:
162:                if (id == null && parent != null) {
163:                    id = parent.resolveInterface(type, interfaces);
164:                }
165:
166:                return id;
167:            }
168:
169:            public Scope getScope(String deploymentId) {
170:                if (deployments.containsKey(deploymentId))
171:                    return scope;
172:
173:                if (parent != null)
174:                    return parent.getScope(deploymentId);
175:
176:                return null;
177:            }
178:
179:            public EnterpriseBeanInfo getEnterpriseBeanInfo(String deploymentId) {
180:                EnterpriseBeanInfo info = deployments.get(deploymentId);
181:                if (info == null && parent != null) {
182:                    info = parent.getEnterpriseBeanInfo(deploymentId);
183:                }
184:                return info;
185:            }
186:
187:            public String resolve(Reference ref, URI moduleUri) {
188:
189:                if (ref.getMappedName() != null
190:                        && !ref.getMappedName().equals("")) {
191:                    return ref.getMappedName();
192:                }
193:
194:                String targetId = this .resolveLink(ref.getEjbLink(), moduleUri);
195:
196:                if (targetId == null && ref.getEjbLink() == null) {
197:                    targetId = this .resolveInterface(ref.getRefType(), ref
198:                            .getHome(), ref.getInterface());
199:                }
200:
201:                return targetId;
202:            }
203:
204:            private static class Interfaces implements  Comparable {
205:                private final String homeInterface;
206:                private final String objectInterface;
207:
208:                public Interfaces(String objectInterface) {
209:                    if (objectInterface == null)
210:                        throw new NullPointerException(
211:                                "objectInterface is null");
212:                    this .homeInterface = "<none>";
213:                    this .objectInterface = objectInterface;
214:                }
215:
216:                public Interfaces(String homeInterface, String objectInterface) {
217:                    if (homeInterface == null)
218:                        homeInterface = "<none>";
219:                    if (objectInterface == null)
220:                        throw new NullPointerException(
221:                                "objectInterface is null");
222:                    this .homeInterface = homeInterface;
223:                    this .objectInterface = objectInterface;
224:                }
225:
226:                public boolean equals(Object o) {
227:                    if (this  == o)
228:                        return true;
229:                    if (o == null || getClass() != o.getClass())
230:                        return false;
231:
232:                    Interfaces that = (Interfaces) o;
233:
234:                    return homeInterface.equals(that.homeInterface)
235:                            && objectInterface.equals(that.objectInterface);
236:                }
237:
238:                public int hashCode() {
239:                    int result;
240:                    result = homeInterface.hashCode();
241:                    result = 31 * result + objectInterface.hashCode();
242:                    return result;
243:                }
244:
245:                public int compareTo(Object o) {
246:                    if (this  == o)
247:                        return 0;
248:
249:                    Interfaces that = (Interfaces) o;
250:                    return toString().compareTo(that.toString());
251:                }
252:
253:                public String toString() {
254:                    return homeInterface + ":" + objectInterface;
255:                }
256:            }
257:
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.