Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb.assembler.classic;
import org.apache.openejb.AppContext;
import org.apache.openejb.BeanContext;
import org.apache.openejb.InterfaceType;
import org.apache.openejb.ModuleContext;
import org.apache.openejb.OpenEJBRuntimeException;
import org.apache.openejb.core.ivm.naming.BusinessLocalBeanReference;
import org.apache.openejb.core.ivm.naming.BusinessLocalReference;
import org.apache.openejb.core.ivm.naming.BusinessRemoteReference;
import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
import org.apache.openejb.core.ivm.naming.ObjectReference;
import org.apache.openejb.loader.Options;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.spi.ContainerSystem;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.StringTemplate;
import org.apache.openejb.util.Strings;
import javax.ejb.embeddable.EJBContainer;
import javax.jms.MessageListener;
import javax.naming.Context;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NamingException;
import javax.naming.Reference;
import java.lang.reflect.Constructor;
import java.rmi.Remote;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import static org.apache.openejb.util.Classes.packageName;
/**
* @version $Rev$ $Date$
*/
public class JndiBuilder {
public static final String DEFAULT_NAME_KEY = "default";
final boolean embeddedEjbContainerApi;
public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, JndiBuilder.class.getPackage().getName());
private static boolean USE_OLD_JNDI_NAMES = SystemInstance.get().getOptions().get("openejb.use-old-jndi-names", false);
private final Context openejbContext;
private static final String JNDINAME_STRATEGY_CLASS = "openejb.jndiname.strategy.class";
private static final String JNDINAME_FAILONCOLLISION = "openejb.jndiname.failoncollision";
private final boolean failOnCollision;
public JndiBuilder(final Context openejbContext) {
this.openejbContext = openejbContext;
final Options options = SystemInstance.get().getOptions();
failOnCollision = options.get(JNDINAME_FAILONCOLLISION, true);
embeddedEjbContainerApi = options.get(EJBContainer.class.getName(), false);
}
public void build(final EjbJarInfo ejbJar, final HashMap deployments) {
final JndiNameStrategy strategy = createStrategy(ejbJar, deployments);
for (final EnterpriseBeanInfo beanInfo : ejbJar.enterpriseBeans) {
final BeanContext beanContext = deployments.get(beanInfo.ejbDeploymentId);
strategy.begin(beanContext);
try {
bind(ejbJar, beanContext, beanInfo, strategy);
} finally {
strategy.end();
}
}
}
public static JndiNameStrategy createStrategy(final EjbJarInfo ejbJar, final Map deployments) {
final Options options = new Options(ejbJar.properties, SystemInstance.get().getOptions());
final Class strategyClass = options.get(JNDINAME_STRATEGY_CLASS, TemplatedStrategy.class);
final String strategyClassName = strategyClass.getName();
try {
try {
final Constructor constructor = strategyClass.getConstructor(EjbJarInfo.class, Map.class);
return (JndiNameStrategy) constructor.newInstance(ejbJar, deployments);
} catch (final NoSuchMethodException e) {
// no-op
}
final Constructor constructor = strategyClass.getConstructor();
return (JndiNameStrategy) constructor.newInstance();
} catch (final InstantiationException e) {
throw new IllegalStateException("Could not instantiate JndiNameStrategy: " + strategyClassName, e);
} catch (final IllegalAccessException e) {
throw new IllegalStateException("Could not access JndiNameStrategy: " + strategyClassName, e);
} catch (final Throwable t) {
throw new IllegalStateException("Could not create JndiNameStrategy: " + strategyClassName, t);
}
}
public interface JndiNameStrategy {
enum Interface {
REMOTE_HOME(InterfaceType.EJB_HOME, "RemoteHome", "home", ""),
LOCAL_HOME(InterfaceType.EJB_LOCAL_HOME, "LocalHome", "local-home", "Local"),
BUSINESS_LOCAL(InterfaceType.BUSINESS_LOCAL, "Local", "business-local", "BusinessLocal"),
LOCALBEAN(InterfaceType.LOCALBEAN, "LocalBean", "localbean", "LocalBean"),
BUSINESS_REMOTE(InterfaceType.BUSINESS_REMOTE, "Remote", "business-remote", "BusinessRemote"),
SERVICE_ENDPOINT(InterfaceType.SERVICE_ENDPOINT, "Endpoint", "service-endpoint", "ServiceEndpoint");
private final InterfaceType type;
private final String annotatedName;
private final String xmlName;
private final String xmlNameCc;
private final String openejbLegacy;
Interface(final InterfaceType type, final String annotatedName, final String xmlName, final String openejbLegacy) {
this.type = type;
this.annotatedName = annotatedName;
this.xmlName = xmlName;
this.xmlNameCc = Strings.camelCase(xmlName);
this.openejbLegacy = openejbLegacy;
}
public InterfaceType getType() {
return type;
}
public String getAnnotationName() {
return annotatedName;
}
public String getXmlName() {
return xmlName;
}
public String getXmlNameCc() {
return xmlNameCc;
}
public String getOpenejbLegacy() {
return openejbLegacy;
}
}
void begin(BeanContext beanContext);
String getName(Class interfce, String key, Interface type);
Map getNames(Class interfce, Interface type);
void end();
}
// TODO: put these into the classpath and get them with xbean-finder
public static class TemplatedStrategy implements JndiNameStrategy {
private static final String JNDINAME_FORMAT = "openejb.jndiname.format";
private static final String KEYS = "default,local,global,app";
private StringTemplate template;
private HashMap beanInfos;
// Set in begin()
private BeanContext bean;
// Set in begin()
private HashMap> templates;
private String format;
private Map appContext;
private HashMap beanContext;
public TemplatedStrategy(final EjbJarInfo ejbJarInfo, final Map deployments) {
final Options options = new Options(ejbJarInfo.properties, SystemInstance.get().getOptions());
format = options.get(JNDINAME_FORMAT, "{deploymentId}{interfaceType.annotationName}");
{ // illegal format check
final int index = format.indexOf(":");
if (index > -1) {
logger.error("Illegal " + JNDINAME_FORMAT + " contains a colon ':'. Everything before the colon will be removed, '" + format + "' ");
format = format.substring(index + 1);
}
}
this.template = new StringTemplate(format);
beanInfos = new HashMap();
for (final EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
beanInfos.put(beanInfo.ejbDeploymentId, beanInfo);
}
final Iterator it = deployments.values().iterator();
if (!it.hasNext()) {
return;
}
// TODO we should just pass in the ModuleContext
final ModuleContext moduleContext = it.next().getModuleContext();
appContext = new HashMap();
putAll(appContext, SystemInstance.get().getProperties());
putAll(appContext, moduleContext.getAppContext().getProperties());
putAll(appContext, moduleContext.getProperties());
appContext.put("appName", moduleContext.getAppContext().getId());
appContext.put("appId", moduleContext.getAppContext().getId());
appContext.put("moduleName", moduleContext.getId());
appContext.put("moduleId", moduleContext.getId());
}
private void putAll(final Map map, final Properties properties) {
for (final Map.Entry