Seam SVN: r13581 - in modules/faces/trunk: api/src/main/java/org/jboss/seam/faces/transaction and 4 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-09 06:58:31 -0400 (Mon, 09 Aug 2010)
New Revision: 13581
Added:
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransaction.java
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransactionType.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/transaction/
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/transaction/TransactionPhaseListener.java
Modified:
modules/faces/trunk/impl/pom.xml
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java
Log:
Seam managed transactions, no tests yet
Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransaction.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransaction.java (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransaction.java 2010-08-09 10:58:31 UTC (rev 13581)
@@ -0,0 +1,40 @@
+/*
+ * 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.jboss.seam.faces.transaction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Configuration annotation for seam managed transactions
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.FIELD)
+public @interface SeamManagedTransaction
+{
+ SeamManagedTransactionType value();
+}
Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransactionType.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransactionType.java (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/transaction/SeamManagedTransactionType.java 2010-08-09 10:58:31 UTC (rev 13581)
@@ -0,0 +1,37 @@
+/*
+ * 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.jboss.seam.faces.transaction;
+
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
+public enum SeamManagedTransactionType
+{
+
+ ENABLED, DISABLED,
+ /**
+ * Transactions are only enabled during the RENDER_RESPONSE phase
+ */
+ RENDER_RESPONSE;
+}
Modified: modules/faces/trunk/impl/pom.xml
===================================================================
--- modules/faces/trunk/impl/pom.xml 2010-08-09 10:45:30 UTC (rev 13580)
+++ modules/faces/trunk/impl/pom.xml 2010-08-09 10:58:31 UTC (rev 13581)
@@ -1,59 +1,70 @@
<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <artifactId>seam-faces-parent</artifactId>
- <groupId>org.jboss.seam.faces</groupId>
- <version>3.0.0-SNAPSHOT</version>
+ <parent>
+ <artifactId>seam-faces-parent</artifactId>
+ <groupId>org.jboss.seam.faces</groupId>
+ <version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
- </parent>
+ </parent>
- <artifactId>seam-faces</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <artifactId>seam-faces</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>Seam Faces Module Core Implementation</name>
+ <packaging>jar</packaging>
+ <name>Seam Faces Module Core Implementation</name>
- <dependencies>
- <dependency>
+ <dependencies>
+ <dependency>
<!-- Required until the Servlet 3.0 API can be resolved in Central -->
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <artifactId>seam-faces-api</artifactId>
- <groupId>org.jboss.seam.faces</groupId>
- <version>${project.version}</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.seam.international</groupId>
- <artifactId>seam-international</artifactId>
- <version>${seam.i18n.version}</version>
- </dependency>
- </dependencies>
+ <dependency>
+ <artifactId>seam-faces-api</artifactId>
+ <groupId>org.jboss.seam.faces</groupId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <artifactId>seam-persistence-api</artifactId>
+ <groupId>org.jboss.seam.persistence</groupId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.seam.international</groupId>
+ <artifactId>seam-international</artifactId>
+ <version>${seam.i18n.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
- <profiles>
- <profile>
- <id>code-coverage</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>emma-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.sonatype.maven.plugin</groupId>
- <artifactId>emma4it-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
+ <profiles>
+ <profile>
+ <id>code-coverage</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>emma-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.sonatype.maven.plugin</groupId>
+ <artifactId>emma4it-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java 2010-08-09 10:45:30 UTC (rev 13580)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/DelegatingPhaseListener.java 2010-08-09 10:58:31 UTC (rev 13581)
@@ -28,6 +28,7 @@
import javax.faces.event.PhaseListener;
import org.jboss.seam.faces.context.FlashScopedContext;
+import org.jboss.seam.faces.transaction.TransactionPhaseListener;
/**
* Provide CDI injection to PhaseListener artifacts by delegating through this
@@ -79,7 +80,7 @@
@SuppressWarnings("unchecked")
private List<PhaseListener> getPhaseListeners()
{
- return getListeners(FlashScopedContext.class, PhaseEventBridge.class);
+ return getListeners(FlashScopedContext.class, PhaseEventBridge.class, TransactionPhaseListener.class);
}
}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/transaction/TransactionPhaseListener.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/transaction/TransactionPhaseListener.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/transaction/TransactionPhaseListener.java 2010-08-09 10:58:31 UTC (rev 13581)
@@ -0,0 +1,196 @@
+/*
+ * 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.jboss.seam.faces.transaction;
+
+import static javax.faces.event.PhaseId.ANY_PHASE;
+import static javax.faces.event.PhaseId.RENDER_RESPONSE;
+
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.inject.Inject;
+
+import org.jboss.seam.faces.viewdata.ViewDataStore;
+import org.jboss.seam.persistence.transaction.PersistenceContexts;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Phase listener that is resposible for seam managed transactions. It is also
+ * resposible for setting the correct flush mode on the persistence context
+ * during the render response phase
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class TransactionPhaseListener implements PhaseListener
+{
+ private static final long serialVersionUID = -9127555729455066493L;
+
+ private static final Logger log = LoggerFactory.getLogger(TransactionPhaseListener.class);
+
+ @Inject
+ SeamTransaction transaction;
+
+ @Inject
+ ViewDataStore dataStore;
+
+ @Inject
+ PersistenceContexts persistenceContexts;
+
+ public PhaseId getPhaseId()
+ {
+ return ANY_PHASE;
+ }
+
+ public void beforePhase(PhaseEvent event)
+ {
+ log.trace("before phase: " + event.getPhaseId());
+ handleTransactionsBeforePhase(event);
+ }
+
+ public void afterPhase(PhaseEvent event)
+ {
+ if (event.getPhaseId() == RENDER_RESPONSE)
+ {
+ persistenceContexts.afterRender();
+ }
+ handleTransactionsAfterPhase(event);
+ }
+
+
+ public void handleTransactionsBeforePhase(PhaseEvent event)
+ {
+ PhaseId phaseId = event.getPhaseId();
+ if (seamManagedTransactionStatus(phaseId))
+ {
+ if (phaseId == RENDER_RESPONSE)
+ {
+ persistenceContexts.beforeRender();
+ }
+ boolean beginTran = (phaseId == PhaseId.RENDER_RESPONSE || phaseId == PhaseId.RESTORE_VIEW);
+ if (beginTran)
+ {
+ begin(phaseId);
+ }
+ }
+ }
+
+ public void handleTransactionsAfterPhase(PhaseEvent event)
+ {
+ PhaseId phaseId = event.getPhaseId();
+ if (seamManagedTransactionStatus(phaseId))
+ {
+ boolean commitTran = phaseId == PhaseId.INVOKE_APPLICATION || event.getFacesContext().getRenderResponse() ||
+ event.getFacesContext().getResponseComplete() || phaseId == PhaseId.RENDER_RESPONSE;
+
+ if (commitTran)
+ {
+ commitOrRollback(phaseId); // we commit before destroying contexts,
+ // cos the contexts have the PC in them
+ }
+ }
+ }
+
+ void begin(PhaseId phaseId)
+ {
+ begin("prior to phase: " + phaseId);
+ }
+
+ void begin(String phaseString)
+ {
+ try
+ {
+ if (!transaction.isActiveOrMarkedRollback())
+ {
+ log.debug("beginning transaction " + phaseString);
+ transaction.begin();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Could not start transaction", e);
+ }
+ }
+
+ void commitOrRollback(PhaseId phaseId)
+ {
+ commitOrRollback("after phase: " + phaseId);
+ }
+
+ void commitOrRollback(String phaseString)
+ {
+ try
+ {
+ if (transaction.isActive())
+ {
+ try
+ {
+ log.debug("committing transaction " + phaseString);
+ transaction.commit();
+
+ }
+ catch (IllegalStateException e)
+ {
+ log.warn("TX commit failed with illegal state exception. This may be because the tx timed out and was rolled back in the background.", e);
+ }
+ }
+ else if (transaction.isRolledBackOrMarkedRollback())
+ {
+ log.debug("rolling back transaction " + phaseString);
+ transaction.rollback();
+ }
+
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Could not commit transaction", e);
+ }
+ }
+
+ private boolean seamManagedTransactionStatus(PhaseId phase)
+ {
+ SeamManagedTransaction an = dataStore.getData(SeamManagedTransaction.class);
+ SeamManagedTransactionType config;
+ if (an == null)
+ {
+ // enable seam managed transactions by default
+ config = SeamManagedTransactionType.ENABLED;
+ }
+ else
+ {
+ config = an.value();
+ }
+ if (config == SeamManagedTransactionType.DISABLED)
+ {
+ return false;
+ }
+ else if (config == SeamManagedTransactionType.RENDER_RESPONSE && phase != PhaseId.RENDER_RESPONSE)
+ {
+ return false;
+ }
+ return true;
+ }
+}
15 years, 4 months
Seam SVN: r13580 - in modules/faces/trunk: impl/src/main/java/org/jboss/seam/faces/viewdata and 2 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-09 06:45:30 -0400 (Mon, 09 Aug 2010)
New Revision: 13580
Added:
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewConfig.java
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewData.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationExtension.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationEnum.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationTest.java
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java
modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
add ability to configure view data from an enum
Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewConfig.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewConfig.java (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewConfig.java 2010-08-09 10:45:30 UTC (rev 13580)
@@ -0,0 +1,43 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that is applied to an enum to signify that it contains
+ * configuration for view specific data
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.TYPE)
+@Documented
+public @interface ViewConfig
+{
+
+}
Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewData.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewData.java (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewData.java 2010-08-09 10:45:30 UTC (rev 13580)
@@ -0,0 +1,43 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that is applied to an enum constant to configure view specific
+ * information
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.FIELD)
+@Documented
+public @interface ViewData
+{
+ String value();
+}
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationExtension.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationExtension.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationExtension.java 2010-08-09 10:45:30 UTC (rev 13580)
@@ -0,0 +1,89 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Extension that scans enums for view specific configuration
+ *
+ * @author stuart
+ *
+ */
+public class ViewDataConfigurationExtension implements Extension
+{
+
+ private final Logger log = LoggerFactory.getLogger(ViewDataConfigurationExtension.class);
+
+ private final Map<String, Set<Annotation>> data = new HashMap<String, Set<Annotation>>();
+
+ public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event)
+ {
+ AnnotatedType<T> tp = event.getAnnotatedType();
+ if (tp.isAnnotationPresent(ViewConfig.class))
+ {
+ if (!tp.getJavaClass().isEnum())
+ {
+ log.warn("ViewConfig annotation should only be applied to enums, and {} is not an enum.", tp.getJavaClass());
+ }
+ else
+ {
+ for (Field f : tp.getJavaClass().getDeclaredFields())
+ {
+ if (f.isAnnotationPresent(ViewData.class))
+ {
+ ViewData viewConfig = f.getAnnotation(ViewData.class);
+ Set<Annotation> viewData = new HashSet<Annotation>();
+ data.put(viewConfig.value(), viewData);
+ for (Annotation a : f.getAnnotations())
+ {
+ if (a.annotationType() != ViewData.class)
+ {
+ viewData.add(a);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Map<String, Set<Annotation>> getData()
+ {
+ return Collections.unmodifiableMap(data);
+ }
+
+}
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java 2010-08-09 09:54:48 UTC (rev 13579)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java 2010-08-09 10:45:30 UTC (rev 13580)
@@ -27,11 +27,13 @@
import java.util.Comparator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.context.FacesContext;
+import javax.inject.Inject;
/**
* Data store for view specific data.
@@ -49,6 +51,26 @@
private final ConcurrentHashMap<Class<? extends Annotation>, ConcurrentHashMap<String, Annotation>> data = new ConcurrentHashMap<Class<? extends Annotation>, ConcurrentHashMap<String, Annotation>>();
+ /**
+ * setup the bean with the configuration from the extension
+ *
+ * It would be better if the extension could do this, but the extension
+ * cannot resolve the bean until after all lifecycle events have been
+ * processed
+ *
+ */
+ @Inject
+ public void setup(ViewDataConfigurationExtension extension)
+ {
+ for (Entry<String, Set<Annotation>> e : extension.getData().entrySet())
+ {
+ for (Annotation i : e.getValue())
+ {
+ addData(e.getKey(), i);
+ }
+ }
+ }
+
public synchronized void addData(String viewId, Annotation annotation)
{
ConcurrentHashMap<String, Annotation> map = data.get(annotation.annotationType());
Modified: modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-08-09 09:54:48 UTC (rev 13579)
+++ modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-08-09 10:45:30 UTC (rev 13580)
@@ -2,3 +2,4 @@
org.jboss.seam.faces.context.ViewScopedExtension
org.jboss.seam.faces.context.FlashScopedExtension
org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension
+org.jboss.seam.faces.viewdata.ViewDataConfigurationExtension
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationEnum.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationEnum.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationEnum.java 2010-08-09 10:45:30 UTC (rev 13580)
@@ -0,0 +1,38 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+@ViewConfig
+public enum ViewDataConfigurationEnum
+{
+ @ViewData("/*")
+ @Icon("default.gif")
+ DEFAULT,
+ @ViewData("/happy/*")
+ @Icon("happy.gif")
+ HAPPY,
+ @ViewData("/sad/*")
+ @Icon("sad.gif")
+ SAD,
+ @ViewData("/happy/done.xhtml")
+ @Icon("finished.gif")
+ HAPPY_DONE;
+}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationTest.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataConfigurationTest.java 2010-08-09 10:45:30 UTC (rev 13580)
@@ -0,0 +1,88 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class ViewDataConfigurationTest
+{
+
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class);
+ archive.addPackage(ViewDataConfigurationTest.class.getPackage());
+ archive.addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ return archive;
+ }
+
+ @Inject
+ ViewDataStore store;
+
+ @Test
+ public void testViewDataStore()
+ {
+
+ store.addData("/*", new IconLiteral("default.gif"));
+ store.addData("/sad/*", new IconLiteral("sad.gif"));
+ store.addData("/happy/*", new IconLiteral("happy.gif"));
+ store.addData("/happy/done.xhtml", new IconLiteral("finished.gif"));
+
+ Icon data;
+ data = store.getData("/happy/done.xhtml", Icon.class);
+ Assert.assertEquals("finished.gif", data.value());
+ data = store.getData("/happy/other.xhtml", Icon.class);
+ Assert.assertEquals("happy.gif", data.value());
+ data = store.getData("/default/news.xhtml", Icon.class);
+ Assert.assertEquals("default.gif", data.value());
+
+ List<Icon> dlist;
+ dlist = store.getAllData("/happy/done.xhtml", Icon.class);
+ Assert.assertEquals(3, dlist.size());
+ Assert.assertEquals("finished.gif", dlist.get(0).value());
+ Assert.assertEquals("happy.gif", dlist.get(1).value());
+ Assert.assertEquals("default.gif", dlist.get(2).value());
+ dlist = store.getAllData("/happy/other.xhtml", Icon.class);
+ Assert.assertEquals(2, dlist.size());
+ Assert.assertEquals("happy.gif", dlist.get(0).value());
+ Assert.assertEquals("default.gif", dlist.get(1).value());
+ dlist = store.getAllData("/default/news.xhtml", Icon.class);
+ Assert.assertEquals(1, dlist.size());
+ Assert.assertEquals("default.gif", dlist.get(0).value());
+
+ }
+}
15 years, 4 months
Seam SVN: r13579 - in modules/faces/trunk: api/src/main/java/org/jboss/seam/faces/viewdata and 4 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-09 05:54:48 -0400 (Mon, 09 Aug 2010)
New Revision: 13579
Added:
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStore.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/Icon.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/IconLiteral.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataStoreTest.java
Log:
Add view data store for storing view specific data
Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStore.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStore.java (rev 0)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStore.java 2010-08-09 09:54:48 UTC (rev 13579)
@@ -0,0 +1,66 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.lang.annotation.Annotation;
+import java.util.List;
+/**
+ * stores data specific to a given view is a heiracial fashion
+ * @author Stuart Douglas
+ *
+ */
+public interface ViewDataStore
+{
+
+ /**
+ * Adds data to the store
+ *
+ * @param viewId The view id to associate the data with. A * at the end of
+ * the view id is considered a wildcard
+ * @param annotation the data to store
+ */
+ public abstract void addData(String viewId, Annotation annotation);
+
+ /**
+ * gets the most specific data for a given viewId
+ *
+ */
+ public abstract <T extends Annotation> T getData(String viewId, Class<T> type);
+
+ /**
+ * gets the most specific data for the current viewId
+ */
+ public abstract <T extends Annotation> T getData(Class<T> type);
+
+ /**
+ * returns all data for a given viewId, with the most specific data at the
+ * start of the list
+ */
+ public abstract <T extends Annotation> List<T> getAllData(String viewId, Class<T> type);
+
+ /**
+ * returns all data for the current viewId, with the most specific data at
+ * the start of the list
+ */
+ public abstract <T extends Annotation> List<T> getAllData(Class<T> type);
+
+}
\ No newline at end of file
Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java (rev 0)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/viewdata/ViewDataStoreImpl.java 2010-08-09 09:54:48 UTC (rev 13579)
@@ -0,0 +1,170 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.faces.context.FacesContext;
+
+/**
+ * Data store for view specific data.
+ *
+ * @author Stuart Douglas
+ *
+ */
+@ApplicationScoped
+public class ViewDataStoreImpl implements ViewDataStore
+{
+ /**
+ * cache of viewId to a given data list
+ */
+ private final ConcurrentHashMap<Class<? extends Annotation>, ConcurrentHashMap<String, List<? extends Annotation>>> cache = new ConcurrentHashMap<Class<? extends Annotation>, ConcurrentHashMap<String, List<? extends Annotation>>>();
+
+ private final ConcurrentHashMap<Class<? extends Annotation>, ConcurrentHashMap<String, Annotation>> data = new ConcurrentHashMap<Class<? extends Annotation>, ConcurrentHashMap<String, Annotation>>();
+
+ public synchronized void addData(String viewId, Annotation annotation)
+ {
+ ConcurrentHashMap<String, Annotation> map = data.get(annotation.annotationType());
+ if (map == null)
+ {
+ map = new ConcurrentHashMap<String, Annotation>();
+ data.put(annotation.annotationType(), map);
+ }
+ map.put(viewId, annotation);
+ }
+
+ public <T extends Annotation> T getData(String viewId, Class<T> type)
+ {
+ List<T> data = prepareCache(viewId, type);
+ if (data != null)
+ {
+ return data.get(0);
+ }
+ return null;
+ }
+
+ public <T extends Annotation> T getData(Class<T> type)
+ {
+ return getData(FacesContext.getCurrentInstance().getViewRoot().getViewId(), type);
+ }
+
+ public <T extends Annotation> List<T> getAllData(String viewId, Class<T> type)
+ {
+ List<T> data = prepareCache(viewId, type);
+ if (data != null)
+ {
+ return Collections.unmodifiableList(data);
+ }
+ return null;
+ }
+
+ public <T extends Annotation> List<T> getAllData(Class<T> type)
+ {
+ return getAllData(FacesContext.getCurrentInstance().getViewRoot().getViewId(), type);
+ }
+
+ private <T extends Annotation> List<T> prepareCache(String viewId, Class<T> type)
+ {
+ // we need to synchonise to make sure that no threads see a half completed
+ // list due to instruction re-ordering
+ ConcurrentHashMap<String, List<? extends Annotation>> map = cache.get(type);
+ if (map == null)
+ {
+ ConcurrentHashMap<String, List<? extends Annotation>> newMap = new ConcurrentHashMap<String, List<? extends Annotation>>();
+ map = cache.putIfAbsent(type, newMap);
+ if (map == null)
+ {
+ map = newMap;
+ }
+ }
+ List<? extends Annotation> annotationData = map.get(viewId);
+ if (annotationData == null)
+ {
+ List<Annotation> newList = new ArrayList<Annotation>();
+ Map<String, Annotation> viewData = data.get(type);
+ List<String> resultingViews = new ArrayList<String>();
+ if (viewData != null)
+ {
+ for (Entry<String, Annotation> e : viewData.entrySet())
+ {
+ if (e.getKey().endsWith("*"))
+ {
+ String cutView = e.getKey().substring(0, e.getKey().length() - 1);
+ if (viewId.startsWith(cutView))
+ {
+ resultingViews.add(e.getKey());
+ }
+ }
+ else
+ {
+ if (e.getKey().equals(viewId))
+ {
+ resultingViews.add(e.getKey());
+ }
+ }
+ }
+ // sort the keys by length, longest is the most specific and so
+ // should go first
+ Collections.sort(resultingViews, StringLengthComparator.INSTANCE);
+ for (String i : resultingViews)
+ {
+ newList.add(viewData.get(i));
+ }
+ }
+
+ annotationData = map.putIfAbsent(viewId, newList);
+ if (annotationData == null)
+ {
+ annotationData = newList;
+ }
+ }
+ return (List) annotationData;
+ }
+
+ private static class StringLengthComparator implements Comparator<String>
+ {
+
+ public int compare(String o1, String o2)
+ {
+ if (o1.length() > o2.length())
+ {
+ return -1;
+ }
+ if (o1.length() < o2.length())
+ {
+ return 1;
+ }
+ return 0;
+ }
+
+ public static final StringLengthComparator INSTANCE = new StringLengthComparator();
+
+ }
+}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/Icon.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/Icon.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/Icon.java 2010-08-09 09:54:48 UTC (rev 13579)
@@ -0,0 +1,31 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Icon
+{
+ public String value();
+}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/IconLiteral.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/IconLiteral.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/IconLiteral.java 2010-08-09 09:54:48 UTC (rev 13579)
@@ -0,0 +1,40 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+public class IconLiteral extends AnnotationLiteral<Icon> implements Icon
+{
+ private final String value;
+
+ public IconLiteral(String value)
+ {
+ this.value = value;
+ }
+
+ public String value()
+ {
+ return value;
+ }
+
+}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataStoreTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataStoreTest.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/viewdata/ViewDataStoreTest.java 2010-08-09 09:54:48 UTC (rev 13579)
@@ -0,0 +1,64 @@
+/*
+ * 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.jboss.seam.faces.viewdata;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+public class ViewDataStoreTest
+{
+ @Test
+ public void testViewDataStore()
+ {
+ ViewDataStore store = new ViewDataStoreImpl();
+ store.addData("/*", new IconLiteral("default.gif"));
+ store.addData("/sad/*", new IconLiteral("sad.gif"));
+ store.addData("/happy/*", new IconLiteral("happy.gif"));
+ store.addData("/happy/done.xhtml", new IconLiteral("finished.gif"));
+
+ Icon data;
+ data = store.getData("/happy/done.xhtml", Icon.class);
+ Assert.assertEquals("finished.gif", data.value());
+ data = store.getData("/happy/other.xhtml", Icon.class);
+ Assert.assertEquals("happy.gif", data.value());
+ data = store.getData("/default/news.xhtml", Icon.class);
+ Assert.assertEquals("default.gif", data.value());
+
+ List<Icon> dlist;
+ dlist = store.getAllData("/happy/done.xhtml", Icon.class);
+ Assert.assertEquals(3, dlist.size());
+ Assert.assertEquals("finished.gif", dlist.get(0).value());
+ Assert.assertEquals("happy.gif", dlist.get(1).value());
+ Assert.assertEquals("default.gif", dlist.get(2).value());
+ dlist = store.getAllData("/happy/other.xhtml", Icon.class);
+ Assert.assertEquals(2, dlist.size());
+ Assert.assertEquals("happy.gif", dlist.get(0).value());
+ Assert.assertEquals("default.gif", dlist.get(1).value());
+ dlist = store.getAllData("/default/news.xhtml", Icon.class);
+ Assert.assertEquals(1, dlist.size());
+ Assert.assertEquals("default.gif", dlist.get(0).value());
+
+ }
+}
15 years, 4 months
Seam SVN: r13578 - branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/webdriver.
by seam-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-08-09 04:22:58 -0400 (Mon, 09 Aug 2010)
New Revision: 13578
Modified:
branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/webdriver/ConversationTest.java
Log:
JBSEAM-4610, hopefully fixed testConversations failing for icefaces example
Modified: branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/webdriver/ConversationTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/webdriver/ConversationTest.java 2010-08-07 13:44:20 UTC (rev 13577)
+++ branches/community/Seam_2_2/src/test/ftest/src/main/org/jboss/seam/example/common/test/booking/webdriver/ConversationTest.java 2010-08-09 08:22:58 UTC (rev 13578)
@@ -167,9 +167,9 @@
public boolean login(AjaxWebDriver driver, String username, String password)
{
- if (isLoggedIn(driver)) {
+ /*if (isLoggedIn(driver)) {
fail("User already logged in.");
- }
+ }*/
driver.get(serverURL + contextPath + HOME_PAGE);
if (!driver.getTitle().equals(PAGE_TITLE))
15 years, 4 months
Seam SVN: r13577 - modules/international/trunk.
by seam-commits@lists.jboss.org
Author: kenfinni
Date: 2010-08-07 09:44:20 -0400 (Sat, 07 Aug 2010)
New Revision: 13577
Modified:
modules/international/trunk/pom.xml
Log:
Updated Seam Parent POM and Repositories
Modified: modules/international/trunk/pom.xml
===================================================================
--- modules/international/trunk/pom.xml 2010-08-07 03:15:09 UTC (rev 13576)
+++ modules/international/trunk/pom.xml 2010-08-07 13:44:20 UTC (rev 13577)
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-parent</artifactId>
- <version>2</version>
+ <version>3</version>
</parent>
<artifactId>seam-international-parent</artifactId>
@@ -136,6 +136,45 @@
<module>docs/reference</module>
</modules>
</profile>
+ <profile>
+ <id>jboss-public-repository</id>
+ <activation>
+ <property>
+ <name>jboss-public-repository</name>
+ <value>!false</value>
+ </property>
+ </activation>
+ <repositories>
+ <repository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
</profiles>
<developers>
15 years, 4 months
Seam SVN: r13576 - in modules/persistence/trunk: api/src/main/java/org/jboss/seam/persistence and 2 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-06 23:15:09 -0400 (Fri, 06 Aug 2010)
New Revision: 13576
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/SeamManaged.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/FlushModeType.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/PersistenceContexts.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextsImpl.java
Removed:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java
Modified:
modules/persistence/trunk/api/pom.xml
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java
Log:
update the API
Modified: modules/persistence/trunk/api/pom.xml
===================================================================
--- modules/persistence/trunk/api/pom.xml 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/api/pom.xml 2010-08-07 03:15:09 UTC (rev 13576)
@@ -23,7 +23,11 @@
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
Copied: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/SeamManaged.java (from rev 13554, modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java)
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/SeamManaged.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/SeamManaged.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -0,0 +1,65 @@
+/*
+ * 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.jboss.seam.persistence;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.Dependent;
+import javax.persistence.EntityManagerFactory;
+
+/**
+ * Signifies that a resource producer field or producer method that produces an
+ * {@link EntityManagerFactory} should also produce a Seam managed persistence
+ * context. For example:
+ *
+ * <pre>
+ * @SeamManaged
+ * @Produces
+ * @PersistenceUnit
+ * @ConversationScoped
+ * @SomeQualifier
+ * EntityManagerFactory emf;
+ * </pre>
+ *
+ * will create a conversation scoped seam managed persistence context that is
+ * conversation scoped with the qualifier @SomeQualifier.
+ *
+ * This field still produces the EntityManagerFactory with qualifier
+ *
+ * @SomeQualifier, however the scope for the producer field is changed to
+ * {@link Dependent}, as the specification does not allow
+ * resource producer fields to have a scope other than Depedent
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.FIELD, ElementType.METHOD })
+@Documented
+public @interface SeamManaged
+{
+
+}
Copied: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/FlushModeType.java (from rev 13555, modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java)
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/FlushModeType.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/FlushModeType.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -0,0 +1,42 @@
+package org.jboss.seam.persistence.transaction;
+
+/**
+ * A full set of flush modes, including MANUAL,
+ * which is a glaring missing feature of the JPA
+ * spec.
+ *
+ * @author Gavin King
+ *
+ */
+public enum FlushModeType
+{
+
+ /**
+ * Flushing never occurs automatically, all changes are queued
+ * until the application calls flush() explicitly.
+ */
+ MANUAL,
+
+ /**
+ * Flushing occurs automatically at commit time and when necessary
+ * before query executions.
+ */
+ AUTO,
+
+ /**
+ * Flushing occurs automatically at transaction commit time.
+ */
+ COMMIT;
+
+ /**
+ * Does this flush mode keep unflushed changes past a
+ * transaction commit?
+ *
+ * @return false for all flush modes except for MANUAL
+ */
+ public boolean dirtyBetweenTransactions()
+ {
+ return this==MANUAL;
+ }
+
+}
Added: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/PersistenceContexts.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/PersistenceContexts.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/PersistenceContexts.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -0,0 +1,23 @@
+package org.jboss.seam.persistence.transaction;
+
+
+public interface PersistenceContexts
+{
+
+ public abstract FlushModeType getFlushMode();
+
+ public abstract void changeFlushMode(FlushModeType flushMode);
+
+ public abstract void changeFlushMode(FlushModeType flushMode, boolean temporary);
+
+ /**
+ * Restore the previous flush mode if the current flush mode is marked as
+ * temporary.
+ */
+ public abstract void restoreFlushMode();
+
+ public abstract void beforeRender();
+
+ public abstract void afterRender();
+
+}
\ No newline at end of file
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeManager.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -25,6 +25,8 @@
import javax.enterprise.context.ApplicationScoped;
+import org.jboss.seam.persistence.transaction.FlushModeType;
+
/**
* Provides for programmatic configuration of the default flush mode.
*
Deleted: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/FlushModeType.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -1,42 +0,0 @@
-package org.jboss.seam.persistence;
-
-/**
- * A full set of flush modes, including MANUAL,
- * which is a glaring missing feature of the JPA
- * spec.
- *
- * @author Gavin King
- *
- */
-public enum FlushModeType
-{
-
- /**
- * Flushing never occurs automatically, all changes are queued
- * until the application calls flush() explicitly.
- */
- MANUAL,
-
- /**
- * Flushing occurs automatically at commit time and when necessary
- * before query executions.
- */
- AUTO,
-
- /**
- * Flushing occurs automatically at transaction commit time.
- */
- COMMIT;
-
- /**
- * Does this flush mode keep unflushed changes past a
- * transaction commit?
- *
- * @return false for all flush modes except for MANUAL
- */
- public boolean dirtyBetweenTransactions()
- {
- return this==MANUAL;
- }
-
-}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -16,6 +16,7 @@
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.VersionType;
+import org.jboss.seam.persistence.transaction.FlushModeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,7 +33,7 @@
{
@Inject
- Instance<PersistenceContexts> persistenceContexts;
+ Instance<PersistenceContextsImpl> persistenceContexts;
private static Logger log = LoggerFactory.getLogger(HibernatePersistenceProvider.class);
private static Class FULL_TEXT_SESSION_PROXY_CLASS;
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContext.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -24,6 +24,8 @@
import java.lang.annotation.Annotation;
import java.util.Set;
+import org.jboss.seam.persistence.transaction.FlushModeType;
+
/**
* Support for changing flushmodes for an existing persistence context.
*
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextProxyHandler.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -29,6 +29,7 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;
+import org.jboss.seam.persistence.transaction.FlushModeType;
import org.jboss.seam.persistence.util.InstanceResolver;
import org.jboss.weld.extensions.el.Expressions;
import org.slf4j.Logger;
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -1,205 +1,38 @@
package org.jboss.seam.persistence;
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.Set;
-import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.jboss.seam.persistence.PersistenceContextsImpl.PersistenceContextDefintition;
+import org.jboss.seam.persistence.transaction.FlushModeType;
-/**
- * Maintains the set of persistence contexts that have been touched in a
- * conversation. Also controls the flush mode used by the persistence contexts
- * during the render phase.
- *
- * @author Gavin King
- */
-@ConversationScoped
-public class PersistenceContexts implements Serializable
+public interface PersistenceContexts
{
- private static final long serialVersionUID = -4897350516435283182L;
- private static final Logger log = LoggerFactory.getLogger(PersistenceContexts.class);
- /**
- * persistences contexts are referenced by their qualifiers
- */
- private Set<PersistenceContextDefintition> set = new HashSet<PersistenceContextDefintition>();
- private FlushModeType flushMode;
-
- // the real flush mode is a backup of the flush mode when doing a temporary
- // switch (such as during render)
- private FlushModeType realFlushMode;
-
@Inject
- BeanManager beanManager;
+ public abstract void create(FlushModeManager manager);
- @Inject
- @Any
- Instance<PersistenceContext> persistenceContexts;
+ public abstract FlushModeType getFlushMode();
- @Inject
- Instance<PersistenceProvider> persistenceProvider;
+ public abstract Set<PersistenceContextDefintition> getTouchedContexts();
- @Inject
- public void create(FlushModeManager manager)
- {
- FlushModeType defaultFlushMode = manager.getFlushModeType();
- if (defaultFlushMode != null)
- {
- flushMode = defaultFlushMode;
- }
- else
- {
- flushMode = FlushModeType.AUTO;
- }
- }
+ public abstract void touch(PersistenceContext context);
- public FlushModeType getFlushMode()
- {
- return flushMode;
- }
+ public abstract void untouch(PersistenceContext context);
- public Set<PersistenceContextDefintition> getTouchedContexts()
- {
- return Collections.unmodifiableSet(set);
- }
+ public abstract void changeFlushMode(FlushModeType flushMode);
- public void touch(PersistenceContext context)
- {
- set.add(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType()));
- }
+ public abstract void changeFlushMode(FlushModeType flushMode, boolean temporary);
- public void untouch(PersistenceContext context)
- {
- set.remove(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType()));
- }
-
- public void changeFlushMode(FlushModeType flushMode)
- {
- changeFlushMode(flushMode, false);
- }
-
- public void changeFlushMode(FlushModeType flushMode, boolean temporary)
- {
- if (temporary)
- {
- realFlushMode = this.flushMode;
- }
- this.flushMode = flushMode;
- changeFlushModes();
- }
-
/**
* Restore the previous flush mode if the current flush mode is marked as
* temporary.
*/
- public void restoreFlushMode()
- {
- if (realFlushMode != null && realFlushMode != flushMode)
- {
- flushMode = realFlushMode;
- realFlushMode = null;
- changeFlushModes();
- }
- }
+ public abstract void restoreFlushMode();
- private void changeFlushModes()
- {
+ public abstract void beforeRender();
- for (PersistenceContext context : persistenceContexts)
- {
- if (set.contains(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType())))
- try
- {
- context.changeFlushMode(flushMode);
- }
- catch (UnsupportedOperationException uoe)
- {
- // we won't be nasty and throw and exception, but we'll log a
- // warning to the developer
- log.warn(uoe.getMessage());
- }
- }
- }
+ public abstract void afterRender();
- public void beforeRender()
- {
- // some JPA providers may not support MANUAL flushing
- // defer the decision to the provider manager component
- persistenceProvider.get().setRenderFlushMode();
- }
-
- public void afterRender()
- {
- restoreFlushMode();
- }
-
- public static class PersistenceContextDefintition
- {
- private final Set<Annotation> qualifiers;
- private final Class<?> type;
-
- public PersistenceContextDefintition(Set<Annotation> qualifiers, Class<?> type)
- {
- this.qualifiers = new HashSet<Annotation>(qualifiers);
- this.type = type;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return qualifiers;
- }
-
- public Class<?> getType()
- {
- return type;
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((qualifiers == null) ? 0 : qualifiers.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- PersistenceContextDefintition other = (PersistenceContextDefintition) obj;
- if (qualifiers == null)
- {
- if (other.qualifiers != null)
- return false;
- }
- else if (!qualifiers.equals(other.qualifiers))
- return false;
- if (type == null)
- {
- if (other.type != null)
- return false;
- }
- else if (!type.equals(other.type))
- return false;
- return true;
- }
-
- }
-
-}
+}
\ No newline at end of file
Copied: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextsImpl.java (from rev 13555, modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContexts.java)
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextsImpl.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextsImpl.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -0,0 +1,202 @@
+package org.jboss.seam.persistence;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import org.jboss.seam.persistence.transaction.FlushModeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Maintains the set of persistence contexts that have been touched in a
+ * conversation. Also controls the flush mode used by the persistence contexts
+ * during the render phase.
+ *
+ * @author Gavin King
+ */
+@ConversationScoped
+public class PersistenceContextsImpl implements Serializable, PersistenceContexts
+{
+ private static final long serialVersionUID = -4897350516435283182L;
+ private static final Logger log = LoggerFactory.getLogger(PersistenceContextsImpl.class);
+ /**
+ * persistences contexts are referenced by their qualifiers
+ */
+ private Set<PersistenceContextDefintition> set = new HashSet<PersistenceContextDefintition>();
+
+ private FlushModeType flushMode;
+
+ // the real flush mode is a backup of the flush mode when doing a temporary
+ // switch (such as during render)
+ private FlushModeType realFlushMode;
+
+ @Inject
+ BeanManager beanManager;
+
+ @Inject
+ @Any
+ Instance<PersistenceContext> persistenceContexts;
+
+ @Inject
+ Instance<PersistenceProvider> persistenceProvider;
+
+ @Inject
+ public void create(FlushModeManager manager)
+ {
+ FlushModeType defaultFlushMode = manager.getFlushModeType();
+ if (defaultFlushMode != null)
+ {
+ flushMode = defaultFlushMode;
+ }
+ else
+ {
+ flushMode = FlushModeType.AUTO;
+ }
+ }
+
+ public FlushModeType getFlushMode()
+ {
+ return flushMode;
+ }
+
+ public Set<PersistenceContextDefintition> getTouchedContexts()
+ {
+ return Collections.unmodifiableSet(set);
+ }
+
+ public void touch(PersistenceContext context)
+ {
+ set.add(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType()));
+ }
+
+ public void untouch(PersistenceContext context)
+ {
+ set.remove(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType()));
+ }
+
+ public void changeFlushMode(FlushModeType flushMode)
+ {
+ changeFlushMode(flushMode, false);
+ }
+
+ public void changeFlushMode(FlushModeType flushMode, boolean temporary)
+ {
+ if (temporary)
+ {
+ realFlushMode = this.flushMode;
+ }
+ this.flushMode = flushMode;
+ changeFlushModes();
+ }
+
+ public void restoreFlushMode()
+ {
+ if (realFlushMode != null && realFlushMode != flushMode)
+ {
+ flushMode = realFlushMode;
+ realFlushMode = null;
+ changeFlushModes();
+ }
+ }
+
+ private void changeFlushModes()
+ {
+
+ for (PersistenceContext context : persistenceContexts)
+ {
+ if (set.contains(new PersistenceContextDefintition(context.getQualifiers(), context.getBeanType())))
+ try
+ {
+ context.changeFlushMode(flushMode);
+ }
+ catch (UnsupportedOperationException uoe)
+ {
+ // we won't be nasty and throw and exception, but we'll log a
+ // warning to the developer
+ log.warn(uoe.getMessage());
+ }
+ }
+ }
+
+ public void beforeRender()
+ {
+ // some JPA providers may not support MANUAL flushing
+ // defer the decision to the provider manager component
+ persistenceProvider.get().setRenderFlushMode();
+ }
+
+ public void afterRender()
+ {
+ restoreFlushMode();
+ }
+
+ public static class PersistenceContextDefintition
+ {
+ private final Set<Annotation> qualifiers;
+ private final Class<?> type;
+
+ public PersistenceContextDefintition(Set<Annotation> qualifiers, Class<?> type)
+ {
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.type = type;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qualifiers == null) ? 0 : qualifiers.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PersistenceContextDefintition other = (PersistenceContextDefintition) obj;
+ if (qualifiers == null)
+ {
+ if (other.qualifiers != null)
+ return false;
+ }
+ else if (!qualifiers.equals(other.qualifiers))
+ return false;
+ if (type == null)
+ {
+ if (other.type != null)
+ return false;
+ }
+ else if (!type.equals(other.type))
+ return false;
+ return true;
+ }
+
+ }
+
+}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceProvider.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -31,6 +31,8 @@
import javax.persistence.PersistenceContexts;
import javax.transaction.Synchronization;
+import org.jboss.seam.persistence.transaction.FlushModeType;
+
/**
* Abstraction layer for persistence providers (JPA implementations). This class
* provides a working base implementation that can be optimized for performance
Deleted: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java 2010-08-07 02:15:38 UTC (rev 13575)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java 2010-08-07 03:15:09 UTC (rev 13576)
@@ -1,65 +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.jboss.seam.persistence;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.enterprise.context.Dependent;
-import javax.persistence.EntityManagerFactory;
-
-/**
- * Signifies that a resource producer field or producer method that produces an
- * {@link EntityManagerFactory} should also produce a Seam managed persistence
- * context. For example:
- *
- * <pre>
- * @SeamManaged
- * @Produces
- * @PersistenceUnit
- * @ConversationScoped
- * @SomeQualifier
- * EntityManagerFactory emf;
- * </pre>
- *
- * will create a conversation scoped seam managed persistence context that is
- * conversation scoped with the qualifier @SomeQualifier.
- *
- * This field still produces the EntityManagerFactory with qualifier
- *
- * @SomeQualifier, however the scope for the producer field is changed to
- * {@link Dependent}, as the specification does not allow
- * resource producer fields to have a scope other than Depedent
- *
- * @author Stuart Douglas
- *
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-@Target( { ElementType.FIELD, ElementType.METHOD })
-@Documented
-public @interface SeamManaged
-{
-
-}
15 years, 4 months
Seam SVN: r13575 - modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-06 22:15:38 -0400 (Fri, 06 Aug 2010)
New Revision: 13575
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java
Log:
change to use ResourceLoadManager
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java 2010-08-07 02:15:11 UTC (rev 13574)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/ResourceLoaderXmlDocumentProvider.java 2010-08-07 02:15:38 UTC (rev 13575)
@@ -25,7 +25,6 @@
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
@@ -34,8 +33,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.jboss.weld.extensions.resourceLoader.ResourceLoader;
-import org.jboss.weld.extensions.util.service.ServiceLoader;
+import org.jboss.weld.extensions.resourceLoader.ResourceLoaderManager;
import org.xml.sax.InputSource;
/**
@@ -47,7 +45,7 @@
public class ResourceLoaderXmlDocumentProvider implements XmlDocumentProvider
{
- private final List<ResourceLoader> resourceLoaders;
+ private final ResourceLoaderManager manager = new ResourceLoaderManager();
static final String[] DEFAULT_RESOURCES = { "seam-beans.xml", "META-INF/seam-beans.xml", "META-INF/beans.xml", "WEB-INF/beans.xml" };
@@ -63,11 +61,6 @@
public ResourceLoaderXmlDocumentProvider(String[] resources)
{
this.resources = resources;
- resourceLoaders = new ArrayList<ResourceLoader>();
- for (ResourceLoader resourceLoader : ServiceLoader.load(ResourceLoader.class))
- {
- resourceLoaders.add(resourceLoader);
- }
}
List<URL> docs;
@@ -95,22 +88,12 @@
for (String i : resources)
{
- Set<URL> e = getResources(i);
+ Set<URL> e = manager.getResources(i);
docs.addAll(e);
}
iterator = docs.listIterator();
}
- protected Set<URL> getResources(String resource)
- {
- Set<URL> ret = new HashSet<URL>();
- for (ResourceLoader r : resourceLoaders)
- {
- ret.addAll(r.getResources(resource));
- }
- return ret;
- }
-
public void close()
{
if (stream != null)
15 years, 4 months
Seam SVN: r13574 - modules/persistence/trunk.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-06 22:15:11 -0400 (Fri, 06 Aug 2010)
New Revision: 13574
Modified:
modules/persistence/trunk/pom.xml
Log:
update parent to version 3
Modified: modules/persistence/trunk/pom.xml
===================================================================
--- modules/persistence/trunk/pom.xml 2010-08-07 02:14:29 UTC (rev 13573)
+++ modules/persistence/trunk/pom.xml 2010-08-07 02:15:11 UTC (rev 13574)
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jboss.seam</groupId>
<artifactId>seam-parent</artifactId>
- <version>2</version>
+ <version>3</version>
</parent>
<artifactId>seam-persistence-parent</artifactId>
15 years, 4 months
Seam SVN: r13573 - modules/xml/trunk.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-08-06 22:14:29 -0400 (Fri, 06 Aug 2010)
New Revision: 13573
Modified:
modules/xml/trunk/pom.xml
Log:
update to seam parent 3
Modified: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml 2010-08-06 18:48:24 UTC (rev 13572)
+++ modules/xml/trunk/pom.xml 2010-08-07 02:14:29 UTC (rev 13573)
@@ -5,7 +5,7 @@
<parent>
<artifactId>seam-parent</artifactId>
<groupId>org.jboss.seam</groupId>
- <version>2</version>
+ <version>3</version>
</parent>
<groupId>org.jboss.seam.xml</groupId>
15 years, 4 months
Seam SVN: r13572 - modules/faces/trunk.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-08-06 14:48:24 -0400 (Fri, 06 Aug 2010)
New Revision: 13572
Modified:
modules/faces/trunk/pom.xml
Log:
Updated Seam Parent POM & Repositories
Modified: modules/faces/trunk/pom.xml
===================================================================
--- modules/faces/trunk/pom.xml 2010-08-06 18:43:46 UTC (rev 13571)
+++ modules/faces/trunk/pom.xml 2010-08-06 18:48:24 UTC (rev 13572)
@@ -1,10 +1,11 @@
-<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">
+<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.jboss.seam</groupId>
<artifactId>seam-parent</artifactId>
- <version>2</version>
+ <version>3</version>
</parent>
<artifactId>seam-faces-parent</artifactId>
@@ -52,7 +53,8 @@
<version>${seam.i18n.version}</version>
</dependency>
- <!-- Need to use dependencyManagement to override org.jboss.seam:seam for submodules -->
+ <!-- Need to use dependencyManagement to override org.jboss.seam:seam
+ for submodules -->
<dependency>
<groupId>org.jboss.seam.faces</groupId>
<artifactId>seam-faces-api</artifactId>
@@ -176,6 +178,45 @@
</dependency>
</dependencies>
</profile>
+ <profile>
+ <id>jboss-public-repository</id>
+ <activation>
+ <property>
+ <name>jboss-public-repository</name>
+ <value>!false</value>
+ </property>
+ </activation>
+ <repositories>
+ <repository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public</url>
+ <releases>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
</profiles>
<developers>
15 years, 4 months