Author: alexsmirnov
Date: 2010-06-18 20:18:43 -0400 (Fri, 18 Jun 2010)
New Revision: 17643
Added:
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjector.java
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
root/core/trunk/impl/src/main/java/org/richfaces/application/CacheProvider.java
root/core/trunk/impl/src/main/java/org/richfaces/application/DefaultModule.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
root/core/trunk/impl/src/test/resources/META-INF/services/
root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List
Removed:
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceReference.java
root/core/trunk/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List
Modified:
root/core/trunk/
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceTracker.java
root/core/trunk/impl/pom.xml
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/trunk/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
Log:
Merged revisions 17590,17598,17627-17629,17632-17633,17640-17641 via svnmerge from
https://svn.jboss.org/repos/richfaces/root/core/branches/jsr-330
.......
r17590 | alexsmirnov | 2010-06-09 17:30:15 -0700 (Wed, 09 Jun 2010) | 1 line
add lightweight jsr-330 implementation
.......
r17598 | alexsmirnov | 2010-06-10 14:35:37 -0700 (Thu, 10 Jun 2010) | 1 line
Fixed Provider binding implementation
.......
r17627 | alexsmirnov | 2010-06-15 13:07:22 -0700 (Tue, 15 Jun 2010) | 1 line
Finish implementation and services loader.
.......
r17628 | alexsmirnov | 2010-06-15 16:29:59 -0700 (Tue, 15 Jun 2010) | 1 line
change serviceTraccker to JSR-330
.......
r17629 | alexsmirnov | 2010-06-15 16:30:51 -0700 (Tue, 15 Jun 2010) | 1 line
add jsr-330 to dependencies
.......
r17632 | alexsmirnov | 2010-06-16 17:23:45 -0700 (Wed, 16 Jun 2010) | 1 line
implement scopes
.......
r17633 | alexsmirnov | 2010-06-16 17:29:54 -0700 (Wed, 16 Jun 2010) | 1 line
fix tests
.......
r17640 | alexsmirnov | 2010-06-18 12:14:03 -0700 (Fri, 18 Jun 2010) | 1 line
set targets and eclipse files to svn:ignore, add new scopes
.......
r17641 | alexsmirnov | 2010-06-18 17:01:14 -0700 (Fri, 18 Jun 2010) | 1 line
merge jsr-330 module to implementation
.......
Property changes on: root/core/trunk
___________________________________________________________________
Name: svnmerge-integrated
- /root/core/branches/jsr-330:1-17588
+ /root/core/branches/jsr-330:1-17642
Deleted:
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
===================================================================
---
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjectionService.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,35 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.application;
-
-import javax.faces.context.FacesContext;
-
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface DependencyInjectionService {
-
- public void inject(FacesContext context, Object bean);
-
-}
Copied:
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjector.java (from
rev 17633,
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjector.java)
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjector.java
(rev 0)
+++
root/core/trunk/api/src/main/java/org/richfaces/application/DependencyInjector.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,41 @@
+/*
+ * $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.application;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface DependencyInjector {
+
+ public <T> T create(Class<T> type);
+
+ public <T> T create(Class<T> type,String name);
+
+ public void inject(Object value);
+
+ public void destroy();
+
+}
Deleted:
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceReference.java
===================================================================
---
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceReference.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceReference.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.application;
-
-/**
- * <p>
- * This interface is coupled with {@link ServiceTracker} class and provides reference to
service implementation,
- * allowing delayed service initialization.
- * </p>
- *
- * <p>Methods provided by this interface are expected to be called from multiple
concurrent threads
- * without any synchronization aids.</p>
- *
- * @author Nick Belaevski
- * @since 4.0
- */
-public interface ServiceReference<T> {
-
- /**
- * <p>Returns instance of service referenced by <code>this</code>
object.</p>
- *
- * <p>Calling this method can cause delayed initialization of service.
- * Clients of this class are not expected to store returned service implementation
object,
- * so storing reference to the created service object to avoid repeated
initialization is the
- * sole responsibility of this class.</p>
- *
- * @return referenced service implementation object
- */
- public T getService();
-
-}
Modified: root/core/trunk/api/src/main/java/org/richfaces/application/ServiceTracker.java
===================================================================
---
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceTracker.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/api/src/main/java/org/richfaces/application/ServiceTracker.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -21,262 +21,113 @@
*/
package org.richfaces.application;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+import javax.faces.FacesException;
import javax.faces.context.FacesContext;
/**
* <p>Tracker class to provide access to various framework implementation
services.
* Examples of such services are: {@link org.richfaces.skin.SkinFactory}, TBD.</p>
*
- * <p>Supports either direct placement of service implementation instances or lazy
- * initialization via {@link ServiceReference} interface.</p>
+ * <p>Supports JSR-330 dependency injection.</p>
*
- * <p>This class represents application-scoped object that is replicated into
attributes
- * of {@link FacesContext} during runtime for better performance.</p>
+ * <p>This class represents application-scoped object that is stored in the map
with {@link Thread#currentThread()} Context classloader. Therefore, there is
+ * only one instance perr JEE application in the current JVM.</p>
*
- * <p>No modifications operations are allowed after {@link ServiceTracker} is
locked,
- * and {@link IllegalStateException} is throws in this case.</p>
*
* <p><b>Note:</b> in initial state this class is not synchronized and
presumes that all
* modification operations are done in a context of single-thread (in JSF initialization
listener).
- * In locked state read operations can be called from multiple threads concurrently
without no need
- * to synchronize explicitly.</p>
+ * </p>
*
* @author Nick Belaevski
* @since 4.0
*/
public final class ServiceTracker {
-
- private static final String SERVICE_TRACKER_ATTRIBUTE =
ServiceTracker.class.getName();
-
- private volatile Map<Class<?>, Object> servicesMap = new
HashMap<Class<?>, Object>();
- private final Date startTime = new Date();
-
- private final ConcurrentMap<Object, Object> concurrentStorage = new
ConcurrentHashMap<Object, Object>();
-
- private ServiceTracker() {
- //utility class private constructor
- }
-
- private <T> T get(Class<T> serviceClass) {
- Object serviceImplementation = null;
- Object serviceObject = servicesMap.get(serviceClass);
-
- if (serviceObject instanceof ServiceReference<?>) {
- serviceImplementation = ((ServiceReference<?>)
serviceObject).getService();
- } else {
- serviceImplementation = serviceObject;
+ private static final class Service {
+ final DependencyInjector injector;
+ final Date startTime = new Date();
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param injector
+ */
+ public Service(DependencyInjector injector) {
+ this.injector = injector;
}
-
- //TODO - null?
- return serviceClass.cast(serviceImplementation);
- }
-
- private void put(Class<?> key, Object value) {
- try {
- servicesMap.put(key, value);
- } catch (UnsupportedOperationException e) {
- throw new IllegalStateException("Service tracker is locked, no
modification operation is allowed!");
- }
}
- private Collection<Class<?>> getRegisteredServiceClasses() {
- return Collections.unmodifiableCollection(servicesMap.keySet());
- }
-
- private synchronized void lockModification() {
- servicesMap = Collections.unmodifiableMap(servicesMap);
- }
-
/**
- * Returns unmodifiable collection of registered service classes.
- *
- * @param context current instance of {@link FacesContext}
- * @return collection of registered service classes
- *
- * @throws NullPointerException if <code>context</code> is
<code>null</code>
+ * <p class="changed_added_4_0">
+ * </p>
*/
- public static Collection<Class<?>>
getRegisteredServiceClasses(FacesContext context) {
- if (context == null) {
- throw new NullPointerException("context");
- }
+ private static final Map<ClassLoader, Service> INSTANCES =
+ new ConcurrentHashMap<ClassLoader, Service>();
- ServiceTracker serviceTracker = getServiceTracker(context);
- return serviceTracker.getRegisteredServiceClasses();
+ private ServiceTracker() {
}
- /**
- * Lookup registered service implementation by service class.
- *
- * @param context current instance of {@link FacesContext}
- * @param serviceClass class for which implementation has been registered.
- * @return registered implementation or <code>null</code>
- *
- * @throws NullPointerException if <code>context</code> or
<code>serviceClass</code> is <code>null</code>
- */
- public static <T> T getService(FacesContext context, Class<T>
serviceClass) {
- if (context == null) {
- throw new NullPointerException("context");
- }
+ public static <T> T getService(Class<T> target,String name) {
+ return getInjector().create(target,name);
+ }
- if (serviceClass == null) {
- throw new NullPointerException("serviceClass");
- }
+ public static <T> T getService(Class<T> target) {
+ return getInjector().create(target);
+ }
- ServiceTracker serviceTracker = getServiceTracker(context);
- return serviceTracker.get(serviceClass);
+ public static <T> T getService(FacesContext context, Class<T> target) {
+ return getInjector().create(target);
}
/**
- * Registers service implementation for the given service class.
- *
- * @param context current instance of {@link FacesContext}
- * @param serviceClass class for which implementation is to be registered
- * @param serviceImplementation service implementation
- *
- * @throws NullPointerException if <code>context</code>,
<code>serviceClass</code> or
- * <code>serviceImplementation</code> is <code>null</code>
- * @throws IllegalStateException if current {@link ServiceTracker} is in locked
state.
+ * <p class="changed_added_4_0">Inject dependencies to the object
instance.</p>
+ * @param value
*/
- public static <T> void setService(FacesContext context,
- Class<T> serviceClass,
- T serviceImplementation) {
+ public static void inject(Object value){
+ getInjector().inject(value);
+ }
+
+ private static DependencyInjector getInjector() {
+ Service service = getCurrentService();
- if (context == null) {
- throw new NullPointerException("context");
- }
+ return service.injector;
+ }
- if (serviceClass == null) {
- throw new NullPointerException("serviceClass");
+ private static Service getCurrentService() {
+ if(!INSTANCES.containsKey(getCurrentLoader())){
+ throw new FacesException("Service Traccker has not been
initialized");
}
-
- if (serviceImplementation == null) {
- throw new NullPointerException("serviceImplementation");
- }
-
- ServiceTracker serviceTracker = getServiceTracker(context);
- serviceTracker.put(serviceClass, serviceImplementation);
+ Service service = INSTANCES.get(getCurrentLoader());
+ return service;
}
- /**
- * Registers {@link ServiceReference} for the given service class.
- *
- * @param context current instance of {@link FacesContext}
- * @param serviceClass class for which reference is to be registered
- * @param serviceReference instance of service reference
- *
- * @throws NullPointerException if <code>context</code>,
<code>serviceClass</code> or
- * <code>serviceReference</code> is <code>null</code>
- * @throws IllegalStateException if current {@link ServiceTracker} is in locked
state.
- */
- public static <T> void setServiceReference(FacesContext context,
- Class<T> serviceClass,
- ServiceReference<T> serviceReference) {
-
- if (context == null) {
- throw new NullPointerException("context");
+ private static ClassLoader getCurrentLoader() {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (null == contextClassLoader) {
+ contextClassLoader = ServiceTracker.class.getClassLoader();
}
-
- if (serviceClass == null) {
- throw new NullPointerException("serviceClass");
- }
-
- if (serviceReference == null) {
- throw new NullPointerException("serviceReference");
- }
-
- ServiceTracker serviceTracker = getServiceTracker(context);
- serviceTracker.put(serviceClass, serviceReference);
+ return contextClassLoader;
}
/**
- * <p>Releases application-scoped {@link ServiceTracker}.</p>
- * <p>Called during application shutdown; shouldn't be called explicitly by
user.</p>
- *
- * @param context current instance of {@link FacesContext}
+ * <p class="changed_added_4_0">Set dependency injection service
implementation.</p>
+ * @param injector
*/
- public static void release(FacesContext context) {
- removeServiceTracker(context);
+ public static void setInjector(DependencyInjector injector) {
+ INSTANCES.put(getCurrentLoader(), new Service(injector));
}
-
- /**
- * <p>Switches application-scoped {@link ServiceTracker} to locked state,
preventing further modifications
- * of registered services via {@link #setService(FacesContext, Class, Object)} or
- * {@link #setServiceReference(FacesContext, Class, ServiceReference)}
methods.</p>
- *
- * <p>Called at the beginning of the very first application request life cycle;
shouldn't be called explicitly
- * by user.</p>
- *
- * @param context current instance of {@link FacesContext}
- */
- public static void lockModification(FacesContext context) {
- ServiceTracker serviceTracker = getServiceTracker(context);
- serviceTracker.lockModification();
- }
/**
- * Returns {@link ServiceTracker} instantiation time. Corresponds to application
initialization time.
- *
- * @param context
- * @return instantiation time
+ * <p class="changed_added_4_0">Remove dependency injection service
associated with current context.</p>
*/
- public static Date getStartTime(FacesContext context) {
- return getServiceTracker(context).startTime;
+ public static void release() {
+ INSTANCES.remove(getCurrentLoader());
}
-
- /**
- * Returns {@link ConcurrentMap} stored in {@link ServiceTracker}. This map is
intended
- * to be used as fast application-scoped storage.
- *
- * @param context
- * @return
- */
- public static ConcurrentMap<Object, Object> getConcurrentStorage(FacesContext
context) {
- return getServiceTracker(context).concurrentStorage;
- }
-
- private static ServiceTracker getServiceTrackerFromApplicationMap(FacesContext
facesContext) {
- Object appContext = facesContext.getExternalContext().getContext();
-
- synchronized (appContext) {
- ServiceTracker serviceTracker;
- Map<String, Object> applicationMap =
facesContext.getExternalContext().getApplicationMap();
- serviceTracker = (ServiceTracker)
applicationMap.get(SERVICE_TRACKER_ATTRIBUTE);
- if (serviceTracker == null) {
- serviceTracker = new ServiceTracker();
- applicationMap.put(SERVICE_TRACKER_ATTRIBUTE, serviceTracker);
- }
-
- return serviceTracker;
- }
-
- }
-
- private static ServiceTracker getServiceTracker(FacesContext facesContext) {
- ServiceTracker serviceTracker = (ServiceTracker)
facesContext.getAttributes().get(SERVICE_TRACKER_ATTRIBUTE);
- if (serviceTracker == null) {
- serviceTracker = getServiceTrackerFromApplicationMap(facesContext);
-
- //replicate in FacesContext map for better performance
- facesContext.getAttributes().put(SERVICE_TRACKER_ATTRIBUTE, serviceTracker);
- }
-
- return serviceTracker;
+ public static Date getStartTime(FacesContext context) {
+ return getCurrentService().startTime;
}
- private static void removeServiceTracker(FacesContext facesContext) {
- Map<String, Object> applicationMap =
facesContext.getExternalContext().getApplicationMap();
- applicationMap.remove(SERVICE_TRACKER_ATTRIBUTE);
-
- facesContext.getAttributes().remove(SERVICE_TRACKER_ATTRIBUTE);
- }
}
Deleted:
root/core/trunk/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java
===================================================================
---
root/core/trunk/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,173 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.application;
-
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-import javax.servlet.ServletContext;
-
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class ServiceTrackerTest {
-
- private MockFacesEnvironment environment;
-
- private FacesContext context;
-
- private ServletContext servletContext;
-
- private Map<String, Object> applicationMap;
-
- private Map<Object, Object> contextMap;
-
- private SkinServiceImpl skinServiceImpl;
-
- private ConfigServiceImpl configServiceImpl;
-
- private ConfigServiceReferenceImpl configServiceReference;
-
- private static interface SkinService {};
-
- private static class SkinServiceImpl implements SkinService {}
-
- private static interface ConfigService {};
-
- private static class ConfigServiceReferenceImpl implements
ServiceReference<ConfigService> {
-
- private ConfigService service;
-
- public ConfigServiceReferenceImpl(ConfigService service) {
- super();
- this.service = service;
- }
-
- public ConfigService getService() {
- return service;
- }
- }
-
- private static class ConfigServiceImpl implements ConfigService {}
-
- private void setupRequestObjects() {
-
expect(environment.getExternalContext().getApplicationMap()).andStubReturn(applicationMap);
-
expect(environment.getExternalContext().getContext()).andStubReturn(servletContext);
-
- contextMap = new HashMap<Object, Object>();
- expect(environment.getFacesContext().getAttributes()).andStubReturn(contextMap);
- }
-
- @Before
- public void setUp() throws Exception {
- skinServiceImpl = new SkinServiceImpl();
- configServiceImpl = new ConfigServiceImpl();
- configServiceReference = new ConfigServiceReferenceImpl(configServiceImpl);
-
- environment = MockFacesEnvironment.createEnvironment().withExternalContext();
- context = environment.getFacesContext();
-
- applicationMap = new HashMap<String, Object>();
- servletContext = environment.createMock(ServletContext.class);
-
- setupRequestObjects();
- }
-
- @After
- public void tearDown() throws Exception {
- skinServiceImpl = null;
- configServiceImpl = null;
- configServiceReference = null;
-
- context = null;
- applicationMap = null;
- contextMap = null;
-
- environment.verify();
- environment.release();
- environment = null;
- }
-
- @Test
- public void testBasic() throws Exception {
- environment.replay();
-
- ServiceTracker.setService(context, SkinService.class, skinServiceImpl);
- ServiceTracker.setServiceReference(context, ConfigService.class,
configServiceReference);
-
- ServiceTracker.lockModification(context);
-
- Collection<Class<?>> serviceClasses =
ServiceTracker.getRegisteredServiceClasses(context);
- assertFalse(serviceClasses.isEmpty());
-
- assertTrue(serviceClasses.contains(SkinService.class));
- assertTrue(serviceClasses.contains(ConfigService.class));
-
- assertSame(skinServiceImpl, ServiceTracker.getService(context,
SkinService.class));
- assertSame(configServiceImpl, ServiceTracker.getService(context,
ConfigService.class));
-
- environment.reset();
- setupRequestObjects();
- environment.replay();
-
- serviceClasses = ServiceTracker.getRegisteredServiceClasses(context);
- assertFalse(serviceClasses.isEmpty());
-
- assertTrue(serviceClasses.contains(SkinService.class));
- assertTrue(serviceClasses.contains(ConfigService.class));
-
- assertSame(skinServiceImpl, ServiceTracker.getService(context,
SkinService.class));
- assertSame(configServiceImpl, ServiceTracker.getService(context,
ConfigService.class));
-
- ServiceTracker.release(context);
- }
-
- @Test
- public void testLockModifications() throws Exception {
- environment.replay();
-
- ServiceTracker.lockModification(context);
-
- try {
- ServiceTracker.setService(context, SkinService.class, skinServiceImpl);
-
- fail();
- } catch (IllegalStateException e) {
- }
-
- ServiceTracker.release(context);
- }
-}
\ No newline at end of file
Modified: root/core/trunk/impl/pom.xml
===================================================================
--- root/core/trunk/impl/pom.xml 2010-06-19 00:07:09 UTC (rev 17642)
+++ root/core/trunk/impl/pom.xml 2010-06-19 00:18:43 UTC (rev 17643)
@@ -1,157 +1,159 @@
- <!--
- JBoss, Home of Professional Open Source Copyright 2010, Red Hat,
- Inc. and individual contributors by the @authors tag. See the
- copyright.txt in the distribution for a full listing of
- individual contributors. This is free software; you can
- redistribute it and/or modify it under the terms of the GNU
- Lesser General Public License as published by the Free Software
- Foundation; either version 2.1 of the License, or (at your
- option) any later version. This software 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 software; if not,
- write to the Free Software Foundation, Inc., 51 Franklin St,
- Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site:
-
http://www.fsf.org.
- -->
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <!--
+ JBoss, Home of Professional Open Source Copyright 2010, Red Hat, Inc.
+ and individual contributors by the @authors tag. See the copyright.txt
+ in the distribution for a full listing of individual contributors.
+ This is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2.1 of the License, or (at
+ your option) any later version. This software 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 software; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ USA, or see the FSF site:
http://www.fsf.org.
+ -->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-parent</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath>../parent/pom.xml</relativePath>
- </parent>
+ <parent>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-parent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-impl</artifactId>
- <name>RichFaces Core Implementation</name>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-impl</artifactId>
+ <name>RichFaces Core Implementation</name>
- <description>
+ <description>
The RichFaces Core Implementation.
</description>
- <dependencies>
- <!-- Runtime Dependencies -->
- <dependency>
- <groupId>org.richfaces.core</groupId>
- <artifactId>richfaces-core-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.richfaces.commons</groupId>
- <artifactId>richfaces-commons-api</artifactId>
- </dependency>
- <dependency>
- <groupId>net.sourceforge.cssparser</groupId>
- <artifactId>cssparser</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
+ <dependencies>
+ <!-- Runtime Dependencies -->
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.commons</groupId>
+ <artifactId>richfaces-commons-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.cssparser</groupId>
+ <artifactId>cssparser</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ </dependency>
- <!-- Provided Dependencies -->
- <dependency>
- <groupId>${jsf2.api.groupid}</groupId>
- <artifactId>${jsf2.api.artifactid}</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.el</groupId>
- <artifactId>el-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet.jsp</groupId>
- <artifactId>jsp-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- <scope>provided</scope>
- </dependency>
+ <!-- Provided Dependencies -->
+ <dependency>
+ <groupId>${jsf2.api.groupid}</groupId>
+ <artifactId>${jsf2.api.artifactid}</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <scope>provided</scope>
+ </dependency>
- <!-- Cache Impls -->
- <dependency>
- <groupId>org.jboss.cache</groupId>
- <artifactId>jbosscache-core</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>opensymphony</groupId>
- <artifactId>oscache</artifactId>
- <optional>true</optional>
- </dependency>
+ <!-- Cache Impls -->
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>opensymphony</groupId>
+ <artifactId>oscache</artifactId>
+ <optional>true</optional>
+ </dependency>
- <!-- Test Dependencies -->
- <dependency>
- <groupId>org.jboss.test-jsf</groupId>
- <artifactId>htmlunit-client</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.test-jsf</groupId>
- <artifactId>jsf-mock</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymockclassextension</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${jsf2.impl.groupid}</groupId>
- <artifactId>${jsf2.impl.artifactid}</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>htmlunit-client</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test-jsf</groupId>
+ <artifactId>jsf-mock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${jsf2.impl.groupid}</groupId>
+ <artifactId>${jsf2.impl.artifactid}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <build>
+ <build>
- <plugins>
- <!--
- TODO Centralize this because calendar and context menu
- use this too
- Note: This may be removed by redisgn
- -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>javacc-maven-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>javacc</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
+ <plugins>
+ <!--
+ TODO Centralize this because calendar and context menu use this too
+ Note: This may be removed by redisgn
+ -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
+ <artifactId>javacc-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>javacc</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
@@ -180,81 +182,80 @@
</archive>
</configuration>
</plugin>
- </plugins>
- </build>
+ </plugins>
+ </build>
- <profiles>
- <profile>
- <id>release</id>
- <!-- TODO need to centralize - need to research first -->
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <configuration>
- <javadocVersion>1.5</javadocVersion>
- <aggregate>true</aggregate>
- </configuration>
- <executions>
- <execution>
- <id>generate-javadoc</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <!--
- TODO - this can go to central, but should
- check settings. This is also related to docs
- so perhaps add to a doc profile Configure
- JavaScript Doc Tool
- -->
- <groupId>gr.abiss.mvn.plugins</groupId>
- <artifactId>maven-jstools-plugin</artifactId>
- <executions>
- <execution>
- <id>jsdoc</id>
- <configuration>
-
<jsDir>${basedir}/src/main/resources/META-INF/resources</jsDir>
- <includes>**/*.js</includes>
- <caseSensitive>true</caseSensitive>
- </configuration>
- <goals>
- <goal>jsdoc</goal>
- </goals>
- <phase>process-sources</phase>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <!-- pack jsdoc to jar -->
- <artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <id>pack-jsodcs</id>
- <phase>package</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
-
<classesDirectory>${basedir}/target/site/jsdoc</classesDirectory>
- <classifier>jsdoc</classifier>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <scm>
-
<
connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/root/core/...
-
<
developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root...
-
<
url>http://fisheye.jboss.org/browse/richfaces/root/core/trunk/impl<...
- </scm>
+ <profiles>
+ <profile>
+ <id>release</id>
+ <!-- TODO need to centralize - need to research first -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <javadocVersion>1.5</javadocVersion>
+ <aggregate>true</aggregate>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-javadoc</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!--
+ TODO - this can go to central, but should check settings. This is
+ also related to docs so perhaps add to a doc profile Configure
+ JavaScript Doc Tool
+ -->
+ <groupId>gr.abiss.mvn.plugins</groupId>
+ <artifactId>maven-jstools-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jsdoc</id>
+ <configuration>
+ <jsDir>${basedir}/src/main/resources/META-INF/resources</jsDir>
+ <includes>**/*.js</includes>
+ <caseSensitive>true</caseSensitive>
+ </configuration>
+ <goals>
+ <goal>jsdoc</goal>
+ </goals>
+ <phase>process-sources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- pack jsdoc to jar -->
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>pack-jsodcs</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classesDirectory>${basedir}/target/site/jsdoc</classesDirectory>
+ <classifier>jsdoc</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <scm>
+ <
connection>scm:svn:http://anonsvn.jboss.org/repos/richfaces/root/core/...
+ <
developerConnection>scm:svn:https://svn.jboss.org/repos/richfaces/root...
+ <
url>http://fisheye.jboss.org/browse/richfaces/root/core/trunk/impl<...
+ </scm>
</project>
\ No newline at end of file
Modified:
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -190,13 +190,13 @@
return ("true".equalsIgnoreCase(stringValue) ||
"yes".equalsIgnoreCase(stringValue));
}
- private static ConcurrentMap<Object, Object> getExpressionsMap(FacesContext
context) {
- ConcurrentMap<Object, Object> concurrentStorage =
ServiceTracker.getConcurrentStorage(context);
+ private static InitParametersStorage getExpressionsMap(FacesContext context) {
+ InitParametersStorage concurrentStorage =
ServiceTracker.getService(InitParametersStorage.class);
return concurrentStorage;
}
private static String evaluateInitParameter(FacesContext context, String
parameterName) {
- ConcurrentMap<Object, Object> expressionsMap = getExpressionsMap(context);
+ InitParametersStorage expressionsMap = getExpressionsMap(context);
String parameterKey = INIT_PARAM_PREFIX + parameterName;
Object parameterValue = expressionsMap.get(parameterKey);
Copied: root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
(from rev 17633,
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,52 @@
+/*
+ * $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.ajax4jsf.context;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.inject.Singleton;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@Singleton
+public class InitParametersStorage {
+
+ ConcurrentMap<String,Object> storage = new ConcurrentHashMap<String,
Object>(5);
+
+ public Object get(String key){
+ return storage.get(key);
+ }
+
+ public Object put(String key,Object value) {
+ return storage.put(key, value);
+ }
+
+ public boolean containsKey(String key) {
+ return storage.containsKey(key);
+ }
+}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/application/CacheProvider.java
(from rev 17633,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/CacheProvider.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/application/CacheProvider.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/CacheProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,70 @@
+/*
+ * $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.application;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.inject.Provider;
+
+import org.ajax4jsf.cache.Cache;
+import org.ajax4jsf.cache.CacheManager;
+import org.richfaces.jsr330.Binders;
+import org.richfaces.jsr330.Initializable;
+import org.richfaces.resource.ResourceHandlerImpl;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+
+public class CacheProvider implements Provider<Cache>, Initializable {
+
+ private Cache instance;
+ private CacheManager cacheManager;
+
+ /* (non-Javadoc)
+ * @see org.richfaces.jsr330.Initializable#destroy()
+ */
+ public void destroy() {
+ cacheManager.destroy();
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.jsr330.Initializable#init(org.richfaces.jsr330.Binders)
+ */
+ public boolean init(Binders injectorImpl) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ cacheManager = new CacheManager();
+ Map<?, ?> envMap =
facesContext.getExternalContext().getInitParameterMap();
+ instance = cacheManager.createCache(facesContext,
ResourceHandlerImpl.RESOURCE_CACHE_NAME, envMap);
+ return true; // Cache is singleton.
+ }
+
+ public Cache get() {
+ return instance;
+ }
+
+}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/application/DefaultModule.java
(from rev 17633,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DefaultModule.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/application/DefaultModule.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,21 @@
+package org.richfaces.application;
+
+import org.ajax4jsf.cache.Cache;
+import org.ajax4jsf.renderkit.AJAXDataSerializer;
+import org.richfaces.jsr330.Module;
+import org.richfaces.jsr330.InjectorConfig;
+import org.richfaces.resource.DefaultResourceCodec;
+import org.richfaces.resource.ResourceCodec;
+import org.richfaces.skin.SkinFactory;
+import org.richfaces.skin.SkinFactoryImpl;
+
+public class DefaultModule implements Module {
+
+ public void configure(InjectorConfig injector) {
+ injector.register(SkinFactory.class).to(SkinFactoryImpl.class).asSingleton();
+
injector.register(AJAXDataSerializer.class).to(AJAXDataSerializer.class).asSingleton();
+
injector.register(ResourceCodec.class).toService(DefaultResourceCodec.class).asSingleton();
+ injector.register(Cache.class).toProviderInstance(new CacheProvider());
+ }
+
+}
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,373 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.application;
-
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.text.MessageFormat;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.el.ExpressionFactory;
-import javax.el.ValueExpression;
-import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.resource.PostConstructResource;
-import org.richfaces.resource.ResourceParameter;
-import org.richfaces.resource.ResourceParameterELResolver;
-import org.slf4j.Logger;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class DependencyInjectionServiceImpl implements DependencyInjectionService {
-
- private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
-
- private abstract static class Injector<T extends Annotation> {
-
- private PropertyDescriptor propertyDescriptor;
-
- private T dependency;
-
- public Injector(PropertyDescriptor propertyDescriptor, T dependency) {
- super();
- this.propertyDescriptor = propertyDescriptor;
- this.dependency = dependency;
- }
-
- protected T getDependency() {
- return dependency;
- }
-
- protected PropertyDescriptor getPropertyDescriptor() {
- return propertyDescriptor;
- }
-
- protected abstract Object evaluateProperty(FacesContext context, Class<?>
propertyType);
-
- public void inject(FacesContext context, Object bean) throws
IllegalArgumentException, IllegalAccessException,
- InvocationTargetException {
-
- Method writeMethod = propertyDescriptor.getWriteMethod();
-
- if (writeMethod != null) {
- writeMethod.invoke(bean, evaluateProperty(context,
propertyDescriptor.getPropertyType()));
- } else {
- throw new IllegalStateException(
- MessageFormat.format("Write method for property {0} doesn't
exist", propertyDescriptor.getName()));
- }
- }
-
- }
-
- private static final class PropertyDependencyInjector extends
Injector<ResourceParameter> {
-
- public PropertyDependencyInjector(PropertyDescriptor propertyDescriptor,
ResourceParameter dependency) {
- super(propertyDescriptor, dependency);
- }
-
- private Object getExpressionValue(FacesContext context, String expressionString,
Class<?> expectedType) {
- ExpressionFactory expressionFactory =
context.getApplication().getExpressionFactory();
- ValueExpression expression =
expressionFactory.createValueExpression(context.getELContext(),
- expressionString, expectedType);
- return expression.getValue(context.getELContext());
- }
-
- protected Object evaluateProperty(FacesContext context, Class<?>
propertyType) {
- Class<?> expectedType;
- if (!propertyType.isPrimitive()) {
- expectedType = Object.class;
- } else {
- expectedType = propertyType;
- }
-
- ResourceParameter resourceParameter = getDependency();
-
- String expression = resourceParameter.expression();
- String name = resourceParameter.name();
-
- if (expression.length() != 0 && name.length() != 0) {
- throw new IllegalStateException(MessageFormat.format(
- "'name' and 'expression' should not be specified
simultaneously: {0}",
- resourceParameter));
- }
-
- Object propertyValue = null;
- if (expression.length() != 0) {
- propertyValue = getExpressionValue(context, expression, expectedType);
- } else {
- if (name.length() == 0) {
- name = getPropertyDescriptor().getName();
- }
-
- Map<String, Object> parameters = (Map<String, Object>)
context.getAttributes().get(
- ResourceParameterELResolver.CONTEXT_ATTRIBUTE_NAME);
-
- propertyValue = parameters.get(name);
- }
-
- if (propertyValue == null || "".equals(propertyValue)) {
- String defaultValue = resourceParameter.defaultValue();
- if (defaultValue != null && defaultValue.length() != 0) {
- propertyValue = getExpressionValue(context, defaultValue,
expectedType);
- }
- }
-
- if (!propertyType.isPrimitive() && propertyValue != null) {
- propertyValue =
context.getApplication().getExpressionFactory().coerceToType(propertyValue,
propertyType);
- }
-
- return propertyValue;
- }
- }
-
- private static final class IntrospectionData {
-
- private Method postConstructMethod = null;
-
- private Map<String, Injector<?>> injectorsMap = null;
-
- public Map<String, Injector<?>> getInjectorsMap() {
- if (injectorsMap != null) {
- return injectorsMap;
- }
-
- return Collections.emptyMap();
- }
-
- public void addInjector(String propertyName, Injector<?> injector) {
- if (injectorsMap == null) {
- injectorsMap = new HashMap<String, Injector<?>>();
- }
-
- injectorsMap.put(propertyName, injector);
- }
-
- public Method getPostConstructMethod() {
- return postConstructMethod;
- }
-
- public void setPostConstructMethod(Method postConstructMethod) {
- this.postConstructMethod = postConstructMethod;
- }
- }
-
- private ConcurrentMap<Class<?>, IntrospectionData> classesCache = new
ConcurrentHashMap<Class<?>, IntrospectionData>();
-
- private void invokeMethod(Object bean, Method method) throws
IllegalArgumentException, IllegalAccessException,
- InvocationTargetException {
-
- if (method != null) {
- method.setAccessible(true);
- method.invoke(bean);
- }
- }
-
- private boolean isUncheckedException(Class<?> type) {
- // JLS 2nd edition - 11.2 Compile-Time Checking of Exceptions
- return RuntimeException.class.isAssignableFrom(type) ||
Error.class.isAssignableFrom(type);
- }
-
- private void verifyPostConstructMethod(Method method) {
- if (method.getParameterTypes().length != 0) {
- throw new IllegalStateException(
- MessageFormat.format("Post-construction method {0} has one or more
parameters", method.toString()));
- }
-
- if (!Void.TYPE.equals(method.getReturnType())) {
- throw new IllegalStateException(
- MessageFormat.format("Post-construction method {0} has incorrect
return type", method.toString()));
- }
-
- if ((method.getModifiers() & Modifier.STATIC) != 0) {
- throw new IllegalStateException(
- MessageFormat.format("Post-construction method {0} is static",
method.toString()));
- }
-
- Class<?>[] exceptionTypes = method.getExceptionTypes();
- for (Class<?> exceptionType : exceptionTypes) {
- if (isUncheckedException(exceptionType)) {
- continue;
- }
-
- throw new IllegalStateException(
- MessageFormat.format("Post-construction method {0} throws checked
exception", method.toString()));
- }
- }
-
- private void inspectMethod(Method method, Class<? extends Annotation>
annotationClass,
- IntrospectionData introspectionData) {
-
- Annotation annotation = method.getAnnotation(annotationClass);
- if (annotation != null) {
- verifyPostConstructMethod(method);
-
- if (introspectionData.getPostConstructMethod() != null) {
- throw new IllegalStateException(
- MessageFormat.format("There are two conflicting
post-construction methods: {0} and {1}",
- method.toString(),
introspectionData.getPostConstructMethod().toString()));
- }
-
- introspectionData.setPostConstructMethod(method);
- }
- }
-
- private void locatePostConstructMethods(Class<?> clazz, IntrospectionData
introspectionData) {
- Method[] methods = clazz.getDeclaredMethods();
- for (Method method : methods) {
- inspectMethod(method, PostConstructResource.class, introspectionData);
- }
-
- Class<?> superclass = clazz.getSuperclass();
- if (!Object.class.equals(superclass)) {
- locatePostConstructMethods(superclass, introspectionData);
- }
- }
-
- private void locateManagedPropertyFields(Class<?> clazz, Map<String,
ResourceParameter> fieldsMap) {
- Field[] fields = clazz.getDeclaredFields();
- for (Field field : fields) {
- ResourceParameter dependency = field.getAnnotation(ResourceParameter.class);
-
- if (dependency != null) {
- String propertyName = field.getName();
-
- if (!fieldsMap.containsKey(propertyName)) {
- fieldsMap.put(propertyName, dependency);
- }
- }
- }
-
- Class<?> superclass = clazz.getSuperclass();
- if (!Object.class.equals(superclass)) {
- locateManagedPropertyFields(superclass, fieldsMap);
- }
- }
-
- private <T extends Annotation> T getAnnotation(PropertyDescriptor descriptor,
Class<T> annotationClass) {
- T annotation = null;
-
- Method writeMethod = descriptor.getWriteMethod();
- if (writeMethod != null) {
- annotation = writeMethod.getAnnotation(annotationClass);
- }
-
- if (annotation == null) {
- Method readMethod = descriptor.getReadMethod();
- if (readMethod != null) {
- annotation = readMethod.getAnnotation(annotationClass);
- }
- }
-
- return annotation;
- }
-
- private void locateManagedPropertyDescriptors(Class<?> clazz, IntrospectionData
introspectionData,
- Map<String, ResourceParameter> injectableFields) {
-
- try {
- BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
- if (beanInfo != null) {
- PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
- if (descriptors != null) {
- for (PropertyDescriptor descriptor : descriptors) {
- String propertyName = descriptor.getName();
-
- ResourceParameter dependency =
injectableFields.get(propertyName);
-
- if (dependency == null) {
- dependency = getAnnotation(descriptor,
ResourceParameter.class);
- }
-
- if (dependency != null) {
- Injector<?> injector = new
PropertyDependencyInjector(descriptor, dependency);
- introspectionData.addInjector(propertyName, injector);
- }
- }
- }
- }
- } catch (IntrospectionException e) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(e.getMessage(), e);
- }
- } finally {
- Introspector.flushFromCaches(clazz);
- }
- }
-
- protected IntrospectionData createIntrospectionData(Class<?> beanClass) {
- IntrospectionData introspectionData = new IntrospectionData();
-
- Map<String, ResourceParameter> injectableFields = new HashMap<String,
ResourceParameter>();
- locateManagedPropertyFields(beanClass, injectableFields);
-
- locateManagedPropertyDescriptors(beanClass, introspectionData,
injectableFields);
-
- locatePostConstructMethods(beanClass, introspectionData);
-
- return introspectionData;
- }
-
- public void inject(FacesContext context, Object bean) {
- Class<?> beanClass = bean.getClass();
-
- IntrospectionData introspectionData = classesCache.get(beanClass);
- if (introspectionData == null) {
- introspectionData = createIntrospectionData(beanClass);
- classesCache.put(beanClass, introspectionData);
- }
-
- try {
- Map<String, Injector<?>> injectorsMap =
introspectionData.getInjectorsMap();
- if (!injectorsMap.isEmpty()) {
- for (Injector<?> injector : injectorsMap.values()) {
- injector.inject(context, bean);
- }
- }
-
- Method postConstructMethod = introspectionData.getPostConstructMethod();
- if (postConstructMethod != null) {
- invokeMethod(bean, postConstructMethod);
- }
- } catch (IllegalArgumentException e) {
- throw new FacesException(e.getMessage(), e);
- } catch (IllegalAccessException e) {
- throw new FacesException(e.getMessage(), e);
- } catch (InvocationTargetException e) {
- throw new FacesException(e.getMessage(), e);
- }
- }
-}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/InitializationListener.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -21,34 +21,21 @@
*/
package org.richfaces.application;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
-import java.util.Map;
+import java.util.ArrayList;
import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.PostConstructApplicationEvent;
import javax.faces.event.PreDestroyApplicationEvent;
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
-import org.ajax4jsf.cache.Cache;
-import org.ajax4jsf.cache.CacheManager;
-import org.ajax4jsf.renderkit.AJAXDataSerializer;
-import org.ajax4jsf.resource.util.URLToStreamHelper;
-import org.richfaces.log.RichfacesLogger;
-import org.richfaces.resource.DefaultResourceCodec;
-import org.richfaces.resource.ResourceCodec;
-import org.richfaces.resource.ResourceHandlerImpl;
-import org.richfaces.skin.SkinFactory;
-import org.richfaces.skin.SkinFactoryImpl;
-import org.slf4j.Logger;
+import org.richfaces.jsr330.Module;
+import org.richfaces.jsr330.DependencyException;
+import org.richfaces.jsr330.InjectorImpl;
+import org.richfaces.jsr330.ServiceException;
+import org.richfaces.jsr330.ServiceLoader;
/**
* @author Nick Belaevski
@@ -56,11 +43,6 @@
*/
public class InitializationListener implements SystemEventListener {
- private static final String META_INF_SERVICES = "META-INF/services/";
-
- private static final Logger LOG = RichfacesLogger.APPLICATION.getLogger();
-
- private static final String CACHE_MANAGER_ATTRIBUTE_NAME =
InitializationListener.class.getName() + ":CacheManager";
/* (non-Javadoc)
* @see javax.faces.event.SystemEventListener#isListenerForSource(java.lang.Object)
@@ -69,135 +51,28 @@
return true;
}
- private static <T> T instantiate(Class<T> interfaceClass,
- Class<? extends T> implementationClass,
- Class<? extends T> defaultImplementationClass)
{
+ protected void onStart() {
+ DependencyInjector injector = createInjector();
+ ServiceTracker.setInjector(injector);
+ }
- Constructor<? extends T> constructor = null;
- Object[] constructorArguments = null;
-
- if (implementationClass != null) {
- if (defaultImplementationClass != null &&
!defaultImplementationClass.equals(implementationClass)) {
- try {
- constructor = implementationClass.getConstructor(interfaceClass);
- T defaultImplementation = instantiate(interfaceClass,
defaultImplementationClass, null);
- constructorArguments = new Object[]{defaultImplementation};
- } catch (NoSuchMethodException e) {
- /* ignore */
- }
- }
-
- if (constructor == null) {
- try {
- constructor = implementationClass.getConstructor();
- } catch (NoSuchMethodException e) {
- throw new FacesException(MessageFormat.format("Class {0} has no
public no-arg constructor",
- implementationClass.getName()), e);
- }
- }
-
- } else {
- try {
- constructor = defaultImplementationClass.getConstructor();
- } catch (NoSuchMethodException e) {
- throw new FacesException(MessageFormat.format("Class {0} has no
public no-arg constructor",
- defaultImplementationClass.getName()), e);
- }
- }
-
+ protected DependencyInjector createInjector() {
+ InjectorImpl injector = new InjectorImpl();
+ ArrayList<Module> modules = new ArrayList<Module>();
+ modules.add(new DefaultModule());
try {
- return constructor.newInstance(constructorArguments);
- } catch (IllegalArgumentException e) {
- throw new FacesException(MessageFormat.format("Cannot instantiate {0}
class, error was: {1}",
- constructor.getDeclaringClass(), e.getMessage()), e);
- } catch (InstantiationException e) {
- throw new FacesException(MessageFormat.format("Cannot instantiate {0}
class, error was: {1}",
- constructor.getDeclaringClass(), e.getMessage()), e);
- } catch (IllegalAccessException e) {
- throw new FacesException(MessageFormat.format("Cannot instantiate {0}
class, error was: {1}",
- constructor.getDeclaringClass(), e.getMessage()), e);
- } catch (InvocationTargetException e) {
- Throwable cause = e.getCause();
- if (cause == null) {
- cause = e;
- }
- throw new FacesException(MessageFormat.format("Cannot instantiate {0}
class, error was: {1}",
- constructor.getDeclaringClass(), cause.getMessage()), cause);
+ modules.addAll(ServiceLoader.loadServices(Module.class));
+ injector.init(modules.toArray(new Module[]{}));
+ } catch (ServiceException e) {
+ throw new FacesException(e);
+ } catch (DependencyException e) {
+ throw new FacesException(e);
}
+ return injector;
}
- private static <T> T createServiceInstance(Class<T> interfaceClass,
Class<? extends T> defaultImplementationClass) {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- InputStream input = URLToStreamHelper.urlToStreamSafe(
- loader.getResource(META_INF_SERVICES + interfaceClass.getName()));
-
- Class<? extends T> implementationClass = null;
-
- // have services file.
- if (input != null) {
- try {
- BufferedReader reader = new BufferedReader(new
InputStreamReader(input));
- String factoryClassName = reader.readLine();
-
- implementationClass = Class.forName(factoryClassName, false,
loader).asSubclass(interfaceClass);
- } catch (Exception e) {
- LOG.warn(MessageFormat.format("Error loading class for {0} service:
{1} ",
- interfaceClass.getName(), e.getMessage()), e);
- } finally {
- try {
- input.close();
- } catch (IOException e) {
- // can be ignored
- }
- }
- }
-
- return instantiate(interfaceClass, implementationClass,
defaultImplementationClass);
- }
-
- private CacheManager createAndStoreCacheManager(FacesContext context) {
- CacheManager cacheManager = new CacheManager();
- Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
- applicationMap.put(CACHE_MANAGER_ATTRIBUTE_NAME, cacheManager);
-
- return cacheManager;
- }
-
- private CacheManager getStoredCacheManager(FacesContext context) {
- Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
- return (CacheManager) applicationMap.get(CACHE_MANAGER_ATTRIBUTE_NAME);
- }
-
- protected void onStart() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- SkinFactory skinFactory = createServiceInstance(SkinFactory.class,
SkinFactoryImpl.class);
- ServiceTracker.setService(facesContext, SkinFactory.class, skinFactory);
-
- AJAXDataSerializer dataSerializer =
createServiceInstance(AJAXDataSerializer.class, AJAXDataSerializer.class);
- ServiceTracker.setService(facesContext, AJAXDataSerializer.class,
dataSerializer);
-
- DependencyInjectionService diService =
createServiceInstance(DependencyInjectionService.class,
- DependencyInjectionServiceImpl.class);
- ServiceTracker.setService(facesContext, DependencyInjectionService.class,
diService);
-
- ResourceCodec resourceCodec = createServiceInstance(ResourceCodec.class,
DefaultResourceCodec.class);
- ServiceTracker.setService(facesContext, ResourceCodec.class, resourceCodec);
-
- CacheManager cacheManager = createAndStoreCacheManager(facesContext);
-
- Map<?, ?> envMap =
facesContext.getExternalContext().getInitParameterMap();
- Cache cache = cacheManager.createCache(facesContext,
ResourceHandlerImpl.RESOURCE_CACHE_NAME, envMap);
- ServiceTracker.setService(facesContext, Cache.class, cache);
- }
-
protected void onStop() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
-
- CacheManager cacheManager = getStoredCacheManager(facesContext);
- cacheManager.destroy();
-
- ServiceTracker.release(facesContext);
+ ServiceTracker.release();
}
/* (non-Javadoc)
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.application;
-
-import javax.faces.event.PhaseEvent;
-import javax.faces.event.PhaseId;
-import javax.faces.event.PhaseListener;
-import javax.faces.lifecycle.Lifecycle;
-
-/**
- * As service tracker is filled by application startup listeners,
- * we can't rely on some "locking" system listener that's the last in
chain,
- * so PhaseListener does the job.
- *
- * @author Nick Belaevski
- */
-public class ServiceTrackerLockPhaseListener implements PhaseListener {
-
- private static final long serialVersionUID = 3206929642757284003L;
-
- public void afterPhase(PhaseEvent event) {
- }
-
- public void beforePhase(PhaseEvent event) {
- ServiceTracker.lockModification(event.getFacesContext());
- ((Lifecycle) event.getSource()).removePhaseListener(this);
- }
-
- public PhaseId getPhaseId() {
- return PhaseId.ANY_PHASE;
- }
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330 (from rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330)
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,65 +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">
- * 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();
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java (from rev
17641, root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binder.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binder.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -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/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,398 +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.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);
- }
- }
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java (from rev
17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -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/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binders.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,12 +0,0 @@
-package org.richfaces.jsr330;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public interface Binders {
-
- public BinderImpl<?> getBinding(Target type);
-
-}
\ No newline at end of file
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java (from rev
17641, root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Binders.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Binders.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,12 @@
+package org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface Binders {
+
+ public BinderImpl<?> getBinding(Target type);
+
+}
\ No newline at end of file
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/DependencyException.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,66 +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;
-
-/**
- * <p class="changed_added_4_0">Dependency injection errors.</p>
- * @author asmirnov(a)exadel.com
- *
- */
-@SuppressWarnings("serial")
-public class DependencyException extends RuntimeException {
-
- /**
- * <p class="changed_added_4_0"></p>
- */
- public DependencyException() {
-
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param message
- */
- public DependencyException(String message) {
- super(message);
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param cause
- */
- public DependencyException(Throwable cause) {
- super(cause);
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param message
- * @param cause
- */
- public DependencyException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java
(from rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/DependencyException.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DependencyException.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,66 @@
+/*
+ * $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;
+
+/**
+ * <p class="changed_added_4_0">Dependency injection errors.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@SuppressWarnings("serial")
+public class DependencyException extends RuntimeException {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ */
+ public DependencyException() {
+
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ */
+ public DependencyException(String message) {
+ super(message);
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param cause
+ */
+ public DependencyException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ * @param cause
+ */
+ public DependencyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,165 +0,0 @@
-package org.richfaces.jsr330;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-/**
- * <p class="changed_added_4_0">Dynamicaly </p>
- * @author asmirnov(a)exadel.com
- *
- * @param <T>
- */
-public class DynamicProvider<T> implements Provider<T>, Initializable {
-
- private final Class<? extends T> type;
-
- private Constructor<T> constructor;
-
- private List<BinderImpl<?>> constructorArguments;
-
- private Map<Field, BinderImpl<?>> injectedFields;
-
- private Map<Method, List<BinderImpl<?>>> injectedMethods;
-
- public DynamicProvider(Class<? extends T> type) {
- this.type = type;
- }
-
- void findInjectorMethods(Binders injectorImpl) throws Exception {
- injectedMethods = new HashMap<Method, List<BinderImpl<?>>>();
- Method[] methods = this.type.getMethods();
- for (Method method : methods) {
- if (method.isAnnotationPresent(Inject.class)) {
- Type[] parameterTypes = method.getGenericParameterTypes();
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
- injectedMethods.put(method, getParameterBindings(injectorImpl,
parameterTypes, parameterAnnotations));
- }
- }
- }
-
- void findInjectedFields(Binders injectorImpl) throws Exception {
- Field[] declaredFields = this.type.getDeclaredFields();
- this.injectedFields = new HashMap<Field, BinderImpl<?>>();
- for (Field field : declaredFields) {
- if (field.isAnnotationPresent(Inject.class)) {
- Type fieldType = field.getGenericType();
- if (fieldType instanceof Class<?>) {
- Class<?> fieldClass = (Class<?>) fieldType;
- this.injectedFields.put(field,
injectorImpl.getBinding(Target.createNamed(fieldClass, field
- .getAnnotations())));
- }
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- void findConstructor(Binders injectorImpl) throws Exception {
- Constructor<?>[] constructors = this.type.getConstructors();
- for (Constructor<?> constructor : constructors) {
- if (constructor.isAnnotationPresent(Inject.class)) {
- if (null != this.constructor) {
- throw new DependencyException("More then one constructor have
@Inject annotation " + this.type);
- }
- this.constructor = (Constructor<T>) constructor;
- Type[] parameterTypes = constructor.getGenericParameterTypes();
- Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
- this.constructorArguments = getParameterBindings(injectorImpl,
parameterTypes, parameterAnnotations);
- }
- }
- if (null == constructor) {
- constructor = (Constructor<T>) this.type.getConstructor();
- this.constructorArguments = Collections.emptyList();
- }
- }
-
- List<BinderImpl<?>> getParameterBindings(Binders injectorImpl, Type[]
parameterTypes,
- Annotation[][] parameterAnnotations) {
- List<BinderImpl<?>> arguments = new
ArrayList<BinderImpl<?>>(parameterTypes.length);
- int i = 0;
- for (Type parameterType : parameterTypes) {
- arguments.add(injectorImpl.getBinding(Target.createNamed(parameterType,
parameterAnnotations[i])));
- i++;
- }
- return arguments;
- }
-
-
- void invokeInjectionMethods(Object instance) throws Exception {
- for (Method method : injectedMethods.keySet()) {
- method.invoke(instance, getArgumentValues(injectedMethods.get(method)));
- }
-
- }
-
- void injectFields(Object instance) throws Exception {
- for (Field field : injectedFields.keySet()) {
- boolean accessible = field.isAccessible();
- if (!accessible) {
- field.setAccessible(true);
- }
- field.set(instance, injectedFields.get(field).get());
- if (!accessible) {
- field.setAccessible(accessible);
- }
- }
- }
-
- public T get() {
- try {
- Object[] arguments = getArgumentValues(this.constructorArguments);
- T instance = constructor.newInstance(arguments);
- inject(instance);
- return instance;
- } catch (Exception e) {
- throw new DependencyException(e);
- }
- }
-
- void inject(T instance) throws Exception {
- injectFields(instance);
- invokeInjectionMethods(instance);
- }
-
- Object[] getArgumentValues(List<BinderImpl<?>> argumentBinding) {
- Object[] arguments = new Object[argumentBinding.size()];
- int i = 0;
- for (BinderImpl<?> provider : argumentBinding) {
- arguments[i++] = provider.get();
- }
- return arguments;
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.jsr330.Initializable#init(org.richfaces.jsr330.Binders)
- */
- public boolean init(Binders injectorImpl) {
- try {
- findConstructor(injectorImpl);
- findInjectedFields(injectorImpl);
- findInjectorMethods(injectorImpl);
- return type.isAnnotationPresent(Singleton.class);
- } catch (Exception e) {
- throw new DependencyException(e);
- }
- }
-
- public void destroy() {
- constructor = null;
- constructorArguments = null;
- injectedFields = null;
- injectedMethods = null;
- }
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,165 @@
+package org.richfaces.jsr330;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+/**
+ * <p class="changed_added_4_0">Dynamicaly </p>
+ * @author asmirnov(a)exadel.com
+ *
+ * @param <T>
+ */
+public class DynamicProvider<T> implements Provider<T>, Initializable {
+
+ private final Class<? extends T> type;
+
+ private Constructor<T> constructor;
+
+ private List<BinderImpl<?>> constructorArguments;
+
+ private Map<Field, BinderImpl<?>> injectedFields;
+
+ private Map<Method, List<BinderImpl<?>>> injectedMethods;
+
+ public DynamicProvider(Class<? extends T> type) {
+ this.type = type;
+ }
+
+ void findInjectorMethods(Binders injectorImpl) throws Exception {
+ injectedMethods = new HashMap<Method, List<BinderImpl<?>>>();
+ Method[] methods = this.type.getMethods();
+ for (Method method : methods) {
+ if (method.isAnnotationPresent(Inject.class)) {
+ Type[] parameterTypes = method.getGenericParameterTypes();
+ Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+ injectedMethods.put(method, getParameterBindings(injectorImpl,
parameterTypes, parameterAnnotations));
+ }
+ }
+ }
+
+ void findInjectedFields(Binders injectorImpl) throws Exception {
+ Field[] declaredFields = this.type.getDeclaredFields();
+ this.injectedFields = new HashMap<Field, BinderImpl<?>>();
+ for (Field field : declaredFields) {
+ if (field.isAnnotationPresent(Inject.class)) {
+ Type fieldType = field.getGenericType();
+ if (fieldType instanceof Class<?>) {
+ Class<?> fieldClass = (Class<?>) fieldType;
+ this.injectedFields.put(field,
injectorImpl.getBinding(Target.createNamed(fieldClass, field
+ .getAnnotations())));
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ void findConstructor(Binders injectorImpl) throws Exception {
+ Constructor<?>[] constructors = this.type.getConstructors();
+ for (Constructor<?> constructor : constructors) {
+ if (constructor.isAnnotationPresent(Inject.class)) {
+ if (null != this.constructor) {
+ throw new DependencyException("More then one constructor have
@Inject annotation " + this.type);
+ }
+ this.constructor = (Constructor<T>) constructor;
+ Type[] parameterTypes = constructor.getGenericParameterTypes();
+ Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
+ this.constructorArguments = getParameterBindings(injectorImpl,
parameterTypes, parameterAnnotations);
+ }
+ }
+ if (null == constructor) {
+ constructor = (Constructor<T>) this.type.getConstructor();
+ this.constructorArguments = Collections.emptyList();
+ }
+ }
+
+ List<BinderImpl<?>> getParameterBindings(Binders injectorImpl, Type[]
parameterTypes,
+ Annotation[][] parameterAnnotations) {
+ List<BinderImpl<?>> arguments = new
ArrayList<BinderImpl<?>>(parameterTypes.length);
+ int i = 0;
+ for (Type parameterType : parameterTypes) {
+ arguments.add(injectorImpl.getBinding(Target.createNamed(parameterType,
parameterAnnotations[i])));
+ i++;
+ }
+ return arguments;
+ }
+
+
+ void invokeInjectionMethods(Object instance) throws Exception {
+ for (Method method : injectedMethods.keySet()) {
+ method.invoke(instance, getArgumentValues(injectedMethods.get(method)));
+ }
+
+ }
+
+ void injectFields(Object instance) throws Exception {
+ for (Field field : injectedFields.keySet()) {
+ boolean accessible = field.isAccessible();
+ if (!accessible) {
+ field.setAccessible(true);
+ }
+ field.set(instance, injectedFields.get(field).get());
+ if (!accessible) {
+ field.setAccessible(accessible);
+ }
+ }
+ }
+
+ public T get() {
+ try {
+ Object[] arguments = getArgumentValues(this.constructorArguments);
+ T instance = constructor.newInstance(arguments);
+ inject(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new DependencyException(e);
+ }
+ }
+
+ void inject(T instance) throws Exception {
+ injectFields(instance);
+ invokeInjectionMethods(instance);
+ }
+
+ Object[] getArgumentValues(List<BinderImpl<?>> argumentBinding) {
+ Object[] arguments = new Object[argumentBinding.size()];
+ int i = 0;
+ for (BinderImpl<?> provider : argumentBinding) {
+ arguments[i++] = provider.get();
+ }
+ return arguments;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.jsr330.Initializable#init(org.richfaces.jsr330.Binders)
+ */
+ public boolean init(Binders injectorImpl) {
+ try {
+ findConstructor(injectorImpl);
+ findInjectedFields(injectorImpl);
+ findInjectorMethods(injectorImpl);
+ return type.isAnnotationPresent(Singleton.class);
+ } catch (Exception e) {
+ throw new DependencyException(e);
+ }
+ }
+
+ public void destroy() {
+ constructor = null;
+ constructorArguments = null;
+ injectedFields = null;
+ injectedMethods = null;
+ }
+
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Initializable.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,14 +0,0 @@
-package org.richfaces.jsr330;
-
-/**
- * <p class="changed_added_4_0">Classes that require initialization
should implement this interface</p>
- * @author asmirnov(a)exadel.com
- *
- */
-public interface Initializable {
-
- public boolean init(Binders injectorImpl);
-
- public void destroy();
-
-}
\ No newline at end of file
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Initializable.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Initializable.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,14 @@
+package org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0">Classes that require initialization
should implement this interface</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface Initializable {
+
+ public boolean init(Binders injectorImpl);
+
+ public void destroy();
+
+}
\ No newline at end of file
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,19 +0,0 @@
-package org.richfaces.jsr330;
-
-/**
- * <p class="changed_added_4_0">
- * Implementation provides instance of this interface to let user register services and
its implementations.
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public interface InjectorConfig {
-
- public <T> Binder<T> register(Target type);
-
- public <T> Binder<T> register(Class<T> type, Class<?>...
typeArguments);
-
- public <T> Binder<T> register(String name, Class<T> type,
Class<?>... typeArguments);
-
-}
\ No newline at end of file
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorConfig.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,19 @@
+package org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0">
+ * Implementation provides instance of this interface to let user register services and
its implementations.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface InjectorConfig {
+
+ public <T> Binder<T> register(Target type);
+
+ public <T> Binder<T> register(Class<T> type, Class<?>...
typeArguments);
+
+ public <T> Binder<T> register(String name, Class<T> type,
Class<?>... typeArguments);
+
+}
\ No newline at end of file
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -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 (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);
- }
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -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/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Module.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,12 +0,0 @@
-package org.richfaces.jsr330;
-
-/**
- * <p class="changed_added_4_0">User-provided configuration
module.</p>
- * @author asmirnov(a)exadel.com
- *
- */
-public interface Module {
-
- public void configure(InjectorConfig injector);
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java (from rev
17641, root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Module.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Module.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,12 @@
+package org.richfaces.jsr330;
+
+/**
+ * <p class="changed_added_4_0">User-provided configuration
module.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface Module {
+
+ public void configure(InjectorConfig injector);
+
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,49 +0,0 @@
-package org.richfaces.jsr330;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.richfaces.application.DependencyInjector;
-
-/**
- * Implementation independent factory for JSR-330 beans.
- *
- */
-public final class ObjectFactory {
- /**
- * <p class="changed_added_4_0">
- * </p>
- */
- private static final Map<ClassLoader, DependencyInjector> INSTANCES =
- new ConcurrentHashMap<ClassLoader, DependencyInjector>();
-
- private ObjectFactory() {
- }
-
- public static <T> T create(Class<T> target,String name) {
- return getInjector().create(target,name);
- }
-
- public static <T> T create(Class<T> target) {
- return getInjector().create(target);
- }
-
- public static void inject(Object value){
- getInjector().inject(value);
- }
- private static DependencyInjector getInjector() {
- return INSTANCES.get(getCurrentLoader());
- }
-
- private static ClassLoader getCurrentLoader() {
- ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- if (null == contextClassLoader) {
- contextClassLoader = ObjectFactory.class.getClassLoader();
- }
- return contextClassLoader;
- }
-
- public static void setInjector(DependencyInjector injector) {
- INSTANCES.put(getCurrentLoader(), injector);
- }
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,49 @@
+package org.richfaces.jsr330;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.richfaces.application.DependencyInjector;
+
+/**
+ * Implementation independent factory for JSR-330 beans.
+ *
+ */
+public final class ObjectFactory {
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ */
+ private static final Map<ClassLoader, DependencyInjector> INSTANCES =
+ new ConcurrentHashMap<ClassLoader, DependencyInjector>();
+
+ private ObjectFactory() {
+ }
+
+ public static <T> T create(Class<T> target,String name) {
+ return getInjector().create(target,name);
+ }
+
+ public static <T> T create(Class<T> target) {
+ return getInjector().create(target);
+ }
+
+ public static void inject(Object value){
+ getInjector().inject(value);
+ }
+ private static DependencyInjector getInjector() {
+ return INSTANCES.get(getCurrentLoader());
+ }
+
+ private static ClassLoader getCurrentLoader() {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (null == contextClassLoader) {
+ contextClassLoader = ObjectFactory.class.getClassLoader();
+ }
+ return contextClassLoader;
+ }
+
+ public static void setInjector(DependencyInjector injector) {
+ INSTANCES.put(getCurrentLoader(), injector);
+ }
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Scope.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java 2010-06-19 00:18:43
UTC (rev 17643)
@@ -1,35 +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
- *
- */
-interface Scope<T> extends Provider<T> {
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java (from rev
17641, root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Scope.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Scope.java 2010-06-19 00:18:43
UTC (rev 17643)
@@ -0,0 +1,35 @@
+/*
+ * $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
+ *
+ */
+interface Scope<T> extends Provider<T> {
+
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/ServiceException.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,65 +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;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-@SuppressWarnings("serial")
-public class ServiceException extends Exception {
-
- /**
- * <p class="changed_added_4_0"></p>
- */
- public ServiceException() {
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param message
- */
- public ServiceException(String message) {
- super(message);
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param cause
- */
- public ServiceException(Throwable cause) {
- super(cause);
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param message
- * @param cause
- */
- public ServiceException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java
(from rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/ServiceException.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java
(rev 0)
+++
root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceException.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -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;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@SuppressWarnings("serial")
+public class ServiceException extends Exception {
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ */
+ public ServiceException() {
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ */
+ public ServiceException(String message) {
+ super(message);
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param cause
+ */
+ public ServiceException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param message
+ * @param cause
+ */
+ public ServiceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,195 +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.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-/**
- * <p class="changed_added_4_0">
- * This class loads services from files placed to the META-INF/services in classpath.
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public final class ServiceLoader {
-
- private static final String META_INF_SERVICES = "META-INF/services/";
- private static final Pattern LEGAL_JAVA_NAME =
Pattern.compile("^(([A-Za-z0-9_])+\\.)+[A-Z]([A-Za-z0-9_]*)$");
-
- private ServiceLoader() {
-
- }
-
- /**
- * <p class="changed_added_4_0">
- * Load and instantiate all service implementations.
- * </p>
- *
- * @param <S>
- * @param serviceClass
- * @return
- * @throws ServiceException
- */
- public static <S> Collection<S> loadServices(Class<S> serviceClass)
throws ServiceException {
- Collection<Class<? extends S>> serviceClasses =
loadServiceClasses(serviceClass);
- List<S> instances = new ArrayList<S>();
- try {
- for (Class<? extends S> implementationClass : serviceClasses) {
- instances.add(implementationClass.newInstance());
- }
-
- } catch (InstantiationException e) {
- throw new ServiceException("Cannot instantiate service class, does it
have default constructor ?", e);
- } catch (IllegalAccessException e) {
- throw new ServiceException("Cannot instantiate service class, illegal
access", e);
- }
- return instances;
- }
-
- /**
- * <p class="changed_added_4_0">
- * Load service implementation classes.
- * </p>
- *
- * @param <S>
- * @param serviceClass
- * @return
- * @throws ServiceException
- */
- public static <S> Collection<Class<? extends S>>
loadServiceClasses(Class<S> serviceClass) throws ServiceException {
- ClassLoader classLoader = getClassLoader(serviceClass);
- Set<String> names = new HashSet<String>();
- Enumeration<URL> resources;
- try {
- resources = classLoader.getResources(META_INF_SERVICES +
serviceClass.getName());
- while (resources.hasMoreElements()) {
- names.addAll(parse(resources.nextElement()));
- }
- } catch (IOException e) {
- throw new ServiceException("Error load service descriptions", e);
- }
- List<Class<? extends S>> instanceClasses = new
ArrayList<Class<? extends S>>();
- for (String className : names) {
- instanceClasses.add(loadClass(serviceClass, classLoader, className));
- }
- return instanceClasses;
-
- }
-
- static Collection<String> parse(URL url) throws ServiceException, IOException
{
- InputStream inputStream = null;
- try {
- URLConnection connection = url.openConnection();
- try {
- connection.setUseCaches(false);
- } catch (IllegalArgumentException e) {
- // Do nothing.
- }
- Set<String> names = new HashSet<String>();
- inputStream = connection.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,
"utf-8"));
- String line;
- while (null != (line = reader.readLine())) {
- parseLine(line, names);
- }
- return names;
- } finally {
- if (null != inputStream) {
- inputStream.close();
- }
- }
- }
-
- /**
- * <p class="changed_added_4_0">
- * Parse a single line from service description. Skips empty lines and comments
started with #
- * </p>
- *
- * @param line
- * @param names
- * @throws ServiceException
- */
- static void parseLine(String line, Collection<String> names) throws
ServiceException {
- String name;
- int commentIndex = line.indexOf('#');
- if (commentIndex >= 0) {
- name = line.substring(0, commentIndex);
- } else {
- name = line;
- }
- name = name.trim();
- if (name.length() > 0) {
- if (LEGAL_JAVA_NAME.matcher(name).matches()) {
- names.add(name);
- } else {
- throw new ServiceException("Invalid java class name [" + line +
"]");
- }
- }
- }
-
- /**
- * <p class="changed_added_4_0">
- * Get class loader
- * </p>
- *
- * @param <S>
- * @param serviceClass
- * @return context class loader or loader with which service class has been loaded.
- */
- private static <S> ClassLoader getClassLoader(Class<S> serviceClass) {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if (null == classLoader) {
- classLoader = serviceClass.getClassLoader();
- }
- return classLoader;
- }
-
- private static <S> Class<? extends S> loadClass(Class<S>
serviceClass, ClassLoader classLoader, String className)
- throws ServiceException {
- try {
- Class<?> implementationClass = classLoader.loadClass(className);
- if (serviceClass.isAssignableFrom(implementationClass)) {
- return implementationClass.asSubclass(serviceClass);
- } else {
- throw new ServiceException("Class " + className + " in not
the instance of " + serviceClass.getName());
- }
- } catch (ClassNotFoundException e) {
- throw new ServiceException("Class " + className + " not
found", e);
- }
- }
-
-}
Copied: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/ServiceLoader.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,195 @@
+/*
+ * $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.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/**
+ * <p class="changed_added_4_0">
+ * This class loads services from files placed to the META-INF/services in classpath.
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public final class ServiceLoader {
+
+ private static final String META_INF_SERVICES = "META-INF/services/";
+ private static final Pattern LEGAL_JAVA_NAME =
Pattern.compile("^(([A-Za-z0-9_])+\\.)+[A-Z]([A-Za-z0-9_]*)$");
+
+ private ServiceLoader() {
+
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Load and instantiate all service implementations.
+ * </p>
+ *
+ * @param <S>
+ * @param serviceClass
+ * @return
+ * @throws ServiceException
+ */
+ public static <S> Collection<S> loadServices(Class<S> serviceClass)
throws ServiceException {
+ Collection<Class<? extends S>> serviceClasses =
loadServiceClasses(serviceClass);
+ List<S> instances = new ArrayList<S>();
+ try {
+ for (Class<? extends S> implementationClass : serviceClasses) {
+ instances.add(implementationClass.newInstance());
+ }
+
+ } catch (InstantiationException e) {
+ throw new ServiceException("Cannot instantiate service class, does it
have default constructor ?", e);
+ } catch (IllegalAccessException e) {
+ throw new ServiceException("Cannot instantiate service class, illegal
access", e);
+ }
+ return instances;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Load service implementation classes.
+ * </p>
+ *
+ * @param <S>
+ * @param serviceClass
+ * @return
+ * @throws ServiceException
+ */
+ public static <S> Collection<Class<? extends S>>
loadServiceClasses(Class<S> serviceClass) throws ServiceException {
+ ClassLoader classLoader = getClassLoader(serviceClass);
+ Set<String> names = new HashSet<String>();
+ Enumeration<URL> resources;
+ try {
+ resources = classLoader.getResources(META_INF_SERVICES +
serviceClass.getName());
+ while (resources.hasMoreElements()) {
+ names.addAll(parse(resources.nextElement()));
+ }
+ } catch (IOException e) {
+ throw new ServiceException("Error load service descriptions", e);
+ }
+ List<Class<? extends S>> instanceClasses = new
ArrayList<Class<? extends S>>();
+ for (String className : names) {
+ instanceClasses.add(loadClass(serviceClass, classLoader, className));
+ }
+ return instanceClasses;
+
+ }
+
+ static Collection<String> parse(URL url) throws ServiceException, IOException
{
+ InputStream inputStream = null;
+ try {
+ URLConnection connection = url.openConnection();
+ try {
+ connection.setUseCaches(false);
+ } catch (IllegalArgumentException e) {
+ // Do nothing.
+ }
+ Set<String> names = new HashSet<String>();
+ inputStream = connection.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,
"utf-8"));
+ String line;
+ while (null != (line = reader.readLine())) {
+ parseLine(line, names);
+ }
+ return names;
+ } finally {
+ if (null != inputStream) {
+ inputStream.close();
+ }
+ }
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Parse a single line from service description. Skips empty lines and comments
started with #
+ * </p>
+ *
+ * @param line
+ * @param names
+ * @throws ServiceException
+ */
+ static void parseLine(String line, Collection<String> names) throws
ServiceException {
+ String name;
+ int commentIndex = line.indexOf('#');
+ if (commentIndex >= 0) {
+ name = line.substring(0, commentIndex);
+ } else {
+ name = line;
+ }
+ name = name.trim();
+ if (name.length() > 0) {
+ if (LEGAL_JAVA_NAME.matcher(name).matches()) {
+ names.add(name);
+ } else {
+ throw new ServiceException("Invalid java class name [" + line +
"]");
+ }
+ }
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Get class loader
+ * </p>
+ *
+ * @param <S>
+ * @param serviceClass
+ * @return context class loader or loader with which service class has been loaded.
+ */
+ private static <S> ClassLoader getClassLoader(Class<S> serviceClass) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if (null == classLoader) {
+ classLoader = serviceClass.getClassLoader();
+ }
+ return classLoader;
+ }
+
+ private static <S> Class<? extends S> loadClass(Class<S>
serviceClass, ClassLoader classLoader, String className)
+ throws ServiceException {
+ try {
+ Class<?> implementationClass = classLoader.loadClass(className);
+ if (serviceClass.isAssignableFrom(implementationClass)) {
+ return implementationClass.asSubclass(serviceClass);
+ } else {
+ throw new ServiceException("Class " + className + " in not
the instance of " + serviceClass.getName());
+ }
+ } catch (ClassNotFoundException e) {
+ throw new ServiceException("Class " + className + " not
found", e);
+ }
+ }
+
+}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,210 +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 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/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java (from rev
17641, root/core/branches/jsr-330/impl/src/main/java/org/richfaces/jsr330/Target.java)
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java
(rev 0)
+++ root/core/trunk/impl/src/main/java/org/richfaces/jsr330/Target.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -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();
+ }
+ }
+}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -42,7 +42,6 @@
import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.cache.Cache;
-import org.richfaces.application.DependencyInjectionService;
import org.richfaces.application.ServiceTracker;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.util.Util;
@@ -358,12 +357,11 @@
protected void injectProperties(Object resource, Map<String, String>
parameters) {
FacesContext facesContext = FacesContext.getCurrentInstance();
- DependencyInjectionService diService = ServiceTracker.getService(facesContext,
DependencyInjectionService.class);
Map<Object, Object> attributes = facesContext.getAttributes();
try {
attributes.put(ResourceParameterELResolver.CONTEXT_ATTRIBUTE_NAME,
parameters);
- diService.inject(facesContext, resource);
+ ServiceTracker.inject(resource);
} finally {
attributes.remove(ResourceParameterELResolver.CONTEXT_ATTRIBUTE_NAME);
}
Modified:
root/core/trunk/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml
===================================================================
---
root/core/trunk/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml 2010-06-19
00:18:43 UTC (rev 17643)
@@ -12,8 +12,5 @@
</system-event-listener>
</application>
- <lifecycle>
- <phase-listener>org.richfaces.application.ServiceTrackerLockPhaseListener</phase-listener>
- </lifecycle>
</faces-config>
\ No newline at end of file
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330 (from rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330)
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/BarProvider.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,11 +0,0 @@
-package org.richfaces.jsr330;
-
-import javax.inject.Provider;
-
-public class BarProvider implements Provider<String> {
-
- public String get() {
- return "bar";
- }
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java (from rev
17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/BarProvider.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java
(rev 0)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/BarProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,11 @@
+package org.richfaces.jsr330;
+
+import javax.inject.Provider;
+
+public class BarProvider implements Provider<String> {
+
+ public String get() {
+ return "bar";
+ }
+
+}
Deleted:
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,47 +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.Inject;
-import javax.inject.Named;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class ConstructorInjection implements Interface {
-
- final String param;
-
- @Inject
- public ConstructorInjection( @Named("foo") String param) {
- this.param = param;
- }
-
- public String hello() {
- return param;
- }
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
(from rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
(rev 0)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,47 @@
+/*
+ * $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.Inject;
+import javax.inject.Named;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ConstructorInjection implements Interface {
+
+ final String param;
+
+ @Inject
+ public ConstructorInjection( @Named("foo") String param) {
+ this.param = param;
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,47 +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.Inject;
-import javax.inject.Named;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class FieldInjection implements Interface {
-
- @Inject
- @Named("foo")
- String param;
-
- public FieldInjection( ) {
- }
-
- public String hello() {
- return param;
- }
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
(rev 0)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FieldInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,47 @@
+/*
+ * $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.Inject;
+import javax.inject.Named;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class FieldInjection implements Interface {
+
+ @Inject
+ @Named("foo")
+ String param;
+
+ public FieldInjection( ) {
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/FooProvider.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,39 +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 class FooProvider implements Provider<String> {
-
- public String get() {
- return "foo";
- }
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java (from rev
17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/FooProvider.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java
(rev 0)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/FooProvider.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,39 @@
+/*
+ * $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 class FooProvider implements Provider<String> {
+
+ public String get() {
+ return "foo";
+ }
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,115 +0,0 @@
-package org.richfaces.jsr330;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-
-public class InjectorTest {
-
- @Test
- public void injectByConstructor() throws Exception {
- InjectorImpl injector = new InjectorImpl();
- injector.init(new Module(){
-
- public void configure(InjectorConfig injector) {
- injector.register(Interface.class).to(ConstructorInjection.class);
- injector.register("foo",
String.class).toInstance("bar");
- injector.register("bar",
String.class).toInstance("baz");
- }
-
- });
- Interface testInterface = injector.create(Interface.class);
- assertTrue(testInterface instanceof ConstructorInjection);
- assertEquals("bar",testInterface.hello());
- }
-
- @Test
- public void injectByField() throws Exception {
- InjectorImpl injector = new InjectorImpl();
- injector.init(new Module(){
-
- public void configure(InjectorConfig injector) {
- injector.register(Interface.class).to(FieldInjection.class);
- injector.register("foo",
String.class).toInstance("bar");
- injector.register("bar",
String.class).toInstance("baz");
- }
-
- });
- Interface testInterface = injector.create(Interface.class);
- assertTrue(testInterface instanceof FieldInjection);
- assertEquals("bar",testInterface.hello());
- }
-
- @Test
- public void injectByMethod() throws Exception {
- InjectorImpl injector = new InjectorImpl();
- injector.init(new Module(){
-
- public void configure(InjectorConfig injector) {
- injector.register(Interface.class).to(MethodInjection.class);
- injector.register("foo",
String.class).toInstance("bar");
- injector.register("bar",
String.class).toInstance("baz");
- }
-
- });
- Interface testInterface = injector.create(Interface.class);
- assertTrue(testInterface instanceof MethodInjection);
- assertEquals("bar",testInterface.hello());
- }
-
- @Test
- public void injectByProvider() throws Exception {
- InjectorImpl injector = new InjectorImpl();
- injector.init(new Module(){
-
- public void configure(InjectorConfig injector) {
- injector.register(Interface.class).to(ProviderInjection.class);
- injector.register("foo",
String.class).toInstance("bar");
- injector.register("bar",
String.class).toInstance("baz");
- }
-
- });
- Interface testInterface = injector.create(Interface.class);
- assertTrue(testInterface instanceof ProviderInjection);
- assertEquals("bar",testInterface.hello());
- }
-
- @Test
- public void injectProvider() throws Exception {
- InjectorImpl injector = new InjectorImpl();
- injector.init(new Module(){
-
- public void configure(InjectorConfig injector) {
- injector.register(Interface.class).to(ProviderInjection.class);
- injector.register("foo", String.class).toProviderInstance(new
FooProvider());
- injector.register("bar",
String.class).toProvider(BarProvider.class);
- }
-
- });
- Interface testInterface = injector.create(Interface.class);
- assertTrue(testInterface instanceof ProviderInjection);
- assertEquals("foo",testInterface.hello());
- ProviderInjection instance = (ProviderInjection) testInterface;
- assertEquals("bar",instance.bar);
- assertEquals("foo",instance.foo);
- }
-
- @Test
- public void inject() throws Exception {
- InjectorImpl injector = new InjectorImpl();
- injector.init(new Module(){
-
- public void configure(InjectorConfig injector) {
- injector.register("foo", String.class).toProviderInstance(new
FooProvider());
- injector.register("bar",
String.class).toProvider(BarProvider.class);
- }
-
- });
- ProviderInjection instance = new ProviderInjection();
- injector.inject(instance);
- assertEquals("foo",instance.hello());
- assertEquals("bar",instance.bar);
- assertEquals("foo",instance.foo);
- }
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
(rev 0)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/InjectorTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,115 @@
+package org.richfaces.jsr330;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class InjectorTest {
+
+ @Test
+ public void injectByConstructor() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+
+ public void configure(InjectorConfig injector) {
+ injector.register(Interface.class).to(ConstructorInjection.class);
+ injector.register("foo",
String.class).toInstance("bar");
+ injector.register("bar",
String.class).toInstance("baz");
+ }
+
+ });
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof ConstructorInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+ @Test
+ public void injectByField() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+
+ public void configure(InjectorConfig injector) {
+ injector.register(Interface.class).to(FieldInjection.class);
+ injector.register("foo",
String.class).toInstance("bar");
+ injector.register("bar",
String.class).toInstance("baz");
+ }
+
+ });
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof FieldInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+ @Test
+ public void injectByMethod() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+
+ public void configure(InjectorConfig injector) {
+ injector.register(Interface.class).to(MethodInjection.class);
+ injector.register("foo",
String.class).toInstance("bar");
+ injector.register("bar",
String.class).toInstance("baz");
+ }
+
+ });
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof MethodInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+ @Test
+ public void injectByProvider() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+
+ public void configure(InjectorConfig injector) {
+ injector.register(Interface.class).to(ProviderInjection.class);
+ injector.register("foo",
String.class).toInstance("bar");
+ injector.register("bar",
String.class).toInstance("baz");
+ }
+
+ });
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof ProviderInjection);
+ assertEquals("bar",testInterface.hello());
+ }
+
+ @Test
+ public void injectProvider() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+
+ public void configure(InjectorConfig injector) {
+ injector.register(Interface.class).to(ProviderInjection.class);
+ injector.register("foo", String.class).toProviderInstance(new
FooProvider());
+ injector.register("bar",
String.class).toProvider(BarProvider.class);
+ }
+
+ });
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof ProviderInjection);
+ assertEquals("foo",testInterface.hello());
+ ProviderInjection instance = (ProviderInjection) testInterface;
+ assertEquals("bar",instance.bar);
+ assertEquals("foo",instance.foo);
+ }
+
+ @Test
+ public void inject() throws Exception {
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+
+ public void configure(InjectorConfig injector) {
+ injector.register("foo", String.class).toProviderInstance(new
FooProvider());
+ injector.register("bar",
String.class).toProvider(BarProvider.class);
+ }
+
+ });
+ ProviderInjection instance = new ProviderInjection();
+ injector.inject(instance);
+ assertEquals("foo",instance.hello());
+ assertEquals("bar",instance.bar);
+ assertEquals("foo",instance.foo);
+ }
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/Interface.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,35 +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;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public interface Interface {
-
- public String hello();
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java (from rev
17641, root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/Interface.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java
(rev 0)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/Interface.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,35 @@
+/*
+ * $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;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface Interface {
+
+ public String hello();
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,51 +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.Inject;
-import javax.inject.Named;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class MethodInjection implements Interface {
-
- String param;
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param param the param to set
- */
- @Inject
- public void setParam( @Named("foo") String param) {
- this.param = param;
- }
-
- public String hello() {
- return param;
- }
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java (from
rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
(rev 0)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/MethodInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,51 @@
+/*
+ * $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.Inject;
+import javax.inject.Named;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class MethodInjection implements Interface {
+
+ String param;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param param the param to set
+ */
+ @Inject
+ public void setParam( @Named("foo") String param) {
+ this.param = param;
+ }
+
+ public String hello() {
+ return param;
+ }
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,61 +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.Inject;
-import javax.inject.Named;
-import javax.inject.Provider;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class ProviderInjection implements Interface {
-
- String param;
-
- @Inject
- @Named("bar")
- String bar;
-
- String foo;
- /**
- * <p class="changed_added_4_0"></p>
- * @param param the param to set
- */
- @Inject
- public void setParam( @Named("foo") Provider<String> param) {
- this.param = param.get();
- }
-
- public String hello() {
- return param;
- }
-
- @Inject
- public void setFoo(@Named("foo")String foo) {
- this.foo = foo;
- }
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
(from rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
(rev 0)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,61 @@
+/*
+ * $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.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ProviderInjection implements Interface {
+
+ String param;
+
+ @Inject
+ @Named("bar")
+ String bar;
+
+ String foo;
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param param the param to set
+ */
+ @Inject
+ public void setParam( @Named("foo") Provider<String> param) {
+ this.param = param.get();
+ }
+
+ public String hello() {
+ return param;
+ }
+
+ @Inject
+ public void setFoo(@Named("foo")String foo) {
+ this.foo = foo;
+ }
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,125 +0,0 @@
-package org.richfaces.jsr330;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-public class ServiceImpl implements List<String> {
-
- public boolean add(String o) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void add(int index, String element) {
- // TODO Auto-generated method stub
-
- }
-
- public boolean addAll(Collection<? extends String> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean addAll(int index, Collection<? extends String> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void clear() {
- // TODO Auto-generated method stub
-
- }
-
- public boolean contains(Object o) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean containsAll(Collection<?> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public String get(int index) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int indexOf(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public boolean isEmpty() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public Iterator<String> iterator() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int lastIndexOf(Object o) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public ListIterator<String> listIterator() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public ListIterator<String> listIterator(int index) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public boolean remove(Object o) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public String remove(int index) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public boolean removeAll(Collection<?> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean retainAll(Collection<?> c) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public String set(int index, String element) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public int size() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public List<String> subList(int fromIndex, int toIndex) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object[] toArray() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public <T> T[] toArray(T[] a) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java (from rev
17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
(rev 0)
+++ root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,125 @@
+package org.richfaces.jsr330;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+public class ServiceImpl implements List<String> {
+
+ public boolean add(String o) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void add(int index, String element) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean addAll(Collection<? extends String> c) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean addAll(int index, Collection<? extends String> c) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void clear() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean contains(Object o) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String get(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int indexOf(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public boolean isEmpty() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Iterator<String> iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int lastIndexOf(Object o) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public ListIterator<String> listIterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ListIterator<String> listIterator(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean remove(Object o) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String remove(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String set(int index, String element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int size() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public List<String> subList(int fromIndex, int toIndex) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object[] toArray() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public <T> T[] toArray(T[] a) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Deleted: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java 2010-06-19
00:01:14 UTC (rev 17641)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,156 +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 static org.junit.Assert.*;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class ServiceLoaderTest {
-
- private static final String JAVA_UTIL_LIST = "java.util.List";
-
- private ClassLoader currentLoader;
-
- @Before
- public void setUp() {
- currentLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- }
-
- @After
- public void thearDown() {
- Thread.currentThread().setContextClassLoader(currentLoader);
- }
-
- /**
- * Test method for {@link
org.richfaces.jsr330.ServiceLoader#loadServices(java.lang.Class)}.
- *
- * @throws Exception
- */
- @Test
- public void testLoadServices() throws Exception {
- Collection<List> services = ServiceLoader.loadServices(List.class);
- assertEquals(1, services.size());
- }
-
- /**
- * Test method for {@link
org.richfaces.jsr330.ServiceLoader#loadServiceClasses(java.lang.Class)}.
- *
- * @throws Exception
- */
- @Test
- public void testLoadServiceClasses() throws Exception {
- Collection<Class<? extends List>> serviceClasses =
ServiceLoader.loadServiceClasses(List.class);
- assertEquals(1, serviceClasses.size());
- assertEquals(ServiceImpl.class, serviceClasses.iterator().next());
- }
-
- /**
- * Test method for {@link org.richfaces.jsr330.ServiceLoader#parse(java.net.URL)}.
- *
- * @throws Exception
- * @throws ServiceException
- */
- @Test
- public void testParse() throws Exception {
- URL url =
this.getClass().getResource("/META-INF/services/java.util.List");
- Collection<String> collection = ServiceLoader.parse(url);
- assertEquals(1, collection.size());
- assertEquals(ServiceImpl.class.getName(), collection.iterator().next());
- }
-
- /**
- * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
- *
- * @throws Exception
- */
- @Test
- public void testParseLine() throws Exception {
- String line = "\t" + JAVA_UTIL_LIST + " ";
- ArrayList<String> names = new ArrayList<String>();
- ServiceLoader.parseLine(line, names);
-
- assertEquals(1, names.size());
- assertEquals(JAVA_UTIL_LIST, names.get(0));
- }
-
- /**
- * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
- *
- * @throws Exception
- */
- @Test
- public void testParseLine1() throws Exception {
- String line = ServiceImpl.class.getName();
- ArrayList<String> names = new ArrayList<String>();
- ServiceLoader.parseLine(line, names);
-
- assertEquals(1, names.size());
- assertEquals(ServiceImpl.class.getName(), names.get(0));
- }
-
- /**
- * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
- *
- * @throws Exception
- */
- @Test
- public void testParseLineWithComment() throws Exception {
- String line = JAVA_UTIL_LIST + " # comment";
- ArrayList<String> names = new ArrayList<String>();
- ServiceLoader.parseLine(line, names);
-
- assertEquals(1, names.size());
- assertEquals(JAVA_UTIL_LIST, names.get(0));
- }
-
- /**
- * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
- *
- * @throws Exception
- */
- @Test
- public void testParseLineComment() throws Exception {
- String line = " # comment";
- ArrayList<String> names = new ArrayList<String>();
- ServiceLoader.parseLine(line, names);
-
- assertEquals(0, names.size());
- }
-}
Copied: root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
(from rev 17641,
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java)
===================================================================
--- root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
(rev 0)
+++
root/core/trunk/impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,156 @@
+/*
+ * $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 static org.junit.Assert.*;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ServiceLoaderTest {
+
+ private static final String JAVA_UTIL_LIST = "java.util.List";
+
+ private ClassLoader currentLoader;
+
+ @Before
+ public void setUp() {
+ currentLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ }
+
+ @After
+ public void thearDown() {
+ Thread.currentThread().setContextClassLoader(currentLoader);
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.jsr330.ServiceLoader#loadServices(java.lang.Class)}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLoadServices() throws Exception {
+ Collection<List> services = ServiceLoader.loadServices(List.class);
+ assertEquals(1, services.size());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.jsr330.ServiceLoader#loadServiceClasses(java.lang.Class)}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLoadServiceClasses() throws Exception {
+ Collection<Class<? extends List>> serviceClasses =
ServiceLoader.loadServiceClasses(List.class);
+ assertEquals(1, serviceClasses.size());
+ assertEquals(ServiceImpl.class, serviceClasses.iterator().next());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.jsr330.ServiceLoader#parse(java.net.URL)}.
+ *
+ * @throws Exception
+ * @throws ServiceException
+ */
+ @Test
+ public void testParse() throws Exception {
+ URL url =
this.getClass().getResource("/META-INF/services/java.util.List");
+ Collection<String> collection = ServiceLoader.parse(url);
+ assertEquals(1, collection.size());
+ assertEquals(ServiceImpl.class.getName(), collection.iterator().next());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testParseLine() throws Exception {
+ String line = "\t" + JAVA_UTIL_LIST + " ";
+ ArrayList<String> names = new ArrayList<String>();
+ ServiceLoader.parseLine(line, names);
+
+ assertEquals(1, names.size());
+ assertEquals(JAVA_UTIL_LIST, names.get(0));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testParseLine1() throws Exception {
+ String line = ServiceImpl.class.getName();
+ ArrayList<String> names = new ArrayList<String>();
+ ServiceLoader.parseLine(line, names);
+
+ assertEquals(1, names.size());
+ assertEquals(ServiceImpl.class.getName(), names.get(0));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testParseLineWithComment() throws Exception {
+ String line = JAVA_UTIL_LIST + " # comment";
+ ArrayList<String> names = new ArrayList<String>();
+ ServiceLoader.parseLine(line, names);
+
+ assertEquals(1, names.size());
+ assertEquals(JAVA_UTIL_LIST, names.get(0));
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.jsr330.ServiceLoader#parseLine(java.lang.String, java.util.Set)}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testParseLineComment() throws Exception {
+ String line = " # comment";
+ ArrayList<String> names = new ArrayList<String>();
+ ServiceLoader.parseLine(line, names);
+
+ assertEquals(0, names.size());
+ }
+}
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -41,6 +41,9 @@
import org.easymock.EasyMock;
import org.jboss.test.faces.AbstractFacesTest;
import org.richfaces.application.ServiceTracker;
+import org.richfaces.jsr330.Module;
+import org.richfaces.jsr330.InjectorConfig;
+import org.richfaces.jsr330.InjectorImpl;
import org.richfaces.util.Util;
/**
@@ -127,7 +130,7 @@
public void testGetRequestPath() throws Exception {
String resourceState = "data";
- ResourceCodec resourceCodec = EasyMock.createMock(ResourceCodec.class);
+ final ResourceCodec resourceCodec = EasyMock.createMock(ResourceCodec.class);
EasyMock.expect(resourceCodec.encodeResource(EasyMock.same(facesContext),
EasyMock.eq("org.richfaces.resource.MockStateAwareResource"),
@@ -139,8 +142,16 @@
EasyMock.eq("org.richfaces.resource.MockResource"),
EasyMock.eq(null),
EasyMock.eq("4_0_alpha"))).andReturn("/rfRes/Resource2/4_0_alpha");
EasyMock.replay(resourceCodec);
- ServiceTracker.setService(facesContext, ResourceCodec.class, resourceCodec);
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+ public void configure(InjectorConfig injector) {
+ injector.register(ResourceCodec.class).toInstance(resourceCodec);
+ }
+
+ });
+ ServiceTracker.setInjector(injector);
+
MockStateAwareResourceImpl stateAwareResourceImpl = new
MockStateAwareResourceImpl();
stateAwareResourceImpl.setVersion("4_0_alpha");
Modified:
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
===================================================================
---
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-19
00:07:09 UTC (rev 17642)
+++
root/core/trunk/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-19
00:18:43 UTC (rev 17643)
@@ -41,6 +41,9 @@
import org.jboss.test.faces.AbstractFacesTest;
import org.jboss.test.faces.htmlunit.LocalWebClient;
import org.richfaces.application.ServiceTracker;
+import org.richfaces.jsr330.Module;
+import org.richfaces.jsr330.InjectorConfig;
+import org.richfaces.jsr330.InjectorImpl;
import org.richfaces.util.Util;
import com.gargoylesoftware.htmlunit.Cache;
@@ -219,7 +222,8 @@
public void testStateHolder() throws Exception {
setupFacesRequest();
- ResourceCodec mockedCodec = EasyMock.createNiceMock(ResourceCodec.class);
+ final ResourceCodec mockedCodec = EasyMock.createNiceMock(ResourceCodec.class);
+ final org.ajax4jsf.cache.Cache mockCache =
EasyMock.createNiceMock(org.ajax4jsf.cache.Cache.class);
EasyMock.expect(mockedCodec.decodeResourceName(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn("org.richfaces.resource.StateHolderResourceImpl");
@@ -229,9 +233,18 @@
EasyMock.eq("StateHolderResource"))).andReturn(null);
EasyMock.expect(mockedCodec.getResourceKey(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn("StateHolderResource.jsf?db=1");
- EasyMock.replay(mockedCodec);
- ServiceTracker.setService(facesContext, ResourceCodec.class, mockedCodec);
+ EasyMock.replay(mockedCodec,mockCache);
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new Module(){
+ public void configure(InjectorConfig injector) {
+ injector.register(ResourceCodec.class).toInstance(mockedCodec);
+ injector.register(org.ajax4jsf.cache.Cache.class).toInstance(mockCache);
+ }
+
+ });
+ ServiceTracker.setInjector(injector);
+
WebRequestSettings settings =
new WebRequestSettings(new
URL("http://localhost/rfRes/StateHolderResource.jsf?db=1"));
WebResponse resourceResponse = webClient.loadWebResponse(settings);
Copied: root/core/trunk/impl/src/test/resources/META-INF/services (from rev 17641,
root/core/branches/jsr-330/impl/src/test/resources/META-INF/services)
Deleted: root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List
===================================================================
---
root/core/branches/jsr-330/impl/src/test/resources/META-INF/services/java.util.List 2010-06-19
00:01:14 UTC (rev 17641)
+++ root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List 2010-06-19
00:18:43 UTC (rev 17643)
@@ -1,3 +0,0 @@
-# test implementation of List
-org.richfaces.jsr330.ServiceImpl # comment
-
Copied: root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List (from rev
17641,
root/core/branches/jsr-330/impl/src/test/resources/META-INF/services/java.util.List)
===================================================================
--- root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List
(rev 0)
+++ root/core/trunk/impl/src/test/resources/META-INF/services/java.util.List 2010-06-19
00:18:43 UTC (rev 17643)
@@ -0,0 +1,3 @@
+# test implementation of List
+org.richfaces.jsr330.ServiceImpl # comment
+