Author: alexsmirnov
Date: 2010-06-15 19:29:59 -0400 (Tue, 15 Jun 2010)
New Revision: 17628
Added:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjector.java
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/CacheProvider.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DefaultModule.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/Interface.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
Removed:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceReference.java
root/core/branches/jsr-330/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestServiceImpl.java
Modified:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceTracker.java
root/core/branches/jsr-330/impl/pom.xml
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/InitializationListener.java
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
root/core/branches/jsr-330/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
root/core/branches/jsr-330/jsr330-impl/pom.xml
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Initializable.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
root/core/branches/jsr-330/jsr330-impl/src/test/resources/META-INF/services/java.util.List
Log:
change serviceTraccker to JSR-330
Deleted:
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjectionService.java
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjectionService.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjectionService.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjector.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java)
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjector.java
(rev 0)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/DependencyInjector.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceReference.java
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceReference.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceReference.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceTracker.java
===================================================================
---
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceTracker.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/api/src/main/java/org/richfaces/application/ServiceTracker.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java
===================================================================
---
root/core/branches/jsr-330/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/api/src/test/java/org/richfaces/application/ServiceTrackerTest.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/impl/pom.xml
===================================================================
--- root/core/branches/jsr-330/impl/pom.xml 2010-06-15 20:07:22 UTC (rev 17627)
+++ root/core/branches/jsr-330/impl/pom.xml 2010-06-15 23:29:59 UTC (rev 17628)
@@ -1,157 +1,160 @@
- <!--
- 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>org.richfaces.core</groupId>
+ <artifactId>jsr330-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.cssparser</groupId>
+ <artifactId>cssparser</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</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 +183,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/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/ContextInitParameters.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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);
Added:
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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);
+ }
+}
Property changes on:
root/core/branches/jsr-330/impl/src/main/java/org/ajax4jsf/context/InitParametersStorage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/CacheProvider.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/CacheProvider.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/CacheProvider.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
+ }
+
+}
Property changes on:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/CacheProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DefaultModule.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DefaultModule.java
(rev 0)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DefaultModule.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -0,0 +1,21 @@
+package org.richfaces.application;
+
+import org.ajax4jsf.cache.Cache;
+import org.ajax4jsf.renderkit.AJAXDataSerializer;
+import org.richfaces.jsr330.BindingModule;
+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 BindingModule {
+
+ public void configure(InjectorConfig injector) {
+ injector.register(SkinFactory.class).to(SkinFactoryImpl.class);
+ injector.register(AJAXDataSerializer.class).to(AJAXDataSerializer.class);
+ injector.register(ResourceCodec.class).toService(DefaultResourceCodec.class);
+ injector.register(Cache.class).toProviderInstance(new CacheProvider());
+ }
+
+}
Property changes on:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DefaultModule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/DependencyInjectionServiceImpl.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/impl/src/main/java/org/richfaces/application/InitializationListener.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/InitializationListener.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/InitializationListener.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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.BindingModule;
+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<BindingModule> modules = new ArrayList<BindingModule>();
+ 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(BindingModule.class));
+ injector.init(modules.toArray(new BindingModule[]{}));
+ } 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/branches/jsr-330/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/application/ServiceTrackerLockPhaseListener.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
- }
-
-}
Modified:
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java
===================================================================
---
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/main/java/org/richfaces/resource/ResourceHandlerImpl.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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/branches/jsr-330/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml
===================================================================
---
root/core/branches/jsr-330/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/main/resources/META-INF/initialization-listener.faces-config.xml 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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
Modified:
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/AbstractBaseResourceTest.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -41,6 +41,9 @@
import org.easymock.EasyMock;
import org.jboss.test.faces.AbstractFacesTest;
import org.richfaces.application.ServiceTracker;
+import org.richfaces.jsr330.BindingModule;
+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 BindingModule(){
+ 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/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java
===================================================================
---
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/impl/src/test/java/org/richfaces/resource/ResourceHandlerImplTest.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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.BindingModule;
+import org.richfaces.jsr330.InjectorConfig;
+import org.richfaces.jsr330.InjectorImpl;
import org.richfaces.util.Util;
import com.gargoylesoftware.htmlunit.Cache;
@@ -219,7 +222,7 @@
public void testStateHolder() throws Exception {
setupFacesRequest();
- ResourceCodec mockedCodec = EasyMock.createNiceMock(ResourceCodec.class);
+ final ResourceCodec mockedCodec = EasyMock.createNiceMock(ResourceCodec.class);
EasyMock.expect(mockedCodec.decodeResourceName(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn("org.richfaces.resource.StateHolderResourceImpl");
@@ -230,8 +233,16 @@
EasyMock.expect(mockedCodec.getResourceKey(EasyMock.<FacesContext>notNull(),
EasyMock.eq("StateHolderResource"))).andReturn("StateHolderResource.jsf?db=1");
EasyMock.replay(mockedCodec);
- ServiceTracker.setService(facesContext, ResourceCodec.class, mockedCodec);
+ InjectorImpl injector = new InjectorImpl();
+ injector.init(new BindingModule(){
+ public void configure(InjectorConfig injector) {
+ injector.register(ResourceCodec.class).toInstance(mockedCodec);
+ }
+
+ });
+ ServiceTracker.setInjector(injector);
+
WebRequestSettings settings =
new WebRequestSettings(new
URL("http://localhost/rfRes/StateHolderResource.jsf?db=1"));
WebResponse resourceResponse = webClient.loadWebResponse(settings);
Modified: root/core/branches/jsr-330/jsr330-impl/pom.xml
===================================================================
--- root/core/branches/jsr-330/jsr330-impl/pom.xml 2010-06-15 20:07:22 UTC (rev 17627)
+++ root/core/branches/jsr-330/jsr330-impl/pom.xml 2010-06-15 23:29:59 UTC (rev 17628)
@@ -1,8 +1,14 @@
<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">
<modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-parent</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
- <groupId>org.richfaces</groupId>
+ <groupId>org.richfaces.core</groupId>
<artifactId>jsr330-impl</artifactId>
<version>4.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
@@ -34,10 +40,13 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.richfaces.core</groupId>
+ <artifactId>richfaces-core-api</artifactId>
+ </dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
- <version>1</version>
</dependency>
</dependencies>
</project>
Modified:
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BinderImpl.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/BinderImpl.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -71,7 +71,6 @@
}
public BinderImpl<Provider<T>> asProviderBinder() {
- checkInitialized();
if (null == providerBinder) {
createProviderBinding();
}
@@ -210,4 +209,21 @@
}
return this;
}
+
+ public void destroy(InjectorImpl injectorImpl) {
+ if (null != value && value instanceof Initializable) {
+ ((Initializable) value).destroy();
+ }
+ if (null != provider && provider instanceof Initializable) {
+ ((Initializable) provider).destroy();
+ }
+ if (null != providerOfProvider && providerOfProvider instanceof
Initializable) {
+ ((Initializable) providerOfProvider).destroy();
+ }
+ value = null;
+ provider = null;
+ providerOfProvider = null;
+ providerBinder = null;
+ this.initialized = false;
+ }
}
Deleted:
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DependencyInjector.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
-
-/**
- * <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);
-
-}
Modified:
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/DynamicProvider.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -66,13 +66,13 @@
@SuppressWarnings("unchecked")
void findConstructor(Binders injectorImpl) throws Exception {
- Constructor<T>[] constructors = this.type.getConstructors();
- for (Constructor<T> constructor : constructors) {
+ 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;
+ this.constructor = (Constructor<T>) constructor;
Type[] parameterTypes = constructor.getGenericParameterTypes();
Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
this.constructorArguments = getParameterBindings(injectorImpl,
parameterTypes, parameterAnnotations);
@@ -154,5 +154,12 @@
throw new DependencyException(e);
}
}
+
+ public void destroy() {
+ constructor = null;
+ constructorArguments = null;
+ injectedFields = null;
+ injectedMethods = null;
+ }
}
Modified:
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Initializable.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Initializable.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/Initializable.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -8,5 +8,7 @@
public interface Initializable {
public boolean init(Binders injectorImpl);
+
+ public void destroy();
}
\ No newline at end of file
Modified:
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/InjectorImpl.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -7,6 +7,8 @@
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
@@ -38,6 +40,13 @@
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());
Modified:
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/main/java/org/richfaces/jsr330/ObjectFactory.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -3,6 +3,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.richfaces.application.DependencyInjector;
+
/**
* Implementation independent factory for JSR-330 beans.
*
Copied:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java)
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java
(rev 0)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ConstructorInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
+ }
+
+}
Copied:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java)
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/FieldInjection.java
(rev 0)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/FieldInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
+ }
+
+}
Modified:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/InjectorTest.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -13,14 +13,14 @@
injector.init(new BindingModule(){
public void configure(InjectorConfig injector) {
-
injector.register(TestInterface.class).to(TestConstructorInjection.class);
+ injector.register(Interface.class).to(ConstructorInjection.class);
injector.register("foo",
String.class).toInstance("bar");
injector.register("bar",
String.class).toInstance("baz");
}
});
- TestInterface testInterface = injector.create(TestInterface.class);
- assertTrue(testInterface instanceof TestConstructorInjection);
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof ConstructorInjection);
assertEquals("bar",testInterface.hello());
}
@@ -30,14 +30,14 @@
injector.init(new BindingModule(){
public void configure(InjectorConfig injector) {
- injector.register(TestInterface.class).to(TestFieldInjection.class);
+ injector.register(Interface.class).to(FieldInjection.class);
injector.register("foo",
String.class).toInstance("bar");
injector.register("bar",
String.class).toInstance("baz");
}
});
- TestInterface testInterface = injector.create(TestInterface.class);
- assertTrue(testInterface instanceof TestFieldInjection);
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof FieldInjection);
assertEquals("bar",testInterface.hello());
}
@@ -47,14 +47,14 @@
injector.init(new BindingModule(){
public void configure(InjectorConfig injector) {
- injector.register(TestInterface.class).to(TestMethodInjection.class);
+ injector.register(Interface.class).to(MethodInjection.class);
injector.register("foo",
String.class).toInstance("bar");
injector.register("bar",
String.class).toInstance("baz");
}
});
- TestInterface testInterface = injector.create(TestInterface.class);
- assertTrue(testInterface instanceof TestMethodInjection);
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof MethodInjection);
assertEquals("bar",testInterface.hello());
}
@@ -64,14 +64,14 @@
injector.init(new BindingModule(){
public void configure(InjectorConfig injector) {
- injector.register(TestInterface.class).to(TestProviderInjection.class);
+ injector.register(Interface.class).to(ProviderInjection.class);
injector.register("foo",
String.class).toInstance("bar");
injector.register("bar",
String.class).toInstance("baz");
}
});
- TestInterface testInterface = injector.create(TestInterface.class);
- assertTrue(testInterface instanceof TestProviderInjection);
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof ProviderInjection);
assertEquals("bar",testInterface.hello());
}
@@ -81,17 +81,35 @@
injector.init(new BindingModule(){
public void configure(InjectorConfig injector) {
- injector.register(TestInterface.class).to(TestProviderInjection.class);
+ injector.register(Interface.class).to(ProviderInjection.class);
injector.register("foo", String.class).toProviderInstance(new
FooProvider());
injector.register("bar",
String.class).toProvider(BarProvider.class);
}
});
- TestInterface testInterface = injector.create(TestInterface.class);
- assertTrue(testInterface instanceof TestProviderInjection);
+ Interface testInterface = injector.create(Interface.class);
+ assertTrue(testInterface instanceof ProviderInjection);
assertEquals("foo",testInterface.hello());
- TestProviderInjection instance = (TestProviderInjection) testInterface;
+ 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 BindingModule(){
+
+ 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/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/Interface.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java)
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/Interface.java
(rev 0)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/Interface.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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();
+
+}
Copied:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java)
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/MethodInjection.java
(rev 0)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/MethodInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
+ }
+
+}
Copied:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java)
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java
(rev 0)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ProviderInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
+ }
+}
Copied:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
(from rev 17627,
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestServiceImpl.java)
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
(rev 0)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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;
+ }
+
+}
Property changes on:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/ServiceLoaderTest.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -78,7 +78,7 @@
public void testLoadServiceClasses() throws Exception {
Collection<Class<? extends List>> serviceClasses =
ServiceLoader.loadServiceClasses(List.class);
assertEquals(1, serviceClasses.size());
- assertEquals(TestServiceImpl.class, serviceClasses.iterator().next());
+ assertEquals(ServiceImpl.class, serviceClasses.iterator().next());
}
/**
@@ -92,7 +92,7 @@
URL url =
this.getClass().getResource("/META-INF/services/java.util.List");
Collection<String> collection = ServiceLoader.parse(url);
assertEquals(1, collection.size());
- assertEquals(TestServiceImpl.class.getName(), collection.iterator().next());
+ assertEquals(ServiceImpl.class.getName(), collection.iterator().next());
}
/**
@@ -117,12 +117,12 @@
*/
@Test
public void testParseLine1() throws Exception {
- String line = TestServiceImpl.class.getName();
+ String line = ServiceImpl.class.getName();
ArrayList<String> names = new ArrayList<String>();
ServiceLoader.parseLine(line, names);
assertEquals(1, names.size());
- assertEquals(TestServiceImpl.class.getName(), names.get(0));
+ assertEquals(ServiceImpl.class.getName(), names.get(0));
}
/**
Deleted:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestConstructorInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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 TestConstructorInjection implements TestInterface {
-
- final String param;
-
- @Inject
- public TestConstructorInjection( @Named("foo") String param) {
- this.param = param;
- }
-
- public String hello() {
- return param;
- }
-
-}
Deleted:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestFieldInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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 TestFieldInjection implements TestInterface {
-
- @Inject
- @Named("foo")
- String param;
-
- public TestFieldInjection( ) {
- }
-
- public String hello() {
- return param;
- }
-
-}
Deleted:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestInterface.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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 TestInterface {
-
- public String hello();
-
-}
Deleted:
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestMethodInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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 TestMethodInjection implements TestInterface {
-
- 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/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestProviderInjection.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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 TestProviderInjection implements TestInterface {
-
- 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/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestServiceImpl.java
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestServiceImpl.java 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/java/org/richfaces/jsr330/TestServiceImpl.java 2010-06-15
23:29:59 UTC (rev 17628)
@@ -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 TestServiceImpl 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;
- }
-
-}
Modified:
root/core/branches/jsr-330/jsr330-impl/src/test/resources/META-INF/services/java.util.List
===================================================================
---
root/core/branches/jsr-330/jsr330-impl/src/test/resources/META-INF/services/java.util.List 2010-06-15
20:07:22 UTC (rev 17627)
+++
root/core/branches/jsr-330/jsr330-impl/src/test/resources/META-INF/services/java.util.List 2010-06-15
23:29:59 UTC (rev 17628)
@@ -1,3 +1,3 @@
# test implementation of List
-org.richfaces.jsr330.TestServiceImpl # comment
+org.richfaces.jsr330.ServiceImpl # comment