You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/12/04 22:07:51 UTC
svn commit: r1417182 [6/22] - in /openejb/trunk/openejb:
container/openejb-core/ deps/ deps/webbeans-impl/ deps/webbeans-impl/src/
deps/webbeans-impl/src/main/ deps/webbeans-impl/src/main/java/
deps/webbeans-impl/src/main/java/org/ deps/webbeans-impl/s...
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,357 @@
+/*
+ * 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.webbeans.config;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+
+/**
+ * Defines configuration for OpenWebBeans.
+ *
+ * The algorithm is easy:
+ * <ul>
+ * <li>Load all properties you can find with the name (META-INF/openwebbeans/openwebbeans.properties),
+ * <li>Sort them via configuration.ordinal in ascending order,
+ * <li>Overload them as we do already,
+ * <li>Use the sorted list of properties.
+ * </ul>
+ */
+public class OpenWebBeansConfiguration
+{
+ /**Logger instance*/
+ private final static Logger logger = WebBeansLoggerFacade.getLogger(OpenWebBeansConfiguration.class);
+
+ /**Default configuration files*/
+ private final static String DEFAULT_CONFIG_PROPERTIES_NAME = "META-INF/openwebbeans/openwebbeans.properties";
+
+ /**Property of application*/
+ private final Properties configProperties = new Properties();
+
+ /**Conversation periodic delay in ms.*/
+ public static final String CONVERSATION_PERIODIC_DELAY = "org.apache.webbeans.conversation.Conversation.periodicDelay";
+
+ /**Timeout interval in ms*/
+ public static final String CONVERSATION_TIMEOUT_INTERVAL = "org.apache.webbeans.conversation.Conversation.timeoutInterval";
+
+ /**
+ * Lifycycle methods like {@link javax.annotation.PostConstruct} and
+ * {@link javax.annotation.PreDestroy} must not define a checked Exception
+ * regarding to the spec. But this is often unnecessary restrictive so we
+ * allow to disable this check application wide.
+ */
+ public static final String INTERCEPTOR_FORCE_NO_CHECKED_EXCEPTIONS = "org.apache.webbeans.forceNoCheckedExceptions";
+
+ /**Use EJB Discovery or not*/
+ public static final String USE_EJB_DISCOVERY = "org.apache.webbeans.spi.deployer.useEjbMetaDataDiscoveryService";
+
+ /**Container lifecycle*/
+ public static final String CONTAINER_LIFECYCLE = "org.apache.webbeans.spi.ContainerLifecycle";
+
+ /**JNDI Service SPI*/
+ public static final String JNDI_SERVICE = "org.apache.webbeans.spi.JNDIService";
+
+ /**Scanner Service*/
+ public static final String SCANNER_SERVICE = "org.apache.webbeans.spi.ScannerService";
+
+ /**Contexts Service*/
+ public static final String CONTEXTS_SERVICE = "org.apache.webbeans.spi.ContextsService";
+
+ /**Conversation Service*/
+ public static final String CONVERSATION_SERVICE = "org.apache.webbeans.spi.ConversationService";
+
+ /**Resource Injection Service*/
+ public static final String RESOURCE_INJECTION_SERVICE = "org.apache.webbeans.spi.ResourceInjectionService";
+
+ /**Security Service*/
+ public static final String SECURITY_SERVICE = "org.apache.webbeans.spi.SecurityService";
+
+ /**Validator Service*/
+ public static final String VALIDATOR_SERVICE = "org.apache.webbeans.spi.ValidatorService";
+
+ /**Transaction Service*/
+ public static final String TRANSACTION_SERVICE = "org.apache.webbeans.spi.TransactionService";
+
+ /**Application is core JSP*/
+ public static final String APPLICATION_IS_JSP = "org.apache.webbeans.application.jsp";
+
+ /**Supports conversations*/
+ public static final String APPLICATION_SUPPORTS_CONVERSATION = "org.apache.webbeans.application.supportsConversation";
+
+ /**Use of EJB interceptor to inject EJBs*/
+ public static final String USE_EJBINTERCEPTOR_INJECTION = "org.apache.webbeans.application.useEJBInterceptorInjection";
+
+ /**Use of EJB interceptor to activate EJB contexts*/
+ public static final String USE_EJBINTERCEPTOR_ACTIVATION = "org.apache.webbeans.application.useEJBInterceptorActivation";
+
+ /**EL Adaptor*/
+ public static final String EL_ADAPTOR_CLASS = "org.apache.webbeans.spi.adaptor.ELAdaptor";
+
+ /** prefix followed by the fully qualified scope name, for configuring InterceptorHandlers for our proxies.*/
+ public static final String PROXY_MAPPING_PREFIX = "org.apache.webbeans.proxy.mapping.";
+
+ /**
+ * Use BDABeansXmlScanner to determine if interceptors, decorators, and
+ * alternatives are enabled in the beans.xml of a given BDA. For an
+ * application containing jar1 and jar2, this implies that an interceptor
+ * enabled in the beans.xml of jar1 is not automatically enabled in jar2
+ **/
+ public static final String USE_BDA_BEANSXML_SCANNER = "org.apache.webbeans.useBDABeansXMLScanner";
+
+ /**
+ * a comma-separated list of fully qualified class names that should be ignored
+ * when determining if a decorator matches its delegate. These are typically added by
+ * weaving or bytecode modification.
+ */
+ public static final String IGNORED_INTERFACES = "org.apache.webbeans.ignoredDecoratorInterfaces";
+
+ private Set<String> ignoredInterfaces;
+
+ /**
+ * you can configure this externally as well.
+ *
+ * @param properties
+ */
+ public OpenWebBeansConfiguration(Properties properties)
+ {
+ configProperties.putAll(properties);
+ }
+
+ /**
+ * Parse configuration.
+ */
+ public OpenWebBeansConfiguration()
+ {
+ parseConfiguration();
+
+ logger.fine("Overriding properties from System properties");
+
+ //Look for System properties
+ loadFromSystemProperties();
+ }
+
+ /**
+ * Load from system properties
+ */
+ private void loadFromSystemProperties()
+ {
+ Properties properties;
+ if(System.getSecurityManager() != null)
+ {
+ properties = doPrivilegedGetSystemProperties();
+ }
+ else
+ {
+ properties = System.getProperties();
+ }
+
+ String value = properties.getProperty(CONVERSATION_PERIODIC_DELAY);
+ setPropertyFromSystemProperty(CONVERSATION_PERIODIC_DELAY, value);
+
+ value = properties.getProperty(USE_EJB_DISCOVERY);
+ setPropertyFromSystemProperty(USE_EJB_DISCOVERY, value);
+
+ value = properties.getProperty(USE_EJBINTERCEPTOR_INJECTION);
+ setPropertyFromSystemProperty(USE_EJBINTERCEPTOR_INJECTION, value);
+
+ value = properties.getProperty(USE_EJBINTERCEPTOR_ACTIVATION);
+ setPropertyFromSystemProperty(USE_EJBINTERCEPTOR_ACTIVATION, value);
+
+ value = properties.getProperty(CONTAINER_LIFECYCLE);
+ setPropertyFromSystemProperty(CONTAINER_LIFECYCLE, value);
+
+ value = properties.getProperty(APPLICATION_IS_JSP);
+ setPropertyFromSystemProperty(APPLICATION_IS_JSP, value);
+
+ value = properties.getProperty(TRANSACTION_SERVICE);
+ setPropertyFromSystemProperty(TRANSACTION_SERVICE, value);
+
+ value = properties.getProperty(VALIDATOR_SERVICE);
+ setPropertyFromSystemProperty(VALIDATOR_SERVICE, value);
+
+ value = properties.getProperty(SECURITY_SERVICE);
+ setPropertyFromSystemProperty(SECURITY_SERVICE, value);
+
+ value = properties.getProperty(RESOURCE_INJECTION_SERVICE);
+ setPropertyFromSystemProperty(RESOURCE_INJECTION_SERVICE, value);
+
+ value = properties.getProperty(CONVERSATION_SERVICE);
+ setPropertyFromSystemProperty(CONVERSATION_SERVICE, value);
+
+ value = properties.getProperty(CONTEXTS_SERVICE);
+ setPropertyFromSystemProperty(CONTEXTS_SERVICE, value);
+
+ value = properties.getProperty(SCANNER_SERVICE);
+ setPropertyFromSystemProperty(SCANNER_SERVICE, value);
+
+ value = properties.getProperty(JNDI_SERVICE);
+ setPropertyFromSystemProperty(JNDI_SERVICE, value);
+
+ value = properties.getProperty(EL_ADAPTOR_CLASS);
+ setPropertyFromSystemProperty(EL_ADAPTOR_CLASS, value);
+
+ value = properties.getProperty(USE_BDA_BEANSXML_SCANNER);
+ setPropertyFromSystemProperty(USE_BDA_BEANSXML_SCANNER, value);
+
+ }
+
+ private Properties doPrivilegedGetSystemProperties()
+ {
+ return AccessController.doPrivileged(
+ new PrivilegedAction<Properties>()
+ {
+ public Properties run()
+ {
+ return System.getProperties();
+ }
+
+ }
+ );
+ }
+
+
+ private void setPropertyFromSystemProperty(String key, String value)
+ {
+ if(value != null)
+ {
+ setProperty(key, value);
+ }
+ }
+
+ /**
+ * (re)read the configuration from the resources in the classpath.
+ * @see #DEFAULT_CONFIG_PROPERTIES_NAME
+ * @see #DEFAULT_CONFIG_PROPERTIES_NAME
+ */
+ public synchronized void parseConfiguration() throws WebBeansConfigurationException
+ {
+ Properties newConfigProperties = PropertyLoader.getProperties(DEFAULT_CONFIG_PROPERTIES_NAME);
+ configProperties.clear();
+
+ // set the new one as perfect fit.
+ if(newConfigProperties != null)
+ {
+ configProperties.putAll(newConfigProperties);
+ }
+ }
+
+
+ /**
+ * Gets property.
+ * @param key
+ * @return String with the property value or <code>null</code>
+ */
+ public String getProperty(String key)
+ {
+ return configProperties.getProperty(key);
+ }
+
+ /**
+ * Gets property value.
+ * @param key
+ * @param defaultValue
+ * @return String with the property value or <code>null</code>
+ */
+ public String getProperty(String key,String defaultValue)
+ {
+ return configProperties.getProperty(key, defaultValue);
+ }
+
+
+ /**
+ * Sets given property.
+ * @param key property name
+ * @param value property value
+ */
+ public synchronized void setProperty(String key, Object value)
+ {
+ configProperties.put(key, value);
+ }
+
+
+ /**
+ * Gets jsp property.
+ * @return true if jsp
+ */
+ public boolean isJspApplication()
+ {
+ String value = getProperty(APPLICATION_IS_JSP);
+
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * Gets conversation supports property.
+ * @return true if supports
+ */
+ public boolean supportsConversation()
+ {
+ String value = getProperty(APPLICATION_SUPPORTS_CONVERSATION);
+
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * Gets EJB injection property.
+ * @return true if EJB interceptor should do injection
+ */
+ public boolean isUseEJBInterceptorInjection()
+ {
+ String value = getProperty(USE_EJBINTERCEPTOR_INJECTION);
+
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * Gets EJB context activation property.
+ * @return true if EJB interceptor should do activation of EJB contexts
+ */
+ public boolean isUseEJBInterceptorActivation()
+ {
+ String value = getProperty(USE_EJBINTERCEPTOR_ACTIVATION);
+
+ return Boolean.valueOf(value);
+ }
+
+ public synchronized Set<String> getIgnoredInterfaces()
+ {
+ if (ignoredInterfaces == null)
+ {
+ String ignoredInterfacesString = getProperty(IGNORED_INTERFACES);
+ if (ignoredInterfacesString != null)
+ {
+ ignoredInterfaces = new HashSet<String>(Arrays.asList(ignoredInterfacesString.split("[,\\p{javaWhitespace}]")));
+ }
+ else
+ {
+ ignoredInterfaces = Collections.emptySet();
+ }
+ }
+ return ignoredInterfaces;
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,162 @@
+/*
+ * 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.webbeans.config;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Custom parametrized type implementation.
+ * @version $Rev: 1182780 $ $Date: 2011-10-13 13:11:03 +0200 (jeu., 13 oct. 2011) $
+ *
+ */
+public class OwbParametrizedTypeImpl implements ParameterizedType
+{
+ /**Owner type*/
+ private final Type owner;
+
+ /**Raw type*/
+ private final Type rawType;
+
+ /**Actual type arguments*/
+ private final List<Type> types = new ArrayList<Type>();
+
+ /**
+ * New instance.
+ * @param owner owner
+ * @param raw raw
+ */
+ public OwbParametrizedTypeImpl(Type owner, Type raw)
+ {
+ this.owner = owner;
+ rawType = raw;
+ }
+
+ public Type[] getActualTypeArguments()
+ {
+ return types.toArray(new Type[types.size()]);
+ }
+
+ public void addTypeArgument(Type type)
+ {
+ types.add(type);
+ }
+
+ public Type getOwnerType()
+ {
+ return owner;
+ }
+
+ public Type getRawType()
+ {
+ return rawType;
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(getActualTypeArguments());
+ result = prime * result + ((owner == null) ? 0 : owner.hashCode());
+ result = prime * result + ((rawType == null) ? 0 : rawType.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ OwbParametrizedTypeImpl other = (OwbParametrizedTypeImpl) obj;
+ if (!Arrays.equals(getActualTypeArguments(), other.getActualTypeArguments()))
+ {
+ return false;
+ }
+ if (owner == null)
+ {
+ if (other.owner != null)
+ {
+ return false;
+ }
+ }
+ else if (!owner.equals(other.owner))
+ {
+ return false;
+ }
+ if (rawType == null)
+ {
+ if (other.rawType != null)
+ {
+ return false;
+ }
+ }
+ else if (!rawType.equals(other.rawType))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(((Class<?>) rawType).getSimpleName());
+ Type[] actualTypes = getActualTypeArguments();
+ if(actualTypes.length > 0)
+ {
+ buffer.append("<");
+ int length = actualTypes.length;
+ for(int i=0;i<length;i++)
+ {
+ buffer.append(actualTypes[i].toString());
+ if(i != actualTypes.length-1)
+ {
+ buffer.append(",");
+ }
+ }
+
+ buffer.append(">");
+ }
+
+ return buffer.toString();
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/PropertyLoader.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,226 @@
+/*
+ * 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.webbeans.config;
+
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
+import org.apache.webbeans.util.WebBeansUtil;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <p>Utility class to load configuration properties via a list of
+ * artibrary property files by a well defined order.</p>
+ * <p>User configurations should start with 'configuration.ordinal'
+ * greather than 100.</p>
+ *
+ */
+public class PropertyLoader
+{
+ public final static int CONFIGURATION_ORDINAL_DEFAULT_VALUE = 100;
+
+ public final static String CONFIGURATION_ORDINAL_PROPERTY_NAME = "configuration.ordinal";
+
+
+ private static final Logger logger = WebBeansLoggerFacade.getLogger(PropertyLoader.class);
+
+
+ private PropertyLoader()
+ {
+ // utility class doesn't have a public ct
+ }
+
+ /**
+ * <p>Look for all property files with the given name (e.g. 'myconfig.properties') in
+ * the classpath. Then load all properties files and sort them by their ascending
+ * configuration order and apply them in this order.</p>
+ *
+ * <p>The idea is to be able to 'override' properties by just providing
+ * a new properties file with the same name but a higher 'configuration.ordinal'
+ * than the old one.</p>
+ *
+ * <p>If a property file defines no 'configuration.ordinal' property than a default
+ * value of {@link #CONFIGURATION_ORDINAL_DEFAULT_VALUE} is assumed. Any sensitive
+ * default which is provided by the system parsing for the configuration should
+ * have a 'configuration.ordinal' value lower than 10. In most cases a value of 1</p>
+ *
+ * <p>If 2 property files have the same ordinal 'configuraiton.order' the outcome
+ * is not really defined. The Properties file which got found first will be
+ * processed first and thus get overwritten by the one found later.</p>
+ *
+ * @param propertyFileName the name of the properties file
+ * @return the final property values
+ */
+ public static synchronized Properties getProperties(String propertyFileName)
+ {
+ try
+ {
+ List<Properties> allProperties = loadAllProperties(propertyFileName);
+ if (allProperties == null)
+ {
+ return null;
+ }
+
+ List<Properties> sortedProperties = sortProperties(allProperties);
+ Properties properties = mergeProperties(sortedProperties);
+ return properties;
+ }
+ catch (IOException e)
+ {
+ logger.log(Level.SEVERE, "Error while loading the propertyFile " + propertyFileName, e);
+ return null;
+ }
+ }
+
+ private static List<Properties> loadAllProperties(String propertyFileName)
+ throws IOException
+ {
+ ClassLoader cl = WebBeansUtil.getCurrentClassLoader();
+ Enumeration<URL> propertyUrls = cl.getResources(propertyFileName);
+ if (propertyUrls == null || !propertyUrls.hasMoreElements())
+ {
+ if(logger.isLoggable(Level.INFO))
+ {
+ logger.info("could not find any property files with name " + propertyFileName);
+ }
+
+ return null;
+ }
+
+ List<Properties> properties = new ArrayList<Properties>();
+
+ while (propertyUrls.hasMoreElements())
+ {
+ URL propertyUrl = propertyUrls.nextElement();
+ InputStream is = null;
+ try
+ {
+ is = propertyUrl.openStream();
+ Properties prop = new Properties();
+ prop.load(is);
+ properties.add(prop);
+
+ // a bit debugging output
+ int ordinal = getConfigurationOrdinal(prop);
+ if(logger.isLoggable(Level.FINE))
+ {
+ logger.fine("loading properties with ordinal " + ordinal + " from file " + propertyUrl.getFile());
+ }
+ }
+ finally
+ {
+ if (is != null)
+ {
+ is.close();
+ }
+ }
+ }
+
+ return properties;
+ }
+
+ /**
+ * Implement a quick and dirty sorting mechanism for the given Properties.
+ * @param allProperties
+ * @return the Properties list sorted by it's 'configuration.ordinal' in ascending order.
+ */
+ private static List<Properties> sortProperties(List<Properties> allProperties)
+ {
+ List<Properties> sortedProperties = new ArrayList<Properties>();
+ for (Properties p : allProperties)
+ {
+ int configOrder = getConfigurationOrdinal(p);
+
+ int i;
+ for (i = 0; i < sortedProperties.size(); i++)
+ {
+ int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i));
+ if (listConfigOrder > configOrder)
+ {
+ // only go as far as we found a higher priority Properties file
+ break;
+ }
+ }
+ sortedProperties.add(i, p);
+ }
+ return sortedProperties;
+ }
+
+ /**
+ * Determine the 'configuration.ordinal' of the given properties.
+ * {@link #CONFIGURATION_ORDINAL_DEFAULT_VALUE} if
+ * {@link #CONFIGURATION_ORDINAL_PROPERTY_NAME} is not set in the
+ * Properties file.
+ *
+ * @param p the Properties from the file.
+ * @return the ordinal number of the given Properties file.
+ */
+ private static int getConfigurationOrdinal(Properties p)
+ {
+ int configOrder = CONFIGURATION_ORDINAL_DEFAULT_VALUE;
+
+ String configOrderString = p.getProperty(CONFIGURATION_ORDINAL_PROPERTY_NAME);
+ if (configOrderString != null && configOrderString.length() > 0)
+ {
+ try
+ {
+ configOrder = Integer.parseInt(configOrderString);
+ }
+ catch(NumberFormatException nfe)
+ {
+ logger.severe(CONFIGURATION_ORDINAL_PROPERTY_NAME + " must be an integer value!");
+ throw nfe;
+ }
+ }
+
+ return configOrder;
+ }
+
+ /**
+ * Merge the given Properties in order of appearance.
+ * @param sortedProperties
+ * @return the merged Properties
+ */
+ private static Properties mergeProperties(List<Properties> sortedProperties)
+ {
+ Properties mergedProperties = new Properties();
+ for (Properties p : sortedProperties)
+ {
+ for (Map.Entry<?,?> entry : p.entrySet())
+ {
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+
+ // simply overwrite the old properties with the new ones.
+ mergedProperties.setProperty(key, value);
+ }
+ }
+
+ return mergedProperties;
+ }
+
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,448 @@
+/*
+ * 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.webbeans.config;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.webbeans.annotation.AnnotationManager;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.ResolutionUtil;
+import org.apache.webbeans.container.SerializableBeanVault;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.context.creational.CreationalContextFactory;
+import org.apache.webbeans.conversation.ConversationManager;
+import org.apache.webbeans.decorator.DecoratorsManager;
+import org.apache.webbeans.deployment.StereoTypeManager;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.inject.AlternativesManager;
+import org.apache.webbeans.inject.impl.InjectionPointFactory;
+import org.apache.webbeans.intercept.InterceptorUtil;
+import org.apache.webbeans.intercept.InterceptorsManager;
+import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
+import org.apache.webbeans.intercept.ejb.EJBInterceptorConfig;
+import org.apache.webbeans.plugins.PluginLoader;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
+import org.apache.webbeans.portable.events.ExtensionLoader;
+import org.apache.webbeans.proxy.ProxyFactory;
+import org.apache.webbeans.proxy.javassist.OpenWebBeansClassLoaderProvider;
+import org.apache.webbeans.service.DefaultLoaderService;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.spi.LoaderService;
+import org.apache.webbeans.spi.ScannerService;
+import org.apache.webbeans.spi.SecurityService;
+import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebBeansContext
+{
+ private final Map<Class<?>, Object> managerMap = new HashMap<Class<?>, Object>();
+
+ private final Map<Class<?>, Object> serviceMap = new HashMap<Class<?>, Object>();
+
+ private final WebBeansUtil webBeansUtil = new WebBeansUtil(this);
+ private final ContextFactory contextFactory = new ContextFactory(this);
+ private final AlternativesManager alternativesManager = new AlternativesManager(this);
+ private final AnnotatedElementFactory annotatedElementFactory = new AnnotatedElementFactory(this);
+ private final BeanManagerImpl beanManagerImpl = new BeanManagerImpl(this);
+ private final ConversationManager conversationManager = new ConversationManager(this);
+ private final CreationalContextFactory creationalContextFactory = new CreationalContextFactory(this);
+ private final DecoratorsManager decoratorsManager = new DecoratorsManager(this);
+ private final EJBInterceptorConfig ejbInterceptorConfig = new EJBInterceptorConfig(this);
+ private final ExtensionLoader extensionLoader = new ExtensionLoader(this);
+ private final InterceptorsManager interceptorsManager = new InterceptorsManager(this);
+ private final WebBeansInterceptorConfig webBeansInterceptorConfig = new WebBeansInterceptorConfig(this);
+ private final ProxyFactory proxyFactory;
+ private final OpenWebBeansConfiguration openWebBeansConfiguration;
+ private final PluginLoader pluginLoader = new PluginLoader();
+ private final SerializableBeanVault serializableBeanVault = new SerializableBeanVault();
+ private final StereoTypeManager stereoTypeManager = new StereoTypeManager();
+ private final AnnotationManager annotationManager = new AnnotationManager(this);
+ private final ResolutionUtil resolutionUtil = new ResolutionUtil(this);
+ private final InjectionPointFactory injectionPointFactory = new InjectionPointFactory(this);
+ private final InterceptorUtil interceptorUtil = new InterceptorUtil(this);
+ private final DefinitionUtil definitionUtil = new DefinitionUtil(this);
+ private final WebBeansAnnotatedTypeUtil annotatedTypeUtil = new WebBeansAnnotatedTypeUtil(this);
+ private final ManagedBeanConfigurator managedBeanConfigurator = new ManagedBeanConfigurator(this);
+ private final SecurityService securityService;
+ private final LoaderService loaderService;
+ private ScannerService scannerService;
+
+ public WebBeansContext()
+ {
+ this(null, new OpenWebBeansConfiguration());
+ }
+
+ public WebBeansContext(Map<Class<?>, Object> initialServices, Properties properties)
+ {
+ this(initialServices, new OpenWebBeansConfiguration(properties));
+ }
+
+ private WebBeansContext(Map<Class<?>, Object> initialServices, OpenWebBeansConfiguration openWebBeansConfiguration)
+ {
+ this.openWebBeansConfiguration = openWebBeansConfiguration;
+
+ //pluggable service-loader
+ if (initialServices == null || !initialServices.containsKey(LoaderService.class))
+ {
+ String implementationLoaderServiceName =
+ openWebBeansConfiguration.getProperty(LoaderService.class.getName());
+ if (implementationLoaderServiceName == null)
+ {
+ serviceMap.put(LoaderService.class, new DefaultLoaderService());
+ }
+ else
+ {
+ serviceMap.put(LoaderService.class, LoaderService.class.cast(get(implementationLoaderServiceName)));
+ }
+ }
+
+ if (initialServices != null)
+ {
+ for (Map.Entry<Class<?>, Object> entry: initialServices.entrySet())
+ {
+ if (!entry.getKey().isAssignableFrom(entry.getValue().getClass()))
+ {
+ throw new IllegalArgumentException("Initial service claiming to be of type " + entry.getKey() + " is a " + entry.getValue().getClass());
+ }
+ serviceMap.put(entry.getKey(), entry.getValue());
+ }
+ }
+ loaderService = getService(LoaderService.class);
+ securityService = getService(SecurityService.class);
+
+ proxyFactory = serviceMap.containsKey(ProxyFactory.class)
+ ? (ProxyFactory) serviceMap.get(ProxyFactory.class)
+ : new ProxyFactory();
+ OpenWebBeansClassLoaderProvider.initProxyFactoryClassLoaderProvider();
+
+ // Allow the WebBeansContext itself to be looked up
+ managerMap.put(getClass(), this);
+
+ // Add them all into the map for backwards compatibility
+ managerMap.put(AlternativesManager.class, alternativesManager);
+ managerMap.put(AnnotatedElementFactory.class, annotatedElementFactory);
+ managerMap.put(BeanManagerImpl.class, beanManagerImpl);
+ managerMap.put(ConversationManager.class, conversationManager);
+ managerMap.put(CreationalContextFactory.class, creationalContextFactory);
+ managerMap.put(DecoratorsManager.class, decoratorsManager);
+ managerMap.put(ExtensionLoader.class, extensionLoader);
+ managerMap.put(InterceptorsManager.class, interceptorsManager);
+ managerMap.put(ProxyFactory.class, proxyFactory);
+ managerMap.put(OpenWebBeansConfiguration.class, openWebBeansConfiguration);
+ managerMap.put(PluginLoader.class, pluginLoader);
+ managerMap.put(SerializableBeanVault.class, serializableBeanVault);
+ managerMap.put(StereoTypeManager.class, stereoTypeManager);
+ }
+
+ @Deprecated
+ public static WebBeansContext getInstance()
+ {
+ WebBeansContext webBeansContext = WebBeansFinder.getSingletonInstance();
+
+ return webBeansContext;
+ }
+
+ /**
+ * Method to be used when static use is truely unavoidable, such as serialization
+ *
+ * Ideally this method would never lazily create a WebBeansContext and as we don't
+ * want to do any deployment of new apps during deserialization, we want to rehydrate
+ * objects from an existing WebBeansContext which should be the active context.
+ *
+ * This method could throw a runtime exception if no instance currently exists.
+ *
+ * @return
+ */
+ public static WebBeansContext currentInstance()
+ {
+ return getInstance();
+ }
+
+ public <T> T getService(Class<T> clazz)
+ {
+ T t = clazz.cast(serviceMap.get(clazz));
+ if (t == null)
+ {
+ t = doServiceLoader(clazz);
+ registerService(clazz, t);
+ }
+ return t;
+ }
+
+ public <T> void registerService(Class<T> clazz, T t)
+ {
+ serviceMap.put(clazz, t);
+ }
+
+ private <T> T doServiceLoader(Class<T> serviceInterface)
+ {
+ String implName = getOpenWebBeansConfiguration().getProperty(serviceInterface.getName());
+
+ if (implName == null)
+ {
+ //Look for plugins
+ List<OpenWebBeansPlugin> plugins = getPluginLoader().getPlugins();
+ if(plugins != null && plugins.size() > 0)
+ {
+ for(OpenWebBeansPlugin plugin : plugins)
+ {
+ if(plugin.supportService(serviceInterface))
+ {
+ return plugin.getSupportedService(serviceInterface);
+ }
+ }
+ }
+
+ return null;
+ }
+ return serviceInterface.cast(get(implName));
+ }
+
+ public ManagedBeanConfigurator getManagedBeanConfigurator()
+ {
+ return managedBeanConfigurator;
+ }
+
+ public InterceptorUtil getInterceptorUtil()
+ {
+ return interceptorUtil;
+ }
+
+ public DefinitionUtil getDefinitionUtil()
+ {
+ return definitionUtil;
+ }
+
+ public WebBeansAnnotatedTypeUtil getAnnotatedTypeUtil()
+ {
+ return annotatedTypeUtil;
+ }
+
+ public InjectionPointFactory getInjectionPointFactory()
+ {
+ return injectionPointFactory;
+ }
+
+ public ResolutionUtil getResolutionUtil()
+ {
+ return resolutionUtil;
+ }
+
+ public WebBeansUtil getWebBeansUtil()
+ {
+ return webBeansUtil;
+ }
+
+ @Deprecated
+ public ContextFactory getContextFactory()
+ {
+ return contextFactory;
+ }
+
+ public AnnotationManager getAnnotationManager()
+ {
+ return annotationManager;
+ }
+
+ public ConversationManager getConversationManager()
+ {
+ return conversationManager;
+ }
+
+ public OpenWebBeansConfiguration getOpenWebBeansConfiguration()
+ {
+ return openWebBeansConfiguration;
+ }
+
+ public AnnotatedElementFactory getAnnotatedElementFactory()
+ {
+ return annotatedElementFactory;
+ }
+
+ public BeanManagerImpl getBeanManagerImpl()
+ {
+ return beanManagerImpl;
+ }
+
+ public SerializableBeanVault getSerializableBeanVault()
+ {
+ return serializableBeanVault;
+ }
+
+ public CreationalContextFactory getCreationalContextFactory()
+ {
+ return creationalContextFactory;
+ }
+
+ public DecoratorsManager getDecoratorsManager()
+ {
+ return decoratorsManager;
+ }
+
+ public WebBeansInterceptorConfig getWebBeansInterceptorConfig()
+ {
+ return webBeansInterceptorConfig;
+ }
+
+ public EJBInterceptorConfig getEJBInterceptorConfig()
+ {
+ return ejbInterceptorConfig;
+ }
+
+ public StereoTypeManager getStereoTypeManager()
+ {
+ return stereoTypeManager;
+ }
+
+ public AlternativesManager getAlternativesManager()
+ {
+ return alternativesManager;
+ }
+
+ public InterceptorsManager getInterceptorsManager()
+ {
+ return interceptorsManager;
+ }
+
+ public PluginLoader getPluginLoader()
+ {
+ return pluginLoader;
+ }
+
+ public ExtensionLoader getExtensionLoader()
+ {
+ return extensionLoader;
+ }
+
+ public ProxyFactory getProxyFactory()
+ {
+ return proxyFactory;
+ }
+
+
+ public ScannerService getScannerService()
+ {
+ if (scannerService == null)
+ {
+ // lazy init
+ scannerService = getService(ScannerService.class);
+ }
+ return scannerService;
+ }
+
+ public ContextsService getContextsService()
+ {
+ return getService(ContextsService.class);
+ }
+
+ public SecurityService getSecurityService()
+ {
+ return securityService;
+ }
+
+ private Object get(String singletonName)
+ {
+ //Load class
+ Class<?> clazz = ClassUtil.getClassFromName(singletonName);
+ if (clazz == null)
+ {
+ throw new WebBeansException("Class not found exception in creating instance with class : " + singletonName,
+ new ClassNotFoundException("Class with name: " + singletonName + " is not found in the system"));
+ }
+ return get(clazz);
+
+ }
+
+ public <T> T get(Class<T> clazz)
+ {
+ //util.Track.get(clazz);
+ T object = clazz.cast(managerMap.get(clazz));
+
+ /* No singleton for this application, create one */
+ if (object == null)
+ {
+ object = createInstance(clazz);
+
+ //Save it
+ managerMap.put(clazz, object);
+ }
+
+ return object;
+ }
+
+ private <T> T createInstance(Class<T> clazz)
+ {
+ try
+ {
+
+ // first try constructor that takes this object as an argument
+ try
+ {
+ Constructor<T> constructor = clazz.getConstructor(WebBeansContext.class);
+ return constructor.newInstance(this);
+ }
+ catch (NoSuchMethodException e)
+ {
+ }
+
+ // then try a no-arg constructor
+ try
+ {
+ Constructor<T> constructor = clazz.getConstructor();
+ return constructor.newInstance();
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new WebBeansException("No suitable constructor : " + clazz.getName(), e.getCause());
+ }
+ }
+ catch (InstantiationException e)
+ {
+ throw new WebBeansException("Unable to instantiate class : " + clazz.getName(), e.getCause());
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new WebBeansException("Unable to instantiate class : " + clazz.getName(), e.getCause());
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new WebBeansException("Illegal access exception in creating instance with class : " + clazz.getName(), e);
+ }
+ }
+
+ public void clear()
+ {
+ managerMap.clear();
+ }
+
+ public LoaderService getLoaderService()
+ {
+ return loaderService;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,73 @@
+/*
+ * 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.webbeans.config;
+
+import org.apache.webbeans.corespi.DefaultSingletonService;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.spi.SingletonService;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * Holds the SingletonService that tracks WebBeansContext instances
+ *
+ * @version $Rev: 1129985 $ $Date: 2011-06-01 04:04:26 +0200 (mer., 01 juin 2011) $
+ *
+ */
+public final class WebBeansFinder
+{
+ //How you use singleton provider ,
+ //As a default we use ClassLoader --> Object
+ private static SingletonService<WebBeansContext> singletonService = new DefaultSingletonService();
+
+ /** safety mechanism to allow setting a special SingletonService only once */
+ private static boolean customSingletonServiceUsed = false;
+
+ /**
+ * No instantiate.
+ */
+ private WebBeansFinder()
+ {
+ //No action
+ }
+
+ public static WebBeansContext getSingletonInstance()
+ {
+ return singletonService.get(WebBeansUtil.getCurrentClassLoader());
+ }
+
+ public static void clearInstances(Object key)
+ {
+ singletonService.clear(key);
+ }
+
+ // Third pary frameworks can set singleton instance
+ // For example, OpenEJB could provide its own provider
+ // This can be called at most once.
+ public static void setSingletonService(SingletonService<WebBeansContext> singletonSvc)
+ {
+ if (customSingletonServiceUsed && !singletonService.equals(singletonSvc))
+ {
+ throw new WebBeansConfigurationException("Already using another custom SingletonService!");
+ }
+
+ singletonService = singletonSvc;
+ customSingletonServiceUsed = true;
+ }
+
+}
\ No newline at end of file
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/AbstractBeanInheritedMetaData.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/AbstractBeanInheritedMetaData.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/AbstractBeanInheritedMetaData.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/AbstractBeanInheritedMetaData.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,118 @@
+/*
+ * 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.webbeans.config.inheritance;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.webbeans.component.AbstractOwbBean;
+
+/**
+ * Defines the bean inherited meta-datas.
+ */
+abstract class AbstractBeanInheritedMetaData<T> implements IBeanInheritedMetaData
+{
+ /**Component that inherits the meta-datas*/
+ protected AbstractOwbBean<T> component;
+
+ /**Inherited class*/
+ protected Class<?> inheritedClazz;
+
+ /**Inherited qualifiers*/
+ protected Set<Annotation> inheritedQualifiers = new HashSet<Annotation>();
+
+ /**Inherited stereotypes*/
+ protected Set<Annotation> inheritedStereoTypes = new HashSet<Annotation>();
+
+ /**Inherited interceptor bindings*/
+ protected Set<Annotation> inheritedInterceptorBindings = new HashSet<Annotation>();
+
+ /**Inherited scope type*/
+ protected Annotation inheritedScopeType = null;
+
+ /**
+ * Create a new bean inherited data.
+ *
+ * @param component webbeans component
+ * @param inheritedClazz inherited class
+ */
+ protected AbstractBeanInheritedMetaData(AbstractOwbBean<T> component, Class<?> inheritedClazz)
+ {
+ this.component = component;
+ this.inheritedClazz = inheritedClazz;
+
+ setInheritedQualifiers();
+ setInheritedInterceptorBindings();
+ setInheritedScopeType();
+ setInheritedStereoTypes();
+ }
+
+
+ public Set<Annotation> getInheritedQualifiers()
+ {
+ return inheritedQualifiers;
+ }
+
+ public Set<Annotation> getInheritedStereoTypes()
+ {
+ return inheritedStereoTypes;
+ }
+
+ public Set<Annotation> getInheritedInterceptorBindings()
+ {
+ return inheritedInterceptorBindings;
+ }
+
+ public Annotation getInheritedScopeType()
+ {
+ return inheritedScopeType;
+ }
+
+ protected AbstractOwbBean<T> getComponent()
+ {
+ return component;
+ }
+
+ protected Class<?> getInheritedClazz()
+ {
+ return inheritedClazz;
+ }
+
+
+ /**
+ * Internally set the inheritedBindingTypes
+ */
+ protected abstract void setInheritedQualifiers();
+
+ /**
+ * Internally set the inheritedStereoTypes
+ */
+ protected abstract void setInheritedStereoTypes();
+
+ /**
+ * Internally set the inheritedInterceptorBindingTypes
+ */
+ protected abstract void setInheritedInterceptorBindings();
+
+ /**
+ * Internally set the inheritedScopeType.
+ */
+ protected abstract void setInheritedScopeType();
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/BeanInheritedMetaData.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/BeanInheritedMetaData.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/BeanInheritedMetaData.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/BeanInheritedMetaData.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,145 @@
+/*
+ * 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.webbeans.config.inheritance;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Inherited;
+import java.util.Set;
+
+import javax.enterprise.context.NormalScope;
+import javax.enterprise.inject.Stereotype;
+import javax.inject.Qualifier;
+import javax.inject.Scope;
+import javax.interceptor.InterceptorBinding;
+
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.util.AnnotationUtil;
+
+public class BeanInheritedMetaData<T> extends AbstractBeanInheritedMetaData<T>
+{
+ public BeanInheritedMetaData(AbstractOwbBean<T> component)
+ {
+ super(component, component.getReturnType().getSuperclass());
+ }
+
+
+ protected void setInheritedQualifiers()
+ {
+ if(inheritedClazz != null && inheritedClazz != Object.class)
+ {
+ setInheritedTypes(getInheritedQualifiers(), inheritedClazz, Qualifier.class);
+ }
+ }
+
+ protected void setInheritedInterceptorBindings()
+ {
+ if(inheritedClazz != null && inheritedClazz != Object.class)
+ {
+ setInheritedTypes(getInheritedInterceptorBindings(), inheritedClazz, InterceptorBinding.class);
+ }
+
+ }
+
+
+ protected void setInheritedScopeType()
+ {
+ if(inheritedClazz != null && inheritedClazz != Object.class)
+ {
+ setInheritedType(inheritedClazz, NormalScope.class);
+ setInheritedType(inheritedClazz, Scope.class);
+
+ }
+ }
+
+
+ protected void setInheritedStereoTypes()
+ {
+ if(inheritedClazz != null && inheritedClazz != Object.class)
+ {
+ setInheritedTypes(getInheritedStereoTypes(), inheritedClazz, Stereotype.class);
+ }
+
+ }
+
+ private void setInheritedType(Class<?> inheritedClass, Class<? extends Annotation> annotationType)
+ {
+ Annotation[] inheritedAnnotations = null;
+
+ if(inheritedClass != null)
+ {
+ inheritedAnnotations = AnnotationUtil.getMetaAnnotations(inheritedClass.getDeclaredAnnotations(), annotationType);
+ }
+
+ if(inheritedAnnotations != null && inheritedAnnotations.length > 0)
+ {
+ if(inheritedAnnotations[0].annotationType().isAnnotationPresent(Inherited.class))
+ {
+ Annotation annotation = inheritedAnnotations[0];
+
+ if(annotationType.equals(NormalScope.class) || annotationType.equals(Scope.class))
+ {
+ inheritedScopeType = annotation;
+ }
+ }
+ }
+ else
+ {
+ if(hasSuperType(inheritedClass))
+ {
+ setInheritedType(inheritedClass.getSuperclass(), annotationType);
+ }
+ }
+
+ }
+
+ private void setInheritedTypes(Set<Annotation> types, Class<?> inheritedClass, Class<? extends Annotation> annotationType)
+ {
+ Annotation[] annotations = null;
+
+ if(inheritedClass != null)
+ {
+ annotations = AnnotationUtil.getMetaAnnotations(inheritedClass.getDeclaredAnnotations(), annotationType);
+ }
+
+ if(annotations != null)
+ {
+ for(Annotation annotation : annotations)
+ {
+ if(!types.contains(annotation))
+ {
+ if(AnnotationUtil.hasClassAnnotation(annotation.annotationType(), Inherited.class))
+ {
+ types.add(annotation);
+ }
+ }
+ }
+ }
+
+ if(hasSuperType(inheritedClass))
+ {
+ setInheritedTypes(types, inheritedClass.getSuperclass(), annotationType);
+ }
+ }
+
+
+ private boolean hasSuperType(Class<?> clazz)
+ {
+ return (clazz.getSuperclass() != Object.class) ? true : false;
+ }
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/IBeanInheritedMetaData.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/IBeanInheritedMetaData.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/IBeanInheritedMetaData.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/config/inheritance/IBeanInheritedMetaData.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.webbeans.config.inheritance;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+public interface IBeanInheritedMetaData
+{
+
+ public Set<Annotation> getInheritedQualifiers();
+
+ public Set<Annotation> getInheritedStereoTypes();
+
+ public Set<Annotation> getInheritedInterceptorBindings();
+
+ public Annotation getInheritedScopeType();
+}
Added: openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java?rev=1417182&view=auto
==============================================================================
--- openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java (added)
+++ openejb/trunk/openejb/deps/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanCacheKey.java Tue Dec 4 21:07:25 2012
@@ -0,0 +1,428 @@
+/*
+ * 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.webbeans.container;
+
+import org.apache.webbeans.util.AnnotationUtil;
+
+import javax.enterprise.util.Nonbinding;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Comparator;
+
+public final class BeanCacheKey
+{
+ private final Type type;
+ private final String path;
+ private final Annotation qualifier;
+ private final Annotation qualifiers[];
+ private final int hashCode;
+ private static final Comparator<Annotation> ANNOTATION_COMPARATOR = new AnnotationComparator();
+
+ public BeanCacheKey( Type type, String path, Annotation... qualifiers )
+ {
+ this.type = type;
+ this.path = path;
+ final int length = qualifiers != null ? qualifiers.length : 0;
+ if (length == 0)
+ {
+ this.qualifier = null;
+ this.qualifiers = null;
+ }
+ else if (length == 1)
+ {
+ this.qualifier = qualifiers[0];
+ this.qualifiers = null;
+ }
+ else
+ {
+ this.qualifier = null;
+ // to save array creations, we only create an array, if we have more than one annotation
+ this.qualifiers = new Annotation[length];
+ System.arraycopy(qualifiers, 0, this.qualifiers, 0, length);
+ Arrays.sort(this.qualifiers, ANNOTATION_COMPARATOR);
+ }
+
+ // this class is directly used in ConcurrentHashMap.get() so simply init the hasCode here
+ hashCode = computeHashCode();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ BeanCacheKey cacheKey = (BeanCacheKey) o;
+
+ if (!type.equals(cacheKey.type))
+ {
+ return false;
+ }
+ if (qualifier != null ? !qualifierEquals(qualifier, cacheKey.qualifier) : cacheKey.qualifier != null)
+ {
+ return false;
+ }
+ if (!qualifierArrayEquals(qualifiers, cacheKey.qualifiers))
+ {
+ return false;
+ }
+ if (path != null ? !path.equals(cacheKey.path) : cacheKey.path != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean qualifierArrayEquals(Annotation[] qualifiers1, Annotation[] qualifiers2)
+ {
+ if (qualifiers1 == qualifiers2)
+ {
+ return true;
+ }
+ else if (qualifiers1 == null || qualifiers2 == null)
+ {
+ return false;
+ }
+ if (qualifiers1.length != qualifiers2.length)
+ {
+ return false;
+ }
+ for (int i = 0; i < qualifiers1.length; i++)
+ {
+ Annotation a1 = qualifiers1[i];
+ Annotation a2 = qualifiers2[i];
+ if (a1 == null ? a2 != null : !qualifierEquals(a1, a2))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return hashCode;
+ }
+
+ /**
+ * We need this method as some weird JVMs return 0 as hashCode for classes.
+ * In that case we return the hashCode of the String.
+ */
+ private int getTypeHashCode(Type type)
+ {
+ int typeHash = type.hashCode();
+ if (typeHash == 0 && type instanceof Class)
+ {
+ return ((Class)type).getName().hashCode();
+ // the type.toString() is always the same: "java.lang.Class@<hexid>"
+ // was: return type.toString().hashCode();
+ }
+
+ return typeHash;
+ }
+
+ /**
+ * Compute the HashCode. This should be called only in the constructor.
+ */
+ private int computeHashCode()
+ {
+ int computedHashCode = 31 * getTypeHashCode(type) + (path != null ? path.hashCode() : 0);
+ if (qualifier != null)
+ {
+ computedHashCode = 31 * computedHashCode + getQualifierHashCode(qualifier);
+ }
+ if (qualifiers != null)
+ {
+ for (int i = 0; i < qualifiers.length; i++)
+ {
+ computedHashCode = 31 * computedHashCode + getQualifierHashCode(qualifiers[i]);
+ }
+ }
+ return computedHashCode;
+ }
+
+ /**
+ * Calculate the hashCode() of a qualifier, which ignores {@link Nonbinding} members.
+ */
+ private int getQualifierHashCode(Annotation a)
+ {
+ Class annotationClass = getAnnotationClass(a.getClass());
+
+ if (annotationClass == null)
+ {
+ return getTypeHashCode(a.getClass());
+ }
+
+ // the hashCode of an Annotation is calculated solely via the hashCodes
+ // of it's members. If there are no members, it is 0.
+ // thus we first need to get the annotation-class hashCode
+ int hashCode = getTypeHashCode(annotationClass);
+
+ // and now add the hashCode of all it's Nonbinding members
+ // the following algorithm is defined by the Annotation class definition
+ // see the JavaDoc for Annotation!
+ // we only change it so far that we skip evaluating @Nonbinding members
+ final Method[] members = annotationClass.getDeclaredMethods();
+
+ for (Method member : members)
+ {
+ if (member.isAnnotationPresent(Nonbinding.class))
+ {
+ // ignore the non binding
+ continue;
+ }
+
+ // Member value
+ final Object object = callMethod(a, member);
+ final int value;
+ if(object.getClass().isArray())
+ {
+ Class<?> type = object.getClass().getComponentType();
+ if(type.isPrimitive())
+ {
+ if(Long.TYPE == type)
+ {
+ value = Arrays.hashCode((long[]) object);
+ }
+ else if(Integer.TYPE == type)
+ {
+ value = Arrays.hashCode((int[])object);
+ }
+ else if(Short.TYPE == type)
+ {
+ value = Arrays.hashCode((short[])object);
+ }
+ else if(Double.TYPE == type)
+ {
+ value = Arrays.hashCode((double[])object);
+ }
+ else if(Float.TYPE == type)
+ {
+ value = Arrays.hashCode((float[])object);
+ }
+ else if(Boolean.TYPE == type)
+ {
+ value = Arrays.hashCode((boolean[])object);
+ }
+ else if(Byte.TYPE == type)
+ {
+ value = Arrays.hashCode((byte[])object);
+ }
+ else if(Character.TYPE == type)
+ {
+ value = Arrays.hashCode((char[])object);
+ }
+ else
+ {
+ value = 0;
+ }
+ }
+ else
+ {
+ value = Arrays.hashCode((Object[])object);
+ }
+ }
+ else
+ {
+ value = object.hashCode();
+ }
+
+ hashCode = 29 * hashCode + value;
+ hashCode = 29 * hashCode + member.getName().hashCode();
+ }
+
+ return hashCode;
+ }
+
+ /**
+ * Implements the equals() method for qualifiers, which ignores {@link Nonbinding} members.
+ */
+ private boolean qualifierEquals(Annotation qualifier1, Annotation qualifier2)
+ {
+ return ANNOTATION_COMPARATOR.compare(qualifier1, qualifier2) == 0;
+ }
+
+ private static Class getAnnotationClass(Class a)
+ {
+ for (Class i : a.getInterfaces())
+ {
+ if (i.isAnnotation())
+ {
+ return i;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Helper method for calculating the hashCode of an annotation.
+ */
+ private static Object callMethod(Object instance, Method method)
+ {
+ try
+ {
+ if (!method.isAccessible())
+ {
+ method.setAccessible(true);
+ }
+
+ return method.invoke(instance, AnnotationUtil.EMPTY_OBJECT_ARRAY);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Exception in method call : " + method.getName(), e);
+ }
+
+ }
+
+ /**
+ * for debugging ...
+ */
+ @Override
+ public String toString()
+ {
+ return "BeanCacheKey{" + "type=" + type + ", path='" + path + '\''
+ + ", qualifiers="
+ + (qualifiers == null ? qualifier : Arrays.asList(qualifiers)) + ", hashCode=" + hashCode + '}';
+ }
+
+ /**
+ * to keep the annotations ordered.
+ */
+ private static class AnnotationComparator implements Comparator<Annotation>
+ {
+
+ // Notice: Sorting is a bit costly, but the use of this code is very rar.
+ public int compare(Annotation annotation1, Annotation annotation2)
+ {
+ final Class<? extends Annotation> type1 = annotation1.annotationType();
+ final Class<? extends Annotation> type2 = annotation2.annotationType();
+ final int temp = type1.getName().compareTo(type2.getName());
+ if (temp != 0)
+ {
+ return temp;
+ }
+ final Method[] member1 = type1.getDeclaredMethods();
+ final Method[] member2 = type2.getDeclaredMethods();
+
+ // TBD: the order of the list of members seems to be deterministic
+
+ int i = 0;
+ int j = 0;
+ final int length1 = member1.length;
+ final int length2 = member2.length;
+
+ // find next nonbinding
+ for (;; i++, j++)
+ {
+ while (i < length1 && member1[i].isAnnotationPresent(Nonbinding.class))
+ {
+ i++;
+ }
+ while (j < length2 && member2[j].isAnnotationPresent(Nonbinding.class))
+ {
+ j++;
+ }
+ if (i >= length1 && j >= length2)
+ { // both ended
+ return 0;
+ }
+ else if (i >= length1)
+ { // #1 ended
+ return 1;
+ }
+ else if (j >= length2)
+ { // #2 ended
+ return -1;
+ }
+ else
+ { // not ended
+ int c = member1[i].getName().compareTo(member2[j].getName());
+ if (c != 0)
+ {
+ return c;
+ }
+ final Object value1 = callMethod(annotation1, member1[i]);
+ final Object value2 = callMethod(annotation2, member2[j]);
+ assert value1.getClass().equals(value2.getClass());
+
+ if (value1 instanceof Comparable)
+ {
+ c = ((Comparable)value1).compareTo(value2);
+ if (c != 0)
+ {
+ return c;
+ }
+ }
+ else if (value1.getClass().isArray())
+ {
+ c = value1.getClass().getComponentType().getName()
+ .compareTo(value2.getClass().getComponentType().getName());
+ if (c != 0)
+ {
+ return c;
+ }
+
+ final int length = Array.getLength(value1);
+ c = length - Array.getLength(value2);
+ if (c != 0)
+ {
+ return c;
+ }
+ for (int k = 0; k < length; k++)
+ {
+ c = ((Comparable)Array.get(value1, k)).compareTo(Array.get(value2, k));
+ if (c != 0)
+ {
+ return c;
+ }
+ }
+
+ }
+ else if (value1 instanceof Class)
+ {
+
+ c = ((Class)value1).getName().compareTo(((Class) value2).getName());
+ if (c != 0)
+ {
+ return c;
+ }
+ }
+ else
+ {
+ // valid types for members are only Comparable, Arrays, or Class
+ assert false;
+ }
+ }
+ }
+ }
+ }
+}