001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.assembler.classic;
018:
019: import org.apache.openejb.Injection;
020: import org.apache.openejb.OpenEJBException;
021:
022: import java.util.List;
023: import java.util.ArrayList;
024:
025: public class InjectionBuilder {
026: private final ClassLoader classLoader;
027:
028: public InjectionBuilder(ClassLoader classLoader) {
029: this .classLoader = classLoader;
030: }
031:
032: public List<Injection> buildInjections(JndiEncInfo jndiEnc)
033: throws OpenEJBException {
034: List<Injection> injections = new ArrayList<Injection>();
035: for (EnvEntryInfo info : jndiEnc.envEntries) {
036: for (InjectionInfo target : info.targets) {
037: Class targetClass = loadClass(target.className);
038: Injection injection = new Injection(info.name,
039: target.propertyName, targetClass);
040: injections.add(injection);
041: }
042: }
043:
044: for (EjbReferenceInfo info : jndiEnc.ejbReferences) {
045: for (InjectionInfo target : info.targets) {
046: Class targetClass = loadClass(target.className);
047: Injection injection = new Injection(info.referenceName,
048: target.propertyName, targetClass);
049: injections.add(injection);
050: }
051: }
052:
053: for (EjbReferenceInfo info : jndiEnc.ejbLocalReferences) {
054: for (InjectionInfo target : info.targets) {
055: Class targetClass = loadClass(target.className);
056: Injection injection = new Injection(info.referenceName,
057: target.propertyName, targetClass);
058: injections.add(injection);
059: }
060: }
061:
062: for (PersistenceUnitReferenceInfo info : jndiEnc.persistenceUnitRefs) {
063: for (InjectionInfo target : info.targets) {
064: Class targetClass = loadClass(target.className);
065: Injection injection = new Injection(info.referenceName,
066: target.propertyName, targetClass);
067: injections.add(injection);
068: }
069: }
070:
071: for (PersistenceContextReferenceInfo info : jndiEnc.persistenceContextRefs) {
072: for (InjectionInfo target : info.targets) {
073: Class targetClass = loadClass(target.className);
074: Injection injection = new Injection(info.referenceName,
075: target.propertyName, targetClass);
076: injections.add(injection);
077: }
078: }
079:
080: for (ResourceReferenceInfo info : jndiEnc.resourceRefs) {
081: for (InjectionInfo target : info.targets) {
082: Class targetClass = loadClass(target.className);
083: Injection injection = new Injection(info.referenceName,
084: target.propertyName, targetClass);
085: injections.add(injection);
086: }
087: }
088:
089: for (ResourceEnvReferenceInfo info : jndiEnc.resourceEnvRefs) {
090: for (InjectionInfo target : info.targets) {
091: Class targetClass = loadClass(target.className);
092: Injection injection = new Injection(
093: info.resourceEnvRefName, target.propertyName,
094: targetClass);
095: injections.add(injection);
096: }
097: }
098:
099: for (ServiceReferenceInfo info : jndiEnc.serviceRefs) {
100: for (InjectionInfo target : info.targets) {
101: Class targetClass = loadClass(target.className);
102: Injection injection = new Injection(info.referenceName,
103: target.propertyName, targetClass);
104: injections.add(injection);
105: }
106: }
107: return injections;
108: }
109:
110: private Class loadClass(String className) throws OpenEJBException {
111: try {
112: Class clazz = Class.forName(className, true, classLoader);
113: // clazz.getDeclaredMethods();
114: // clazz.getDeclaredFields();
115: // clazz.getDeclaredConstructors();
116: // clazz.getInterfaces();
117: return clazz;
118: } catch (Throwable e) {
119: throw new OpenEJBException("Unable to load class "
120: + className);
121: }
122: }
123: }
|