Author: alexsmirnov
Date: 2010-06-18 20:01:14 -0400 (Fri, 18 Jun 2010)
New Revision: 17641
Added:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/
root/core/branches/jsr-330/impl/src/test/resources/META-INF/services/
Removed:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java
root/core/branches/jsr-330/jsr330-impl/
Modified:
root/core/branches/jsr-330/bom/pom.xml
root/core/branches/jsr-330/impl/pom.xml
root/core/branches/jsr-330/pom.xml
Log:
merge jsr-330 module to implementation
Modified: root/core/branches/jsr-330/bom/pom.xml
===================================================================
--- root/core/branches/jsr-330/bom/pom.xml 2010-06-18 19:14:03 UTC (rev 17640)
+++ root/core/branches/jsr-330/bom/pom.xml 2010-06-19 00:01:14 UTC (rev 17641)
@@ -62,11 +62,6 @@
<artifactId>richfaces-core-impl</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.richfaces.core</groupId>
- <artifactId>jsr330-impl</artifactId>
- <version>${project.version}</version>
- </dependency>
<!-- Required for EL-CSS func -->
<dependency>
Modified: root/core/branches/jsr-330/impl/pom.xml
===================================================================
--- root/core/branches/jsr-330/impl/pom.xml 2010-06-18 19:14:03 UTC (rev 17640)
+++ root/core/branches/jsr-330/impl/pom.xml 2010-06-19 00:01:14 UTC (rev 17641)
@@ -45,10 +45,6 @@
<artifactId>richfaces-commons-api</artifactId>
</dependency>
<dependency>
- <groupId>org.richfaces.core</groupId>
- <artifactId>jsr330-impl</artifactId>
- </dependency>
- <dependency>
<groupId>net.sourceforge.cssparser</groupId>
<artifactId>cssparser</artifactId>
</dependency>
@@ -56,6 +52,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
<!-- Provided Dependencies -->
<dependency>
Copied: root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330 (from rev
17639, root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330)
Deleted: root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Binder.java 2010-06-18
18:16:11 UTC (rev 17639)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -1,55 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.jsr330;
-
-import javax.inject.Provider;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public interface Binder<T> {
-
-
- public Binder<T> to(Class<? extends T> implementation);
-
- public Binder<T> toInstance(T value);
-
- public Binder<T> toProvider(Class<? extends Provider<T>>
provaderImplementation);
-
- public Binder<T> toProviderInstance(Provider<T> provider);
-
- public Binder<T> toService();
-
- public Binder<T> toService(Class<? extends T> defaultImplementation);
-
- public Binder<T> asSingleton();
- public Binder<T> asSessionScope();
- public Binder<T> asRequestScope();
- public Binder<T> asApplicationScope();
-
-}
Copied: root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java
(from rev 17640,
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Binder.java)
===================================================================
--- root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.jsr330;
+
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0">
+ * This interface lets {@link Module} to register concrete implementation of service.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ * @param T
+ * type of object provided by binder
+ *
+ */
+public interface Binder<T> {
+
+ public Binder<T> to(Class<? extends T> implementation);
+
+ public Binder<T> toInstance(T value);
+
+ public Binder<T> toProvider(Class<? extends Provider<T>>
provaderImplementation);
+
+ public Binder<T> toProviderInstance(Provider<T> provider);
+
+ public Binder<T> toService();
+
+ public Binder<T> toService(Class<? extends T> defaultImplementation);
+
+ public Binder<T> asSingleton();
+
+ public Binder<T> asSessionScope();
+
+ public Binder<T> asRequestScope();
+
+ public Binder<T> asApplicationScope();
+
+ public abstract Binder<T> asComponentScope();
+
+ public abstract Binder<T> asContexScope();
+
+}
Deleted:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-18
18:16:11 UTC (rev 17639)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -1,330 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.jsr330;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import javax.faces.context.FacesContext;
-import javax.inject.Provider;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- * @param <T>
- */
-public final class BinderImpl<T> implements Binder<T> {
-
- private final Scope<T> defaultScope = new Scope<T>() {
- public T get() {
- return getProvider().get();
- }
- };
-
- private final Scope<T> singltonScope = new Scope<T>() {
-
- private volatile boolean instantiated = false;
-
- private volatile T value;
-
- public T get() {
- if (!instantiated) {
- value = getProvider().get();
- instantiated = true;
- }
- return value;
- }
- };
-
- private abstract class FacesScope implements Scope<T> {
-
- private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
-
- public T get() {
- T value;
- rwLock.readLock().lock();
- try {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if (null != facesContext) {
- Map<String, Object> map = getMap(facesContext);
- String key = target.toString();
- value = (T) map.get(key);
- if(null == value){
- rwLock.readLock().unlock();
- rwLock.writeLock().lock();
- try {
- value = getProvider().get();
- map.put(key, value);
- } finally {
- rwLock.readLock().lock();
- rwLock.writeLock().unlock();
- }
- }
- } else {
- value = getProvider().get();
- }
- } finally {
- rwLock.readLock().unlock();
- }
- return value;
- }
-
- protected abstract Map<String, Object> getMap(FacesContext facesContext);
- }
-
- private final Scope<T> sessionScope = new FacesScope() {
-
- @Override
- protected Map<String, Object> getMap(FacesContext facesContext) {
- Map<String, Object> map =
facesContext.getExternalContext().getSessionMap();
- return map;
- }
- };
-
- private final Scope<T> requestScope = new FacesScope() {
- @Override
- protected Map<String, Object> getMap(FacesContext facesContext) {
- return facesContext.getExternalContext().getRequestMap();
- }
- };
-
- private final Scope<T> applicationScope = new FacesScope() {
- @Override
- protected Map<String, Object> getMap(FacesContext facesContext) {
- return facesContext.getExternalContext().getApplicationMap();
- }
- };
-
- private final Target target;
-
- private Provider<T> provider;
-
- private Provider<Provider<T>> providerOfProvider;
-
- private Scope<T> scope;
-
- private volatile BinderImpl<Provider<T>> providerBinder;
-
- private boolean initialized = false;
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param target
- * the target to set
- */
- public BinderImpl(Target target) {
- this.target = target;
- this.scope = defaultScope;
- }
-
- public T get() {
- checkInitialized();
- return scope.get();
- }
-
- public BinderImpl<Provider<T>> asProviderBinder() {
- if (null == providerBinder) {
- createProviderBinding();
- }
- return providerBinder;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.Binder#to(java.lang.Class)
- */
- public Binder<T> to(Class<? extends T> implementation) {
- this.provider = new DynamicProvider<T>(implementation);
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.Binder#toInstance(java.lang.Object)
- */
- public Binder<T> toInstance(final T value) {
- checkNotInitialized();
- this.provider = new Provider<T>() {
-
- public T get() {
- return value;
- }
- };
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.Binder#toProvider(java.lang.Class)
- */
- @SuppressWarnings("unchecked")
- public Binder<T> toProvider(Class<? extends Provider<T>>
providerImplementation) {
- checkNotInitialized();
- this.providerOfProvider = new DynamicProvider(providerImplementation);
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.Binder#toProviderInstance(javax.inject.Provider)
- */
- public Binder<T> toProviderInstance(Provider<T> provider) {
- this.provider = provider;
- return this;
- }
-
- public Binder<T> toService() {
- Collection<Class<? extends T>> service = loadService();
- if (service.size() > 0) {
- this.to(service.iterator().next());
- } else {
- throw new DependencyException("No implementation found for service
" + target);
- }
- return this;
- }
-
- public Binder<T> toService(Class<? extends T> defaultImplementation) {
- Collection<Class<? extends T>> service = loadService();
- if (service.size() > 0) {
- this.to(service.iterator().next());
- } else {
- this.to(defaultImplementation);
- }
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.Binder#asSingleton()
- */
- public Binder<T> asSingleton() {
- this.scope = singltonScope;
- return this;
- }
-
- public Binder<T> asApplicationScope() {
- this.scope = applicationScope;
- return this;
- }
-
- public Binder<T> asRequestScope() {
- this.scope = requestScope;
- return this;
- }
-
- public Binder<T> asSessionScope() {
- this.scope = sessionScope;
- return this;
- }
-
- void init(Binders injector) throws DependencyException {
- checkNotInitialized();
- if (null == provider && null == providerOfProvider) {
- throw new DependencyException("binding not has not been set");
- }
- if (null != provider && provider instanceof Initializable) {
- if( ((Initializable) provider).init(injector)){
- this.scope = singltonScope;
- }
- }
- if (null != providerOfProvider && providerOfProvider instanceof
Initializable) {
- ((Initializable) providerOfProvider).init(injector);
- }
- this.initialized = true;
- }
-
- void createInstances(Binders injector) throws DependencyException {
- checkInitialized();
- if (null == provider && null != providerOfProvider) {
- this.provider = providerOfProvider.get();
- }
- if (this.scope == singltonScope ) {
- scope.get();
- }
- createProviderBinding();
- }
-
- public void destroy(InjectorImpl injectorImpl) {
- if (null != provider && provider instanceof Initializable) {
- ((Initializable) provider).destroy();
- }
- if (null != providerOfProvider && providerOfProvider instanceof
Initializable) {
- ((Initializable) providerOfProvider).destroy();
- }
- provider = null;
- providerOfProvider = null;
- providerBinder = null;
- this.initialized = false;
- }
-
- Provider<T> getProvider() {
- return null == this.provider ? this.providerOfProvider.get() : this.provider;
- }
-
- private void checkInitialized() {
- if (!initialized) {
- throw new DependencyException("Dependency injection implementation has
not been initialized");
- }
- }
-
- private void checkNotInitialized() {
- if (initialized) {
- throw new DependencyException("Dependency injection implementation has
already been initialized");
- }
- }
-
- @SuppressWarnings("unchecked")
- private void createProviderBinding() {
- BinderImpl<Provider<T>> providerBinder = new
BinderImpl(target.toProvider());
- if (null != provider) {
- providerBinder.toInstance(provider);
- } else if (null != providerOfProvider) {
- providerBinder.toProviderInstance(providerOfProvider);
- }
- providerBinder.initialized = true;
- this.providerBinder = providerBinder;
- }
-
- private Collection<Class<? extends T>> loadService() {
- if (null == target) {
- throw new DependencyException("Binder does not configured
correctly");
- }
- try {
- return ServiceLoader.<T> loadServiceClasses((Class<T>)
target.getRawType());
- } catch (ServiceException e) {
- throw new DependencyException("Error loading service ", e);
- }
- }
-}
Copied: root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
(from rev 17640,
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BinderImpl.java)
===================================================================
--- root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -0,0 +1,398 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.jsr330;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ * @param <T>
+ */
+public final class BinderImpl<T> implements Binder<T> {
+
+ private final Scope<T> defaultScope = new Scope<T>() {
+ public T get() {
+ return getProvider().get();
+ }
+ };
+
+ private final Scope<T> singltonScope = new Scope<T>() {
+
+ private volatile boolean instantiated = false;
+
+ private volatile T value;
+
+ public T get() {
+ if (!instantiated) {
+ value = getProvider().get();
+ instantiated = true;
+ }
+ return value;
+ }
+ };
+
+ /**
+ * <p class="changed_added_4_0">
+ * This is base class for JSF single-thread scopes ( request, view, FacesContext
attributes )
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+ private abstract class FacesScope implements Scope<T> {
+
+ @SuppressWarnings("unchecked")
+ public T get() {
+ T value;
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (null != facesContext) {
+ Map map = getMap(facesContext);
+ String key = target.toKey();
+ value = (T) map.get(key);
+ if (null == value) {
+ value = getProvider().get();
+ map.put(key, value);
+ }
+ } else {
+ value = getProvider().get();
+ }
+ return value;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected abstract Map getMap(FacesContext facesContext);
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * This class represent scopes that can be shared between threads, like application,
singleton or session. For
+ * thread-safety, it uses {@link ReentrantReadWriteLock} to insert object instance
into scope map.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+ private abstract class ThreadSafeFacesScope implements Scope<T> {
+
+ private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+ @SuppressWarnings("unchecked")
+ public T get() {
+ T value;
+ rwLock.readLock().lock();
+ try {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (null != facesContext) {
+ Map<String, Object> map = getMap(facesContext);
+ String key = target.toKey();
+ value = (T) map.get(key);
+ if (null == value) {
+ rwLock.readLock().unlock();
+ rwLock.writeLock().lock();
+ try {
+ value = getProvider().get();
+ map.put(key, value);
+ } finally {
+ rwLock.readLock().lock();
+ rwLock.writeLock().unlock();
+ }
+ }
+ } else {
+ value = getProvider().get();
+ }
+ } finally {
+ rwLock.readLock().unlock();
+ }
+ return value;
+ }
+
+ protected abstract Map<String, Object> getMap(FacesContext facesContext);
+ }
+
+ private final Scope<T> sessionScope = new ThreadSafeFacesScope() {
+
+ @Override
+ protected Map<String, Object> getMap(FacesContext facesContext) {
+ Map<String, Object> map =
facesContext.getExternalContext().getSessionMap();
+ return map;
+ }
+ };
+
+ private final Scope<T> requestScope = new FacesScope() {
+ @Override
+ protected Map<String, Object> getMap(FacesContext facesContext) {
+ return facesContext.getExternalContext().getRequestMap();
+ }
+ };
+
+ private final Scope<T> contextScope = new FacesScope() {
+ @Override
+ protected Map<Object, Object> getMap(FacesContext facesContext) {
+ return facesContext.getAttributes();
+ }
+ };
+
+ private final Scope<T> componentScope = new FacesScope() {
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Map<String, Object> getMap(FacesContext facesContext) {
+ Map<String, Object> map =
+ (Map<String, Object>)
facesContext.getAttributes().get(UIComponent.CURRENT_COMPONENT);
+ if (null == map) {
+ throw new DependencyException("Current component is not set for
dependency target " + target.toString());
+ }
+ return map;
+ }
+ };
+ private final Scope<T> applicationScope = new ThreadSafeFacesScope() {
+ @Override
+ protected Map<String, Object> getMap(FacesContext facesContext) {
+ return facesContext.getExternalContext().getApplicationMap();
+ }
+ };
+
+ private final Target target;
+
+ private Provider<T> provider;
+
+ private Provider<Provider<T>> providerOfProvider;
+
+ private Scope<T> scope;
+
+ private volatile Binder<Provider<T>> providerBinder;
+
+ private boolean initialized = false;
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param target
+ * the target to set
+ */
+ public BinderImpl(Target target) {
+ this.target = target;
+ this.scope = defaultScope;
+ }
+
+ public T get() {
+ checkInitialized();
+ return scope.get();
+ }
+
+ public Binder<Provider<T>> asProviderBinder() {
+ if (null == providerBinder) {
+ createProviderBinding();
+ }
+ return providerBinder;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.Binder#to(java.lang.Class)
+ */
+ public Binder<T> to(Class<? extends T> implementation) {
+ this.provider = new DynamicProvider<T>(implementation);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.Binder#toInstance(java.lang.Object)
+ */
+ public Binder<T> toInstance(final T value) {
+ checkNotInitialized();
+ this.provider = new Provider<T>() {
+
+ public T get() {
+ return value;
+ }
+ };
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.Binder#toProvider(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ public Binder<T> toProvider(Class<? extends Provider<T>>
providerImplementation) {
+ checkNotInitialized();
+ this.providerOfProvider = new DynamicProvider(providerImplementation);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.Binder#toProviderInstance(javax.inject.Provider)
+ */
+ public Binder<T> toProviderInstance(Provider<T> provider) {
+ this.provider = provider;
+ return this;
+ }
+
+ public Binder<T> toService() {
+ Collection<Class<? extends T>> service = loadService();
+ if (service.size() > 0) {
+ this.to(service.iterator().next());
+ } else {
+ throw new DependencyException("No implementation found for service
" + target);
+ }
+ return this;
+ }
+
+ public Binder<T> toService(Class<? extends T> defaultImplementation) {
+ Collection<Class<? extends T>> service = loadService();
+ if (service.size() > 0) {
+ this.to(service.iterator().next());
+ } else {
+ this.to(defaultImplementation);
+ }
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.Binder#asSingleton()
+ */
+ public Binder<T> asSingleton() {
+ this.scope = singltonScope;
+ return this;
+ }
+
+ public Binder<T> asApplicationScope() {
+ this.scope = applicationScope;
+ return this;
+ }
+
+ public Binder<T> asRequestScope() {
+ this.scope = requestScope;
+ return this;
+ }
+
+ public Binder<T> asSessionScope() {
+ this.scope = sessionScope;
+ return this;
+ }
+
+ public Binder<T> asContexScope() {
+ this.scope = contextScope;
+ return this;
+ }
+
+ public Binder<T> asComponentScope() {
+ this.scope = componentScope;
+ return this;
+ }
+
+ void init(Binders injector) throws DependencyException {
+ checkNotInitialized();
+ if (null == provider && null == providerOfProvider) {
+ throw new DependencyException("binding not has not been set");
+ }
+ if (null != provider && provider instanceof Initializable) {
+ if (((Initializable) provider).init(injector)) {
+ this.scope = singltonScope;
+ }
+ }
+ if (null != providerOfProvider && providerOfProvider instanceof
Initializable) {
+ ((Initializable) providerOfProvider).init(injector);
+ }
+ this.initialized = true;
+ }
+
+ void createInstances(Binders injector) throws DependencyException {
+ checkInitialized();
+ if (null == provider && null != providerOfProvider) {
+ this.provider = providerOfProvider.get();
+ }
+ if (this.scope == singltonScope) {
+ scope.get();
+ }
+ createProviderBinding();
+ }
+
+ public void destroy(InjectorImpl injectorImpl) {
+ if (null != provider && provider instanceof Initializable) {
+ ((Initializable) provider).destroy();
+ }
+ if (null != providerOfProvider && providerOfProvider instanceof
Initializable) {
+ ((Initializable) providerOfProvider).destroy();
+ }
+ provider = null;
+ providerOfProvider = null;
+ providerBinder = null;
+ this.initialized = false;
+ }
+
+ Provider<T> getProvider() {
+ return null == this.provider ? this.providerOfProvider.get() : this.provider;
+ }
+
+ private void checkInitialized() {
+ if (!initialized) {
+ throw new DependencyException("Dependency injection implementation has
not been initialized");
+ }
+ }
+
+ private void checkNotInitialized() {
+ if (initialized) {
+ throw new DependencyException("Dependency injection implementation has
already been initialized");
+ }
+ }
+
+ private void createProviderBinding() {
+ BinderImpl<Provider<T>> providerBinder = new
BinderImpl<Provider<T>>(target.toProvider());
+ providerBinder.toInstance(scope);
+ providerBinder.initialized = true;
+ this.providerBinder = providerBinder;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Collection<Class<? extends T>> loadService() {
+ if (null == target) {
+ throw new DependencyException("Binder does not configured
correctly");
+ }
+ try {
+ return ServiceLoader.<T> loadServiceClasses((Class<T>)
target.getRawType());
+ } catch (ServiceException e) {
+ throw new DependencyException("Error loading service ", e);
+ }
+ }
+}
Deleted:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-18
18:16:11 UTC (rev 17639)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -1,137 +0,0 @@
-package org.richfaces.jsr330;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.inject.Provider;
-
-import org.richfaces.application.DependencyInjector;
-
-/**
- * <p class="changed_added_4_0">
- * Lightweight implementation for JSR-330 dependency injection. Supports only {@link
javax.inject.Named} annotations, no
- * scopes except {@link javax.inject.Singleton}
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class InjectorImpl implements DependencyInjector, Binders, InjectorConfig {
-
- private final Map<Target, BinderImpl<?>> bindings = new
ConcurrentHashMap<Target, BinderImpl<?>>();
-
- @SuppressWarnings("unchecked")
- public <T> T create(Class<T> type, String name) {
- Target target = Target.create(name, type);
- return (T) getBinding(target).get();
- }
-
- public <T> T create(Class<T> type) {
- return create(type, null);
- }
-
- public void init(Module... modules) {
- register(DependencyInjector.class).toInstance(this);
- for (Module bindingModule : modules) {
- bindingModule.configure(this);
- }
- initProviders();
- initSingletons();
- }
-
- public void destroy() {
- for (BinderImpl<?> binding : bindings.values()) {
- binding.destroy(this);
- }
- bindings.clear();
- }
-
- private void initSingletons() {
- Collection<BinderImpl<?>> values = new
ArrayList<BinderImpl<?>>(bindings.values());
- for (BinderImpl<?> binding : values) {
- binding.createInstances(this);
- }
- }
-
- private void initProviders() {
- Collection<BinderImpl<?>> values = new
ArrayList<BinderImpl<?>>(bindings.values());
- for (BinderImpl<?> binding : values) {
- binding.init(this);
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.Binders#getBinding(org.richfaces.jsr330.Target)
- */
- @SuppressWarnings("unchecked")
- public BinderImpl<?> getBinding(Target type) {
- if (bindings.containsKey(type)) {
- return bindings.get(type);
- } else if (type.isConcrete()) {
- // Concrete classes can be created without configuration.
- BinderImpl binding = new BinderImpl(type);
- binding.to(type.getRawType());
- binding.init(this);
- binding.createInstances(this);
- registerBinding(type, binding);
- return binding;
- } else if (type.isProvider()) {
- return getBinding(type.toProviderTarget()).asProviderBinder();
- } else {
- throw new DependencyException("Type " + type + " has not been
registered");
- }
- }
-
- @SuppressWarnings("unchecked")
- public void inject(Object value) {
- Target target = Target.create(value.getClass());
- Provider<?> provider = getBinding(target).getProvider();
- if (provider instanceof DynamicProvider) {
- try {
- ((DynamicProvider) provider).inject(value);
- } catch (Exception e) {
- throw new DependencyException("Cannot inject dependencies into
object " + value, e);
- }
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.InjectorConfig#register(org.richfaces.jsr330.Target)
- */
- @SuppressWarnings("unchecked")
- public <T> Binder<T> register(Target type) {
- BinderImpl<T> binding = new BinderImpl(type);
- registerBinding(type, binding);
- return binding;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.InjectorConfig#register(java.lang.Class,
java.lang.Class)
- */
- public <T> Binder<T> register(Class<T> type, Class<?>...
typeArguments) {
- return register(Target.create(type, typeArguments));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.jsr330.InjectorConfig#register(java.lang.String,
java.lang.Class, java.lang.Class)
- */
- public <T> Binder<T> register(String name, Class<T> type,
Class<?>... typeArguments) {
- return register(Target.create(name, type, typeArguments));
- }
-
- private void registerBinding(Target type, BinderImpl<?> binder) {
- bindings.put(type, binder);
- }
-}
Copied:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java (from
rev 17640,
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java)
===================================================================
--- root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -0,0 +1,137 @@
+package org.richfaces.jsr330;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.inject.Provider;
+
+import org.richfaces.application.DependencyInjector;
+
+/**
+ * <p class="changed_added_4_0">
+ * Lightweight implementation for JSR-330 dependency injection. Supports only {@link
javax.inject.Named} annotations, no
+ * scopes except {@link javax.inject.Singleton}
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class InjectorImpl implements DependencyInjector, Binders, InjectorConfig {
+
+ private final Map<Target, BinderImpl<?>> bindings = new
ConcurrentHashMap<Target, BinderImpl<?>>();
+
+ @SuppressWarnings("unchecked")
+ public <T> T create(Class<T> type, String name) {
+ Target target = Target.create(name, type);
+ return (T) getBinding(target).get();
+ }
+
+ public <T> T create(Class<T> type) {
+ return create(type, null);
+ }
+
+ public void init(Module... modules) {
+ register(DependencyInjector.class).toInstance(this);
+ for (Module bindingModule : modules) {
+ bindingModule.configure(this);
+ }
+ initProviders();
+ initSingletons();
+ }
+
+ public void destroy() {
+ for (BinderImpl<?> binding : bindings.values()) {
+ binding.destroy(this);
+ }
+ bindings.clear();
+ }
+
+ private void initSingletons() {
+ Collection<BinderImpl<?>> values = new
ArrayList<BinderImpl<?>>(bindings.values());
+ for (BinderImpl<?> binding : values) {
+ binding.createInstances(this);
+ }
+ }
+
+ private void initProviders() {
+ Collection<BinderImpl<?>> values = new
ArrayList<BinderImpl<?>>(bindings.values());
+ for (BinderImpl<?> binding : values) {
+ binding.init(this);
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.Binders#getBinding(org.richfaces.jsr330.Target)
+ */
+ @SuppressWarnings("unchecked")
+ public BinderImpl<?> getBinding(Target type) {
+ if (bindings.containsKey(type)) {
+ return bindings.get(type);
+ } else if (type.isConcrete()) {
+ // Concrete classes can be created without configuration.
+ BinderImpl binding = new BinderImpl(type);
+ binding.to(type.getRawType());
+ binding.init(this);
+ binding.createInstances(this);
+ registerBinding(type, binding);
+ return binding;
+ } else if (type.isProvider()) {
+ return (BinderImpl<?>)
getBinding(type.toProviderTarget()).asProviderBinder();
+ } else {
+ throw new DependencyException("Type " + type + " has not been
registered");
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void inject(Object value) {
+ Target target = Target.create(value.getClass());
+ Provider<?> provider = getBinding(target).getProvider();
+ if (provider instanceof DynamicProvider) {
+ try {
+ ((DynamicProvider) provider).inject(value);
+ } catch (Exception e) {
+ throw new DependencyException("Cannot inject dependencies into
object " + value, e);
+ }
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.InjectorConfig#register(org.richfaces.jsr330.Target)
+ */
+ @SuppressWarnings("unchecked")
+ public <T> Binder<T> register(Target type) {
+ BinderImpl<T> binding = new BinderImpl(type);
+ registerBinding(type, binding);
+ return binding;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.InjectorConfig#register(java.lang.Class,
java.lang.Class)
+ */
+ public <T> Binder<T> register(Class<T> type, Class<?>...
typeArguments) {
+ return register(Target.create(type, typeArguments));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.jsr330.InjectorConfig#register(java.lang.String,
java.lang.Class, java.lang.Class)
+ */
+ public <T> Binder<T> register(String name, Class<T> type,
Class<?>... typeArguments) {
+ return register(Target.create(name, type, typeArguments));
+ }
+
+ private void registerBinding(Target type, BinderImpl<?> binder) {
+ bindings.put(type, binder);
+ }
+}
Deleted: root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-18
18:16:11 UTC (rev 17639)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -1,203 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.jsr330;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Arrays;
-
-import javax.inject.Named;
-import javax.inject.Provider;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class Target {
-
- private static final Class<?>[] EMPTY_TYPES = new Class<?>[]{};
-
- private final String name;
-
- private final Type type;
-
- private Class<?> rawType;
-
- private Type[] actualTypeArguments;
-
- public Target(Type type) {
- this(null,type);
- }
-
- public Target(String name, Type type) {
- this.type = type;
- this.name = name;
- this.rawType = getRawClass(type);
- this.actualTypeArguments = getActualTypeArguments(type);
- }
-
- public static Target create(Class<?> type, Class<?> ...typeArguments) {
- return create(null, type, typeArguments);
- }
-
- public static Target create(String name, Class<?> type, Class<?>
...typeArguments) {
- Target target = new Target(name, type);
- target.actualTypeArguments = typeArguments;
- return target;
- }
-
- public static Target createNamed(Type type, Annotation... annotations) {
- if (null != annotations) {
- for (Annotation annotation : annotations) {
- if (annotation instanceof Named) {
- return new Target(((Named) annotation).value(), type);
- }
- }
-
- }
- return new Target(type);
- }
-
- public Target toProvider() {
- Target target = new Target(name, type);
- target.rawType = Provider.class;
- target.actualTypeArguments = new Type[]{this.type};
- return target;
- }
-
- public Target toProviderTarget(){
- if(isProvider()){
- return new Target(name,this.actualTypeArguments[0]);
- } else {
- throw new DependencyException("Type "+this+" not is a Provider
type");
- }
- }
-
- public boolean isProvider(){
- return Provider.class.isAssignableFrom(rawType) &&
(1==actualTypeArguments.length);
- }
-
- public boolean isConcrete() {
- return !Modifier.isAbstract((getRawType()).getModifiers());
- }
-
- public Class<?> 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(this.actualTypeArguments);
- result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
- result = prime * result + ((this.rawType == null) ? 0 :
this.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;
- }
- Target other = (Target) obj;
- if (!Arrays.equals(this.actualTypeArguments, other.actualTypeArguments)) {
- return false;
- }
- if (this.name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!this.name.equals(other.name)) {
- return false;
- }
- if (!this.rawType.equals(other.rawType)) {
- return false;
- }
- return true;
- }
-
- public static Type[] getActualTypeArguments(Type type) {
- if(type instanceof Class<?>){
- return EMPTY_TYPES;
- } else if(type instanceof ParameterizedType){
- return ((ParameterizedType) type).getActualTypeArguments();
- } else {
- throw new DependencyException("Unknown type "+type);
- }
- }
-
- public static Class<?> getRawClass(Type type){
- if(type instanceof Class<?>){
- return (Class<?>)type;
- } else if(type instanceof ParameterizedType){
- return getRawClass(((ParameterizedType) type).getRawType());
- } else {
- throw new DependencyException("Unknown type "+type);
- }
-
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the actualTypeArguments
- */
- public Type[] getActualTypeArguments() {
- return this.actualTypeArguments;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append(rawType.getName());
- if(getActualTypeArguments().length>0){
- builder.append("< ");
- for (Type argument : getActualTypeArguments()) {
- builder.append(getRawClass(argument).getSimpleName()).append('
');
- }
- builder.append('>');
- }
- if(null != name){
- builder.append(" :").append(name);
- }
- return builder.toString();
- }
-}
Copied: root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java
(from rev 17640,
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Target.java)
===================================================================
--- root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-19
00:01:14 UTC (rev 17641)
@@ -0,0 +1,210 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.jsr330;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+
+import javax.inject.Named;
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class Target {
+
+ private static final Class<?>[] EMPTY_TYPES = new Class<?>[]{};
+
+ private final String name;
+
+ private final Type type;
+
+ private final Class<?> rawType;
+
+ private Type[] actualTypeArguments;
+
+ public Target(Type type) {
+ this(null,type);
+ }
+
+ public Target(String name, Type type) {
+ this.type = type;
+ this.name = name;
+ this.rawType = getRawClass(type);
+ this.actualTypeArguments = getActualTypeArguments(type);
+ }
+
+ public static Target create(Class<?> type, Class<?> ...typeArguments) {
+ return create(null, type, typeArguments);
+ }
+
+ public static Target create(String name, Class<?> type, Class<?>
...typeArguments) {
+ Target target = new Target(name, type);
+ target.actualTypeArguments = typeArguments;
+ return target;
+ }
+
+ public static Target createNamed(Type type, Annotation... annotations) {
+ if (null != annotations) {
+ for (Annotation annotation : annotations) {
+ if (annotation instanceof Named) {
+ return new Target(((Named) annotation).value(), type);
+ }
+ }
+
+ }
+ return new Target(type);
+ }
+
+ public Target toProvider() {
+ Target target = new Target(name, Provider.class);
+ target.actualTypeArguments = new Type[]{this.type};
+ return target;
+ }
+
+ public Target toProviderTarget(){
+ if(isProvider()){
+ return new Target(name,this.actualTypeArguments[0]);
+ } else {
+ throw new DependencyException("Type "+this+" not is a Provider
type");
+ }
+ }
+
+ public boolean isProvider(){
+ return Provider.class.isAssignableFrom(rawType) &&
(1==actualTypeArguments.length);
+ }
+
+ public boolean isConcrete() {
+ return !Modifier.isAbstract((getRawType()).getModifiers());
+ }
+
+ public Class<?> 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(this.actualTypeArguments);
+ result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
+ result = prime * result + ((this.rawType == null) ? 0 :
this.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;
+ }
+ Target other = (Target) obj;
+ if (!Arrays.equals(this.actualTypeArguments, other.actualTypeArguments)) {
+ return false;
+ }
+ if (this.name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!this.name.equals(other.name)) {
+ return false;
+ }
+ if (!this.rawType.equals(other.rawType)) {
+ return false;
+ }
+ return true;
+ }
+
+ public static Type[] getActualTypeArguments(Type type) {
+ if(type instanceof Class<?>){
+ return EMPTY_TYPES;
+ } else if(type instanceof ParameterizedType){
+ return ((ParameterizedType) type).getActualTypeArguments();
+ } else {
+ throw new DependencyException("Unknown type "+type);
+ }
+ }
+
+ public static Class<?> getRawClass(Type type){
+ if(type instanceof Class<?>){
+ return (Class<?>)type;
+ } else if(type instanceof ParameterizedType){
+ return getRawClass(((ParameterizedType) type).getRawType());
+ } else {
+ throw new DependencyException("Unknown type "+type);
+ }
+
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the actualTypeArguments
+ */
+ public Type[] getActualTypeArguments() {
+ return this.actualTypeArguments;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(rawType.getName());
+ if(getActualTypeArguments().length>0){
+ builder.append("< ");
+ for (Type argument : getActualTypeArguments()) {
+ builder.append(getRawClass(argument).getSimpleName()).append('
');
+ }
+ builder.append('>');
+ }
+ if(null != name){
+ builder.append(" :").append(name);
+ }
+ return builder.toString();
+ }
+
+ public String toKey() {
+ if(null != name){
+ return name;
+ } else {
+ return toString();
+ }
+ }
+}
Copied: root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330 (from rev
17639, root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330)
Copied: root/core/branches/jsr-330/impl/src/test/resources/META-INF/services (from rev
17639, root/core/branches/jsr-330/jsr330-impl/src/test/resources/META-INF/services)
Modified: root/core/branches/jsr-330/pom.xml
===================================================================
--- root/core/branches/jsr-330/pom.xml 2010-06-18 19:14:03 UTC (rev 17640)
+++ root/core/branches/jsr-330/pom.xml 2010-06-19 00:01:14 UTC (rev 17641)
@@ -39,7 +39,6 @@
<module>bom</module>
<module>parent</module>
<module>api</module>
- <module>jsr330-impl</module>
<module>impl</module>
</modules>