You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2008/11/22 19:09:48 UTC
svn commit: r719890 [5/14] - in /incubator/openwebbeans/trunk/webbeans-impl:
./ src/ src/main/ src/main/java/ src/main/java/META-INF/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/webbeans/
src/main/java/org/apache/webbeans/anno...
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ContextRemoveException.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ContextRemoveException.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ContextRemoveException.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ContextRemoveException.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.exception;
+
+/**
+ * Throws when the component is not found in the current context
+ * while trrying to remove.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class ContextRemoveException extends WebBeansException
+{
+ private static final long serialVersionUID = 532093075405474889L;
+
+ public ContextRemoveException(String message)
+ {
+ super(message);
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ContextRemoveException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ResolutionByNameException.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ResolutionByNameException.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ResolutionByNameException.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ResolutionByNameException.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.exception;
+
+/**
+ * Throws when exceptional situation occurs while resolving components
+ * in the web beans container by name.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class ResolutionByNameException extends WebBeansException
+{
+ private static final long serialVersionUID = 532093075405474889L;
+
+ public ResolutionByNameException(String message)
+ {
+ super(message);
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/ResolutionByNameException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansConfigurationException.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansConfigurationException.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansConfigurationException.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansConfigurationException.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,49 @@
+/*
+ * 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.exception;
+
+import javax.webbeans.DefinitionException;
+
+/**
+ * Exception that is thrown by the web beans container at the
+ * intialization time.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class WebBeansConfigurationException extends DefinitionException
+{
+
+ private static final long serialVersionUID = 1863095663133791175L;
+
+
+ public WebBeansConfigurationException()
+ {
+ super();
+ }
+
+ public WebBeansConfigurationException(String message)
+ {
+ super(message);
+ }
+
+ public WebBeansConfigurationException(Throwable e)
+ {
+ super(e);
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansConfigurationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansCreationException.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansCreationException.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansCreationException.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansCreationException.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.exception;
+
+/**
+ * Exception that is thrown by the web beans container at the
+ * deployment time.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class WebBeansCreationException extends WebBeansException
+{
+
+ private static final long serialVersionUID = 1863095663133791175L;
+
+ public WebBeansCreationException(Throwable e)
+ {
+ super(e);
+ }
+
+ public WebBeansCreationException(String message)
+ {
+ super(message);
+ }
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansCreationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansDeploymentException.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansDeploymentException.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansDeploymentException.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansDeploymentException.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.exception;
+
+/**
+ * Exception that is thrown by the web beans container at the
+ * deployment time.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class WebBeansDeploymentException extends WebBeansException
+{
+
+ private static final long serialVersionUID = 1863095663133791175L;
+
+ public WebBeansDeploymentException(Throwable e)
+ {
+ super(e);
+ }
+
+ public WebBeansDeploymentException(String message)
+ {
+ super(message);
+ }
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansDeploymentException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansException.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansException.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansException.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansException.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.exception;
+
+/**
+ * @author Administrator
+ *
+ */
+public class WebBeansException extends RuntimeException
+{
+
+ private static final long serialVersionUID = -3721839220664165557L;
+ private Throwable cause;
+
+ public WebBeansException(String message)
+ {
+ super(message);
+ }
+
+ public WebBeansException(Throwable e)
+ {
+ super(e);
+ this.cause = e;
+ }
+
+ public WebBeansException(String message, Throwable e)
+ {
+ super(message, e);
+ this.cause = e;
+ }
+
+ public Throwable getCause()
+ {
+ return cause;
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/exception/WebBeansException.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,189 @@
+/*
+ * 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.inject;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.webbeans.Dependent;
+import javax.webbeans.New;
+import javax.webbeans.Observable;
+import javax.webbeans.manager.Bean;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.container.ManagerImpl;
+import org.apache.webbeans.container.ResolutionUtil;
+import org.apache.webbeans.context.DependentContext;
+import org.apache.webbeans.context.WebBeansContext;
+import org.apache.webbeans.event.EventImpl;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * Abstract implementation of the {@link Injectable} contract.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+@SuppressWarnings("unchecked")
+public abstract class AbstractInjectable implements Injectable
+{
+ /** Owner component */
+ private AbstractComponent<?> injectionOwnerComponent;
+
+ protected AbstractInjectable(AbstractComponent<?> component)
+ {
+ this.injectionOwnerComponent = component;
+ }
+
+ /**
+ * Gets the injected component instance in its scoped context.
+ *
+ * @param type
+ * type of the injection point, maybe parametrized type
+ * @param annotations
+ * binding annotations at the injection point
+ * @return current component instance in the resolved component scope
+ */
+ public <T> Object inject(Class<T> type, Type[] args, Annotation... annotations)
+ {
+ DependentContext context = (DependentContext)ManagerImpl.getManager().getContext(Dependent.class);
+ boolean isSetOnThis = false;
+ try
+ {
+ if(!context.isActive())
+ {
+ context.setActive(true);
+ isSetOnThis = true;
+ }
+
+ if (isNewBinding(annotations))
+ {
+ return injectForNew(type, annotations);
+ }
+
+ if(isObservableBinding(annotations))
+ {
+ return injectForObservable(args, annotations);
+ }
+
+ Set<Bean<T>> componentSet = InjectionResolver.getInstance().implResolveByType(type, args, annotations);
+ ResolutionUtil.checkResolvedBeans(componentSet, type);
+
+ AbstractComponent<?> component = (AbstractComponent<?>)componentSet.iterator().next();
+
+ if (component.getScopeType().equals(Dependent.class))
+ {
+ return injectForDependent(component);
+ } else
+ {
+ return injectForComponent(component);
+ }
+
+ }finally
+ {
+ if(isSetOnThis)
+ {
+ context.setActive(false);
+ }
+ }
+
+ }
+
+ private boolean isNewBinding(Annotation...annotations)
+ {
+ if (annotations.length == 1)
+ {
+ if (annotations[0].annotationType().equals(New.class))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isObservableBinding(Annotation...annotations)
+ {
+ for(Annotation ann : annotations)
+ {
+ if(ann.annotationType().equals(Observable.class))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ private Object injectForNew(Type type, Annotation... annotations)
+ {
+ Class<?> clazz = null;
+
+ if (type instanceof ParameterizedType)
+ {
+ clazz = (Class<?>) ((ParameterizedType) type).getRawType();
+ } else if (type instanceof Class)
+ {
+ clazz = (Class<?>) type;
+ }
+
+ return injectForDependent(WebBeansUtil.createNewComponent(clazz));
+ }
+
+
+ private <T> Object injectForObservable(Type[] args, Annotation... annotations)
+ {
+ Class<?> eventType = (Class<?>) args[0];
+
+ return injectForDependent(WebBeansUtil.createObservableImplicitComponent(EventImpl.class, eventType, annotations));
+ }
+
+ private Object injectForDependent(AbstractComponent<?> component)
+ {
+ Object object = null;
+ object = this.injectionOwnerComponent.getDependent(component);
+
+ return object;
+ }
+
+ private Object injectForComponent(AbstractComponent<?> component)
+ {
+ WebBeansContext context = null;
+ Object object = null;
+
+ context = (WebBeansContext) ManagerImpl.getManager().getContext(component.getScopeType());
+ object = context.get(component, true);
+
+ return object;
+
+ }
+
+ /**
+ * Gets the component.
+ *
+ * @return the component
+ */
+ public AbstractComponent<?> getInjectionOwnerComponent()
+ {
+ return injectionOwnerComponent;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.inject;
+
+
+/**
+ * Marker interface for all injectable elements of the web
+ * beans components.
+ *
+ * <p>
+ * There are several injectable elements in the web beans container;
+ *
+ * <ul>
+ * <li>Constructor,</li>
+ * <li>Methods,</li>
+ * <li>Fields</li>
+ * </ul>
+ * </p>
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ *
+ * @see InjectableConstructor
+ * @see InjectableField
+ * @see InjectableMethods
+ * @see AbstractInjectable
+ */
+public interface Injectable
+{
+ /**
+ * Responsible for injecting the owner required injected
+ * component instances. Maybe returning an component instance,
+ * for example, {@link InjectableConstructor#doInjection()} returns
+ * a new web bean component instance.
+ *
+ * <p>
+ * Each injetable elements parameters, web beans component instances, are resolved
+ * using the resolution type algorithm.
+ * </p>
+ *
+ * @return if the return instance if available
+ */
+ public Object doInjection();
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/Injectable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,129 @@
+/*
+ * 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.inject;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.webbeans.Dependent;
+
+import org.apache.webbeans.annotation.CurrentLiteral;
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.component.ComponentImpl;
+import org.apache.webbeans.ejb.EJBUtil;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
+import org.apache.webbeans.util.AnnotationUtil;
+
+/**
+ * Injects the parameters of the {@link ComponentImpl} constructor and returns
+ * the created instance.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ * @see AbstractInjectable
+ */
+@SuppressWarnings("unchecked")
+public class InjectableConstructor<T> extends AbstractInjectable
+{
+ /** Injectable constructor instance */
+ private Constructor<T> con;
+
+ /**
+ * Sets the constructor.
+ *
+ * @param cons
+ * injectable constructor
+ */
+ public InjectableConstructor(Constructor<T> cons, AbstractComponent<?> owner)
+ {
+ super(owner);
+ this.con = cons;
+ }
+
+ /**
+ * Creates the instance from the constructor. Each constructor parameter
+ * instance is resolved using the resolution algorithm.
+ */
+ public T doInjection()
+ {
+ T instance = null;
+
+ Type[] types = con.getGenericParameterTypes();
+ Annotation[][] annots = con.getParameterAnnotations();
+ List<Object> list = new ArrayList<Object>();
+ if (types.length > 0)
+ {
+ int i = 0;
+ for (Type type : types)
+ {
+ Annotation[] annot = annots[i];
+ if (annot.length == 0)
+ {
+ annot = new Annotation[1];
+ annot[0] = new CurrentLiteral();
+ }
+
+ Type[] args = new Type[0];
+ Class<?> clazz = null;
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType pt = (ParameterizedType) type;
+ args = new Type[1];
+ args = pt.getActualTypeArguments();
+
+ clazz = (Class<?>) pt.getRawType();
+ } else
+ {
+ clazz = (Class<?>) type;
+ }
+
+ list.add(inject(clazz, args, AnnotationUtil.getBindingAnnotations(annot)));
+
+ i++;
+
+ }
+
+ }
+
+ try
+ {
+ if (!EJBUtil.isEJBSessionClass(con.getDeclaringClass()))
+ {
+ if(getInjectionOwnerComponent().getScopeType().equals(Dependent.class))
+ {
+ instance = con.newInstance(list.toArray());
+ }
+ else
+ {
+ instance = (T) JavassistProxyFactory.createNewProxyInstance(con.getDeclaringClass(), con.getParameterTypes(), list.toArray(), getInjectionOwnerComponent());
+ }
+ }
+
+ } catch (Throwable e)
+ {
+ e.printStackTrace();
+ throw new WebBeansException(e);
+ }
+
+ return instance;
+ }
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableConstructor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.inject;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import org.apache.webbeans.annotation.CurrentLiteral;
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.ClassUtil;
+
+/**
+ * Field type injection.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class InjectableField extends AbstractInjectable
+{
+ private Field field;
+ private Object instance;
+
+ public InjectableField(Field field, Object instance, AbstractComponent<?> owner)
+ {
+ super(owner);
+ this.field = field;
+ this.instance = instance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.webbeans.inject.Injectable#doInjection()
+ */
+ public Object doInjection()
+ {
+ Type type = field.getGenericType();
+
+ Annotation[] annots = field.getAnnotations();
+
+ annots = AnnotationUtil.getBindingAnnotations(annots);
+
+ try
+ {
+ if (annots.length == 0)
+ {
+ annots = new Annotation[1];
+ annots[0] = new CurrentLiteral();
+ }
+
+ if (!ClassUtil.isPublic(field.getModifiers()))
+ {
+ field.setAccessible(true);
+ }
+
+ Type[] args = new Type[0];
+ Class<?> clazz = null;
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType pt = (ParameterizedType) type;
+ args = new Type[1];
+ args = pt.getActualTypeArguments();
+
+ clazz = (Class<?>) pt.getRawType();
+ } else
+ {
+ clazz = (Class<?>) type;
+ }
+
+ field.set(instance, inject(clazz, args, annots));
+
+ } catch (Throwable e)
+ {
+ // no-op
+ e.printStackTrace();
+
+ }
+
+ return null;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableField.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,116 @@
+/*
+ * 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.inject;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.webbeans.annotation.CurrentLiteral;
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.ClassUtil;
+
+@SuppressWarnings("unchecked")
+public class InjectableMethods<T> extends AbstractInjectable
+{
+ /** Injectable method */
+ private Method m;
+
+ /** Component instance that owns the method */
+ private Object instance;
+
+ /**
+ * Constructs new instance.
+ *
+ * @param m
+ * injectable method
+ * @param instance
+ * component instance
+ */
+ public InjectableMethods(Method m, Object instance, AbstractComponent<?> owner)
+ {
+ super(owner);
+ this.m = m;
+ this.instance = instance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.webbeans.inject.Injectable#doInjection()
+ */
+ public T doInjection()
+ {
+ Type[] types = m.getGenericParameterTypes();
+ Annotation[][] annots = m.getParameterAnnotations();
+ List<Object> list = new ArrayList<Object>();
+ if (types.length > 0)
+ {
+ int i = 0;
+ for (Type type : types)
+ {
+ Annotation[] annot = annots[i];
+ if (annot.length == 0)
+ {
+ annot = new Annotation[1];
+ annot[0] = new CurrentLiteral();
+ }
+
+ Type[] args = new Type[0];
+ Class<?> clazz = null;
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType pt = (ParameterizedType) type;
+ args = new Type[1];
+ args = pt.getActualTypeArguments();
+
+ clazz = (Class<?>) pt.getRawType();
+ } else
+ {
+ clazz = (Class<?>) type;
+ }
+
+ list.add(inject(clazz, args, AnnotationUtil.getBindingAnnotations(annot)));
+
+ i++;
+
+ }
+
+ }
+
+ try
+ {
+ if (!ClassUtil.isPublic(m.getModifiers()))
+ {
+ m.setAccessible(true);
+ }
+
+ return (T) m.invoke(instance, list.toArray());
+
+ } catch (Throwable e)
+ {
+ // no-op
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorComparator.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorComparator.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorComparator.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorComparator.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,49 @@
+/*
+ * 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.intercept;
+
+import java.util.Comparator;
+
+import javax.webbeans.manager.Interceptor;
+
+import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+
+public class InterceptorComparator implements Comparator<Interceptor>
+{
+
+ public int compare(Interceptor o1, Interceptor o2)
+ {
+ WebBeansInterceptor src = (WebBeansInterceptor) o1;
+ WebBeansInterceptor target = (WebBeansInterceptor)o2;
+
+
+ if(o1.equals(o2))
+ {
+ return 0;
+ }
+ else
+ {
+ Class<?> o1Clazz = src.getClazz();
+ Class<?> o2Clazz = target.getClazz();
+
+ return InterceptorsManager.getInstance().compare(o1Clazz, o2Clazz);
+
+ }
+ }
+
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorComparator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,143 @@
+/*
+ * 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.intercept;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.webbeans.Interceptor;
+import javax.webbeans.InterceptorBindingType;
+
+/**
+ * Web Beans general interceptor API contract. There are two types of interceptor
+ * definition in the Web Beans Container. These are;
+ *
+ * <p>
+ * <ul>
+ * <li>EJB related interceptors with {@link Interceptors} annotation</li>
+ * <li>WebBeans specific interceptor definition with using {@link InterceptorBindingType} and {@link Interceptor} </li>
+ * </ul>
+ * </p>
+ *
+ * <p>
+ * If the web beans is an EJB component, EJB container is responsible for calling
+ * the EJB related interceptors, otherwise Web Beans container takes the responsibility.
+ * In the both cases, Web Beans Container is responsible for calling web beans related inteceptors.
+ * </p>
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public interface InterceptorData
+{
+ /**
+ * Gets the list of {@link PostConstruct} annotated methods.
+ *
+ * @return the list of post-construct methods
+ */
+ public Method getPostConstruct();
+
+ /**
+ * Gets the list of {@link PreDestroy} annotated methods.
+ *
+ * @return the list of pre-destroy methods
+ */
+ public Method getPreDestroy();
+
+ /**
+ * Gets the list of {@link AroundInvoke} annotated methods.
+ *
+ * @return the list of around invoke methods
+ */
+ public Method getAroundInvoke();
+
+
+ /**
+ * Sets the interceptor method.
+ *
+ * @param m interceptor method
+ * @param annotation annotation class
+ */
+ public void setInterceptor(Method m, Class<? extends Annotation> annotation);
+
+ /**
+ * Sets the source of the interceptor.
+ *
+ * @param definedInInterceptorClass defined in interceptor class
+ */
+ public void setDefinedInInterceptorClass(boolean definedInInterceptorClass);
+
+ /**
+ * Gets the interceptor instance.
+ *
+ * @return the interceptor instance
+ */
+ public Object getInterceptorInstance();
+
+ /**
+ * Sets the interceptor instance.
+ *
+ * @param instance interceptor instance
+ */
+ public void setInterceptorInstance(Object instance);
+
+ /**
+ * Checks the interceptor is defined at the method level.
+ *
+ * @return inteceptor defined in method
+ */
+ public boolean isDefinedInMethod();
+
+ /**
+ * Sets true if interceptor is defined at the method, false ow.
+ *
+ * @param definedInMethod defined in method flag
+ */
+ public void setDefinedInMethod(boolean definedInMethod);
+
+ /**
+ * Gets the interceptor annotated method.
+ *
+ * @return the method
+ */
+ public Method getAnnotatedMethod();
+
+ /**
+ * Sets the interceptor annotated method.
+ *
+ * @param annotatedMethod interceptor annotated method.
+ */
+ public void setAnnotatedMethod(Method annotatedMethod);
+
+ /**
+ * Checks whether the interceptor is defined at the interceptor class.
+ *
+ * @return true if inteceptor is defined at the interceptor class
+ */
+ public boolean isDefinedInInterceptorClass();
+
+ /**
+ * Checks whether interceptor is configured with webbeans interceptor definition or not.
+ *
+ * @return true if interceptor is configured with webbeans interceptor definition
+ */
+ public boolean isDefinedWithWebBeansInterceptor();
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,221 @@
+/*
+ * 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.intercept;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+
+/**
+ * Abstract implementation of the {@link InterceptorData} api
+ * contract.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class InterceptorDataImpl implements InterceptorData
+{
+ /**Around invokes method*/
+ private Method aroundInvoke = null;
+
+ /**Post construct methods*/
+ private Method postConstruct = null;
+
+ /**Predestroy Method*/
+ private Method preDestroy = null;
+
+ /**Instance of the method*/
+ private Object interceptorInstance;
+
+ /**Defined in the interceptor or bean*/
+ private boolean definedInInterceptorClass;
+
+ /**Whether the interceptor class is defined in the method*/
+ private boolean definedInMethod;
+
+ /**If defined in method true, then this method holds the interceptor annotated method*/
+ private Method annotatedMethod;
+
+ /**Defined with webbeans specific interceptor*/
+ private boolean isDefinedWithWebBeansInterceptor;
+
+
+ public InterceptorDataImpl(boolean isDefinedWithWebBeansInterceptor)
+ {
+ this.isDefinedWithWebBeansInterceptor = isDefinedWithWebBeansInterceptor;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#setInterceptor(java.lang.reflect.Method, java.lang.Class)
+ */
+ public void setInterceptor(Method m, Class<? extends Annotation> annotation)
+ {
+ if(annotation.equals(AroundInvoke.class))
+ {
+ setAroundInvoke(m);
+ }
+ else if(annotation.equals(PostConstruct.class))
+ {
+ setPostConstruct(m);
+ }
+ else if(annotation.equals(PreDestroy.class))
+ {
+ setPreDestroy(m);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#addAroundInvoke(java.lang.reflect.Method)
+ */
+ protected void setAroundInvoke(Method m)
+ {
+ this.aroundInvoke = m;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#addPostConstruct(java.lang.reflect.Method)
+ */
+ protected void setPostConstruct(Method m)
+ {
+ this.postConstruct = m;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#addPreDestroy(java.lang.reflect.Method)
+ */
+ protected void setPreDestroy(Method m)
+ {
+ this.preDestroy = m;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#getPostConstruct()
+ */
+ public Method getPostConstruct()
+ {
+ return this.postConstruct;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#getPreDestroy()
+ */
+ public Method getPreDestroy()
+ {
+ return this.preDestroy;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#getAroundInvoke()
+ */
+ public Method getAroundInvoke()
+ {
+ return this.aroundInvoke;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#getInterceptorInstance()
+ */
+ public Object getInterceptorInstance()
+ {
+ return interceptorInstance;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#setInterceptorInstance(java.lang.Object)
+ */
+ public void setInterceptorInstance(Object interceptorInstance)
+ {
+ this.interceptorInstance = interceptorInstance;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#isDefinedInInterceptorClass()
+ */
+ public boolean isDefinedInInterceptorClass()
+ {
+ return definedInInterceptorClass;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#setDefinedInInterceptorClass(boolean)
+ */
+ public void setDefinedInInterceptorClass(boolean definedInInterceptorClass)
+ {
+ this.definedInInterceptorClass = definedInInterceptorClass;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#isDefinedInMethod()
+ */
+ public boolean isDefinedInMethod()
+ {
+ return definedInMethod;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#setDefinedInMethod(boolean)
+ */
+ public void setDefinedInMethod(boolean definedInMethod)
+ {
+ this.definedInMethod = definedInMethod;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#getAnnotatedMethod()
+ */
+ public Method getAnnotatedMethod()
+ {
+ return annotatedMethod;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#setAnnotatedMethod(java.lang.reflect.Method)
+ */
+ public void setAnnotatedMethod(Method annotatedMethod)
+ {
+ this.annotatedMethod = annotatedMethod;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.webbeans.intercept.InterceptorData#isDefinedWithWebBeansInterceptor()
+ */
+ public boolean isDefinedWithWebBeansInterceptor()
+ {
+ return isDefinedWithWebBeansInterceptor;
+ }
+
+
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,257 @@
+/*
+ * 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.intercept;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.Interceptors;
+import javax.webbeans.InterceptorBindingType;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+import javassist.util.proxy.MethodHandler;
+
+public class InterceptorHandler implements MethodHandler
+{
+ private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorHandler.class);
+
+ private AbstractComponent<?> component = null;
+
+ private Method calledMethod = null;
+
+ private boolean isSameDecMethod = false;
+
+ public InterceptorHandler(AbstractComponent<?> component)
+ {
+ this.component = component;
+ }
+
+ public Object invoke(Object instance, Method method, Method proceed, Object[] arguments) throws Throwable
+ {
+ if(!ClassUtil.isObjectMethod(method.getName()) && InterceptorUtil.isWebBeansBusinessMethod(method))
+ {
+ if(this.calledMethod == null)
+ {
+ this.calledMethod = method;
+ }
+ else if(this.calledMethod.equals(method))
+ {
+ this.isSameDecMethod = true;
+ }
+ else
+ {
+ this.calledMethod = method;
+ this.isSameDecMethod = false;
+ }
+
+
+ //Run around invoke chain
+ List<InterceptorData> stack = component.getInterceptorStack();
+
+ filterEJBInterceptorStackList(stack, method);
+ filterWebBeansInterceptorStackList(stack, method);
+
+ if(WebBeansUtil.isContainsInterceptorMethod(stack, InterceptorType.AROUND_INVOKE))
+ {
+ callAroundInvokes(instance, proceed, arguments,WebBeansUtil.getInterceptorMethods(stack, InterceptorType.AROUND_INVOKE));
+ }
+
+ List<Object> decorators = component.getDecoratorStack();
+ callDecorators(decorators, method, arguments);
+
+ }
+
+ return proceed.invoke(instance, arguments);
+ }
+
+ private void callDecorators(List<Object> decorators, Method method, Object[] arguments)
+ {
+
+ Iterator<Object> itDec = decorators.iterator();
+ while(itDec.hasNext())
+ {
+ Object decorator = itDec.next();
+ try
+ {
+ Method decMethod = decorator.getClass().getMethod(method.getName(), method.getParameterTypes());
+
+ if(decMethod != null)
+ {
+ if(!this.isSameDecMethod)
+ {
+ if(!decMethod.isAccessible())
+ {
+ decMethod.setAccessible(true);
+ }
+
+ decMethod.invoke(decorator, arguments);
+ }
+ }
+
+ } catch (SecurityException e)
+ {
+ logger.error("Method security access violation for method " + method.getName() + " for decorator class : " + decorator.getClass().getName());
+ throw new WebBeansException(e);
+
+ } catch (NoSuchMethodException e)
+ {
+ continue;
+ }
+ catch(InvocationTargetException e)
+ {
+ logger.error("Exception in calling method " + method.getName() + " for decorator class : " + decorator.getClass().getName() + ". Look log for target checked exception.", e.getTargetException());
+ throw new WebBeansException(e);
+ }
+ catch(IllegalAccessException e)
+ {
+ logger.error("Method illegal access for method " + method.getName() + " for decorator class : " + decorator.getClass().getName());
+ throw new WebBeansException(e);
+ }
+
+ }
+
+ }
+
+ private <T> void callAroundInvokes(Object instance, Method proceed, Object[] arguments, List<InterceptorData> stack) throws Exception
+ {
+ InvocationContextImpl impl = new InvocationContextImpl(instance,proceed,arguments,stack,InterceptorType.AROUND_INVOKE);
+
+ impl.proceed();
+
+ }
+
+ private void filterEJBInterceptorStackList(List<InterceptorData> stack, Method method)
+ {
+ boolean isMethodAnnotatedWithInterceptorClass = false;
+ boolean isMethodAnnotatedWithExcludeInterceptorClass = false;
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, Interceptors.class))
+ isMethodAnnotatedWithInterceptorClass = true;
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, ExcludeClassInterceptors.class))
+ isMethodAnnotatedWithExcludeInterceptorClass = true;
+
+
+ Iterator<InterceptorData> it = stack.iterator();
+ while(it.hasNext())
+ {
+ InterceptorData data = it.next();
+ if(isMethodAnnotatedWithInterceptorClass)
+ {
+ if(isMethodAnnotatedWithExcludeInterceptorClass)
+ {
+ if(!data.isDefinedInMethod() && data.isDefinedInInterceptorClass())
+ {
+ it.remove();
+ }
+ else if(data.isDefinedInMethod())
+ {
+ if(!data.getAnnotatedMethod().equals(method))
+ {
+ it.remove();
+ }
+ }
+ }
+ else
+ {
+ if(data.isDefinedInMethod())
+ {
+ if(!data.getAnnotatedMethod().equals(method))
+ {
+ it.remove();
+ }
+ }
+ }
+ }
+ else
+ {
+ if(data.isDefinedInMethod())
+ {
+ it.remove();
+ }
+ }
+
+ }
+
+ }
+
+ private void filterWebBeansInterceptorStackList(List<InterceptorData> stack, Method method)
+ {
+ boolean isMethodAnnotatedWithInterceptorClass = false;
+ boolean isMethodAnnotatedWithExcludeInterceptorClass = false;
+
+ if(AnnotationUtil.isMetaAnnotationExist(method.getDeclaredAnnotations(), InterceptorBindingType.class))
+ isMethodAnnotatedWithInterceptorClass = true;
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, ExcludeClassInterceptors.class))
+ isMethodAnnotatedWithExcludeInterceptorClass = true;
+
+
+ Iterator<InterceptorData> it = stack.iterator();
+ while(it.hasNext())
+ {
+ InterceptorData data = it.next();
+ if(isMethodAnnotatedWithInterceptorClass)
+ {
+ if(isMethodAnnotatedWithExcludeInterceptorClass)
+ {
+ if(!data.isDefinedInMethod() && data.isDefinedInInterceptorClass() && data.isDefinedWithWebBeansInterceptor())
+ {
+ it.remove();
+ }
+ else if(data.isDefinedInMethod() && data.isDefinedWithWebBeansInterceptor())
+ {
+ if(!data.getAnnotatedMethod().equals(method))
+ {
+ it.remove();
+ }
+ }
+ }
+ else
+ {
+ if(data.isDefinedInMethod() && data.isDefinedWithWebBeansInterceptor())
+ {
+ if(!data.getAnnotatedMethod().equals(method))
+ {
+ it.remove();
+ }
+ }
+ }
+ }
+ else
+ {
+ if(data.isDefinedInMethod() && data.isDefinedWithWebBeansInterceptor())
+ {
+ it.remove();
+ }
+ }
+
+ }
+
+ }
+
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorType.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorType.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorType.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorType.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.intercept;
+
+import javax.webbeans.manager.InterceptionType;
+
+import org.apache.webbeans.exception.WebBeansException;
+
+/**
+ * Type of the interceptors. Defines in the EJB specification and
+ * common annotations.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public enum InterceptorType
+{
+ AROUND_INVOKE,
+ POST_CONSTRUCT,
+ PRE_DESTROY,
+ PRE_PASSIVATE,
+ POST_ACTIVATE;
+
+
+ public static InterceptorType getType(InterceptionType type)
+ {
+ if(type.equals(InterceptionType.AROUND_INVOKE))
+ {
+ return AROUND_INVOKE;
+ }
+ else if(type.equals(InterceptionType.POST_CONSTRUCT))
+ {
+ return POST_CONSTRUCT;
+ }
+ else if(type.equals(InterceptionType.PRE_DESTROY))
+ {
+ return PRE_DESTROY;
+ }
+ else if(type.equals(InterceptionType.PRE_PASSIVATE))
+ {
+ return PRE_PASSIVATE;
+ }
+ else if(type.equals(InterceptionType.POST_ACTIVATE))
+ {
+ return POST_ACTIVATE;
+ }
+ else
+ {
+ throw new WebBeansException("Undefined interceptor type!");
+ }
+
+ }
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,258 @@
+/*
+ * 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.intercept;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.lang.reflect.Method;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remove;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import javax.webbeans.Destructor;
+import javax.webbeans.Disposes;
+import javax.webbeans.Initializer;
+import javax.webbeans.InterceptorBindingType;
+import javax.webbeans.Observes;
+import javax.webbeans.Produces;
+import javax.webbeans.manager.InterceptionType;
+
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+public final class InterceptorUtil
+{
+ private InterceptorUtil()
+ {
+
+ }
+
+ public static boolean isWebBeansBusinessMethod(Method method)
+ {
+ Asserts.nullCheckForMethod(method);
+
+ int modifiers = method.getModifiers();
+
+ if(ClassUtil.isStatic(modifiers) || ClassUtil.isPrivate(modifiers) || ClassUtil.isFinal(modifiers))
+ {
+ return false;
+ }
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, Initializer.class))
+ {
+ return false;
+ }
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, Destructor.class)
+ || AnnotationUtil.isMethodHasAnnotation(method, Remove.class))
+ {
+ return false;
+ }
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, PreDestroy.class)
+ || AnnotationUtil.isMethodHasAnnotation(method, PostConstruct.class)
+ || AnnotationUtil.isMethodHasAnnotation(method, AroundInvoke.class))
+ {
+ return false;
+ }
+
+ if(AnnotationUtil.isMethodHasAnnotation(method, Produces.class)
+ || AnnotationUtil.isMethodParameterAnnotationExist(method, Disposes.class)
+ || AnnotationUtil.isMethodParameterAnnotationExist(method, Observes.class))
+ {
+ return true;
+ }
+
+ return true;
+ }
+
+ public static Class<? extends Annotation> getInterceptorAnnotationClazz(InterceptionType type)
+ {
+ if(type.equals(InterceptionType.AROUND_INVOKE))
+ {
+ return AroundInvoke.class;
+ }
+ else if(type.equals(InterceptionType.POST_ACTIVATE))
+ {
+ return PostActivate.class;
+ }
+ else if(type.equals(InterceptionType.POST_CONSTRUCT))
+ {
+ return PostConstruct.class;
+ }
+ else if(type.equals(InterceptionType.PRE_DESTROY))
+ {
+ return PreDestroy.class;
+ }
+ else if(type.equals(InterceptionType.PRE_PASSIVATE))
+ {
+ return PrePassivate.class;
+ }
+ else
+ {
+ throw new WebBeansException("Undefined interceotion type");
+ }
+ }
+
+ public static boolean isBusinessMethodInterceptor(Class<?> clazz)
+ {
+ Asserts.nullCheckForClass(clazz);
+ Method[] methods = clazz.getDeclaredMethods();
+ for(Method method : methods)
+ {
+ if (AnnotationUtil.isMethodHasAnnotation(method, AroundInvoke.class))
+ {
+ if (ClassUtil.isMethodHasParameter(method))
+ {
+ Class<?>[] params = ClassUtil.getMethodParameterTypes(method);
+ if (params.length == 1 && params[0].equals(InvocationContext.class))
+ {
+ if (ClassUtil.getReturnType(method).equals(Object.class))
+ {
+ if (ClassUtil.isMethodHasException(method))
+ {
+ if (!ClassUtil.isStatic(method.getModifiers()) && !ClassUtil.isFinal(method.getModifiers()))
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean isLifecycleMethodInterceptor(Class<?> clazz)
+ {
+ Asserts.nullCheckForClass(clazz);
+ Method[] methods = clazz.getDeclaredMethods();
+ for(Method method : methods)
+ {
+ if (AnnotationUtil.isMethodHasAnnotation(method, PostConstruct.class) ||
+ AnnotationUtil.isMethodHasAnnotation(method, PreDestroy.class) ||
+ AnnotationUtil.isMethodHasAnnotation(method, PostActivate.class) ||
+ AnnotationUtil.isMethodHasAnnotation(method, PrePassivate.class))
+ {
+ if (ClassUtil.isMethodHasParameter(method))
+ {
+ Class<?>[] params = ClassUtil.getMethodParameterTypes(method);
+ if (params.length == 1 && params[0].equals(InvocationContext.class))
+ {
+ if (ClassUtil.getReturnType(method).equals(Void.TYPE))
+ {
+ if (!ClassUtil.isMethodHasCheckedException(method))
+ {
+ if (!ClassUtil.isStatic(method.getModifiers()))
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static void checkInterceptorConditions(Class<?> clazz)
+ {
+ Asserts.nullCheckForClass(clazz);
+ if(!AnnotationUtil.isMetaAnnotationExist(clazz.getDeclaredAnnotations(), InterceptorBindingType.class))
+ {
+ throw new WebBeansConfigurationException("WebBeans Interceptor class : " + clazz.getName() + " must have at least one @InterceptorBindingType annotation");
+ }
+
+ if(isLifecycleMethodInterceptor(clazz) && !isBusinessMethodInterceptor(clazz))
+ {
+ Annotation[] anns = AnnotationUtil.getMetaAnnotations(clazz.getDeclaredAnnotations(), InterceptorBindingType.class);
+
+ for(Annotation annotation : anns)
+ {
+ Target target = annotation.annotationType().getAnnotation(Target.class);
+ ElementType[] elementTypes = target.value();
+
+ if(!(elementTypes.length == 1 && elementTypes[0].equals(ElementType.TYPE)))
+ {
+ throw new WebBeansConfigurationException("Lifecycle interceptor : " + clazz.getName()+ " interceptor binding type must be defined as @Target{TYPE}");
+ }
+ }
+ }
+ }
+
+ public static void checkSimpleWebBeansInterceptorConditions(Class<?> clazz)
+ {
+ Asserts.nullCheckForClass(clazz);
+ Annotation[] anns = clazz.getDeclaredAnnotations();
+
+ boolean hasClassInterceptors = false;
+ if(AnnotationUtil.getMetaAnnotations(anns, InterceptorBindingType.class).length > 0)
+ {
+ hasClassInterceptors = true;
+ }else
+ {
+ Annotation[] stereoTypes = WebBeansUtil.getComponentStereoTypes(anns);
+ for(Annotation stero : stereoTypes)
+ {
+ if(AnnotationUtil.isMetaAnnotationExist(stero.annotationType().getDeclaredAnnotations(), InterceptorBindingType.class))
+ {
+ hasClassInterceptors = true;
+ break;
+ }
+ }
+ }
+
+ Method[] methods = clazz.getDeclaredMethods();
+
+ for(Method method : methods)
+ {
+ int modifiers = method.getModifiers();
+ if(!ClassUtil.isStatic(modifiers) && !ClassUtil.isPrivate(modifiers) && ClassUtil.isFinal(modifiers))
+ {
+ if(hasClassInterceptors)
+ {
+ throw new WebBeansConfigurationException("Simple web bean class : " + clazz.getName() + " can not define non-static, non-private final methods. Because it is annotated with at least one @InterceptorBindintType");
+ }
+ else
+ {
+ if(AnnotationUtil.isMetaAnnotationExist(method.getDeclaredAnnotations(), InterceptorBindingType.class))
+ {
+ throw new WebBeansConfigurationException("Method : "+ method.getName() + "in simple web bean class : " + clazz.getName() +
+ " can not be defined as non-static, non-private and final . Because it is annotated with at least one @InterceptorBindintType");
+ }
+ }
+ }
+ }
+
+ }
+
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.intercept;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.webbeans.util.Asserts;
+
+public class InterceptorsManager
+{
+ private static InterceptorsManager instance = new InterceptorsManager();
+
+ private List<Class<?>> enabledInterceptors = new CopyOnWriteArrayList<Class<?>>();
+
+ private InterceptorsManager()
+ {
+
+ }
+
+ public static InterceptorsManager getInstance()
+ {
+ return instance;
+ }
+
+ public void addNewInterceptor(Class<?> interceptorClazz)
+ {
+ Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null");
+
+ if (!enabledInterceptors.contains(interceptorClazz))
+ getInstance().enabledInterceptors.add(interceptorClazz);
+ }
+
+ public int compare(Class<?> src, Class<?> target)
+ {
+ Asserts.assertNotNull(src, "src parameter can not be null");
+ Asserts.assertNotNull(target, "target parameter can not be null");
+
+ int srcIndex = enabledInterceptors.indexOf(src);
+ int targetIndex = enabledInterceptors.indexOf(target);
+
+ if (srcIndex == -1 || targetIndex == -1)
+ {
+ throw new IllegalArgumentException("One of the compare class of the list : [" + src.getName() + "," + target.getName() + "]" + " is not contained in the enabled interceptors list!");
+ }
+
+ if (srcIndex == targetIndex)
+ return 0;
+ else if (srcIndex < targetIndex)
+ return -1;
+ else
+ return 1;
+ }
+
+ public boolean isInterceptorEnabled(Class<?> interceptorClazz)
+ {
+ Asserts.nullCheckForClass(interceptorClazz, "interceptorClazz can not be null");
+
+ return getInstance().enabledInterceptors.contains(interceptorClazz);
+ }
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,252 @@
+/*
+ * 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.intercept;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * Implementation of the {@link InvocationContext} interface.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ */
+public class InvocationContextImpl implements InvocationContext
+{
+ /**Context data for passing between interceptors*/
+ private Map<String, Object> contextData = new HashMap<String, Object>();
+
+ /**Invoked method*/
+ private Method method;
+
+ /**Method parameters*/
+ private Object[] parameters;
+
+ /**Interceptor stack*/
+ private List<InterceptorData> interceptorDatas;
+
+ /**Target object*/
+ private Object target;
+
+ /**Interceptor type*/
+ private InterceptorType type;
+
+ /**Used for numbering interceptors*/
+ private int currentMethod = 1;
+
+ /**
+ * Initializes the context.
+ *
+ * @param target target object
+ * @param method method
+ * @param parameters method parameters
+ * @param datas interceptor stack
+ * @param type interceptor type
+ */
+ public InvocationContextImpl(Object target, Method method, Object[] parameters, List<InterceptorData> datas, InterceptorType type)
+ {
+ this.target = target;
+ this.method = method;
+ this.parameters = parameters;
+ this.interceptorDatas = datas;
+ this.type = type;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.interceptor.InvocationContext#getContextData()
+ */
+ public Map<String, Object> getContextData()
+ {
+ return this.contextData;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.interceptor.InvocationContext#getMethod()
+ */
+ public Method getMethod()
+ {
+ return this.method;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.interceptor.InvocationContext#getParameters()
+ */
+ public Object[] getParameters()
+ {
+ return this.parameters;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.interceptor.InvocationContext#getTarget()
+ */
+ public Object getTarget()
+ {
+ return this.target;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.interceptor.InvocationContext#proceed()
+ */
+ public Object proceed() throws Exception
+ {
+ try
+ {
+ if(type.equals(InterceptorType.AROUND_INVOKE))
+ {
+ return proceedAroundInvokes(this.interceptorDatas);
+ }
+ else
+ {
+ return proceedCommonAnnots(this.interceptorDatas, this.type);
+ }
+
+ }catch(Exception e)
+ {
+ this.target = null; //destroy target instance
+
+ throw e;
+ }
+ }
+
+ /*
+ * Around invoke chain.
+ */
+ private Object proceedAroundInvokes(List<InterceptorData> datas) throws Exception
+ {
+ Object result = null;
+
+ if(currentMethod <= datas.size())
+ {
+ InterceptorData intc = datas.get(currentMethod-1);
+
+ Method method = intc.getAroundInvoke();
+
+ Object t = intc.getInterceptorInstance();
+ if(t == null)
+ {
+ t = target;
+ }
+
+ currentMethod++;
+ result = method.invoke(t, new Object[]{this});
+ }
+ else
+ {
+ result = this.method.invoke(target, parameters);
+ }
+
+ return result;
+ }
+
+ /*
+ * PreDestroy and PostConstruct chain
+ */
+ private Object proceedCommonAnnots(List<InterceptorData> datas, InterceptorType type) throws Exception
+ {
+ Object result = null;
+
+ if(currentMethod <= datas.size())
+ {
+ InterceptorData intc = datas.get(currentMethod-1);
+ Method method = null;
+
+ if(type.equals(InterceptorType.POST_CONSTRUCT))
+ {
+ method = intc.getPostConstruct();
+ }
+ else if(type.equals(InterceptorType.PRE_DESTROY))
+ {
+ method = intc.getPreDestroy();
+ }
+
+
+ currentMethod++;
+
+ Object t = intc.getInterceptorInstance();
+ if(t == null)
+ {
+ t = target;
+ result = method.invoke(t, new Object[]{});
+ }
+ else
+ {
+ result = method.invoke(t, new Object[]{this});
+ }
+
+
+ }
+
+ return result;
+ }
+
+
+
+ /*
+ * (non-Javadoc)
+ * @see javax.interceptor.InvocationContext#setParameters(java.lang.Object[])
+ */
+ public void setParameters(Object[] params)
+ {
+ if(getMethod() != null)
+ {
+ if(params == null)
+ {
+ if(this.parameters.length > 0)
+ {
+ throw new IllegalArgumentException("Parameters is null");
+ }
+ }
+ else
+ {
+ List<Class<?>> src = new ArrayList<Class<?>>();
+
+ if(params.length != this.parameters.length)
+ {
+ throw new IllegalArgumentException("Parameters length not match");
+ }
+
+ for(Object param : params)
+ {
+ src.add(param.getClass());
+ }
+
+
+ for(Class<?> param : this.method.getParameterTypes())
+ {
+ if(!src.contains(param))
+ throw new IllegalArgumentException("Parameters types not match");
+ }
+
+ System.arraycopy(params, 0, this.parameters, 0, params.length);
+
+ }
+
+ }
+ }
+
+}
\ No newline at end of file
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=719890&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java Sat Nov 22 10:09:38 2008
@@ -0,0 +1,249 @@
+/*
+ * 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.intercept;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.webbeans.InterceptorBindingType;
+import javax.webbeans.manager.Interceptor;
+
+import org.apache.webbeans.component.AbstractComponent;
+import org.apache.webbeans.container.ManagerImpl;
+import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * Configures the Web Beans related interceptors.
+ *
+ * @author <a href="mailto:gurkanerdogdu@yahoo.com">Gurkan Erdogdu</a>
+ * @since 1.0
+ * @see WebBeansInterceptor
+ */
+public final class WebBeansInterceptorConfig
+{
+ /** Logger instance */
+ private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansInterceptorConfig.class);
+
+ /*
+ * Private
+ */
+ private WebBeansInterceptorConfig()
+ {
+
+ }
+
+ /**
+ * Configures WebBeans specific interceptor class.
+ *
+ * @param interceptorClazz
+ * interceptor class
+ */
+ public static void configureInterceptorClass(AbstractComponent<Object> delegate)
+ {
+ logger.info("Configuring the Web Beans Interceptor Class : " + delegate.getReturnType().getName() + " started");
+
+ WebBeansInterceptor interceptor = new WebBeansInterceptor(delegate);
+
+ Annotation[] anns = AnnotationUtil.getMetaAnnotations(delegate.getReturnType().getDeclaredAnnotations(), InterceptorBindingType.class);
+
+ for (Annotation ann : anns)
+ {
+ interceptor.addInterceptorBindingType(ann.annotationType(), ann);
+ }
+
+ logger.info("Configuring the Web Beans Interceptor Class : " + delegate.getReturnType() + " ended");
+
+ ManagerImpl.getManager().addInterceptor(interceptor);
+
+ }
+
+ /**
+ * Configures the given class for applicable interceptors.
+ *
+ * @param clazz
+ * configuration interceptors for this
+ */
+ public static void configure(Class<?> clazz, List<InterceptorData> stack)
+ {
+ if (AnnotationUtil.isMetaAnnotationExist(clazz.getDeclaredAnnotations(), InterceptorBindingType.class))
+ {
+
+ Set<Annotation> bindingTypeSet = new HashSet<Annotation>();
+
+ Annotation[] anns = AnnotationUtil.getMetaAnnotations(clazz.getDeclaredAnnotations(), InterceptorBindingType.class);
+
+ for(Annotation ann : anns)
+ {
+ bindingTypeSet.add(ann);
+ }
+
+ Annotation[] stereoTypes = WebBeansUtil.getComponentStereoTypes(clazz.getDeclaredAnnotations());
+ for(Annotation stero : stereoTypes)
+ {
+ if(AnnotationUtil.isMetaAnnotationExist(stero.annotationType().getDeclaredAnnotations(), InterceptorBindingType.class))
+ {
+ Annotation[] steroInterceptorBindings = AnnotationUtil.getMetaAnnotations(stero.annotationType().getDeclaredAnnotations(), InterceptorBindingType.class);
+
+ for(Annotation ann : steroInterceptorBindings)
+ {
+ bindingTypeSet.add(ann);
+ }
+ }
+ }
+
+ anns = new Annotation[bindingTypeSet.size()];
+ anns = bindingTypeSet.toArray(anns);
+
+ Set<Interceptor> set = findDeployedWebBeansInterceptor(anns);
+
+ // Adding class interceptors
+ addComponentInterceptors(set, clazz, stack);
+ }
+
+ // Method level interceptors.
+ addMethodInterceptors(clazz, stack);
+
+ }
+
+ private static void addComponentInterceptors(Set<Interceptor> set, Class<?> clazz, List<InterceptorData> stack)
+ {
+ Iterator<Interceptor> it = set.iterator();
+ while (it.hasNext())
+ {
+ WebBeansInterceptor interceptor = (WebBeansInterceptor) it.next();
+
+ // interceptor binding
+ WebBeansUtil.configureInterceptorMethods(interceptor.getClazz(), AroundInvoke.class, true, false, stack, null, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor.getClazz(), PostConstruct.class, true, false, stack, null, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor.getClazz(), PreDestroy.class, true, false, stack, null, true);
+
+ }
+
+ }
+
+ private static void addMethodInterceptors(Class<?> clazz, List<InterceptorData> stack)
+ {
+ Method[] methods = clazz.getDeclaredMethods();
+
+ for (Method method : methods)
+ {
+ if (AnnotationUtil.isMetaAnnotationExist(method.getAnnotations(), InterceptorBindingType.class))
+ {
+ Annotation[] anns = AnnotationUtil.getMetaAnnotations(method.getDeclaredAnnotations(), InterceptorBindingType.class);
+ Annotation[] annsClazz = AnnotationUtil.getMetaAnnotations(clazz.getDeclaredAnnotations(), InterceptorBindingType.class);
+
+
+ Set<Annotation> set = new HashSet<Annotation>();
+
+ for (Annotation ann : anns)
+ {
+ set.add(ann);
+ }
+
+ for (Annotation ann : annsClazz)
+ {
+ set.add(ann);
+ }
+
+ Annotation[] stereoTypes = WebBeansUtil.getComponentStereoTypes(clazz.getDeclaredAnnotations());
+ for(Annotation stero : stereoTypes)
+ {
+ if(AnnotationUtil.isMetaAnnotationExist(stero.annotationType().getDeclaredAnnotations(), InterceptorBindingType.class))
+ {
+ Annotation[] steroInterceptorBindings = AnnotationUtil.getMetaAnnotations(stero.annotationType().getDeclaredAnnotations(), InterceptorBindingType.class);
+
+ for(Annotation ann : steroInterceptorBindings)
+ {
+ set.add(ann);
+ }
+ }
+ }
+
+ Annotation[] result = new Annotation[set.size()];
+ result = set.toArray(result);
+
+ Set<Interceptor> setInterceptors = findDeployedWebBeansInterceptor(result);
+ Iterator<Interceptor> it = setInterceptors.iterator();
+
+ while (it.hasNext())
+ {
+ WebBeansInterceptor interceptor = (WebBeansInterceptor) it.next();
+
+ WebBeansUtil.configureInterceptorMethods(interceptor.getClazz(), AroundInvoke.class, false, true, stack, method, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor.getClazz(), PostConstruct.class, false, true, stack, method, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor.getClazz(), PreDestroy.class, false, true, stack, method, true);
+ }
+
+ }
+ }
+
+ }
+
+ /**
+ * Gets the configured webbeans interceptors.
+ *
+ * @return the configured webbeans interceptors
+ */
+ private static Set<Interceptor> getWebBeansInterceptors()
+ {
+ return Collections.unmodifiableSet(ManagerImpl.getManager().getInterceptors());
+ }
+
+ /*
+ * Find the deployed interceptors with given interceptor binding types.
+ */
+ public static Set<Interceptor> findDeployedWebBeansInterceptor(Annotation[] anns)
+ {
+ Set<Interceptor> set = new HashSet<Interceptor>();
+
+ Iterator<Interceptor> it = getWebBeansInterceptors().iterator();
+ WebBeansInterceptor interceptor = null;
+
+ List<Class<? extends Annotation>> bindingTypes = new ArrayList<Class<? extends Annotation>>();
+ List<Annotation> listAnnot = new ArrayList<Annotation>();
+ for (Annotation ann : anns)
+ {
+ bindingTypes.add(ann.annotationType());
+ listAnnot.add(ann);
+ }
+
+ while (it.hasNext())
+ {
+ interceptor = (WebBeansInterceptor) it.next();
+
+ if (interceptor.isBindingTypesExist(bindingTypes, listAnnot))
+ {
+ set.add(interceptor);
+ set.addAll(interceptor.getMetaInceptors());
+ }
+ }
+
+ return set;
+ }
+}
Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
------------------------------------------------------------------------------
svn:eol-style = native