Seam SVN: r13477 - in modules/persistence/trunk: api/src/main/java/org/jboss/seam/persistence/transaction/literal and 5 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 07:51:52 -0400 (Thu, 22 Jul 2010)
New Revision: 13477
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java
Removed:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java
Modified:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
Log:
rename UserTransaction to SeamTransaction and add DefaultTransaction qualifier
Added: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -0,0 +1,29 @@
+package org.jboss.seam.persistence.transaction;
+
+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.inject.Qualifier;
+import javax.transaction.UserTransaction;
+
+/**
+ * Qualifier that is used to denote the SeamTransaction implementation that is
+ * used by the transaction interceptor and other seam transaction services.
+ *
+ * A qualifier is nessesary to prevent the seam provided {@link UserTransaction}
+ * wrapper {@link SeamTransaction} from conflicting with the container provided
+ * builtin UserTransaction
+ *
+ * @author Stuart Douglas
+ *
+ */
+@Qualifier
+@Documented
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
+public @interface DefaultTransaction
+{;
+}
Copied: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java (from rev 13467, modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java)
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -0,0 +1,58 @@
+/*
+ * 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.transaction;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+/**
+ * Extends the standard UserTransaction interface with a couple of helpful
+ * methods.
+ *
+ *
+ * @author Gavin King
+ *
+ */
+public interface SeamTransaction extends javax.transaction.UserTransaction
+{
+
+ public boolean isActive() throws SystemException;
+
+ public boolean isActiveOrMarkedRollback() throws SystemException;
+
+ public boolean isRolledBackOrMarkedRollback() throws SystemException;
+
+ public boolean isMarkedRollback() throws SystemException;
+
+ public boolean isNoTransaction() throws SystemException;
+
+ public boolean isRolledBack() throws SystemException;
+
+ public boolean isCommitted() throws SystemException;
+
+ public boolean isConversationContextRequired();
+
+ public abstract void registerSynchronization(Synchronization sync);
+
+ public void enlist(EntityManager entityManager) throws SystemException;
+}
Modified: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -28,7 +28,6 @@
import java.lang.annotation.Target;
import javax.enterprise.context.NormalScope;
-import javax.enterprise.util.AnnotationLiteral;
/**
*
@@ -41,9 +40,5 @@
@NormalScope(passivating = false)
public @interface TransactionScoped
{
- public static class TransactionScopedLiteral extends AnnotationLiteral<TransactionScoped> implements TransactionScoped
- {
- }
-
}
Deleted: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -1,58 +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.transaction;
-
-import javax.persistence.EntityManager;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-
-/**
- * Extends the standard UserTransaction interface with a couple of helpful
- * methods.
- *
- *
- * @author Gavin King
- *
- */
-public interface UserTransaction extends javax.transaction.UserTransaction
-{
-
- public boolean isActive() throws SystemException;
-
- public boolean isActiveOrMarkedRollback() throws SystemException;
-
- public boolean isRolledBackOrMarkedRollback() throws SystemException;
-
- public boolean isMarkedRollback() throws SystemException;
-
- public boolean isNoTransaction() throws SystemException;
-
- public boolean isRolledBack() throws SystemException;
-
- public boolean isCommitted() throws SystemException;
-
- public boolean isConversationContextRequired();
-
- public abstract void registerSynchronization(Synchronization sync);
-
- public void enlist(EntityManager entityManager) throws SystemException;
-}
Added: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.jboss.seam.persistence.transaction.literal;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+
+public class DefaultTransactionLiteral extends AnnotationLiteral<DefaultTransaction> implements DefaultTransaction
+{
+ private DefaultTransactionLiteral()
+ {
+ }
+
+ public static final DefaultTransactionLiteral INSTANCE = new DefaultTransactionLiteral();
+
+}
\ No newline at end of file
Added: modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java
===================================================================
--- modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java (rev 0)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.jboss.seam.persistence.transaction.literal;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.seam.persistence.transaction.TransactionScoped;
+
+public class TransactionScopedLiteral extends AnnotationLiteral<TransactionScoped> implements TransactionScoped
+{
+ private TransactionScopedLiteral()
+ {
+ }
+
+ TransactionScopedLiteral INSTANCE = new TransactionScopedLiteral();
+
+}
\ No newline at end of file
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -79,6 +79,9 @@
this.manager = manager;
}
+ /**
+ * creates the proxy
+ */
public EntityManager create(BeanImpl<EntityManager> bean, CreationalContext<EntityManager> arg0)
{
try
@@ -101,13 +104,16 @@
arg1.release();
}
+ /**
+ * lazily resolve the relevant EMF
+ */
private EntityManagerFactory getEntityManagerFactory()
{
if (emf == null)
{
try
{
- emf = BeanResolver.getReference(EntityManagerFactory.class, qualifiers, manager);
+ emf = BeanResolver.getReference(EntityManagerFactory.class, manager, qualifiers);
}
catch (BeanResolutionException e)
{
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -30,8 +30,8 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
import org.jboss.weld.extensions.util.BeanResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,7 +53,7 @@
private transient BeanManager beanManager;
- private transient UserTransaction userTransaction;
+ private transient SeamTransaction userTransaction;
private transient boolean synchronizationRegistered;
@@ -76,7 +76,7 @@
private void joinTransaction() throws SystemException
{
- UserTransaction transaction = getUserTransaction();
+ SeamTransaction transaction = getUserTransaction();
if (transaction.isActive())
{
transaction.enlist(delegate);
@@ -95,13 +95,13 @@
}
}
- private UserTransaction getUserTransaction()
+ private SeamTransaction getUserTransaction()
{
if (userTransaction == null)
{
try
{
- userTransaction = BeanResolver.getDefaultReference(UserTransaction.class, beanManager);
+ userTransaction = BeanResolver.getReference(SeamTransaction.class, beanManager, DefaultTransactionLiteral.INSTANCE);
}
catch (Exception e)
{
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -31,7 +31,7 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
/**
* Base implementation of UserTransaction
@@ -39,7 +39,7 @@
* @author Gavin King
*
*/
-public abstract class AbstractUserTransaction implements UserTransaction
+public abstract class AbstractUserTransaction implements SeamTransaction
{
private final Synchronizations synchronizations;
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -27,7 +27,7 @@
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
-import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.weld.extensions.managedproducer.ManagedProducer;
/**
@@ -48,7 +48,7 @@
@ManagedProducer
@TransactionQualifier
- public UserTransaction getTransaction() throws NamingException
+ public SeamTransaction getTransaction() throws NamingException
{
try
{
@@ -67,17 +67,17 @@
}
}
- protected UserTransaction createNoTransaction()
+ protected SeamTransaction createNoTransaction()
{
return new NoTransaction();
}
- protected UserTransaction createCMTTransaction() throws NamingException
+ protected SeamTransaction createCMTTransaction() throws NamingException
{
return new CMTTransaction(EJB.getEJBContext(), synchronizations);
}
- protected UserTransaction createUTTransaction() throws NamingException
+ protected SeamTransaction createUTTransaction() throws NamingException
{
return new UTTransaction(getUserTransaction(), synchronizations);
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -21,29 +21,26 @@
*/
package org.jboss.seam.persistence.transaction;
-import java.util.Collections;
-import java.util.Set;
-
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
import org.jboss.weld.extensions.bean.BeanImpl;
import org.jboss.weld.extensions.bean.BeanLifecycle;
import org.jboss.weld.extensions.defaultbean.DefaultBeanExtension;
+import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.weld.extensions.util.BeanResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Extension than provides a {@link UserTransaction} if no other UserTransaction
+ * Extension than provides a {@link SeamTransaction} if no other UserTransaction
* has been registered.
*
* This allows the user to register a transaction via seam XML and have it
@@ -59,22 +56,21 @@
*/
public class TransactionExtension implements Extension
{
- private boolean transactionRegistered = false;
private static final Logger log = LoggerFactory.getLogger(TransactionExtension.class);
- public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event,BeanManager manager)
+ public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager manager)
{
- AnnotatedTypeBuilder<UserTransaction> utbuilder = AnnotatedTypeBuilder.newInstance(UserTransaction.class);
- BeanBuilder<UserTransaction> builder = new BeanBuilder<UserTransaction>(utbuilder.create(), manager);
+ AnnotatedTypeBuilder<SeamTransaction> utbuilder = AnnotatedTypeBuilder.newInstance(SeamTransaction.class);
+ BeanBuilder<SeamTransaction> builder = new BeanBuilder<SeamTransaction>(utbuilder.create(), manager);
builder.defineBeanFromAnnotatedType();
-
builder.setBeanLifecycle(new TransactionLifecycle(manager));
- builder.setInjectionTarget(new NoOpInjectionTarget());
- DefaultBeanExtension.addDefaultBean(UserTransaction.class, builder.create());
+ builder.getQualifiers().clear();
+ builder.getQualifiers().add(DefaultTransactionLiteral.INSTANCE);
+ DefaultBeanExtension.addDefaultBean(SeamTransaction.class, builder.create());
}
- private static class TransactionLifecycle implements BeanLifecycle<UserTransaction>
+ private static class TransactionLifecycle implements BeanLifecycle<SeamTransaction>
{
private final BeanManager manager;
@@ -86,7 +82,7 @@
this.manager = manager;
}
- public UserTransaction create(BeanImpl<UserTransaction> bean, CreationalContext<UserTransaction> ctx)
+ public SeamTransaction create(BeanImpl<SeamTransaction> bean, CreationalContext<SeamTransaction> ctx)
{
if (transactionBean == null)
{
@@ -94,10 +90,10 @@
// is initialised twice
setupBeanDefinition();
}
- return (UserTransaction) manager.getReference(transactionBean, UserTransaction.class, ctx);
+ return (SeamTransaction) manager.getReference(transactionBean, SeamTransaction.class, ctx);
}
- public void destroy(BeanImpl<UserTransaction> bean, UserTransaction arg0, CreationalContext<UserTransaction> arg1)
+ public void destroy(BeanImpl<SeamTransaction> bean, SeamTransaction arg0, CreationalContext<SeamTransaction> arg1)
{
arg1.release();
}
@@ -107,52 +103,16 @@
*/
private void setupBeanDefinition()
{
- Set<Bean<?>> beans = manager.getBeans(UserTransaction.class, new TransactionQualifier.TransactionQualifierLiteral());
- if (beans.isEmpty())
+ try
{
- log.error("No bean with type " + UserTransaction.class.getName() + " and qualifier " + TransactionQualifier.class.getName() + " registered, SEAM TRANSACTIONS ARE DISABLED");
+ transactionBean = BeanResolver.resolveBean(SeamTransaction.class, manager, new TransactionQualifier.TransactionQualifierLiteral());
}
- else if (beans.size() > 1)
+ catch (BeanResolutionException e)
{
- log.error("More than 1 bean with type " + UserTransaction.class.getName() + " and qualifier " + TransactionQualifier.class.getName() + " registered, SEAM TRANSACTIONS ARE DISABLED");
+ throw new RuntimeException(e);
}
- transactionBean = beans.iterator().next();
}
}
- private static class NoOpInjectionTarget implements InjectionTarget<UserTransaction>
- {
-
- public UserTransaction produce(CreationalContext<UserTransaction> ctx)
- {
- return null;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return Collections.emptySet();
- }
-
- public void dispose(UserTransaction instance)
- {
-
- }
-
- public void preDestroy(UserTransaction instance)
- {
-
- }
-
- public void postConstruct(UserTransaction instance)
- {
-
- }
-
- public void inject(UserTransaction instance, CreationalContext<UserTransaction> ctx)
- {
-
- }
-
- }
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -33,10 +33,6 @@
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
-import org.jboss.seam.persistence.transaction.TransactionPropagation;
-import org.jboss.seam.persistence.transaction.Transactional;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-
/**
* Implements transaction propagation rules for Seam JavaBean components.
*
@@ -51,7 +47,9 @@
transient private Map<AnnotatedElement, TransactionMetadata> transactionMetadata = new HashMap<AnnotatedElement, TransactionMetadata>();
- @Inject Instance<UserTransaction> transaction;
+ @Inject
+ @DefaultTransaction
+ Instance<SeamTransaction> transaction;
private class TransactionMetadata
{
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -44,7 +44,7 @@
return !transactionActive;
}
- public final T workInTransaction(org.jboss.seam.persistence.transaction.UserTransaction transaction) throws Exception
+ public final T workInTransaction(org.jboss.seam.persistence.transaction.SeamTransaction transaction) throws Exception
{
boolean transactionActive = transaction.isActiveOrMarkedRollback() || transaction.isRolledBack();
// TODO: temp workaround, what should we really do in this case??
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -24,20 +24,20 @@
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.TransactionScoped;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
+import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.weld.extensions.util.BeanResolver;
/**
* Context for the {@link TransactionScoped} scope
@@ -48,7 +48,7 @@
public class TransactionScopeContext implements Context, Synchronization
{
- private UserTransaction userTransaction;
+ private SeamTransaction userTransaction;
private final BeanManager beanManager;
@@ -76,10 +76,14 @@
{
if (userTransaction == null)
{
- Set<Bean<?>> beans = beanManager.getBeans(UserTransaction.class, new DefaultLiteral());
- Bean<UserTransaction> userTransactionBean = (Bean<UserTransaction>) beans.iterator().next();
- CreationalContext<?> ctx = beanManager.createCreationalContext(userTransactionBean);
- userTransaction = (UserTransaction) beanManager.getReference(userTransactionBean, UserTransaction.class, ctx);
+ try
+ {
+ userTransaction = BeanResolver.getReference(SeamTransaction.class, beanManager, DefaultTransactionLiteral.INSTANCE);
+ }
+ catch (BeanResolutionException e)
+ {
+ throw new RuntimeException(e);
+ }
}
}
}
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -15,8 +15,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
@@ -47,7 +48,8 @@
}
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@Inject
EntityManager em;
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -36,9 +36,10 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
import org.jboss.seam.persistence.transaction.TransactionInterceptor;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.DontRollBackException;
import org.jboss.seam.transactions.test.util.EntityManagerProvider;
@@ -79,7 +80,8 @@
TransactionManagedBean bean;
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@PersistenceContext
EntityManager em;
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -13,8 +13,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
@@ -45,7 +46,8 @@
}
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@PersistenceUnit
EntityManagerFactory emf;
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-22 10:54:46 UTC (rev 13476)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-22 11:51:52 UTC (rev 13477)
@@ -15,8 +15,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
@@ -45,7 +46,8 @@
}
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@PersistenceContext
EntityManager em;
14 years, 5 months
Seam SVN: r13476 - in sandbox/modules/spreadsheet/src: main/java/org/jboss/seam/spreadsheet/model and 3 other directories.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-07-22 06:54:46 -0400 (Thu, 22 Jul 2010)
New Revision: 13476
Added:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnAutoWidthCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/ColumnAutoWidthCommand.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/ColumnAutoWidthCommandTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java
Modified:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Range.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java
Log:
auto column widths
max used ranges for worksheets
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java 2010-07-22 10:43:47 UTC (rev 13475)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -2,6 +2,7 @@
import jxl.write.WritableSheet;
+import org.jboss.seam.spreadsheet.model.command.ColumnAutoWidthCommand;
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
import org.jboss.seam.spreadsheet.model.command.Command;
import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
@@ -20,6 +21,8 @@
return new JxlRowHeightCommand((RowHeightCommand) command, jxlWorksheet);
case MERGE_CELLS:
return new JxlMergeCellsCommand((MergeCellsCommand) command, jxlWorksheet);
+ case COLUMN_AUTOWIDTH:
+ return new JxlColumnAutoWidthCommand((ColumnAutoWidthCommand) command, jxlWorksheet);
}
return null;
}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnAutoWidthCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnAutoWidthCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnAutoWidthCommand.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -0,0 +1,30 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import jxl.CellView;
+import jxl.write.WritableSheet;
+
+import org.jboss.seam.spreadsheet.model.command.ColumnAutoWidthCommand;
+import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
+
+public class JxlColumnAutoWidthCommand extends AbstractJxlCommand
+{
+ private ColumnAutoWidthCommand columnAutoWidthCommand;
+
+ public JxlColumnAutoWidthCommand(ColumnAutoWidthCommand columnAutoWidthCommand, WritableSheet jxlWorksheet)
+ {
+ super(jxlWorksheet);
+ this.columnAutoWidthCommand = columnAutoWidthCommand;
+ }
+
+ @Override
+ public void execute()
+ {
+ for (int column = columnAutoWidthCommand.getColumnStart(); column <= columnAutoWidthCommand.getColumnEnd(); column++)
+ {
+ CellView cellView = jxlWorksheet.getColumnView(column);
+ cellView.setAutosize(true);
+ jxlWorksheet.setColumnView(column, cellView);
+ }
+ }
+
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Range.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Range.java 2010-07-22 10:43:47 UTC (rev 13475)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Range.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -1,5 +1,7 @@
package org.jboss.seam.spreadsheet.model;
+import org.jboss.seam.spreadsheet.util.HashUtil;
+
public class Range
{
private Coordinate topLeft;
@@ -36,4 +38,32 @@
{
return String.format("Range from %s to %s", topLeft, bottomRight);
}
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (!(other instanceof Range))
+ {
+ return false;
+ }
+ Range otherRange = (Range) other;
+ if (!HashUtil.same(topLeft, otherRange.getTopLeft()))
+ {
+ return false;
+ }
+ if (!HashUtil.same(bottomRight, otherRange.getBottomRight()))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hashCode = 0;
+ hashCode += topLeft == null ? 0 : topLeft.hashCode();
+ hashCode += bottomRight == null ? 0 : bottomRight.hashCode();
+ return hashCode;
+ }
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 10:43:47 UTC (rev 13475)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -59,4 +59,5 @@
{
this.settings = settings;
}
+
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 10:43:47 UTC (rev 13475)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -79,4 +79,34 @@
{
this.settings = settings;
}
+
+ public Range getUsedRange()
+ {
+ int minColumn = 0;
+ int minRow = 0;
+ int maxColumn = 0;
+ int maxRow = 0;
+
+ for (Cell cell : cells)
+ {
+ if (minColumn == 0 || cell.getCoordinate().getRow() < minRow)
+ {
+ minRow = cell.getCoordinate().getRow();
+ }
+ if (minRow == 0 || cell.getCoordinate().getRow() > maxRow)
+ {
+ maxRow = cell.getCoordinate().getRow();
+ }
+ if (maxColumn == 0 || cell.getCoordinate().getColumn() < minColumn)
+ {
+ minColumn = cell.getCoordinate().getColumn();
+ }
+ if (maxRow == 0 || cell.getCoordinate().getColumn() > maxColumn)
+ {
+ maxColumn = cell.getCoordinate().getColumn();
+ }
+ }
+ return Range.of(minColumn, minRow, maxColumn, maxRow);
+ }
+
}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/ColumnAutoWidthCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/ColumnAutoWidthCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/ColumnAutoWidthCommand.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -0,0 +1,36 @@
+package org.jboss.seam.spreadsheet.model.command;
+
+public class ColumnAutoWidthCommand implements Command
+{
+ private int columnStart;
+ private int columnEnd;
+
+ public ColumnAutoWidthCommand(int columnStart, int columnEnd)
+ {
+ this.columnStart = columnStart;
+ this.columnEnd = columnEnd;
+ }
+
+ public ColumnAutoWidthCommand(int column)
+ {
+ columnStart = column;
+ columnEnd = column;
+ }
+
+ @Override
+ public CommandId getCommandId()
+ {
+ return CommandId.COLUMN_AUTOWIDTH;
+ }
+
+ public int getColumnStart()
+ {
+ return columnStart;
+ }
+
+ public int getColumnEnd()
+ {
+ return columnEnd;
+ }
+
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java 2010-07-22 10:43:47 UTC (rev 13475)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -4,7 +4,7 @@
{
public enum CommandId
{
- COLUMN_WIDTH, ROW_HEIGHT, MERGE_CELLS
+ COLUMN_WIDTH, ROW_HEIGHT, MERGE_CELLS, COLUMN_AUTOWIDTH
};
public abstract CommandId getCommandId();
Added: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/ColumnAutoWidthCommandTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/ColumnAutoWidthCommandTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/ColumnAutoWidthCommandTest.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -0,0 +1,46 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Coordinate;
+import org.jboss.seam.spreadsheet.model.Workbook;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.command.ColumnAutoWidthCommand;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+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 ColumnAutoWidthCommandTest extends SpreadsheetTest
+{
+
+ @Deployment
+ public static JavaArchive getArchive()
+ {
+ return ShrinkWrap.create("foo.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Test
+ public void mergeTest()
+ {
+ Cell cell = Cell.of("Nicklas Karlsson", Coordinate.ORIGO);
+ Worksheet ws = Worksheet.named("foo");
+ ws.getCells().add(cell);
+ ws.getCommands().add(new ColumnAutoWidthCommand(0));
+ Workbook wb = new Workbook();
+ wb.getWorksheets().add(ws);
+ jxl.Workbook jWb = getWorkbook(wb);
+ workbookToFile(wb, "c:/temp/foo.xls");
+ Assert.assertEquals(4096, jWb.getSheet(0).getColumnView(0).getSize());
+ Assert.assertEquals(2048, jWb.getSheet(0).getColumnView(1).getSize());
+ }
+}
Added: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java 2010-07-22 10:54:46 UTC (rev 13476)
@@ -0,0 +1,36 @@
+package org.jboss.seam.spreadsheet.model;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Test;
+
+public class WorksheetTest extends SpreadsheetTest
+{
+
+ @Test
+ public void freshWorksheetStateTest()
+ {
+ Worksheet worksheet = Worksheet.named("foo");
+ Assert.assertTrue(worksheet.getCellFormatRules().isEmpty());
+ Assert.assertTrue(worksheet.getCells().isEmpty());
+ Assert.assertTrue(worksheet.getCommands().isEmpty());
+ Assert.assertNull(worksheet.getSettings());
+ }
+
+ @Test
+ public void usedRangeTest() {
+ Worksheet worksheet = Worksheet.named("foo");
+ Assert.assertEquals(Range.of(0, 0, 0, 0), worksheet.getUsedRange());
+ }
+
+ @Test
+ public void usedRangeTest2() {
+ Worksheet worksheet = Worksheet.named("foo");
+ worksheet.getCells().add(Cell.of("foo", Coordinate.of(10, 10)));
+ worksheet.getCells().add(Cell.of("bar", Coordinate.of(20, 20)));
+ Assert.assertEquals(Range.of(10, 10, 20, 20), worksheet.getUsedRange());
+ }
+
+
+}
14 years, 5 months
Seam SVN: r13475 - branches/enterprise.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2010-07-22 06:43:47 -0400 (Thu, 22 Jul 2010)
New Revision: 13475
Added:
branches/enterprise/JBPAPP_5_0_1_JBPAPP-4717/
Log:
created branch for JBPAPP-4717
Copied: branches/enterprise/JBPAPP_5_0_1_JBPAPP-4717 (from rev 13474, tags/JBPAPP_5_0_1)
14 years, 5 months
Seam SVN: r13474 - in sandbox/modules/spreadsheet/src: main/java/org/jboss/seam/spreadsheet/jxl/writer and 6 other directories.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-07-22 06:29:54 -0400 (Thu, 22 Jul 2010)
New Revision: 13474
Modified:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/SpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
Log:
workbook settings
splitting up writer interface into process and write
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/SpreadsheetWriter.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/SpreadsheetWriter.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/SpreadsheetWriter.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -4,7 +4,7 @@
public interface SpreadsheetWriter
{
- public abstract byte[] writeWorkbook(Workbook workbook);
- public abstract byte[] writeWorkbook(Workbook workbook, byte[] template);
+ public abstract SpreadsheetWriter processWorkbook(Workbook workbook);
+ public byte[] writeWorkbook();
public abstract Object getRawWorkbook();
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -29,6 +29,7 @@
private CellFactory cellFactory;
private CellFormatResolver cellFormatResolver;
private WritableWorkbook jxlWorkbook;
+ private ByteArrayOutputStream outStream;
private SettingsHelper settingsHelper = new SettingsHelper();
@@ -36,34 +37,40 @@
private Events events;
@Override
- public byte[] writeWorkbook(Workbook workbook) throws SpreadsheetException
+ public SpreadsheetWriter processWorkbook(Workbook workbook) throws SpreadsheetException
{
if (workbook.getWorksheets().isEmpty())
{
throw new SpreadsheetException("You must have at least one worksheet");
}
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
cellFactory = new CellFactory();
cellFormatResolver = new CellFormatResolver(workbook.getCellFormatRules());
try
{
- jxlWorkbook = jxl.Workbook.createWorkbook(outStream);
- processWorkbook(workbook);
- jxlWorkbook.write();
- jxlWorkbook.close();
+ initWorkbook(workbook);
+ _processWorkbook(workbook);
}
catch (IOException e)
{
throw new SpreadsheetException("Could not create workbook", e);
}
- catch (WriteException e)
+ return this;
+ }
+
+ private void initWorkbook(Workbook workbook) throws IOException
+ {
+ outStream = new ByteArrayOutputStream();
+ if (workbook.getSettings() == null)
{
- throw new SpreadsheetException("Could not write workbook", e);
+ jxlWorkbook = jxl.Workbook.createWorkbook(outStream);
}
- return outStream.toByteArray();
+ else
+ {
+ jxlWorkbook = jxl.Workbook.createWorkbook(outStream, new SettingsHelper().createWorkbookSettings(workbook.getSettings()));
+ }
}
- private void processWorkbook(Workbook workbook)
+ private void _processWorkbook(Workbook workbook)
{
for (Worksheet worksheet : workbook.getWorksheets())
{
@@ -120,15 +127,28 @@
}
@Override
- public byte[] writeWorkbook(Workbook workbook, byte[] template) throws SpreadsheetException
+ public Object getRawWorkbook()
{
- return null;
+ return jxlWorkbook;
}
@Override
- public Object getRawWorkbook()
+ public byte[] writeWorkbook()
{
- return jxlWorkbook;
+ try
+ {
+ jxlWorkbook.write();
+ jxlWorkbook.close();
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException(String.format("Could not generate workbook"), e);
+ }
+ catch (IOException e)
+ {
+ throw new SpreadsheetException(String.format("Could not write workbook"), e);
+ }
+ return outStream.toByteArray();
}
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -12,6 +12,8 @@
private List<CellFormatRule> cellFormatRules = new ArrayList<CellFormatRule>();
private List<Command> commands = new ArrayList<Command>();
+ private WorkbookSettings settings;
+
public List<Worksheet> getWorksheets()
{
return worksheets;
@@ -47,4 +49,14 @@
{
return String.format("Workbook with %d sheets", worksheets.size());
}
+
+ public WorkbookSettings getSettings()
+ {
+ return settings;
+ }
+
+ public void setSettings(WorkbookSettings settings)
+ {
+ this.settings = settings;
+ }
}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -45,6 +45,7 @@
workbook.getWorksheets().add(worksheet);
worksheet.getCells().add(Cell.of("foo", Coordinate.of(0, 0)));
worksheet.getCommands().add(new ColumnWidthCommand(1, 100));
+ @SuppressWarnings("unused")
jxl.Workbook jxlWorkbook = getWorkbook(workbook);
Assert.assertTrue(eventObserver.isCellAdded());
Assert.assertTrue(eventObserver.isWorksheetCreated());
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -1,7 +1,5 @@
package org.jboss.seam.spreadsheet.jxl.command;
-import junit.framework.Assert;
-
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -25,7 +25,7 @@
}
@Test
- public void testFreshWorkbook()
+ public void freshWorkbookStateTest()
{
Workbook workbook = new Workbook();
Assert.assertTrue(workbook.getWorksheets().isEmpty());
@@ -33,9 +33,21 @@
}
@Test(expected = SpreadsheetException.class)
- public void testImplicitWorksheet()
+ public void noWorksheetsFailTest()
{
Workbook workbook = new Workbook();
+ @SuppressWarnings("unused")
jxl.Workbook jxlWorkbook = getWorkbook(workbook);
}
+
+ @Test
+ public void workbookSettingsTest() {
+ Workbook workbook = new Workbook();
+ workbook.getWorksheets().add(Worksheet.named("foo"));
+ WorkbookSettings settings = new WorkbookSettings();
+ settings.setEncoding("UTF-8");
+ workbook.getWorksheets().iterator().next().getCells().add(Cell.of("���", Coordinate.ORIGO));
+ workbook.setSettings(settings);
+ workbookToFile(workbook, "c:/temp/foo.xls");
+ }
}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -1,14 +1,10 @@
package org.jboss.seam.spreadsheet.model.builder;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
-import org.jboss.seam.spreadsheet.SpreadsheetWriter;
-import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Range;
@@ -51,6 +47,7 @@
final Person person = new Person("Nicklas Karlsson", 35);
List<Person> persons = new ArrayList<Person>()
{
+ private static final long serialVersionUID = 1L;
{
add(person);
}
@@ -143,6 +140,7 @@
final Person pete = new Person("Pete Muir", 26);
List<Person> persons = new ArrayList<Person>()
{
+ private static final long serialVersionUID = 1L;
{
add(nik);
add(pete);
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java 2010-07-22 09:24:25 UTC (rev 13473)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java 2010-07-22 10:29:54 UTC (rev 13474)
@@ -1,7 +1,6 @@
package org.jboss.seam.spreadsheet.model.formatting;
import java.io.ByteArrayInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -47,7 +46,7 @@
{
try
{
- byte[] data = getSpreadsheetWriter().writeWorkbook(workbook);
+ byte[] data = getSpreadsheetWriter().processWorkbook(workbook).writeWorkbook();
return jxl.Workbook.getWorkbook(new ByteArrayInputStream(data));
}
catch (BiffException e)
@@ -136,7 +135,7 @@
try
{
FileOutputStream out = new FileOutputStream(fileName);
- out.write(sw.writeWorkbook(workbook));
+ out.write(sw.processWorkbook(workbook).writeWorkbook());
out.flush();
out.close();
}
14 years, 5 months
Seam SVN: r13473 - modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 05:24:25 -0400 (Thu, 22 Jul 2010)
New Revision: 13473
Removed:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProducer.java
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java
Log:
clean up managed persistence context implementation
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 08:36:20 UTC (rev 13472)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 09:24:25 UTC (rev 13473)
@@ -29,13 +29,14 @@
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.jboss.weld.extensions.bean.BeanImpl;
import org.jboss.weld.extensions.bean.BeanLifecycle;
+import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.weld.extensions.util.BeanResolver;
/**
* Class that is responsible for creating and destroying the seam managed
@@ -104,20 +105,15 @@
{
if (emf == null)
{
- Set<Bean<?>> beans = manager.getBeans(EntityManagerFactory.class, qualifiers);
- if (beans.size() == 0)
+ try
{
- throw new RuntimeException("No bean found with type EntityManagerFactory and qualifiers " + qualifiers);
+ emf = BeanResolver.getReference(EntityManagerFactory.class, qualifiers, manager);
}
- if (beans.size() != 1)
+ catch (BeanResolutionException e)
{
- throw new RuntimeException("More than 1 bean found with type EntityManagerFactory and qualifiers " + qualifiers);
+ throw new RuntimeException(e);
}
- Bean<?> emfBean = beans.iterator().next();
- CreationalContext<?> emfCreationalContext = manager.createCreationalContext(emfBean);
- emf = (EntityManagerFactory) manager.getReference(emfBean, EntityManagerFactory.class, emfCreationalContext);
}
return emf;
}
-
}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-07-22 08:36:20 UTC (rev 13472)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-07-22 09:24:25 UTC (rev 13473)
@@ -45,11 +45,10 @@
* Extension the wraps producer methods/fields that produce an entity manager to
* turn them into Seam Managed Persistence Contexts.
*
- * At present this happens automatically, in future we will need some way to
- * configure it
*
- * @author stuart
*
+ * @author Stuart Douglas
+ *
*/
public class ManagedPersistenceContextExtension implements Extension
{
Deleted: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProducer.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProducer.java 2010-07-22 08:36:20 UTC (rev 13472)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProducer.java 2010-07-22 09:24:25 UTC (rev 13473)
@@ -1,75 +0,0 @@
-package org.jboss.seam.persistence;
-
-import java.io.Serializable;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.Producer;
-import javax.persistence.EntityManager;
-
-/**
- * implementation of Producer that proxies a produced EntityManager
- *
- * @author stuart
- *
- */
-public class ManagedPersistenceContextProducer implements Producer<EntityManager>
-{
- static final Class<?> proxyClass = Proxy.getProxyClass(EntityManager.class.getClassLoader(), EntityManager.class, Serializable.class);
-
- static final Constructor<?> proxyConstructor;
-
- static
- {
- try
- {
- proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- private final Producer<EntityManager> delegate;
-
- private final BeanManager beanManager;
-
- public ManagedPersistenceContextProducer(Producer<EntityManager> delegate, BeanManager beanManager)
- {
- this.delegate = delegate;
- this.beanManager = beanManager;
- }
-
- public void dispose(EntityManager instance)
- {
- delegate.dispose(instance);
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return delegate.getInjectionPoints();
- }
-
- public EntityManager produce(CreationalContext<EntityManager> ctx)
- {
- try
- {
- EntityManager entityManager = delegate.produce(ctx);
- ManagedPersistenceContextProxyHandler handler = new ManagedPersistenceContextProxyHandler(entityManager, beanManager);
- EntityManager proxy = (EntityManager) proxyConstructor.newInstance(handler);
- return proxy;
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
-
- }
-
-}
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-07-22 08:36:20 UTC (rev 13472)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-07-22 09:24:25 UTC (rev 13473)
@@ -1,3 +1,24 @@
+/*
+ * 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.io.Serializable;
@@ -3,8 +24,5 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
-import java.util.Set;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.persistence.EntityManager;
@@ -13,14 +31,24 @@
import javax.transaction.SystemException;
import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
-import org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.weld.extensions.util.BeanResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Proxy handler for the seam managed persistence context. This handler makes
+ * sure that the EntityManager is enrolled in the current transaction before
+ * passing the call through to the delegate
+ *
+ * @author Stuart Douglas
+ *
+ */
public class ManagedPersistenceContextProxyHandler implements InvocationHandler, Serializable, Synchronization
{
+ private static final long serialVersionUID = -6539267789786229774L;
+
private final EntityManager delegate;
private transient BeanManager beanManager;
@@ -67,31 +95,18 @@
}
}
- private BeanManager getBeanManager()
- {
- if (beanManager == null)
- {
- beanManager = BeanManagerAccessor.getManager();
- }
- return beanManager;
- }
-
private UserTransaction getUserTransaction()
{
if (userTransaction == null)
{
- Set<Bean<?>> beans = beanManager.getBeans(UserTransaction.class, DefaultLiteral.INSTANCE);
- if (beans.size() == 0)
+ try
{
- throw new RuntimeException("No bean with class" + UserTransaction.class.getName() + " and qualifiers Default found");
+ userTransaction = BeanResolver.getDefaultReference(UserTransaction.class, beanManager);
}
- else if (beans.size() != 1)
+ catch (Exception e)
{
- throw new RuntimeException("More than 1 bean with class" + UserTransaction.class.getName() + " and qualifiers Default found");
+ throw new RuntimeException(e);
}
- Bean<UserTransaction> userTransactionBean = (Bean<UserTransaction>) beans.iterator().next();
- CreationalContext<UserTransaction> ctx = beanManager.createCreationalContext(userTransactionBean);
- userTransaction = (UserTransaction) beanManager.getReference(userTransactionBean, UserTransaction.class, ctx);
}
return userTransaction;
}
@@ -103,7 +118,6 @@
public void beforeCompletion()
{
- // TODO Auto-generated method stub
}
Modified: 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-07-22 08:36:20 UTC (rev 13472)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java 2010-07-22 09:24:25 UTC (rev 13473)
@@ -21,13 +21,43 @@
*/
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
+ *
+ */
@Retention(RetentionPolicy.RUNTIME)
-@Target( { ElementType.FIELD })
+@Target( { ElementType.FIELD, ElementType.METHOD })
+@Documented
public @interface SeamManaged
{
14 years, 5 months
Seam SVN: r13472 - in modules/persistence/trunk/impl/src: main/java/org/jboss/seam/persistence/util and 6 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 04:36:20 -0400 (Thu, 22 Jul 2010)
New Revision: 13472
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java
Removed:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java
Log:
change implementation of managed persistence context, update tests
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -37,6 +37,13 @@
import org.jboss.weld.extensions.bean.BeanImpl;
import org.jboss.weld.extensions.bean.BeanLifecycle;
+/**
+ * Class that is responsible for creating and destroying the seam managed
+ * persistence context
+ *
+ * @author Stuart Douglas
+ *
+ */
public class ManagedPersistenceContextBeanLifecycle implements BeanLifecycle<EntityManager>
{
@@ -46,17 +53,6 @@
static final Class<?> proxyClass = Proxy.getProxyClass(EntityManager.class.getClassLoader(), EntityManager.class, Serializable.class);
- public ManagedPersistenceContextBeanLifecycle(Set<Annotation> qualifiers, BeanManager manager)
- {
- this.qualifiers = new Annotation[qualifiers.size()];
- int i = 0;
- for (Annotation a : qualifiers)
- {
- this.qualifiers[i++] = a;
- }
- this.manager = manager;
- }
-
static final Constructor<?> proxyConstructor;
static
@@ -71,6 +67,17 @@
}
}
+ public ManagedPersistenceContextBeanLifecycle(Set<Annotation> qualifiers, BeanManager manager)
+ {
+ this.qualifiers = new Annotation[qualifiers.size()];
+ int i = 0;
+ for (Annotation a : qualifiers)
+ {
+ this.qualifiers[i++] = a;
+ }
+ this.manager = manager;
+ }
+
public EntityManager create(BeanImpl<EntityManager> bean, CreationalContext<EntityManager> arg0)
{
try
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -22,22 +22,20 @@
package org.jboss.seam.persistence;
import java.lang.annotation.Annotation;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.context.Dependent;
-import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.ProcessProducer;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
@@ -58,37 +56,64 @@
Set<Bean<?>> beans = new HashSet<Bean<?>>();
- public <T> void processProducer(@Observes ProcessProducer<T, EntityManagerFactory> event, BeanManager manager)
+ /**
+ * loops through the fields on an AnnotatedType looking for a @PersistnceUnit
+ * producer field that is annotated {@link SeamManaged}. Then found a
+ * corresponding smpc bean is created and registered. Any scope declaration
+ * on the producer are removed as this is not supported by the spec
+ *
+ */
+ public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event, BeanManager manager)
{
- if (!event.getAnnotatedMember().isAnnotationPresent(SeamManaged.class))
+ AnnotatedTypeBuilder<T> modifiedType = null;
+ for (AnnotatedField<? super T> f : event.getAnnotatedType().getFields())
{
- return;
- }
- Set<Annotation> qualifiers = new HashSet<Annotation>();
- Class scope = Dependent.class;
- for (Annotation a : event.getAnnotatedMember().getAnnotations())
- {
- if (manager.isQualifier(a.annotationType()))
+ // look for a seam managed persistence unit declaration
+ if (f.isAnnotationPresent(SeamManaged.class) && f.isAnnotationPresent(PersistenceUnit.class) && f.isAnnotationPresent(Produces.class))
{
- qualifiers.add(a);
+ if (modifiedType == null)
+ {
+ modifiedType = AnnotatedTypeBuilder.newInstance(event.getAnnotatedType()).mergeAnnotations(event.getAnnotatedType(), true);
+ }
+ Set<Annotation> qualifiers = new HashSet<Annotation>();
+ Class<? extends Annotation> scope = Dependent.class;
+ // get the qualifier and scope for the new bean
+ for (Annotation a : f.getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ else if (manager.isScope(a.annotationType()))
+ {
+ scope = a.annotationType();
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new DefaultLiteral());
+ }
+ // we need to remove the scope, they are not nessesarily supported
+ // on producer fields
+ if (scope != Dependent.class)
+ {
+ modifiedType.removeFromField(f.getJavaMember(), scope);
+ }
+ // create the new bean to be registerd later
+ AnnotatedTypeBuilder<EntityManager> typeBuilder = AnnotatedTypeBuilder.newInstance(EntityManager.class);
+ BeanBuilder<EntityManager> builder = new BeanBuilder<EntityManager>(typeBuilder.create(), manager);
+ builder.defineBeanFromAnnotatedType();
+ builder.setQualifiers(qualifiers);
+ builder.setScope(scope);
+ builder.setBeanLifecycle(new ManagedPersistenceContextBeanLifecycle(qualifiers, manager));
+ beans.add(builder.create());
}
- else if (manager.isScope(a.annotationType()))
- {
- scope = a.annotationType();
- }
+
}
- if (qualifiers.isEmpty())
+ if (modifiedType != null)
{
- qualifiers.add(new DefaultLiteral());
+ event.setAnnotatedType(modifiedType.create());
}
- AnnotatedTypeBuilder<EntityManager> typeBuilder = AnnotatedTypeBuilder.newInstance(EntityManager.class);
- BeanBuilder<EntityManager> builder = new BeanBuilder<EntityManager>(typeBuilder.create(), manager);
- builder.defineBeanFromAnnotatedType();
- builder.setQualifiers(qualifiers);
- builder.setScope(scope);
- builder.setInjectionTarget(new NoOpInjectionTarget());
- builder.setBeanLifecycle(new ManagedPersistenceContextBeanLifecycle(qualifiers, manager));
- beans.add(builder.create());
}
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event)
@@ -99,38 +124,4 @@
}
}
- private static class NoOpInjectionTarget implements InjectionTarget<EntityManager>
- {
-
- public EntityManager produce(CreationalContext<EntityManager> ctx)
- {
- return null;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return Collections.emptySet();
- }
-
- public void dispose(EntityManager instance)
- {
-
- }
-
- public void preDestroy(EntityManager instance)
- {
-
- }
-
- public void postConstruct(EntityManager instance)
- {
-
- }
-
- public void inject(EntityManager instance, CreationalContext<EntityManager> ctx)
- {
-
- }
-
- }
}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,107 @@
+/*
+ * 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.util;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.weld.extensions.util.Reflections;
+
+/**
+ * Utility class that provides access to some annotations from the Java
+ * Enterprise Edition specs if they are present on the classpath
+ *
+ *
+ */
+public class EjbApi
+{
+
+ public @interface Dummy
+ {
+ }
+
+ public static final Class<Annotation> STATELESS;
+ public static final Class<Annotation> STATEFUL;
+ public static final Class<Annotation> MESSAGE_DRIVEN;
+ public static final Class<Annotation> PRE_PASSIVATE;
+ public static final Class<Annotation> POST_ACTIVATE;
+ public static final Class<Annotation> PRE_DESTROY;
+ public static final Class<Annotation> POST_CONSTRUCT;
+ public static final Class<Annotation> REMOTE;
+ public static final Class<Annotation> REMOVE;
+ public static final Class<Annotation> LOCAL;
+ public static final Class<Annotation> APPLICATION_EXCEPTION;
+ public static final Class<Annotation> PERSISTENCE_CONTEXT;
+ public static final Class<Annotation> PERSISTENCE_UNIT;
+ public static final Class<Annotation> INTERCEPTORS;
+ public static final Class<Annotation> AROUND_INVOKE;
+ public static final Class<Annotation> EJB_EXCEPTION;
+ public static final boolean INVOCATION_CONTEXT_AVAILABLE;
+
+ private static Class classForName(String name)
+ {
+ try
+ {
+ return Reflections.classForName(name);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ return Dummy.class;
+ }
+ }
+
+ static
+ {
+ STATELESS = classForName("javax.ejb.Stateless");
+ STATEFUL = classForName("javax.ejb.Stateful");
+ MESSAGE_DRIVEN = classForName("javax.ejb.MessageDriven");
+ APPLICATION_EXCEPTION = classForName("javax.ejb.ApplicationException");
+ PERSISTENCE_CONTEXT = classForName("javax.persistence.PersistenceContext");
+ PERSISTENCE_UNIT = classForName("javax.persistence.PersistenceUnit");
+ REMOVE = classForName("javax.ejb.Remove");
+ REMOTE = classForName("javax.ejb.Remote");
+ LOCAL = classForName("javax.ejb.Local");
+ PRE_PASSIVATE = classForName("javax.ejb.PrePassivate");
+ POST_ACTIVATE = classForName("javax.ejb.PostActivate");
+ PRE_DESTROY = classForName("javax.annotation.PreDestroy");
+ POST_CONSTRUCT = classForName("javax.annotation.PostConstruct");
+ INTERCEPTORS = classForName("javax.interceptor.Interceptors");
+ AROUND_INVOKE = classForName("javax.interceptor.AroundInvoke");
+ EJB_EXCEPTION = classForName("javax.ejb.EJBException");
+ INVOCATION_CONTEXT_AVAILABLE = !classForName("javax.interceptor.InvocationContext").equals(Dummy.class);
+ }
+
+ public static String name(Annotation annotation)
+ {
+ return (String) Reflections.invokeAndWrap(Reflections.getMethod(annotation.annotationType(), "name"), annotation);
+ }
+
+ public static Class[] value(Annotation annotation)
+ {
+ return (Class[]) Reflections.invokeAndWrap(Reflections.getMethod(annotation.annotationType(), "value"), annotation);
+ }
+
+ public static boolean rollback(Annotation annotation)
+ {
+ return (Boolean) Reflections.invokeAndWrap(Reflections.getMethod(annotation.annotationType(), "rollback"), annotation);
+ }
+
+}
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -18,8 +18,8 @@
import org.jboss.seam.persistence.transaction.Transaction;
import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
-import org.jboss.seam.transactions.test.util.EntityManagerProvider;
import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -39,7 +39,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(Transaction.class.getPackage());
war.addPackage(PersistenceContextExtension.class.getPackage());
- war.addClasses(ManagedPersistenceContextTest.class, Hotel.class, EntityManagerProvider.class);
+ war.addClasses(ManagedPersistenceContextTest.class, Hotel.class, ManagedPersistenceContextProvider.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java (from rev 13468, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,119 @@
+/*
+ * 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.transactions.test;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.TransactionInterceptor;
+import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.DontRollBackException;
+import org.jboss.seam.transactions.test.util.EntityManagerProvider;
+import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests the @Transactional interceptor
+ *
+ * @author stuart
+ *
+ */
+(a)RunWith(Arquillian.class)
+public class TransactionInterceptorTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+
+ WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(Transaction.class.getPackage());
+ war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
+ war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
+ war.addWebResource(new ByteArrayAsset(("<beans><interceptors><class>" + TransactionInterceptor.class.getName() + "</class></interceptors></beans>").getBytes()), "beans.xml");
+ war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ return war;
+ }
+
+ @Inject
+ TransactionManagedBean bean;
+
+ @Inject
+ UserTransaction transaction;
+
+ @PersistenceContext
+ EntityManager em;
+
+ @Test
+ public void testTransactionInterceptor() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+
+ bean.addHotel();
+ assertHotels(1);
+ try
+ {
+ bean.failToAddHotel();
+ }
+ catch (Exception e)
+ {
+ }
+ assertHotels(1);
+ try
+ {
+ bean.addHotelWithApplicationException();
+ }
+ catch (DontRollBackException e)
+ {
+ }
+ assertHotels(2);
+ }
+
+ public void assertHotels(int count) throws NotSupportedException, SystemException
+ {
+ transaction.begin();
+ em.joinTransaction();
+ List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
+ Assert.assertTrue("Wrong number of hotels: " + hotels.size(), hotels.size() == count);
+ transaction.rollback();
+ }
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -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.transactions.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.persistence.transaction.TransactionPropagation;
+import org.jboss.seam.persistence.transaction.Transactional;
+import org.jboss.seam.transactions.test.util.DontRollBackException;
+import org.jboss.seam.transactions.test.util.Hotel;
+
+(a)Transactional(TransactionPropagation.REQUIRED)
+public class TransactionManagedBean
+{
+
+ @Inject
+ EntityManager entityManager;
+
+ public void addHotel()
+ {
+ entityManager.joinTransaction();
+ Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ entityManager.persist(h);
+ entityManager.flush();
+ }
+
+ public void failToAddHotel()
+ {
+ entityManager.joinTransaction();
+ Hotel h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ entityManager.persist(h);
+ entityManager.flush();
+ throw new RuntimeException("Roll back transaction");
+ }
+
+ public void addHotelWithApplicationException() throws DontRollBackException
+ {
+ entityManager.joinTransaction();
+ Hotel h = new Hotel("test3", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ entityManager.persist(h);
+ entityManager.flush();
+ throw new DontRollBackException();
+ }
+
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,19 @@
+package org.jboss.seam.persistence.transactions.test;
+
+import org.jboss.seam.persistence.transaction.TransactionScoped;
+
+@TransactionScoped
+public class TransactionScopedObject
+{
+ int value = 0;
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public void setValue(int value)
+ {
+ this.value = value;
+ }
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,75 @@
+package org.jboss.seam.persistence.transactions.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
+import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class TransactionScopedTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(Transaction.class.getPackage());
+ war.addPackage(TransactionScopeExtension.class.getPackage());
+ war.addClasses(TransactionScopedTest.class, Hotel.class, TransactionScopedObject.class);
+ war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
+ war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ return war;
+ }
+
+ @Inject
+ UserTransaction transaction;
+
+ @PersistenceUnit
+ EntityManagerFactory emf;
+
+ @Inject
+ TransactionScopedObject transactionScopedObject;
+
+ @Test
+ public void transactionScopeTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+ transaction.begin();
+ transactionScopedObject.setValue(10);
+ Assert.assertTrue(transactionScopedObject.getValue() == 10);
+ transaction.commit();
+
+ transaction.begin();
+ Assert.assertTrue(transactionScopedObject.getValue() == 0);
+ transactionScopedObject.setValue(20);
+ Assert.assertTrue(transactionScopedObject.getValue() == 20);
+ transaction.rollback();
+
+ transaction.begin();
+ Assert.assertTrue(transactionScopedObject.getValue() == 0);
+ transaction.rollback();
+ }
+
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,81 @@
+package org.jboss.seam.persistence.transactions.test;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class UserTransactionTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(Transaction.class.getPackage());
+ war.addClasses(UserTransactionTest.class, Hotel.class);
+ war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
+ war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ return war;
+ }
+
+ @Inject
+ UserTransaction transaction;
+
+ @PersistenceContext
+ EntityManager em;
+
+ @Test
+ public void userTransactionTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+ transaction.begin();
+ em.joinTransaction();
+ Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.commit();
+ em.clear();
+
+ transaction.begin();
+ em.joinTransaction();
+ h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.rollback();
+ em.clear();
+
+ transaction.begin();
+ em.joinTransaction();
+ List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
+ Assert.assertTrue(hotels.size() == 1);
+ transaction.rollback();
+ em.clear();
+
+ }
+
+}
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,119 +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.transactions.test;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-
-import junit.framework.Assert;
-
-import org.jboss.arquillian.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.TransactionInterceptor;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.seam.transactions.test.util.ArtifactNames;
-import org.jboss.seam.transactions.test.util.DontRollBackException;
-import org.jboss.seam.transactions.test.util.EntityManagerProvider;
-import org.jboss.seam.transactions.test.util.Hotel;
-import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-/**
- * Tests the @Transactional interceptor
- *
- * @author stuart
- *
- */
-(a)RunWith(Arquillian.class)
-public class TransactionInterceptorTest
-{
- @Deployment
- public static Archive<?> createTestArchive()
- {
-
- WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
- war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
- war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
- war.addWebResource(new ByteArrayAsset(("<beans><interceptors><class>" + TransactionInterceptor.class.getName() + "</class></interceptors></beans>").getBytes()), "beans.xml");
- war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
- return war;
- }
-
- @Inject
- TransactionManagedBean bean;
-
- @Inject
- UserTransaction transaction;
-
- @PersistenceContext
- EntityManager em;
-
- @Test
- public void testTransactionInterceptor() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
- {
-
- bean.addHotel();
- assertHotels(1);
- try
- {
- bean.failToAddHotel();
- }
- catch (Exception e)
- {
- }
- assertHotels(1);
- try
- {
- bean.addHotelWithApplicationException();
- }
- catch (DontRollBackException e)
- {
- }
- assertHotels(2);
- }
-
- public void assertHotels(int count) throws NotSupportedException, SystemException
- {
- transaction.begin();
- em.joinTransaction();
- List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
- Assert.assertTrue("Wrong number of hotels: " + hotels.size(), hotels.size() == count);
- transaction.rollback();
- }
-}
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,45 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.persistence.transaction.TransactionPropagation;
-import org.jboss.seam.persistence.transaction.Transactional;
-import org.jboss.seam.transactions.test.util.DontRollBackException;
-import org.jboss.seam.transactions.test.util.Hotel;
-
-(a)Transactional(TransactionPropagation.REQUIRED)
-public class TransactionManagedBean
-{
-
- @Inject
- EntityManager entityManager;
-
-
- public void addHotel()
- {
- entityManager.joinTransaction();
- Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- entityManager.persist(h);
- entityManager.flush();
- }
-
- public void failToAddHotel()
- {
- entityManager.joinTransaction();
- Hotel h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- entityManager.persist(h);
- entityManager.flush();
- throw new RuntimeException("Roll back transaction");
- }
-
- public void addHotelWithApplicationException() throws DontRollBackException
- {
- entityManager.joinTransaction();
- Hotel h = new Hotel("test3", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- entityManager.persist(h);
- entityManager.flush();
- throw new DontRollBackException();
- }
-
-}
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,19 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import org.jboss.seam.persistence.transaction.TransactionScoped;
-
-@TransactionScoped
-public class TransactionScopedObject
-{
- int value = 0;
-
- public int getValue()
- {
- return value;
- }
-
- public void setValue(int value)
- {
- this.value = value;
- }
-}
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,75 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-
-import junit.framework.Assert;
-
-import org.jboss.arquillian.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
-import org.jboss.seam.transactions.test.util.ArtifactNames;
-import org.jboss.seam.transactions.test.util.Hotel;
-import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-(a)RunWith(Arquillian.class)
-public class TransactionScopedTest
-{
- @Deployment
- public static Archive<?> createTestArchive()
- {
- WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
- war.addPackage(TransactionScopeExtension.class.getPackage());
- war.addClasses(TransactionScopedTest.class, Hotel.class, TransactionScopedObject.class);
- war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
- war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
- war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
- return war;
- }
-
- @Inject
- UserTransaction transaction;
-
- @PersistenceUnit
- EntityManagerFactory emf;
-
- @Inject
- TransactionScopedObject transactionScopedObject;
-
- @Test
- public void transactionScopeTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
- {
- transaction.begin();
- transactionScopedObject.setValue(10);
- Assert.assertTrue(transactionScopedObject.getValue() == 10);
- transaction.commit();
-
- transaction.begin();
- Assert.assertTrue(transactionScopedObject.getValue() == 0);
- transactionScopedObject.setValue(20);
- Assert.assertTrue(transactionScopedObject.getValue() == 20);
- transaction.rollback();
-
- transaction.begin();
- Assert.assertTrue(transactionScopedObject.getValue() == 0);
- transaction.rollback();
- }
-
-}
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,81 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-
-import junit.framework.Assert;
-
-import org.jboss.arquillian.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.seam.transactions.test.util.ArtifactNames;
-import org.jboss.seam.transactions.test.util.Hotel;
-import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-(a)RunWith(Arquillian.class)
-public class UserTransactionTest
-{
- @Deployment
- public static Archive<?> createTestArchive()
- {
- WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
- war.addClasses(UserTransactionTest.class, Hotel.class);
- war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
- war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
- war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
- return war;
- }
-
- @Inject
- UserTransaction transaction;
-
- @PersistenceContext
- EntityManager em;
-
- @Test
- public void userTransactionTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
- {
- transaction.begin();
- em.joinTransaction();
- Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- em.persist(h);
- em.flush();
- transaction.commit();
- em.clear();
-
- transaction.begin();
- em.joinTransaction();
- h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- em.persist(h);
- em.flush();
- transaction.rollback();
- em.clear();
-
- transaction.begin();
- em.joinTransaction();
- List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
- Assert.assertTrue(hotels.size() == 1);
- transaction.rollback();
- em.clear();
-
- }
-
-}
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,17 +1,33 @@
+/*
+ * 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.transactions.test.util;
-import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
-import org.jboss.seam.persistence.SeamManaged;
-
public class EntityManagerProvider
{
- @PersistenceUnit
- @RequestScoped
+ @PersistenceContext
@Produces
- @SeamManaged
- EntityManagerFactory emf;
+ EntityManager em;
}
Added: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -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.transactions.test.util;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+
+import org.jboss.seam.persistence.SeamManaged;
+
+public class ManagedPersistenceContextProvider
+{
+ @PersistenceUnit
+ @RequestScoped
+ @Produces
+ @SeamManaged
+ EntityManagerFactory emf;
+}
14 years, 5 months
Seam SVN: r13471 - in modules/security/trunk: examples/idmconsole/src/main/webapp/WEB-INF and 3 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-07-22 04:12:29 -0400 (Thu, 22 Jul 2010)
New Revision: 13471
Added:
modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml
Modified:
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml
modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml
modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml
modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java
Log:
add infrastructure for user role management (implementation not complete yet)
Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/classes/seam-beans.xml 2010-07-22 08:12:29 UTC (rev 13471)
@@ -45,7 +45,7 @@
<plidm:identityClass>org.jboss.seam.security.examples.idmconsole.model.IdentityObject</plidm:identityClass>
<plidm:credentialClass>org.jboss.seam.security.examples.idmconsole.model.IdentityObjectCredential</plidm:credentialClass>
<plidm:relationshipClass>org.jboss.seam.security.examples.idmconsole.model.IdentityObjectRelationship</plidm:relationshipClass>
- <plidm:roleNameClass>org.jboss.seam.security.examples.idmconsole.model.IdentityRoleName</plidm:roleNameClass>
+ <plidm:roleTypeClass>org.jboss.seam.security.examples.idmconsole.model.IdentityRoleName</plidm:roleTypeClass>
</plidm:JpaIdentityStoreConfiguration>
</beans>
Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml 2010-07-22 08:12:29 UTC (rev 13471)
@@ -49,9 +49,34 @@
<to-view-id>/manageusers.xhtml</to-view-id>
<redirect/>
</navigation-case>
+
+ <navigation-case>
+ <from-action>#{userAction.addRole}</from-action>
+ <if>#{true}</if>
+ <to-view-id>/roledetail.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
</navigation-rule>
<navigation-rule>
+ <from-view-id>/roledetail.xhtml</from-view-id>
+
+ <navigation-case>
+ <from-action>#{userAction.roleSave}</from-action>
+ <from-outcome>success</from-outcome>
+ <if>#{true}</if>
+ <to-view-id>/userdetail.xhtml</to-view-id>
+ <redirect />
+ </navigation-case>
+
+ <navigation-case>
+ <from-outcome>cancel</from-outcome>
+ <to-view-id>/userdetail.xhtml</to-view-id>
+ <redirect/>
+ </navigation-case>
+ </navigation-rule>
+
+ <navigation-rule>
<from-view-id>/managegroups.xhtml</from-view-id>
<navigation-case>
Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/home.xhtml 2010-07-22 08:12:29 UTC (rev 13471)
@@ -31,7 +31,10 @@
<div class="buttons">
<h:commandButton id="login" value="LOGIN" action="#{identity.login}" styleClass="loginButton"/>
- </div>
+ </div>
+
+ Tip: you can login with a username/password of demo/demo.
+
</h:form>
<br style="clear:both"/>
Added: modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml (rev 0)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/roledetail.xhtml 2010-07-22 08:12:29 UTC (rev 13471)
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ template="/WEB-INF/templates/default.xhtml">
+
+ <ui:define name="sidebar">
+ <ui:include src="menu.xhtml"/>
+ </ui:define>
+
+ <ui:define name="content">
+
+ <div id="contentMain">
+
+ <h2>Add New Role</h2>
+
+ <h:messages globalOnly="true"/>
+
+ <h:form id="role">
+
+ <div class="formRow">
+ <h:outputLabel for="roleType" value="Role type" styleClass="formLabel"/>
+ <h:selectOneMenu value="#{userAction.roleType}">
+ <f:selectItems value="#{userAction.roleTypes}" var="roleType" itemLabel="#{roleType.name}"/>
+ </h:selectOneMenu>
+ <div class="validationError"><h:message for="roleType"/></div>
+ </div>
+
+ <div class="formRow">
+ <h:outputLabel for="roleGroup" value="Role group" styleClass="formLabel"/>
+ <h:inputText id="roleGroup" value="#{userAction.roleGroupName}"/>
+ <div class="validationError"><h:message for="roleGroup"/></div>
+ </div>
+
+ <div class="formButtons">
+ <h:commandButton id="add" value="Add role" action="#{userAction.roleSave}" styleClass="formButton"/>
+ <h:button id="cancel" value="Cancel" outcome="cancel" styleClass="formButton"/>
+ </div>
+
+ <br class="clear"/>
+
+ </h:form>
+
+ </div>
+
+ </ui:define>
+
+</ui:composition>
+
Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/userdetail.xhtml 2010-07-22 08:12:29 UTC (rev 13471)
@@ -46,21 +46,26 @@
<div class="formRow">
<h:outputLabel for="confirm" value="Confirm password" styleClass="formLabel"/>
<h:inputSecret id="confirm" value="#{userAction.confirm}"/>
- </div>
+ </div>
+
+ <div class="formRow">
+ <h:outputLabel for="enabled" value="Account enabled" styleClass="formLabel"/>
+ <h:selectBooleanCheckbox id="enabled" value="#{userAction.enabled}"/>
+ </div>
+ <h4>Role Memberships</h4>
+
<div class="formRow">
<h:outputLabel value="Member of" styleClass="formLabel"/>
<ui:repeat value="#{userAction.roles}" var="role">
#{role.roleType.name}<span> in group </span>#{role.group.name}<br/>
</ui:repeat>
-
</div>
- <div class="formRow">
- <h:outputLabel for="enabled" value="Account enabled" styleClass="formLabel"/>
- <h:selectBooleanCheckbox id="enabled" value="#{userAction.enabled}"/>
- </div>
-
+ <div>
+ <h:commandButton id="addRole" value="Add new role" action="#{userAction.addRole}" styleClass="formButton"/>
+ </div>
+
<div class="formButtons">
<h:commandButton id="save" value="Save" action="#{userAction.save}" styleClass="formButton"/>
<h:commandButton id="cancel" value="Cancel" action="#{userAction.cancel}" styleClass="formButton"/>
Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-07-22 08:12:29 UTC (rev 13471)
@@ -3,7 +3,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
@@ -13,12 +15,14 @@
import org.jboss.seam.persistence.transaction.Transactional;
import org.jboss.seam.security.UserImpl;
import org.picketlink.idm.api.Attribute;
+import org.picketlink.idm.api.Group;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.Role;
import org.picketlink.idm.api.RoleType;
import org.picketlink.idm.api.User;
import org.picketlink.idm.common.exception.FeatureNotSupportedException;
import org.picketlink.idm.common.exception.IdentityException;
+import org.picketlink.idm.impl.api.model.SimpleRole;
/**
* A conversation-scoped component for creating and managing user accounts
@@ -43,6 +47,13 @@
@Inject IdentitySession identitySession;
@Inject Conversation conversation;
+
+ Map<RoleType, Group> newRoles = new HashMap<RoleType, Group>();
+
+ Collection<RoleType> roleTypes;
+
+ private RoleType roleType;
+ private String roleGroupName;
public void createUser()
{
@@ -72,6 +83,21 @@
newUserFlag = false;
}
+ public void addRole() throws IdentityException, FeatureNotSupportedException
+ {
+ roleTypes = identitySession.getRoleManager().findRoleTypes();
+
+ roleType = null;
+ roleGroupName = null;
+ }
+
+ public String roleSave()
+ {
+ //Role role = new SimpleRole();
+ //roles.add(role);
+ return "success";
+ }
+
public void deleteUser(String username) throws IdentityException
{
identitySession.getPersistenceManager().removeUser(new UserImpl(username), true);
@@ -238,4 +264,34 @@
{
this.enabled = enabled;
}
+
+ public RoleType getRoleType()
+ {
+ return roleType;
+ }
+
+ public void setRoleType(RoleType roleType)
+ {
+ this.roleType = roleType;
+ }
+
+ public String getRoleGroupName()
+ {
+ return roleGroupName;
+ }
+
+ public void setRoleGroupName(String roleGroupName)
+ {
+ this.roleGroupName = roleGroupName;
+ }
+
+ public Collection<RoleType> getRoleTypes()
+ {
+ return roleTypes;
+ }
+
+ public void setRoleTypes(Collection<RoleType> roleTypes)
+ {
+ this.roleTypes = roleTypes;
+ }
}
\ No newline at end of file
Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java 2010-07-22 08:12:29 UTC (rev 13471)
@@ -67,7 +67,7 @@
public static final String OPTION_IDENTITY_CLASS_NAME = "identityEntityClassName";
public static final String OPTION_CREDENTIAL_CLASS_NAME = "credentialEntityClassName";
public static final String OPTION_RELATIONSHIP_CLASS_NAME = "relationshipEntityClassName";
- public static final String OPTION_ROLE_NAME_CLASS_NAME = "roleNameEntityClassName";
+ public static final String OPTION_ROLE_TYPE_CLASS_NAME = "roleTypeEntityClassName";
private static final String DEFAULT_USER_IDENTITY_TYPE = "USER";
private static final String DEFAULT_ROLE_IDENTITY_TYPE = "ROLE";
@@ -92,12 +92,11 @@
private static final String PROPERTY_RELATIONSHIP_TYPE_NAME = "RELATIONSHIP_TYPE_NAME";
private static final String PROPERTY_RELATIONSHIP_NAME = "RELATIONSHIP_NAME";
- // Distinct from PROPERTY_RELATIONSHIP NAME - this property refers to the name field in the RELATIONSHIP_NAME entity
- private static final String PROPERTY_RELATIONSHIP_NAME_NAME = "RELATIONSHIP_NAME_NAME";
+ private static final String PROPERTY_ROLE_TYPE_NAME = "RELATIONSHIP_NAME_NAME";
+
private static final String PROPERTY_ATTRIBUTE_NAME = "ATTRIBUTE_NAME";
private static final String PROPERTY_ATTRIBUTE_VALUE = "ATTRIBUTE_VALUE";
- private static final String PROPERTY_ATTRIBUTE_IDENTITY = "ATTRIBUTE_IDENTITY";
- private static final String PROPERTY_ROLE_TYPE_NAME = "ROLE_TYPE_NAME";
+ private static final String PROPERTY_ATTRIBUTE_IDENTITY = "ATTRIBUTE_IDENTITY";
private class EntityToSpiConverter
{
@@ -187,7 +186,6 @@
private Class<?> relationshipClass;
private Class<?> attributeClass;
private Class<?> roleTypeClass;
- private Class<?> relationshipNameClass;
private String userIdentityType = DEFAULT_USER_IDENTITY_TYPE;
private String roleIdentityType = DEFAULT_ROLE_IDENTITY_TYPE;
@@ -286,18 +284,18 @@
boolean namedRelationshipsSupported = false;
clsName = configurationContext.getStoreConfigurationMetaData()
- .getOptionSingleValue(OPTION_ROLE_NAME_CLASS_NAME);
+ .getOptionSingleValue(OPTION_ROLE_TYPE_CLASS_NAME);
if (clsName != null)
{
try
{
- relationshipNameClass = Class.forName(clsName);
+ roleTypeClass = Class.forName(clsName);
namedRelationshipsSupported = true;
}
catch (ClassNotFoundException e)
{
- throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid relationship name entity class: " + clsName);
+ throw new IdentityException("Error bootstrapping JpaIdentityStore - invalid role type entity class: " + clsName);
}
}
@@ -308,11 +306,10 @@
configureCredentials();
configureRelationships();
configureAttributes();
- configureRoleTypeNames();
if (namedRelationshipsSupported)
{
- configureRelationshipNames();
+ configureRoleTypeName();
}
featuresMetaData = new FeaturesMetaDataImpl(
@@ -961,27 +958,12 @@
}
}
- protected void configureRoleTypeNames()
+ protected void configureRoleTypeName()
{
- if (roleTypeClass != null)
- {
- List<Property<Object>> props = PropertyQueries.createQuery(roleTypeClass)
- .addCriteria(new PropertyTypeCriteria(PropertyType.NAME))
- .getResultList();
-
- if (props.size() == 1)
- {
- modelProperties.put(PROPERTY_ROLE_TYPE_NAME, props.get(0));
- }
- }
- }
-
- protected void configureRelationshipNames()
- {
- Property<Object> relationshipNameProp = findNamedProperty(relationshipNameClass, "name");
+ Property<Object> relationshipNameProp = findNamedProperty(roleTypeClass, "name");
if (relationshipNameProp != null)
{
- modelProperties.put(PROPERTY_RELATIONSHIP_NAME_NAME, relationshipNameProp);
+ modelProperties.put(PROPERTY_ROLE_TYPE_NAME, relationshipNameProp);
}
}
@@ -1363,12 +1345,29 @@
}
public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
- IdentityObjectSearchCriteria criteria) throws IdentityException,
+ IdentityObjectSearchCriteria searchCriteria) throws IdentityException,
OperationNotSupportedException
{
- System.out.println("*** Invoked unimplemented method getRelationshipNames()");
- // TODO Auto-generated method stub
- return null;
+ Set<String> names = new HashSet<String>();
+
+ Property<Object> roleTypeNameProp = modelProperties.get(PROPERTY_ROLE_TYPE_NAME);
+
+ if (roleTypeClass != null)
+ {
+ EntityManager em = getEntityManager(ctx);
+
+ CriteriaBuilder builder = em.getCriteriaBuilder();
+ CriteriaQuery<?> criteria = builder.createQuery(roleTypeClass);
+ criteria.from(roleTypeClass);
+
+ List<?> results = em.createQuery(criteria).getResultList();
+ for (Object result : results)
+ {
+ names.add(roleTypeNameProp.getValue(result).toString());
+ }
+ }
+
+ return names;
}
public Set<String> getRelationshipNames(IdentityStoreInvocationContext ctx,
Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java 2010-07-22 08:01:55 UTC (rev 13470)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStoreConfiguration.java 2010-07-22 08:12:29 UTC (rev 13471)
@@ -17,7 +17,7 @@
private Class<?> identityClass;
private Class<?> credentialClass;
private Class<?> relationshipClass;
- private Class<?> roleNameClass;
+ private Class<?> roleTypeClass;
private Class<?> attributeClass;
@Override
@@ -67,14 +67,14 @@
this.relationshipClass = relationshipClass;
}
- public Class<?> getRoleNameClass()
+ public Class<?> getRoleTypeClass()
{
- return roleNameClass;
+ return roleTypeClass;
}
- public void setRoleNameClass(Class<?> roleNameClass)
+ public void setRoleTypeClass(Class<?> roleTypeClass)
{
- this.roleNameClass = roleNameClass;
+ this.roleTypeClass = roleTypeClass;
}
public Class<?> getAttributeClass()
@@ -109,10 +109,10 @@
createOptionList(relationshipClass.getName()));
}
- if (roleNameClass != null)
+ if (roleTypeClass != null)
{
- options.put(JpaIdentityStore.OPTION_ROLE_NAME_CLASS_NAME,
- createOptionList(roleNameClass.getName()));
+ options.put(JpaIdentityStore.OPTION_ROLE_TYPE_CLASS_NAME,
+ createOptionList(roleTypeClass.getName()));
}
store.setOptions(options);
14 years, 5 months
Seam SVN: r13470 - in sandbox/modules/spreadsheet/src: main/java/org/jboss/seam/spreadsheet/jxl/writer and 2 other directories.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-07-22 04:01:55 -0400 (Thu, 22 Jul 2010)
New Revision: 13470
Added:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/SettingsHelper.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorkbookSettings.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorksheetSettings.java
Modified:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java
Log:
constant factory lazy loading
start of worksheet and workbook settings
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java 2010-07-22 06:59:54 UTC (rev 13469)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -11,6 +11,8 @@
import jxl.write.NumberFormats;
import org.jboss.seam.spreadsheet.SpreadsheetException;
+import org.jboss.seam.spreadsheet.model.WorksheetSettings.PageOrientation;
+import org.jboss.seam.spreadsheet.model.WorksheetSettings.PaperSize;
import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
import org.jboss.seam.spreadsheet.model.formatting.Border;
import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
@@ -36,23 +38,9 @@
private Map<Pattern, jxl.format.Pattern> patterns;
private Map<BorderType, jxl.format.Border> borders;
private Map<BorderLineStyle, jxl.format.BorderLineStyle> borderLineStyles;
+ private Map<PaperSize, jxl.format.PaperSize> paperSizes;
+ private Map<PageOrientation, jxl.format.PageOrientation> pageOrientations;
- public ConstantFactory()
- {
- colours = loadConstants(Colour.values(), jxl.format.Colour.class);
- scriptStyles = loadConstants(ScriptStyle.values(), jxl.format.ScriptStyle.class);
- underlineStyles = loadConstants(UnderlineStyle.values(), jxl.format.UnderlineStyle.class);
- numberFormats = loadConstants(DisplayFormat.class, NumberFormats.class);
- dateFormats = loadConstants(DisplayFormat.class, DateFormats.class);
- numberFormatShorthands = loadConstants(String.class, NumberFormat.class, new String[] { "COMPLEX_FORMAT" });
- orientations = loadConstants(Orientation.values(), jxl.format.Orientation.class);
- alignments = loadConstants(Alignment.values(), jxl.format.Alignment.class);
- verticalAlignments = loadConstants(VerticalAlignment.values(), jxl.format.VerticalAlignment.class);
- patterns = loadConstants(Pattern.values(), jxl.format.Pattern.class);
- borders = loadConstants(BorderType.values(), jxl.format.Border.class);
- borderLineStyles = loadConstants(BorderLineStyle.values(), jxl.format.BorderLineStyle.class);
- }
-
@SuppressWarnings("unchecked")
public <V> Map<String, V> loadConstants(Class<V> valueClass, Class<?> sourceClass, String[] ignoreFields)
{
@@ -82,6 +70,10 @@
public jxl.format.Colour getColour(Colour colour)
{
+ if (colours == null)
+ {
+ colours = loadConstants(Colour.values(), jxl.format.Colour.class);
+ }
checkConstantPresent(colours, colour, "Color");
return colours.get(colour);
}
@@ -96,12 +88,20 @@
public jxl.format.ScriptStyle getScriptStyle(ScriptStyle scriptStyle)
{
+ if (scriptStyles == null)
+ {
+ scriptStyles = loadConstants(ScriptStyle.values(), jxl.format.ScriptStyle.class);
+ }
checkConstantPresent(scriptStyles, scriptStyle, "Script style");
return scriptStyles.get(scriptStyle);
}
public jxl.format.UnderlineStyle getUnderlineStyle(UnderlineStyle underlineStyle)
{
+ if (underlineStyles == null)
+ {
+ underlineStyles = loadConstants(UnderlineStyle.values(), jxl.format.UnderlineStyle.class);
+ }
checkConstantPresent(underlineStyles, underlineStyle, "Underline style");
return underlineStyles.get(underlineStyle);
}
@@ -112,7 +112,7 @@
Map<K, V> constants = new HashMap<K, V>();
for (K key : keys)
{
- String fieldName = key.toString().toUpperCase();
+ String fieldName = key.toString();
try
{
V constant = (V) sourceClass.getField(fieldName).get(null);
@@ -133,47 +133,109 @@
public DisplayFormat getNumberFormat(String mask)
{
+ if (numberFormats == null)
+ {
+ numberFormats = loadConstants(DisplayFormat.class, NumberFormats.class);
+ }
return numberFormats.get(mask);
}
public DisplayFormat getDateFormat(String mask)
{
+ if (dateFormats == null)
+ {
+ dateFormats = loadConstants(DisplayFormat.class, DateFormats.class);
+ }
return dateFormats.get(mask);
}
public String getNumberFormatShorthand(String mask)
{
+ if (numberFormatShorthands == null)
+ {
+ numberFormatShorthands = loadConstants(String.class, NumberFormat.class, new String[] { "COMPLEX_FORMAT" });
+ }
return numberFormatShorthands.get(mask);
}
public jxl.format.Alignment getAlignment(Alignment alignment)
{
+ if (alignments == null)
+ {
+ alignments = loadConstants(Alignment.values(), jxl.format.Alignment.class);
+ }
+ checkConstantPresent(alignments, alignment, "Alignment");
return alignments.get(alignment);
}
public jxl.format.Orientation getOrientation(Orientation orientation)
{
+ if (orientations == null)
+ {
+ orientations = loadConstants(Orientation.values(), jxl.format.Orientation.class);
+ }
+ checkConstantPresent(orientations, orientation, "Orientation");
return orientations.get(orientation);
}
public jxl.format.VerticalAlignment getVerticalAlignment(VerticalAlignment verticalAlignment)
{
+ if (verticalAlignments == null)
+ {
+ verticalAlignments = loadConstants(VerticalAlignment.values(), jxl.format.VerticalAlignment.class);
+ }
+ checkConstantPresent(verticalAlignments, verticalAlignment, "Vertical alignment");
return verticalAlignments.get(verticalAlignment);
}
public jxl.format.Pattern getPattern(Pattern pattern)
{
+ if (patterns == null)
+ {
+ patterns = loadConstants(Pattern.values(), jxl.format.Pattern.class);
+ }
+ checkConstantPresent(patterns, pattern, "Pattern");
return patterns.get(pattern);
}
public jxl.format.Border getBorder(BorderType borderType)
{
+ if (borders == null)
+ {
+ borders = loadConstants(BorderType.values(), jxl.format.Border.class);
+ }
+ checkConstantPresent(borders, borderType, "Border");
return borders.get(borderType);
}
public jxl.format.BorderLineStyle getBorderLineStyle(Border.BorderLineStyle lineStyle)
{
+ if (borderLineStyles == null)
+ {
+ borderLineStyles = loadConstants(BorderLineStyle.values(), jxl.format.BorderLineStyle.class);
+ }
+ checkConstantPresent(borderLineStyles, lineStyle, "Border line style");
return borderLineStyles.get(lineStyle);
}
+ public jxl.format.PaperSize getPaperSize(PaperSize paperSize)
+ {
+ if (paperSizes == null)
+ {
+ paperSizes = loadConstants(PaperSize.values(), jxl.format.PaperSize.class);
+ }
+ checkConstantPresent(paperSizes, paperSize, "Paper size");
+ return paperSizes.get(paperSize);
+ }
+
+ public jxl.format.PageOrientation getPageOrientation(PageOrientation orientation)
+ {
+ if (pageOrientations == null)
+ {
+ pageOrientations = loadConstants(PageOrientation.values(), jxl.format.PageOrientation.class);
+ }
+ checkConstantPresent(pageOrientations, orientation, "Page orientation");
+ return pageOrientations.get(orientation);
+ }
+
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java 2010-07-22 06:59:54 UTC (rev 13469)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -30,6 +30,8 @@
private CellFormatResolver cellFormatResolver;
private WritableWorkbook jxlWorkbook;
+ private SettingsHelper settingsHelper = new SettingsHelper();
+
@Inject
private Events events;
@@ -74,6 +76,10 @@
cellFormatResolver.setWorksheetRules(worksheet.getCellFormatRules());
events.worksheetCreated(worksheet);
WritableSheet jxlWorksheet = jxlWorkbook.createSheet(worksheet.getName(), jxlWorkbook.getNumberOfSheets());
+ if (worksheet.getSettings() != null)
+ {
+ settingsHelper.applyWorksheetSettings(jxlWorksheet, worksheet.getSettings());
+ }
for (Cell cell : worksheet.getCells())
{
processCell(worksheet, jxlWorksheet, cell);
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/SettingsHelper.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/SettingsHelper.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/SettingsHelper.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -0,0 +1,282 @@
+package org.jboss.seam.spreadsheet.jxl.writer;
+
+import java.io.File;
+import java.util.Locale;
+
+import jxl.SheetSettings;
+import jxl.write.WritableSheet;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
+import org.jboss.seam.spreadsheet.model.WorkbookSettings;
+import org.jboss.seam.spreadsheet.model.WorksheetSettings;
+
+public class SettingsHelper
+{
+ private ConstantFactory constantFactory = new ConstantFactory();
+
+ public jxl.WorkbookSettings createWorkbookSettings(WorkbookSettings settings)
+ {
+ jxl.WorkbookSettings workbookSettings = new jxl.WorkbookSettings();
+ if (settings.getArrayGrowSize() != null)
+ {
+ workbookSettings.setArrayGrowSize(settings.getArrayGrowSize());
+ }
+ if (settings.getAutoFilterDisabled() != null)
+ {
+ workbookSettings.setAutoFilterDisabled(settings.getAutoFilterDisabled());
+ }
+ if (settings.getAutoFilterDisabled() != null)
+ {
+ workbookSettings.setCellValidationDisabled(settings.getAutoFilterDisabled());
+ }
+ if (settings.getCharacterSet() != null)
+ {
+ workbookSettings.setCharacterSet(settings.getCharacterSet());
+ }
+ if (settings.getDrawingsDisabled() != null)
+ {
+ workbookSettings.setDrawingsDisabled(settings.getDrawingsDisabled());
+ }
+ if (settings.getEncoding() != null)
+ {
+ workbookSettings.setEncoding(settings.getEncoding());
+ }
+ if (settings.getExcelDisplayLanguage() != null)
+ {
+ workbookSettings.setExcelDisplayLanguage(settings.getExcelDisplayLanguage());
+ }
+ if (settings.getExcelRegionalSettings() != null)
+ {
+ workbookSettings.setExcelRegionalSettings(settings.getExcelRegionalSettings());
+ }
+ if (settings.getFormulaAdjust() != null)
+ {
+ workbookSettings.setFormulaAdjust(settings.getFormulaAdjust());
+ }
+ if (settings.getGcDisabled() != null)
+ {
+ workbookSettings.setGCDisabled(settings.getGcDisabled());
+ }
+ if (settings.getIgnoreBlanks() != null)
+ {
+ workbookSettings.setIgnoreBlanks(settings.getIgnoreBlanks());
+ }
+ if (settings.getLocale() != null)
+ {
+ workbookSettings.setLocale(new Locale(settings.getLocale()));
+ }
+ if (settings.getMergedCellCheckingDisabled() != null)
+ {
+ workbookSettings.setMergedCellChecking(settings.getMergedCellCheckingDisabled());
+ }
+ if (settings.getNamesDisabled() != null)
+ {
+ workbookSettings.setNamesDisabled(settings.getNamesDisabled());
+ }
+ if (settings.getPropertySets() != null)
+ {
+ workbookSettings.setPropertySets(settings.getPropertySets());
+ }
+ if (settings.getRationalization() != null)
+ {
+ workbookSettings.setRationalization(settings.getRationalization());
+ }
+ if (settings.getSupressWarnings() != null)
+ {
+ workbookSettings.setSuppressWarnings(settings.getSupressWarnings());
+ }
+ if (settings.getTemporaryFileDuringWriteDirectory() != null)
+ {
+ workbookSettings.setTemporaryFileDuringWriteDirectory(new File(settings.getTemporaryFileDuringWriteDirectory()));
+ }
+ if (settings.getUseTemporaryFileDuringWrite() != null)
+ {
+ workbookSettings.setUseTemporaryFileDuringWrite(settings.getUseTemporaryFileDuringWrite());
+ }
+ return workbookSettings;
+ }
+
+ public void applyWorksheetSettings(WritableSheet worksheet, WorksheetSettings settings)
+ {
+ SheetSettings sheetSettings = worksheet.getSettings();
+ if (settings.getAutomaticFormulaCalculation() != null)
+ {
+ sheetSettings.setAutomaticFormulaCalculation(settings.getAutomaticFormulaCalculation());
+ }
+ if (settings.getBottomMargin() != null)
+ {
+ sheetSettings.setBottomMargin(settings.getBottomMargin());
+ }
+ if (settings.getCopies() != null)
+ {
+ sheetSettings.setCopies(settings.getCopies());
+ }
+ if (settings.getDefaultColumnWidth() != null)
+ {
+ sheetSettings.setDefaultColumnWidth(settings.getDefaultColumnWidth());
+ }
+ if (settings.getDefaultRowHeight() != null)
+ {
+ sheetSettings.setDefaultRowHeight(settings.getDefaultRowHeight());
+ }
+ if (settings.getDisplayZeroValues() != null)
+ {
+ sheetSettings.setDisplayZeroValues(settings.getDisplayZeroValues());
+ }
+ if (settings.getFitHeight() != null)
+ {
+ sheetSettings.setFitHeight(settings.getFitHeight());
+ }
+ if (settings.getFitToPages() != null)
+ {
+ sheetSettings.setFitToPages(settings.getFitToPages());
+ }
+ if (settings.getFitWidth() != null)
+ {
+ sheetSettings.setFitWidth(settings.getFitWidth());
+ }
+ if (settings.getFooterMargin() != null)
+ {
+ sheetSettings.setFooterMargin(settings.getFooterMargin());
+ }
+ if (settings.getHeaderMargin() != null)
+ {
+ sheetSettings.setHeaderMargin(settings.getHeaderMargin());
+ }
+ if (settings.getHidden() != null)
+ {
+ sheetSettings.setHidden(settings.getHidden());
+ }
+ if (settings.getHorizontalCentre() != null)
+ {
+ sheetSettings.setHorizontalCentre(settings.getHorizontalCentre());
+ }
+ if (settings.getHorizontalFreeze() != null)
+ {
+ sheetSettings.setHorizontalFreeze(settings.getHorizontalFreeze());
+ }
+ if (settings.getHorizontalPrintResolution() != null)
+ {
+ sheetSettings.setHorizontalPrintResolution(settings.getHorizontalPrintResolution());
+ }
+ if (settings.getLeftMargin() != null)
+ {
+ sheetSettings.setLeftMargin(settings.getLeftMargin());
+ }
+ if (settings.getNormalMagnification() != null)
+ {
+ sheetSettings.setNormalMagnification(settings.getNormalMagnification());
+ }
+ if (settings.getOrientation() != null)
+ {
+ sheetSettings.setOrientation(constantFactory.getPageOrientation(settings.getOrientation()));
+ }
+ if (settings.getPageBreakPreviewMagnification() != null)
+ {
+ sheetSettings.setPageBreakPreviewMagnification(settings.getPageBreakPreviewMagnification());
+ }
+ if (settings.getPageBreakPreviewMode() != null)
+ {
+ sheetSettings.setPageBreakPreviewMode(settings.getPageBreakPreviewMode());
+ }
+ if (settings.getPageStart() != null)
+ {
+ sheetSettings.setPageStart(settings.getPageStart());
+ }
+ if (settings.getPaperSize() != null)
+ {
+ sheetSettings.setPaperSize(constantFactory.getPaperSize(settings.getPaperSize()));
+ }
+ if (settings.getPassword() != null)
+ {
+ sheetSettings.setPassword(settings.getPassword());
+ }
+ if (settings.getPasswordHash() != null)
+ {
+ sheetSettings.setPasswordHash(settings.getPasswordHash());
+ }
+ if (settings.getPrintGridLines() != null)
+ {
+ sheetSettings.setPrintGridLines(settings.getPrintGridLines());
+ }
+ if (settings.getPrintHeaders() != null)
+ {
+ sheetSettings.setPrintHeaders(settings.getPrintHeaders());
+ }
+ if (settings.getSheetProtected() != null)
+ {
+ sheetSettings.setProtected(settings.getSheetProtected());
+ }
+ if (settings.getRecalculateFormulasBeforeSave() != null)
+ {
+ sheetSettings.setRecalculateFormulasBeforeSave(settings.getRecalculateFormulasBeforeSave());
+ }
+ if (settings.getRightMargin() != null)
+ {
+ sheetSettings.setRightMargin(settings.getRightMargin());
+ }
+ if (settings.getScaleFactor() != null)
+ {
+ sheetSettings.setScaleFactor(settings.getScaleFactor());
+ }
+ if (settings.getSelected() != null)
+ {
+ sheetSettings.setSelected(settings.getSelected());
+ }
+ if (settings.getShowGridLines() != null)
+ {
+ sheetSettings.setShowGridLines(settings.getShowGridLines());
+ }
+ if (settings.getTopMargin() != null)
+ {
+ sheetSettings.setTopMargin(settings.getTopMargin());
+ }
+ if (settings.getVerticalCentre() != null)
+ {
+ sheetSettings.setVerticalCentre(settings.getVerticalCentre());
+ }
+ if (settings.getVerticalFreeze() != null)
+ {
+ sheetSettings.setVerticalFreeze(settings.getVerticalFreeze());
+ }
+ if (settings.getVerticalPrintResolution() != null)
+ {
+ sheetSettings.setVerticalPrintResolution(settings.getVerticalPrintResolution());
+ }
+ if (settings.getZoomFactor() != null)
+ {
+ sheetSettings.setZoomFactor(settings.getZoomFactor());
+ }
+ // Iterates through the worksheet uiWorksheet child elements (print areas,
+ // print titles and headers/footers)
+ // for (UIComponent child : uiWorksheet.getChildren())
+ // {
+ // if (child.getClass() == UIPrintArea.class)
+ // {
+ // UIPrintArea printArea = (UIPrintArea) child;
+ // settings.setPrintArea(printArea.getFirstColumn(),
+ // printArea.getFirstRow(), printArea.getLastColumn(),
+ // printArea.getLastRow());
+ // }
+ // else if (child.getClass() == UIPrintTitles.class)
+ // {
+ // UIPrintTitles printTitles = (UIPrintTitles) child;
+ // settings.setPrintTitles(printTitles.getFirstCol(),
+ // printTitles.getFirstRow(), printTitles.getLastCol(),
+ // printTitles.getLastRow());
+ // }
+ // else if (child.getClass() == UIHeader.class)
+ // {
+ // UIHeader uiHeader = (UIHeader) child;
+ // settings.setHeader(JXLFactory.createHeaderFooter(uiHeader,
+ // settings.getHeader()));
+ // }
+ // else if (child.getClass() == UIFooter.class)
+ // {
+ // UIFooter uiFooter = (UIFooter) child;
+ // settings.setFooter(JXLFactory.createHeaderFooter(uiFooter,
+ // settings.getFooter()));
+ // }
+ // }
+ }
+}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorkbookSettings.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorkbookSettings.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorkbookSettings.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -0,0 +1,236 @@
+package org.jboss.seam.spreadsheet.model;
+
+public class WorkbookSettings
+{
+ private Integer arrayGrowSize;
+ private Boolean autoFilterDisabled;
+ private Boolean cellValidationDisabled;
+ private Integer characterSet;
+ private Boolean drawingsDisabled;
+ private String encoding;
+ private String excelDisplayLanguage;
+ private String excelRegionalSettings;
+ private Boolean formulaAdjust;
+ private Boolean gcDisabled;
+ private Boolean ignoreBlanks;
+ private Integer initialFileSize;
+ private String locale;
+ private Boolean mergedCellCheckingDisabled;
+ private Boolean namesDisabled;
+ private Boolean propertySets;
+ private Boolean rationalization;
+ private Boolean supressWarnings;
+ private String temporaryFileDuringWriteDirectory;
+ private Boolean useTemporaryFileDuringWrite;
+ private Boolean workbookProtected;
+
+ public Integer getArrayGrowSize()
+ {
+ return arrayGrowSize;
+ }
+
+ public void setArrayGrowSize(Integer arrayGrowSize)
+ {
+ this.arrayGrowSize = arrayGrowSize;
+ }
+
+ public Boolean getAutoFilterDisabled()
+ {
+ return autoFilterDisabled;
+ }
+
+ public void setAutoFilterDisabled(Boolean autoFilterDisabled)
+ {
+ this.autoFilterDisabled = autoFilterDisabled;
+ }
+
+ public Boolean getCellValidationDisabled()
+ {
+ return cellValidationDisabled;
+ }
+
+ public void setCellValidationDisabled(Boolean cellValidationDisabled)
+ {
+ this.cellValidationDisabled = cellValidationDisabled;
+ }
+
+ public Integer getCharacterSet()
+ {
+ return characterSet;
+ }
+
+ public void setCharacterSet(Integer characterSet)
+ {
+ this.characterSet = characterSet;
+ }
+
+ public Boolean getDrawingsDisabled()
+ {
+ return drawingsDisabled;
+ }
+
+ public void setDrawingsDisabled(Boolean drawingsDisabled)
+ {
+ this.drawingsDisabled = drawingsDisabled;
+ }
+
+ public String getEncoding()
+ {
+ return encoding;
+ }
+
+ public void setEncoding(String encoding)
+ {
+ this.encoding = encoding;
+ }
+
+ public String getExcelDisplayLanguage()
+ {
+ return excelDisplayLanguage;
+ }
+
+ public void setExcelDisplayLanguage(String excelDisplayLanguage)
+ {
+ this.excelDisplayLanguage = excelDisplayLanguage;
+ }
+
+ public String getExcelRegionalSettings()
+ {
+ return excelRegionalSettings;
+ }
+
+ public void setExcelRegionalSettings(String excelRegionalSettings)
+ {
+ this.excelRegionalSettings = excelRegionalSettings;
+ }
+
+ public Boolean getFormulaAdjust()
+ {
+ return formulaAdjust;
+ }
+
+ public void setFormulaAdjust(Boolean formulaAdjust)
+ {
+ this.formulaAdjust = formulaAdjust;
+ }
+
+ public Boolean getGcDisabled()
+ {
+ return gcDisabled;
+ }
+
+ public void setGcDisabled(Boolean gcDisabled)
+ {
+ this.gcDisabled = gcDisabled;
+ }
+
+ public Boolean getIgnoreBlanks()
+ {
+ return ignoreBlanks;
+ }
+
+ public void setIgnoreBlanks(Boolean ignoreBlanks)
+ {
+ this.ignoreBlanks = ignoreBlanks;
+ }
+
+ public Integer getInitialFileSize()
+ {
+ return initialFileSize;
+ }
+
+ public void setInitialFileSize(Integer initialFileSize)
+ {
+ this.initialFileSize = initialFileSize;
+ }
+
+ public String getLocale()
+ {
+ return locale;
+ }
+
+ public void setLocale(String locale)
+ {
+ this.locale = locale;
+ }
+
+ public Boolean getMergedCellCheckingDisabled()
+ {
+ return mergedCellCheckingDisabled;
+ }
+
+ public void setMergedCellCheckingDisabled(Boolean mergedCellCheckingDisabled)
+ {
+ this.mergedCellCheckingDisabled = mergedCellCheckingDisabled;
+ }
+
+ public Boolean getNamesDisabled()
+ {
+ return namesDisabled;
+ }
+
+ public void setNamesDisabled(Boolean namesDisabled)
+ {
+ this.namesDisabled = namesDisabled;
+ }
+
+ public Boolean getPropertySets()
+ {
+ return propertySets;
+ }
+
+ public void setPropertySets(Boolean propertySets)
+ {
+ this.propertySets = propertySets;
+ }
+
+ public Boolean getRationalization()
+ {
+ return rationalization;
+ }
+
+ public void setRationalization(Boolean rationalization)
+ {
+ this.rationalization = rationalization;
+ }
+
+ public Boolean getSupressWarnings()
+ {
+ return supressWarnings;
+ }
+
+ public void setSupressWarnings(Boolean supressWarnings)
+ {
+ this.supressWarnings = supressWarnings;
+ }
+
+ public String getTemporaryFileDuringWriteDirectory()
+ {
+ return temporaryFileDuringWriteDirectory;
+ }
+
+ public void setTemporaryFileDuringWriteDirectory(String temporaryFileDuringWriteDirectory)
+ {
+ this.temporaryFileDuringWriteDirectory = temporaryFileDuringWriteDirectory;
+ }
+
+ public Boolean getUseTemporaryFileDuringWrite()
+ {
+ return useTemporaryFileDuringWrite;
+ }
+
+ public void setUseTemporaryFileDuringWrite(Boolean useTemporaryFileDuringWrite)
+ {
+ this.useTemporaryFileDuringWrite = useTemporaryFileDuringWrite;
+ }
+
+ public Boolean getWorkbookProtected()
+ {
+ return workbookProtected;
+ }
+
+ public void setWorkbookProtected(Boolean workbookProtected)
+ {
+ this.workbookProtected = workbookProtected;
+ }
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 06:59:54 UTC (rev 13469)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -12,6 +12,7 @@
private List<Cell> cells = new ArrayList<Cell>();
private List<CellFormatRule> cellFormatRules = new ArrayList<CellFormatRule>();
private List<Command> commands = new ArrayList<Command>();
+ private WorksheetSettings settings = null;
protected Worksheet(String name)
{
@@ -68,4 +69,14 @@
{
return String.format("Worksheet %s", name);
}
+
+ public WorksheetSettings getSettings()
+ {
+ return settings;
+ }
+
+ public void setSettings(WorksheetSettings settings)
+ {
+ this.settings = settings;
+ }
}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorksheetSettings.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorksheetSettings.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/WorksheetSettings.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -0,0 +1,422 @@
+package org.jboss.seam.spreadsheet.model;
+
+public class WorksheetSettings
+{
+ public enum PaperSize
+ {
+ A2, A3, A3_EXTRA, A3_EXTRA_TRANSVERSE, A3_ROTATED, A3_TRANSVERSE, A4, A4_EXTRA, A4_PLUS, A4_ROTATED, A4_SMALL, A4_TRANSVERSE, A5, A5_EXTRA, A5_ROTATED, A5_TRANSVERSE, A6, A6_ROTATED, B4, B4_ISO, B4_ISO_2, B4_ROTATED, B5, B5_EXTRA, B5_ISO, B5_ROTATED, B5_TRANSVERSE, B6, B6_ISO, B6_ROTATED, C, D, DOUBLE_JAPANESE_POSTCARD, DOUBLE_JAPANESE_POSTCARD_ROTATED, E, ENVELOPE_10, ENVELOPE_11, ENVELOPE_12, ENVELOPE_14, ENVELOPE_6_75, ENVELOPE_9, ENVELOPE_C3, ENVELOPE_C4, ENVELOPE_C5, ENVELOPE_C6, ENVELOPE_C6_C5, ENVELOPE_DL, ENVELOPE_INVITE, ENVELOPE_ITALY, ENVELOPE_MONARCH, EXECUTIVE, FOLIO, GERMAN_FANFOLD, GERMAN_LEGAL_FANFOLD, JAPANESE_POSTCARD, JAPANESE_POSTCARD_ROTATED, LEDGER, LEGAL, LEGAL_EXTRA, LETTER, LETTER_EXTRA, LETTER_EXTRA_TRANSVERSE, LETTER_PLUS, LETTER_ROTATED, LETTER_SMALL, LETTER_TRANSVERSE, NOTE, QUARTO, SIZE_10x11, SIZE_10x14, SIZE_10x17, SIZE_15x11, SIZE_9x11, STATEMENT, SUPER_A_A4, SUPER_B_A3, TABLOID, TABLOID_EXTRA, UNDEFINED, US_FANFOLD
+ }
+
+ public enum PageOrientation
+ {
+ LANDSCAPE, PORTRAIT
+ }
+
+ private Boolean automaticFormulaCalculation;
+ private Double bottomMargin;
+ private Integer copies;
+ private Integer defaultColumnWidth;
+ private Integer defaultRowHeight;
+ private Boolean displayZeroValues;
+ private Integer fitHeight;
+ private Boolean fitToPages;
+ private Integer fitWidth;
+ private Double footerMargin;
+ private Double headerMargin;
+ private Boolean hidden;
+ private Boolean horizontalCentre;
+ private Integer horizontalFreeze;
+ private Integer horizontalPrintResolution;
+ private Double leftMargin;
+ private Integer normalMagnification;
+ private PageOrientation orientation;
+ private Integer pageBreakPreviewMagnification;
+ private Boolean pageBreakPreviewMode;
+ private Integer pageStart;
+ private PaperSize paperSize;
+ private String password;
+ private Integer passwordHash;
+ private Boolean printGridLines;
+ private Boolean printHeaders;
+ private Boolean sheetProtected;
+ private Boolean recalculateFormulasBeforeSave;
+ private Double rightMargin;
+ private Integer scaleFactor;
+ private Boolean selected;
+ private Boolean showGridLines;
+ private Double topMargin;
+ private Boolean verticalCentre;
+ private Integer verticalFreeze;
+ private Integer verticalPrintResolution;
+ private Integer zoomFactor;
+
+ public Boolean getAutomaticFormulaCalculation()
+ {
+ return automaticFormulaCalculation;
+ }
+
+ public void setAutomaticFormulaCalculation(Boolean automaticFormulaCalculation)
+ {
+ this.automaticFormulaCalculation = automaticFormulaCalculation;
+ }
+
+ public Double getBottomMargin()
+ {
+ return bottomMargin;
+ }
+
+ public void setBottomMargin(Double bottomMargin)
+ {
+ this.bottomMargin = bottomMargin;
+ }
+
+ public Integer getCopies()
+ {
+ return copies;
+ }
+
+ public void setCopies(Integer copies)
+ {
+ this.copies = copies;
+ }
+
+ public Integer getDefaultColumnWidth()
+ {
+ return defaultColumnWidth;
+ }
+
+ public void setDefaultColumnWidth(Integer defaultColumnWidth)
+ {
+ this.defaultColumnWidth = defaultColumnWidth;
+ }
+
+ public Integer getDefaultRowHeight()
+ {
+ return defaultRowHeight;
+ }
+
+ public void setDefaultRowHeight(Integer defaultRowHeight)
+ {
+ this.defaultRowHeight = defaultRowHeight;
+ }
+
+ public Boolean getDisplayZeroValues()
+ {
+ return displayZeroValues;
+ }
+
+ public void setDisplayZeroValues(Boolean displayZeroValues)
+ {
+ this.displayZeroValues = displayZeroValues;
+ }
+
+ public Integer getFitHeight()
+ {
+ return fitHeight;
+ }
+
+ public void setFitHeight(Integer fitHeight)
+ {
+ this.fitHeight = fitHeight;
+ }
+
+ public Boolean getFitToPages()
+ {
+ return fitToPages;
+ }
+
+ public void setFitToPages(Boolean fitToPages)
+ {
+ this.fitToPages = fitToPages;
+ }
+
+ public Integer getFitWidth()
+ {
+ return fitWidth;
+ }
+
+ public void setFitWidth(Integer fitWidth)
+ {
+ this.fitWidth = fitWidth;
+ }
+
+ public Double getFooterMargin()
+ {
+ return footerMargin;
+ }
+
+ public void setFooterMargin(Double footerMargin)
+ {
+ this.footerMargin = footerMargin;
+ }
+
+ public Double getHeaderMargin()
+ {
+ return headerMargin;
+ }
+
+ public void setHeaderMargin(Double headerMargin)
+ {
+ this.headerMargin = headerMargin;
+ }
+
+ public Boolean getHidden()
+ {
+ return hidden;
+ }
+
+ public void setHidden(Boolean hidden)
+ {
+ this.hidden = hidden;
+ }
+
+ public Boolean getHorizontalCentre()
+ {
+ return horizontalCentre;
+ }
+
+ public void setHorizontalCentre(Boolean horizontalCentre)
+ {
+ this.horizontalCentre = horizontalCentre;
+ }
+
+ public Integer getHorizontalFreeze()
+ {
+ return horizontalFreeze;
+ }
+
+ public void setHorizontalFreeze(Integer horizontalFreeze)
+ {
+ this.horizontalFreeze = horizontalFreeze;
+ }
+
+ public Integer getHorizontalPrintResolution()
+ {
+ return horizontalPrintResolution;
+ }
+
+ public void setHorizontalPrintResolution(Integer horizontalPrintResolution)
+ {
+ this.horizontalPrintResolution = horizontalPrintResolution;
+ }
+
+ public Double getLeftMargin()
+ {
+ return leftMargin;
+ }
+
+ public void setLeftMargin(Double leftMargin)
+ {
+ this.leftMargin = leftMargin;
+ }
+
+ public Integer getNormalMagnification()
+ {
+ return normalMagnification;
+ }
+
+ public void setNormalMagnification(Integer normalMagnification)
+ {
+ this.normalMagnification = normalMagnification;
+ }
+
+ public PageOrientation getOrientation()
+ {
+ return orientation;
+ }
+
+ public void setOrientation(PageOrientation orientation)
+ {
+ this.orientation = orientation;
+ }
+
+ public Integer getPageBreakPreviewMagnification()
+ {
+ return pageBreakPreviewMagnification;
+ }
+
+ public void setPageBreakPreviewMagnification(Integer pageBreakPreviewMagnification)
+ {
+ this.pageBreakPreviewMagnification = pageBreakPreviewMagnification;
+ }
+
+ public Boolean getPageBreakPreviewMode()
+ {
+ return pageBreakPreviewMode;
+ }
+
+ public void setPageBreakPreviewMode(Boolean pageBreakPreviewMode)
+ {
+ this.pageBreakPreviewMode = pageBreakPreviewMode;
+ }
+
+ public Integer getPageStart()
+ {
+ return pageStart;
+ }
+
+ public void setPageStart(Integer pageStart)
+ {
+ this.pageStart = pageStart;
+ }
+
+ public PaperSize getPaperSize()
+ {
+ return paperSize;
+ }
+
+ public void setPaperSize(PaperSize paperSize)
+ {
+ this.paperSize = paperSize;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public Integer getPasswordHash()
+ {
+ return passwordHash;
+ }
+
+ public void setPasswordHash(Integer passwordHash)
+ {
+ this.passwordHash = passwordHash;
+ }
+
+ public Boolean getPrintGridLines()
+ {
+ return printGridLines;
+ }
+
+ public void setPrintGridLines(Boolean printGridLines)
+ {
+ this.printGridLines = printGridLines;
+ }
+
+ public Boolean getPrintHeaders()
+ {
+ return printHeaders;
+ }
+
+ public void setPrintHeaders(Boolean printHeaders)
+ {
+ this.printHeaders = printHeaders;
+ }
+
+ public Boolean getSheetProtected()
+ {
+ return sheetProtected;
+ }
+
+ public void setSheetProtected(Boolean sheetProtected)
+ {
+ this.sheetProtected = sheetProtected;
+ }
+
+ public Boolean getRecalculateFormulasBeforeSave()
+ {
+ return recalculateFormulasBeforeSave;
+ }
+
+ public void setRecalculateFormulasBeforeSave(Boolean recalculateFormulasBeforeSave)
+ {
+ this.recalculateFormulasBeforeSave = recalculateFormulasBeforeSave;
+ }
+
+ public Double getRightMargin()
+ {
+ return rightMargin;
+ }
+
+ public void setRightMargin(Double rightMargin)
+ {
+ this.rightMargin = rightMargin;
+ }
+
+ public Integer getScaleFactor()
+ {
+ return scaleFactor;
+ }
+
+ public void setScaleFactor(Integer scaleFactor)
+ {
+ this.scaleFactor = scaleFactor;
+ }
+
+ public Boolean getSelected()
+ {
+ return selected;
+ }
+
+ public void setSelected(Boolean selected)
+ {
+ this.selected = selected;
+ }
+
+ public Boolean getShowGridLines()
+ {
+ return showGridLines;
+ }
+
+ public void setShowGridLines(Boolean showGridLines)
+ {
+ this.showGridLines = showGridLines;
+ }
+
+ public Double getTopMargin()
+ {
+ return topMargin;
+ }
+
+ public void setTopMargin(Double topMargin)
+ {
+ this.topMargin = topMargin;
+ }
+
+ public Boolean getVerticalCentre()
+ {
+ return verticalCentre;
+ }
+
+ public void setVerticalCentre(Boolean verticalCentre)
+ {
+ this.verticalCentre = verticalCentre;
+ }
+
+ public Integer getVerticalFreeze()
+ {
+ return verticalFreeze;
+ }
+
+ public void setVerticalFreeze(Integer verticalFreeze)
+ {
+ this.verticalFreeze = verticalFreeze;
+ }
+
+ public Integer getVerticalPrintResolution()
+ {
+ return verticalPrintResolution;
+ }
+
+ public void setVerticalPrintResolution(Integer verticalPrintResolution)
+ {
+ this.verticalPrintResolution = verticalPrintResolution;
+ }
+
+ public Integer getZoomFactor()
+ {
+ return zoomFactor;
+ }
+
+ public void setZoomFactor(Integer zoomFactor)
+ {
+ this.zoomFactor = zoomFactor;
+ }
+}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java 2010-07-22 08:01:55 UTC (rev 13470)
@@ -3,12 +3,13 @@
import java.util.Map;
import jxl.biff.DisplayFormat;
-import jxl.write.DateFormat;
import jxl.write.DateFormats;
import jxl.write.NumberFormat;
import jxl.write.NumberFormats;
import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
+import org.jboss.seam.spreadsheet.model.WorksheetSettings.PageOrientation;
+import org.jboss.seam.spreadsheet.model.WorksheetSettings.PaperSize;
import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
@@ -104,7 +105,26 @@
Assert.assertNotNull(constantFactory.getOrientation(orientation));
}
}
+
+ @Test
+ public void pageOrientationTest()
+ {
+ for (PageOrientation orientation : PageOrientation.values())
+ {
+ Assert.assertNotNull(constantFactory.getPageOrientation(orientation));
+ }
+ }
+
+ @Test
+ public void paperSizeTest()
+ {
+ for (PaperSize orientation : PaperSize.values())
+ {
+ Assert.assertNotNull(constantFactory.getPaperSize(orientation));
+ }
+ }
+
@Test
public void alignmentTest()
{
14 years, 5 months
Seam SVN: r13469 - in sandbox/modules/spreadsheet/src: main/java/org/jboss/seam/spreadsheet/jxl/command and 14 other directories.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-07-22 02:59:54 -0400 (Thu, 22 Jul 2010)
New Revision: 13469
Added:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java
Removed:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java
Modified:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
Log:
moving stuff
merge cells command
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,19 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-@Qualifier
-@Retention(RUNTIME)
-@Target( { METHOD, FIELD, PARAMETER, TYPE })
-public @interface BeforeAdded
-{
-}
\ No newline at end of file
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,19 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-@Qualifier
-@Retention(RUNTIME)
-@Target( { METHOD, FIELD, PARAMETER, TYPE })
-public @interface BeforeCreated
-{
-}
\ No newline at end of file
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,19 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-@Qualifier
-@Retention(RUNTIME)
-@Target( { METHOD, FIELD, PARAMETER, TYPE })
-public @interface BeforeExecuted
-{
-}
\ No newline at end of file
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,145 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-
-import javax.enterprise.event.Event;
-import javax.inject.Inject;
-
-import jxl.write.WritableSheet;
-import jxl.write.WritableWorkbook;
-import jxl.write.WriteException;
-import jxl.write.biff.RowsExceededException;
-
-import org.jboss.seam.spreadsheet.SpreadsheetException;
-import org.jboss.seam.spreadsheet.SpreadsheetWriter;
-import org.jboss.seam.spreadsheet.jxl.command.CommandFactory;
-import org.jboss.seam.spreadsheet.jxl.command.JxlCommand;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.Workbook;
-import org.jboss.seam.spreadsheet.model.Worksheet;
-import org.jboss.seam.spreadsheet.model.command.Command;
-
-public class JXLSpreadsheetWriter implements SpreadsheetWriter
-{
- CellFactory cellFactory;
- CellFormatResolver cellFormatResolver;
- WritableWorkbook jxlWorkbook;
-
- @Inject
- @BeforeAdded
- Event<Cell> cellAdded;
-
- @Inject
- @BeforeCreated
- Event<Worksheet> worksheetCreated;
-
- @Inject
- @BeforeExecuted
- Event<Command> commandExecuted;
-
- @Override
- public byte[] writeWorkbook(Workbook workbook) throws SpreadsheetException
- {
- if (workbook.getWorksheets().isEmpty())
- {
- throw new SpreadsheetException("You must have at least one worksheet");
- }
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- cellFactory = new CellFactory();
- cellFormatResolver = new CellFormatResolver(workbook.getCellFormatRules());
- try
- {
- jxlWorkbook = jxl.Workbook.createWorkbook(outStream);
- processWorkbook(jxlWorkbook, workbook);
- jxlWorkbook.write();
- jxlWorkbook.close();
- }
- catch (IOException e)
- {
- throw new SpreadsheetException("Could not create workbook", e);
- }
- catch (WriteException e)
- {
- throw new SpreadsheetException("Could not write workbook", e);
- }
- return outStream.toByteArray();
- }
-
- private void processWorkbook(WritableWorkbook jxlWorkbook, Workbook workbook)
- {
- for (Worksheet worksheet : workbook.getWorksheets())
- {
- processWorksheet(worksheet, workbook, jxlWorkbook);
- }
- }
-
- private void processWorksheet(Worksheet worksheet, Workbook workbook, WritableWorkbook jxlWorkbook)
- {
- cellFormatResolver.setWorksheetRules(worksheet.getCellFormatRules());
- worksheetCreated.fire(worksheet);
- WritableSheet jxlWorksheet = jxlWorkbook.createSheet(worksheet.getName(), jxlWorkbook.getNumberOfSheets());
- for (Cell cell : worksheet.getCells())
- {
- processCell(jxlWorksheet, cell);
- }
- processCommands(workbook.getCommands(), jxlWorksheet);
- processCommands(worksheet.getCommands(), jxlWorksheet);
- }
-
- private void processCommands(List<Command> commands, WritableSheet jxlWorksheet)
- {
- for (Command command : commands)
- {
- JxlCommand jxlCommand = CommandFactory.getJxlCommand(command, jxlWorksheet);
- commandExecuted.fire(command);
- jxlCommand.execute();
- }
- }
-
- private void processCell(WritableSheet jxlWorksheet, Cell cell)
- {
- try
- {
- cellAdded.fire(cell);
- jxlWorksheet.addCell(cellFactory.createCell(cell, cellFormatResolver));
- if (cell.getCellSpan() != null)
- {
- mergeCells(jxlWorksheet, cell);
- }
- }
- catch (RowsExceededException e)
- {
- throw new SpreadsheetException("Too many rows", e);
- }
- catch (WriteException e)
- {
- throw new SpreadsheetException("Could not write cell", e);
- }
- }
-
- private void mergeCells(WritableSheet jxlWorksheet, Cell cell) throws RowsExceededException, WriteException
- {
- int columnStart = cell.getCoordinate().getColumn();
- int rowStart = cell.getCoordinate().getRow();
- int columnEnd = columnStart + cell.getCellSpan().getColumnSpan();
- int rowEnd = rowStart + cell.getCellSpan().getRowSpan();
- jxlWorksheet.mergeCells(columnStart, rowStart, columnEnd, rowEnd);
- }
-
- @Override
- public byte[] writeWorkbook(Workbook workbook, byte[] template) throws SpreadsheetException
- {
- return null;
- }
-
- @Override
- public Object getRawWorkbook()
- {
- return jxlWorkbook;
- }
-
-}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,13 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import jxl.write.WritableSheet;
+
+public abstract class AbstractJxlCommand implements JxlCommand
+{
+ protected WritableSheet jxlWorksheet;
+
+ public AbstractJxlCommand(WritableSheet jxlWorksheet)
+ {
+ this.jxlWorksheet = jxlWorksheet;
+ }
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,6 +4,7 @@
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
import org.jboss.seam.spreadsheet.model.command.Command;
+import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
import org.jboss.seam.spreadsheet.model.command.RowHeightCommand;
public class CommandFactory
@@ -17,6 +18,8 @@
return new JxlColumnWidthCommand((ColumnWidthCommand) command, jxlWorksheet);
case ROW_HEIGHT:
return new JxlRowHeightCommand((RowHeightCommand) command, jxlWorksheet);
+ case MERGE_CELLS:
+ return new JxlMergeCellsCommand((MergeCellsCommand) command, jxlWorksheet);
}
return null;
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -5,15 +5,14 @@
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
-public class JxlColumnWidthCommand implements JxlCommand
+public class JxlColumnWidthCommand extends AbstractJxlCommand
{
private ColumnWidthCommand columnWidthCommand;
- private WritableSheet jxlWorksheet;
public JxlColumnWidthCommand(ColumnWidthCommand columnWidthCommand, WritableSheet jxlWorksheet)
{
+ super(jxlWorksheet);
this.columnWidthCommand = columnWidthCommand;
- this.jxlWorksheet = jxlWorksheet;
}
@Override
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,41 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import jxl.write.WritableSheet;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.jboss.seam.spreadsheet.SpreadsheetException;
+import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
+
+public class JxlMergeCellsCommand extends AbstractJxlCommand
+{
+ private MergeCellsCommand command;
+
+ public JxlMergeCellsCommand(MergeCellsCommand command, WritableSheet jxlWorksheet)
+ {
+ super(jxlWorksheet);
+ this.command = command;
+ }
+
+ @Override
+ public void execute()
+ {
+ int startColumn = command.getCoordinate().getColumn();
+ int startRow = command.getCoordinate().getRow();
+ int endColumn = startColumn + command.getCellSpan().getColumnSpan();
+ int endRow = startRow + command.getCellSpan().getRowSpan();
+ try
+ {
+ jxlWorksheet.mergeCells(startColumn, startRow, endColumn, endRow);
+ }
+ catch (RowsExceededException e)
+ {
+ throw new SpreadsheetException(String.format("Too many rows when merging cell at %s", command.getCoordinate()), e);
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException(String.format("Could not merge cells at %s", command.getCoordinate()), e);
+ }
+ }
+
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,15 +4,14 @@
import org.jboss.seam.spreadsheet.model.command.RowHeightCommand;
-public class JxlRowHeightCommand implements JxlCommand
+public class JxlRowHeightCommand extends AbstractJxlCommand
{
private RowHeightCommand rowHeightCommand;
- private WritableSheet jxlWorksheet;
public JxlRowHeightCommand(RowHeightCommand rowHeightCommand, WritableSheet jxlWorksheet)
{
+ super(jxlWorksheet);
this.rowHeightCommand = rowHeightCommand;
- this.jxlWorksheet = jxlWorksheet;
}
@Override
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -7,7 +7,7 @@
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
public class CellFormatResolver
{
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java (from rev 13459, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,128 @@
+package org.jboss.seam.spreadsheet.jxl.writer;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.jboss.seam.spreadsheet.SpreadsheetException;
+import org.jboss.seam.spreadsheet.SpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.command.CommandFactory;
+import org.jboss.seam.spreadsheet.jxl.command.JxlCommand;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Workbook;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.command.Command;
+import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
+
+public class JXLSpreadsheetWriter implements SpreadsheetWriter
+{
+ private CellFactory cellFactory;
+ private CellFormatResolver cellFormatResolver;
+ private WritableWorkbook jxlWorkbook;
+
+ @Inject
+ private Events events;
+
+ @Override
+ public byte[] writeWorkbook(Workbook workbook) throws SpreadsheetException
+ {
+ if (workbook.getWorksheets().isEmpty())
+ {
+ throw new SpreadsheetException("You must have at least one worksheet");
+ }
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ cellFactory = new CellFactory();
+ cellFormatResolver = new CellFormatResolver(workbook.getCellFormatRules());
+ try
+ {
+ jxlWorkbook = jxl.Workbook.createWorkbook(outStream);
+ processWorkbook(workbook);
+ jxlWorkbook.write();
+ jxlWorkbook.close();
+ }
+ catch (IOException e)
+ {
+ throw new SpreadsheetException("Could not create workbook", e);
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException("Could not write workbook", e);
+ }
+ return outStream.toByteArray();
+ }
+
+ private void processWorkbook(Workbook workbook)
+ {
+ for (Worksheet worksheet : workbook.getWorksheets())
+ {
+ processWorksheet(worksheet, workbook.getCommands());
+ }
+ }
+
+ private void processWorksheet(Worksheet worksheet, List<Command> workbookCommands)
+ {
+ cellFormatResolver.setWorksheetRules(worksheet.getCellFormatRules());
+ events.worksheetCreated(worksheet);
+ WritableSheet jxlWorksheet = jxlWorkbook.createSheet(worksheet.getName(), jxlWorkbook.getNumberOfSheets());
+ for (Cell cell : worksheet.getCells())
+ {
+ processCell(worksheet, jxlWorksheet, cell);
+ }
+ processCommands(workbookCommands, jxlWorksheet);
+ processCommands(worksheet.getCommands(), jxlWorksheet);
+ }
+
+ private void processCommands(List<Command> commands, WritableSheet jxlWorksheet)
+ {
+ for (Command command : commands)
+ {
+ JxlCommand jxlCommand = CommandFactory.getJxlCommand(command, jxlWorksheet);
+ events.commandExecuted(command);
+ jxlCommand.execute();
+ }
+ }
+
+ private void processCell(Worksheet worksheet, WritableSheet jxlWorksheet, Cell cell)
+ {
+ try
+ {
+ events.cellAdded(cell);
+ jxlWorksheet.addCell(cellFactory.createCell(cell, cellFormatResolver));
+ if (cell.getCellSpan() != null)
+ {
+ worksheet.getCommands().add(new MergeCellsCommand(cell.getCoordinate(), cell.getCellSpan()));
+ }
+ }
+ catch (RowsExceededException e)
+ {
+ throw new SpreadsheetException("Too many rows", e);
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException("Could not write cell", e);
+ }
+ }
+
+ @Override
+ public byte[] writeWorkbook(Workbook workbook, byte[] template) throws SpreadsheetException
+ {
+ return null;
+ }
+
+ @Override
+ public Object getRawWorkbook()
+ {
+ return jxlWorkbook;
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+@Retention(RUNTIME)
+@Target( { METHOD, FIELD, PARAMETER, TYPE })
+public @interface BeforeAdded
+{
+}
\ No newline at end of file
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+@Retention(RUNTIME)
+@Target( { METHOD, FIELD, PARAMETER, TYPE })
+public @interface BeforeCreated
+{
+}
\ No newline at end of file
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+@Retention(RUNTIME)
+@Target( { METHOD, FIELD, PARAMETER, TYPE })
+public @interface BeforeExecuted
+{
+}
\ No newline at end of file
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,38 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.command.Command;
+
+public class Events
+{
+ @Inject
+ @BeforeAdded
+ private Event<Cell> cellAdded;
+
+ @Inject
+ @BeforeCreated
+ private Event<Worksheet> worksheetCreated;
+
+ @Inject
+ @BeforeExecuted
+ private Event<Command> commandExecuted;
+
+ public void cellAdded(Cell cell)
+ {
+ cellAdded.fire(cell);
+ }
+
+ public void worksheetCreated(Worksheet worksheet)
+ {
+ worksheetCreated.fire(worksheet);
+ }
+
+ public void commandExecuted(Command command)
+ {
+ commandExecuted.fire(command);
+ }
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,7 +4,7 @@
import java.util.List;
import org.jboss.seam.spreadsheet.model.command.Command;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
public class Workbook
{
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,7 +4,7 @@
import java.util.List;
import org.jboss.seam.spreadsheet.model.command.Command;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
public class Worksheet
{
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -11,8 +11,8 @@
import org.jboss.seam.spreadsheet.model.Worksheet;
import org.jboss.seam.spreadsheet.model.command.Command;
import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
-import org.jboss.seam.spreadsheet.model.formatting.RangeCellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.RangeCellFormatRule;
import org.jboss.seam.spreadsheet.util.ReflectionUtil;
public class WorkbookBuilder
@@ -21,7 +21,7 @@
Worksheet worksheet;
IteratingCoordinate cursor;
-
+
public void clear()
{
workbook = new Workbook();
@@ -141,7 +141,7 @@
Coordinate topLeft = Coordinate.of(startCoordinate.getColumn(), startCoordinate.getRow());
Coordinate bottomRight = Coordinate.of(startCoordinate.getColumn() + blockWidth - 1, startCoordinate.getRow());
Range range = Range.of(topLeft, bottomRight);
- addWorksheetCellFormatRule(RangeCellFormatRule.of(cellFormat, range));
+ addWorksheetCellFormatRule(RangeCellFormatRule.of(range, cellFormat));
}
private void addDataCellFormatRule(Coordinate startCoordinate, int blockWidth, CellFormat cellFormat)
@@ -149,7 +149,7 @@
Coordinate topLeft = Coordinate.of(startCoordinate.getColumn(), startCoordinate.getRow());
Coordinate bottomRight = Coordinate.of(startCoordinate.getColumn() + blockWidth - 1, cursor.getRow() - 1);
Range range = Range.of(topLeft, bottomRight);
- addWorksheetCellFormatRule(RangeCellFormatRule.of(cellFormat, range));
+ addWorksheetCellFormatRule(RangeCellFormatRule.of(range, cellFormat));
}
public IteratingCoordinate getCursor()
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,7 +4,7 @@
{
public enum CommandId
{
- COLUMN_WIDTH, ROW_HEIGHT
+ COLUMN_WIDTH, ROW_HEIGHT, MERGE_CELLS
};
public abstract CommandId getCommandId();
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,33 @@
+package org.jboss.seam.spreadsheet.model.command;
+
+import org.jboss.seam.spreadsheet.model.CellSpan;
+import org.jboss.seam.spreadsheet.model.Coordinate;
+
+public class MergeCellsCommand implements Command
+{
+ private Coordinate coordinate;
+ private CellSpan cellSpan;
+
+ public MergeCellsCommand(Coordinate coordinate, CellSpan cellSpan)
+ {
+ this.coordinate = coordinate;
+ this.cellSpan = cellSpan;
+ }
+
+ @Override
+ public CommandId getCommandId()
+ {
+ return CommandId.MERGE_CELLS;
+ }
+
+ public Coordinate getCoordinate()
+ {
+ return coordinate;
+ }
+
+ public CellSpan getCellSpan()
+ {
+ return cellSpan;
+ }
+
+}
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,9 +0,0 @@
-package org.jboss.seam.spreadsheet.model.formatting;
-
-import org.jboss.seam.spreadsheet.model.Cell;
-
-public interface CellFormatRule
-{
- public abstract boolean appliesTo(Cell cell);
- public abstract CellFormat getCellFormat();
-}
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,35 +0,0 @@
-package org.jboss.seam.spreadsheet.model.formatting;
-
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.Coordinate;
-import org.jboss.seam.spreadsheet.model.Range;
-
-public class RangeCellFormatRule implements CellFormatRule
-{
- private CellFormat cellFormat;
- private Range range;
-
- protected RangeCellFormatRule(CellFormat cellFormat, Range range)
- {
- this.cellFormat = cellFormat;
- this.range = range;
- }
-
- public static RangeCellFormatRule of(CellFormat cellFormat, Range range)
- {
- return new RangeCellFormatRule(cellFormat, range);
- }
-
- @Override
- public boolean appliesTo(Cell cell)
- {
- return cell.getCoordinate().within(range);
- }
-
- @Override
- public CellFormat getCellFormat()
- {
- return cellFormat;
- }
-
-}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public abstract class AbstractCellFormatRule implements CellFormatRule
+{
+ protected CellFormat cellFormat;
+
+ public AbstractCellFormatRule(CellFormat cellFormat)
+ {
+ this.cellFormat = cellFormat;
+ }
+
+ @Override
+ public CellFormat getCellFormat()
+ {
+ return cellFormat;
+ }
+}
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,10 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public interface CellFormatRule
+{
+ public abstract boolean appliesTo(Cell cell);
+ public abstract CellFormat getCellFormat();
+}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,20 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class EvenRowRule extends AbstractCellFormatRule
+{
+
+ protected EvenRowRule(CellFormat cellFormat)
+ {
+ super(cellFormat);
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return cell.getCoordinate().getRow() % 2 != 0;
+ }
+
+}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,20 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class OddRowRule extends AbstractCellFormatRule
+{
+
+ protected OddRowRule(CellFormat cellFormat)
+ {
+ super(cellFormat);
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return cell.getCoordinate().getRow() % 2 == 0;
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,28 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Range;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class RangeCellFormatRule extends AbstractCellFormatRule
+{
+ private Range range;
+
+ protected RangeCellFormatRule(Range range, CellFormat cellFormat)
+ {
+ super(cellFormat);
+ this.range = range;
+ }
+
+ public static RangeCellFormatRule of(Range range, CellFormat cellFormat)
+ {
+ return new RangeCellFormatRule(range, cellFormat);
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return cell.getCoordinate().within(range);
+ }
+
+}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,39 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import junit.framework.Assert;
-import jxl.write.WritableCell;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Test;
-
-public class CellFactoryTest extends SpreadsheetTest
-{
-
- @Test
- public void cellFormatsCachedForEqualCellFormatsTest()
- {
- CellFactory cellFactory = new CellFactory();
- CellFormatResolver cellFormatResolver = new CellFormatResolver();
- WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
- WritableCell jxlCell2 = cellFactory.createCell(getTestCell(), cellFormatResolver);
- Assert.assertTrue(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
- }
-
- @Test
- public void cellFormatsNotCachedForNonEqualCellFormatsTest()
- {
- CellFactory cellFactory = new CellFactory();
- CellFormatResolver cellFormatResolver = new CellFormatResolver();
- WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
- Cell cell2 = getTestCell();
- cell2.getCellFormat().setFont(getSampleFont());
- cell2.getCellFormat().getFont().setColour(Colour.GREEN);
- WritableCell jxlCell2 = cellFactory.createCell(cell2, cellFormatResolver);
- Assert.assertFalse(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
- }
-
-}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,241 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.formatting.Background;
-import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
-import org.jboss.seam.spreadsheet.model.formatting.Border;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CellFormatFactoryTest extends SpreadsheetTest
-{
- private CellFactory cellFactory;
- private CellFormatResolver cellFormatResolver;
- private Cell cell;
-
- @Before
- public void init()
- {
- cellFactory = new CellFactory();
- cellFormatResolver = new CellFormatResolver();
- cell = getTestCell();
- }
-
- private jxl.write.WritableCell getJxlCell()
- {
- return cellFactory.createCell(cell, cellFormatResolver);
- }
-
- @Test
- public void fontTest()
- {
- cell.getCellFormat().setFont(getSampleFont());
- jxl.format.Font jxlFont = getJxlCell().getCellFormat().getFont();
- Assert.assertEquals("Times New Roman", jxlFont.getName());
- Assert.assertEquals(700, jxlFont.getBoldWeight());
- Assert.assertEquals(jxl.format.Colour.RED, jxlFont.getColour());
- Assert.assertTrue(jxlFont.isItalic());
- Assert.assertEquals(100, jxlFont.getPointSize());
- Assert.assertTrue(jxlFont.isStruckout());
- Assert.assertEquals(jxl.format.ScriptStyle.SUBSCRIPT, jxlFont.getScriptStyle());
- Assert.assertEquals(jxl.format.UnderlineStyle.DOUBLE, jxlFont.getUnderlineStyle());
- }
-
- @Test
- public void alignmentTest()
- {
- cell.getCellFormat().setAlignment(Alignment.RIGHT);
- Assert.assertEquals(jxl.format.Alignment.RIGHT, getJxlCell().getCellFormat().getAlignment());
- }
-
- @Test
- public void backgroundColourTest()
- {
- cell.getCellFormat().setBackground(new Background());
- cell.getCellFormat().getBackground().setColour(Colour.BLUE);
- Assert.assertEquals(jxl.format.Colour.BLUE, getJxlCell().getCellFormat().getBackgroundColour());
- }
-
- @Test
- public void borderColourTest()
- {
- List<Border> borders = new ArrayList<Border>();
- Border border = new Border(BorderType.TOP);
- border.setColour(Colour.PINK);
- borders.add(border);
- cell.getCellFormat().setBorders(borders);
- Assert.assertEquals(jxl.format.Colour.PINK, getJxlCell().getCellFormat().getBorderColour(jxl.format.Border.TOP));
- }
-
- @Test
- public void rightMergedAllBorderTest() {
- List<Border> borders = new ArrayList<Border>();
- Border borderL = new Border(BorderType.LEFT);
- borderL.setColour(Colour.RED);
- borders.add(borderL);
-
- Border borderA = new Border(BorderType.ALL);
- borderA.setLineStyle(BorderLineStyle.DOUBLE);
- borderA.setColour(Colour.PINK);
- borders.add(borderA);
-
- cell.getCellFormat().setBorders(borders);
-
- jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
- }
-
- @Test
- public void leftMergedAllBorderTest() {
- List<Border> borders = new ArrayList<Border>();
-
- Border borderA = new Border(BorderType.ALL);
- borderA.setLineStyle(BorderLineStyle.DOUBLE);
- borderA.setColour(Colour.PINK);
- borders.add(borderA);
-
- Border borderL = new Border(BorderType.LEFT);
- borderL.setColour(Colour.RED);
- borderL.setLineStyle(BorderLineStyle.DOTTED);
- borders.add(borderL);
-
-
- cell.getCellFormat().setBorders(borders);
-
- jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
- Assert.assertEquals(jxl.format.BorderLineStyle.DOTTED, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
- Assert.assertEquals(jxl.format.Colour.RED, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
- }
-
-
- @Test
- public void borderLineStyleTest()
- {
- List<Border> borders = new ArrayList<Border>();
- Border border = new Border(BorderType.TOP);
- border.setLineStyle(BorderLineStyle.DOUBLE);
- borders.add(border);
- cell.getCellFormat().setBorders(borders);
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, getJxlCell().getCellFormat().getBorderLine(jxl.format.Border.TOP));
- }
-
- @Test
- public void indentationTest()
- {
- cell.getCellFormat().setIndentation(10);
- Assert.assertEquals(10, getJxlCell().getCellFormat().getIndentation());
- }
-
- @Test
- public void orientationTest()
- {
- cell.getCellFormat().setOrientation(Orientation.MINUS_45);
- Assert.assertEquals(jxl.format.Orientation.MINUS_45, getJxlCell().getCellFormat().getOrientation());
- }
-
- @Test
- public void patternTest()
- {
- cell.getCellFormat().setBackground(new Background());
- cell.getCellFormat().getBackground().setPattern(Pattern.GRAY_50);
- Assert.assertEquals(jxl.format.Pattern.GRAY_50, getJxlCell().getCellFormat().getPattern());
- }
-
- @Test
- public void verticalAlignmentTest()
- {
- cell.getCellFormat().setVerticalAlignment(VerticalAlignment.TOP);
- Assert.assertEquals(jxl.format.VerticalAlignment.TOP, getJxlCell().getCellFormat().getVerticalAlignment());
- }
-
- @Test
- public void wrapTest()
- {
- cell.getCellFormat().setWrap(true);
- Assert.assertTrue(getJxlCell().getCellFormat().getWrap());
- }
-
- @Test
- public void lockedTest()
- {
- cell.getCellFormat().setLocked(true);
- Assert.assertTrue(getJxlCell().getCellFormat().isLocked());
- }
-
- @Test
- public void shrinkToFitTest()
- {
- cell.getCellFormat().setShrinkToFit(true);
- Assert.assertTrue(getJxlCell().getCellFormat().isShrinkToFit());
- }
-
- @Test
- public void testCustomDateMask() throws IOException
- {
- cell.setValue(new Date());
- cell.getCellFormat().setMask("dd.MM.yyyy");
-// Assert.assertEquals("MM.yyyy", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testNamedDateMask() throws IOException
- {
- cell.setValue(new Date());
- cell.getCellFormat().setMask("FORMAT9");
-// Assert.assertEquals("M/d/yy H:mm", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testCustomNumberMask()
- {
- cell.setValue(1.1111111f);
- cell.getCellFormat().setMask("#.##");
-// Assert.assertEquals("#.##", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testNamedNumberMask()
- {
- cell.setValue(1.1111111f);
- cell.getCellFormat().setMask("CURRENCY_EURO_PREFIX");
-// Assert.assertEquals("CURRENCY_EURO_PREFIX", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testNamedNumberMask2()
- {
- cell.setValue(1.1111111f);
- cell.getCellFormat().setMask("EXPONENTIAL");
-// Assert.assertEquals("EXPONENTIAL", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
-}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,98 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.Font;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Test;
-
-public class CellFormatResolverTest extends SpreadsheetTest
-{
-
- private class SimpleRule implements CellFormatRule
- {
-
- private CellFormat cellFormat;
-
- public SimpleRule(CellFormat cellFormat)
- {
- this.cellFormat = cellFormat;
- }
-
- @Override
- public boolean appliesTo(Cell cell)
- {
- return true;
- }
-
- @Override
- public CellFormat getCellFormat()
- {
- return cellFormat;
- }
-
- }
-
- @Test
- public void resolveTest() {
-
- CellFormat cellFormat = new CellFormat();
- Font cellFont = new Font();
- cellFont.setBold(true);
- cellFormat.setFont(cellFont);
- Cell cell = new Cell();
- cell.setCellFormat(cellFormat);
-
- CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
- cellFormatResolver.setWorksheetRules(getWorksheetRules());
- CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
- Assert.assertEquals(Colour.RED, effectiveCellFormat.getFont().getColour());
- Assert.assertEquals((Integer)40, effectiveCellFormat.getFont().getPointSize());
- Assert.assertEquals(Boolean.TRUE, effectiveCellFormat.getFont().getBold());
- }
-
- @Test
- public void resolveAbsoluteTest() {
-
- CellFormat cellFormat = new CellFormat();
- cellFormat.setType(CellFormat.Type.ABSOLUTE);
- cellFormat.setFont(new Font());
- Cell cell = new Cell();
- cell.setCellFormat(cellFormat);
-
- CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
- cellFormatResolver.setWorksheetRules(getWorksheetRules());
- CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
- Assert.assertEquals(null, effectiveCellFormat.getFont().getColour());
- Assert.assertEquals(null, effectiveCellFormat.getFont().getPointSize());
- Assert.assertEquals(null, effectiveCellFormat.getFont().getBold());
- }
-
- private List<CellFormatRule> getWorkbookRules() {
- List<CellFormatRule> workbookRules = new ArrayList<CellFormatRule>();
- CellFormat workbookCellFormat = new CellFormat();
- Font workbookFont = new Font();
- workbookFont.setColour(Colour.RED);
- workbookCellFormat.setFont(workbookFont);
- workbookRules.add(new SimpleRule(workbookCellFormat));
- return workbookRules;
- }
-
- private List<CellFormatRule> getWorksheetRules() {
- List<CellFormatRule> worksheetRules = new ArrayList<CellFormatRule>();
- CellFormat worksheetCellFormat = new CellFormat();
- Font worksheetFont = new Font();
- worksheetFont.setPointSize(40);
- worksheetCellFormat.setFont(worksheetFont);
- worksheetRules.add(new SimpleRule(worksheetCellFormat));
- return worksheetRules;
- }
-}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,147 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.util.Map;
-
-import jxl.biff.DisplayFormat;
-import jxl.write.DateFormat;
-import jxl.write.DateFormats;
-import jxl.write.NumberFormat;
-import jxl.write.NumberFormats;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
-import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
-import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ConstantFactoryTest extends SpreadsheetTest
-{
- ConstantFactory constantFactory;
-
- @Before
- public void init()
- {
- constantFactory = new ConstantFactory();
- }
-
- @Test
- public void coloursTest()
- {
- for (Colour colour : Colour.values())
- {
- Assert.assertNotNull(constantFactory.getColour(colour));
- }
- }
-
- @Test
- public void underlineStyleTest()
- {
- for (UnderlineStyle underlineStyle : UnderlineStyle.values())
- {
- Assert.assertNotNull(constantFactory.getUnderlineStyle(underlineStyle));
- }
- }
-
- @Test
- public void scriptStyleTest()
- {
- for (ScriptStyle scriptStyle : ScriptStyle.values())
- {
- Assert.assertNotNull(constantFactory.getScriptStyle(scriptStyle));
- }
- }
-
- @Test
- public void borderLineTest()
- {
- for (BorderLineStyle borderLineStyle : BorderLineStyle.values())
- {
- Assert.assertNotNull(constantFactory.getBorderLineStyle(borderLineStyle));
- }
- }
-
- @Test
- public void borderTypeTest()
- {
- for (BorderType borderType : BorderType.values())
- {
- Assert.assertNotNull(constantFactory.getBorder(borderType));
- }
- }
-
- @Test
- public void patternTest()
- {
- for (Pattern pattern : Pattern.values())
- {
- Assert.assertNotNull(constantFactory.getPattern(pattern));
- }
- }
-
- @Test
- public void verticalAlignmentTest()
- {
- for (VerticalAlignment verticalAlignment : VerticalAlignment.values())
- {
- Assert.assertNotNull(constantFactory.getVerticalAlignment(verticalAlignment));
- }
- }
-
- @Test
- public void orientationTest()
- {
- for (Orientation orientation : Orientation.values())
- {
- Assert.assertNotNull(constantFactory.getOrientation(orientation));
- }
- }
-
- @Test
- public void alignmentTest()
- {
- for (Alignment alignment : Alignment.values())
- {
- Assert.assertNotNull(constantFactory.getAlignment(alignment));
- }
- }
-
- @Test
- public void numberFormatTest()
- {
- Map<String, DisplayFormat> numberFormats = constantFactory.loadConstants(DisplayFormat.class, NumberFormats.class);
- for (String key : numberFormats.keySet())
- {
- Assert.assertNotNull(constantFactory.getNumberFormat(key));
- }
- }
-
- @Test
- public void numberFormatShorthandTest()
- {
- Map<String, String> numberFormatShorthands = constantFactory.loadConstants(String.class, NumberFormat.class);
- for (String key : numberFormatShorthands.keySet())
- {
-// Assert.assertNotNull(constantFactory.getNumberFormatShorthand(key));
- }
- }
-
- @Test
- public void dateFormatTest()
- {
- Map<String, DisplayFormat> dateFormats = constantFactory.loadConstants(DisplayFormat.class, DateFormats.class);
- for (String key : dateFormats.keySet())
- {
- Assert.assertNotNull(constantFactory.getDateFormat(key));
- }
- }
-
-}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -3,6 +3,9 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
+import org.jboss.seam.spreadsheet.jxl.writer.event.BeforeAdded;
+import org.jboss.seam.spreadsheet.jxl.writer.event.BeforeCreated;
+import org.jboss.seam.spreadsheet.jxl.writer.event.BeforeExecuted;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Worksheet;
import org.jboss.seam.spreadsheet.model.command.Command;
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -10,6 +10,8 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Workbook;
@@ -30,7 +32,7 @@
@Deployment
public static JavaArchive getArchive()
{
- return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, EventObserver.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class, EventObserver.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
}
@Inject EventObserver eventObserver;
Added: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,43 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.CellSpan;
+import org.jboss.seam.spreadsheet.model.Coordinate;
+import org.jboss.seam.spreadsheet.model.Workbook;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+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 CellMergeCommandTest extends SpreadsheetTest
+{
+
+ @Deployment
+ public static JavaArchive getArchive()
+ {
+ return ShrinkWrap.create("foo.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Test
+ public void mergeTest()
+ {
+ Cell cell = Cell.of("foo", Coordinate.ORIGO);
+ cell.setCellSpan(CellSpan.of(10, 10));
+ Worksheet ws = Worksheet.named("foo");
+ ws.getCells().add(cell);
+ Workbook wb = new Workbook();
+ wb.getWorksheets().add(ws);
+ // Assert
+ }
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java (from rev 13461, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,39 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import junit.framework.Assert;
+import jxl.write.WritableCell;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Test;
+
+public class CellFactoryTest extends SpreadsheetTest
+{
+
+ @Test
+ public void cellFormatsCachedForEqualCellFormatsTest()
+ {
+ CellFactory cellFactory = new CellFactory();
+ CellFormatResolver cellFormatResolver = new CellFormatResolver();
+ WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
+ WritableCell jxlCell2 = cellFactory.createCell(getTestCell(), cellFormatResolver);
+ Assert.assertTrue(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
+ }
+
+ @Test
+ public void cellFormatsNotCachedForNonEqualCellFormatsTest()
+ {
+ CellFactory cellFactory = new CellFactory();
+ CellFormatResolver cellFormatResolver = new CellFormatResolver();
+ WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
+ Cell cell2 = getTestCell();
+ cell2.getCellFormat().setFont(getSampleFont());
+ cell2.getCellFormat().getFont().setColour(Colour.GREEN);
+ WritableCell jxlCell2 = cellFactory.createCell(cell2, cellFormatResolver);
+ Assert.assertFalse(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java (from rev 13459, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,241 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.Background;
+import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
+import org.jboss.seam.spreadsheet.model.formatting.Border;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CellFormatFactoryTest extends SpreadsheetTest
+{
+ private CellFactory cellFactory;
+ private CellFormatResolver cellFormatResolver;
+ private Cell cell;
+
+ @Before
+ public void init()
+ {
+ cellFactory = new CellFactory();
+ cellFormatResolver = new CellFormatResolver();
+ cell = getTestCell();
+ }
+
+ private jxl.write.WritableCell getJxlCell()
+ {
+ return cellFactory.createCell(cell, cellFormatResolver);
+ }
+
+ @Test
+ public void fontTest()
+ {
+ cell.getCellFormat().setFont(getSampleFont());
+ jxl.format.Font jxlFont = getJxlCell().getCellFormat().getFont();
+ Assert.assertEquals("Times New Roman", jxlFont.getName());
+ Assert.assertEquals(700, jxlFont.getBoldWeight());
+ Assert.assertEquals(jxl.format.Colour.RED, jxlFont.getColour());
+ Assert.assertTrue(jxlFont.isItalic());
+ Assert.assertEquals(100, jxlFont.getPointSize());
+ Assert.assertTrue(jxlFont.isStruckout());
+ Assert.assertEquals(jxl.format.ScriptStyle.SUBSCRIPT, jxlFont.getScriptStyle());
+ Assert.assertEquals(jxl.format.UnderlineStyle.DOUBLE, jxlFont.getUnderlineStyle());
+ }
+
+ @Test
+ public void alignmentTest()
+ {
+ cell.getCellFormat().setAlignment(Alignment.RIGHT);
+ Assert.assertEquals(jxl.format.Alignment.RIGHT, getJxlCell().getCellFormat().getAlignment());
+ }
+
+ @Test
+ public void backgroundColourTest()
+ {
+ cell.getCellFormat().setBackground(new Background());
+ cell.getCellFormat().getBackground().setColour(Colour.BLUE);
+ Assert.assertEquals(jxl.format.Colour.BLUE, getJxlCell().getCellFormat().getBackgroundColour());
+ }
+
+ @Test
+ public void borderColourTest()
+ {
+ List<Border> borders = new ArrayList<Border>();
+ Border border = new Border(BorderType.TOP);
+ border.setColour(Colour.PINK);
+ borders.add(border);
+ cell.getCellFormat().setBorders(borders);
+ Assert.assertEquals(jxl.format.Colour.PINK, getJxlCell().getCellFormat().getBorderColour(jxl.format.Border.TOP));
+ }
+
+ @Test
+ public void rightMergedAllBorderTest() {
+ List<Border> borders = new ArrayList<Border>();
+ Border borderL = new Border(BorderType.LEFT);
+ borderL.setColour(Colour.RED);
+ borders.add(borderL);
+
+ Border borderA = new Border(BorderType.ALL);
+ borderA.setLineStyle(BorderLineStyle.DOUBLE);
+ borderA.setColour(Colour.PINK);
+ borders.add(borderA);
+
+ cell.getCellFormat().setBorders(borders);
+
+ jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
+ }
+
+ @Test
+ public void leftMergedAllBorderTest() {
+ List<Border> borders = new ArrayList<Border>();
+
+ Border borderA = new Border(BorderType.ALL);
+ borderA.setLineStyle(BorderLineStyle.DOUBLE);
+ borderA.setColour(Colour.PINK);
+ borders.add(borderA);
+
+ Border borderL = new Border(BorderType.LEFT);
+ borderL.setColour(Colour.RED);
+ borderL.setLineStyle(BorderLineStyle.DOTTED);
+ borders.add(borderL);
+
+
+ cell.getCellFormat().setBorders(borders);
+
+ jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOTTED, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
+ Assert.assertEquals(jxl.format.Colour.RED, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
+ }
+
+
+ @Test
+ public void borderLineStyleTest()
+ {
+ List<Border> borders = new ArrayList<Border>();
+ Border border = new Border(BorderType.TOP);
+ border.setLineStyle(BorderLineStyle.DOUBLE);
+ borders.add(border);
+ cell.getCellFormat().setBorders(borders);
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, getJxlCell().getCellFormat().getBorderLine(jxl.format.Border.TOP));
+ }
+
+ @Test
+ public void indentationTest()
+ {
+ cell.getCellFormat().setIndentation(10);
+ Assert.assertEquals(10, getJxlCell().getCellFormat().getIndentation());
+ }
+
+ @Test
+ public void orientationTest()
+ {
+ cell.getCellFormat().setOrientation(Orientation.MINUS_45);
+ Assert.assertEquals(jxl.format.Orientation.MINUS_45, getJxlCell().getCellFormat().getOrientation());
+ }
+
+ @Test
+ public void patternTest()
+ {
+ cell.getCellFormat().setBackground(new Background());
+ cell.getCellFormat().getBackground().setPattern(Pattern.GRAY_50);
+ Assert.assertEquals(jxl.format.Pattern.GRAY_50, getJxlCell().getCellFormat().getPattern());
+ }
+
+ @Test
+ public void verticalAlignmentTest()
+ {
+ cell.getCellFormat().setVerticalAlignment(VerticalAlignment.TOP);
+ Assert.assertEquals(jxl.format.VerticalAlignment.TOP, getJxlCell().getCellFormat().getVerticalAlignment());
+ }
+
+ @Test
+ public void wrapTest()
+ {
+ cell.getCellFormat().setWrap(true);
+ Assert.assertTrue(getJxlCell().getCellFormat().getWrap());
+ }
+
+ @Test
+ public void lockedTest()
+ {
+ cell.getCellFormat().setLocked(true);
+ Assert.assertTrue(getJxlCell().getCellFormat().isLocked());
+ }
+
+ @Test
+ public void shrinkToFitTest()
+ {
+ cell.getCellFormat().setShrinkToFit(true);
+ Assert.assertTrue(getJxlCell().getCellFormat().isShrinkToFit());
+ }
+
+ @Test
+ public void testCustomDateMask() throws IOException
+ {
+ cell.setValue(new Date());
+ cell.getCellFormat().setMask("dd.MM.yyyy");
+// Assert.assertEquals("MM.yyyy", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testNamedDateMask() throws IOException
+ {
+ cell.setValue(new Date());
+ cell.getCellFormat().setMask("FORMAT9");
+// Assert.assertEquals("M/d/yy H:mm", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testCustomNumberMask()
+ {
+ cell.setValue(1.1111111f);
+ cell.getCellFormat().setMask("#.##");
+// Assert.assertEquals("#.##", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testNamedNumberMask()
+ {
+ cell.setValue(1.1111111f);
+ cell.getCellFormat().setMask("CURRENCY_EURO_PREFIX");
+// Assert.assertEquals("CURRENCY_EURO_PREFIX", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testNamedNumberMask2()
+ {
+ cell.setValue(1.1111111f);
+ cell.getCellFormat().setMask("EXPONENTIAL");
+// Assert.assertEquals("EXPONENTIAL", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java (from rev 13456, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,98 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.Font;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.junit.Test;
+
+public class CellFormatResolverTest extends SpreadsheetTest
+{
+
+ private class SimpleRule implements CellFormatRule
+ {
+
+ private CellFormat cellFormat;
+
+ public SimpleRule(CellFormat cellFormat)
+ {
+ this.cellFormat = cellFormat;
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return true;
+ }
+
+ @Override
+ public CellFormat getCellFormat()
+ {
+ return cellFormat;
+ }
+
+ }
+
+ @Test
+ public void resolveTest() {
+
+ CellFormat cellFormat = new CellFormat();
+ Font cellFont = new Font();
+ cellFont.setBold(true);
+ cellFormat.setFont(cellFont);
+ Cell cell = new Cell();
+ cell.setCellFormat(cellFormat);
+
+ CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
+ cellFormatResolver.setWorksheetRules(getWorksheetRules());
+ CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
+ Assert.assertEquals(Colour.RED, effectiveCellFormat.getFont().getColour());
+ Assert.assertEquals((Integer)40, effectiveCellFormat.getFont().getPointSize());
+ Assert.assertEquals(Boolean.TRUE, effectiveCellFormat.getFont().getBold());
+ }
+
+ @Test
+ public void resolveAbsoluteTest() {
+
+ CellFormat cellFormat = new CellFormat();
+ cellFormat.setType(CellFormat.Type.ABSOLUTE);
+ cellFormat.setFont(new Font());
+ Cell cell = new Cell();
+ cell.setCellFormat(cellFormat);
+
+ CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
+ cellFormatResolver.setWorksheetRules(getWorksheetRules());
+ CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
+ Assert.assertEquals(null, effectiveCellFormat.getFont().getColour());
+ Assert.assertEquals(null, effectiveCellFormat.getFont().getPointSize());
+ Assert.assertEquals(null, effectiveCellFormat.getFont().getBold());
+ }
+
+ private List<CellFormatRule> getWorkbookRules() {
+ List<CellFormatRule> workbookRules = new ArrayList<CellFormatRule>();
+ CellFormat workbookCellFormat = new CellFormat();
+ Font workbookFont = new Font();
+ workbookFont.setColour(Colour.RED);
+ workbookCellFormat.setFont(workbookFont);
+ workbookRules.add(new SimpleRule(workbookCellFormat));
+ return workbookRules;
+ }
+
+ private List<CellFormatRule> getWorksheetRules() {
+ List<CellFormatRule> worksheetRules = new ArrayList<CellFormatRule>();
+ CellFormat worksheetCellFormat = new CellFormat();
+ Font worksheetFont = new Font();
+ worksheetFont.setPointSize(40);
+ worksheetCellFormat.setFont(worksheetFont);
+ worksheetRules.add(new SimpleRule(worksheetCellFormat));
+ return worksheetRules;
+ }
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java (from rev 13463, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,147 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import java.util.Map;
+
+import jxl.biff.DisplayFormat;
+import jxl.write.DateFormat;
+import jxl.write.DateFormats;
+import jxl.write.NumberFormat;
+import jxl.write.NumberFormats;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
+import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConstantFactoryTest extends SpreadsheetTest
+{
+ ConstantFactory constantFactory;
+
+ @Before
+ public void init()
+ {
+ constantFactory = new ConstantFactory();
+ }
+
+ @Test
+ public void coloursTest()
+ {
+ for (Colour colour : Colour.values())
+ {
+ Assert.assertNotNull(constantFactory.getColour(colour));
+ }
+ }
+
+ @Test
+ public void underlineStyleTest()
+ {
+ for (UnderlineStyle underlineStyle : UnderlineStyle.values())
+ {
+ Assert.assertNotNull(constantFactory.getUnderlineStyle(underlineStyle));
+ }
+ }
+
+ @Test
+ public void scriptStyleTest()
+ {
+ for (ScriptStyle scriptStyle : ScriptStyle.values())
+ {
+ Assert.assertNotNull(constantFactory.getScriptStyle(scriptStyle));
+ }
+ }
+
+ @Test
+ public void borderLineTest()
+ {
+ for (BorderLineStyle borderLineStyle : BorderLineStyle.values())
+ {
+ Assert.assertNotNull(constantFactory.getBorderLineStyle(borderLineStyle));
+ }
+ }
+
+ @Test
+ public void borderTypeTest()
+ {
+ for (BorderType borderType : BorderType.values())
+ {
+ Assert.assertNotNull(constantFactory.getBorder(borderType));
+ }
+ }
+
+ @Test
+ public void patternTest()
+ {
+ for (Pattern pattern : Pattern.values())
+ {
+ Assert.assertNotNull(constantFactory.getPattern(pattern));
+ }
+ }
+
+ @Test
+ public void verticalAlignmentTest()
+ {
+ for (VerticalAlignment verticalAlignment : VerticalAlignment.values())
+ {
+ Assert.assertNotNull(constantFactory.getVerticalAlignment(verticalAlignment));
+ }
+ }
+
+ @Test
+ public void orientationTest()
+ {
+ for (Orientation orientation : Orientation.values())
+ {
+ Assert.assertNotNull(constantFactory.getOrientation(orientation));
+ }
+ }
+
+ @Test
+ public void alignmentTest()
+ {
+ for (Alignment alignment : Alignment.values())
+ {
+ Assert.assertNotNull(constantFactory.getAlignment(alignment));
+ }
+ }
+
+ @Test
+ public void numberFormatTest()
+ {
+ Map<String, DisplayFormat> numberFormats = constantFactory.loadConstants(DisplayFormat.class, NumberFormats.class);
+ for (String key : numberFormats.keySet())
+ {
+ Assert.assertNotNull(constantFactory.getNumberFormat(key));
+ }
+ }
+
+ @Test
+ public void numberFormatShorthandTest()
+ {
+ Map<String, String> numberFormatShorthands = constantFactory.loadConstants(String.class, NumberFormat.class);
+ for (String key : numberFormatShorthands.keySet())
+ {
+// Assert.assertNotNull(constantFactory.getNumberFormatShorthand(key));
+ }
+ }
+
+ @Test
+ public void dateFormatTest()
+ {
+ Map<String, DisplayFormat> dateFormats = constantFactory.loadConstants(DisplayFormat.class, DateFormats.class);
+ for (String key : dateFormats.keySet())
+ {
+ Assert.assertNotNull(constantFactory.getDateFormat(key));
+ }
+ }
+
+}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -5,7 +5,8 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.spreadsheet.SpreadsheetException;
-import org.jboss.seam.spreadsheet.jxl.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -20,7 +21,7 @@
@Deployment
public static JavaArchive getArchive()
{
- return ShrinkWrap.create("test.jar", JavaArchive.class).addClass(JXLSpreadsheetWriter.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
}
@Test
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -8,7 +8,7 @@
import junit.framework.Assert;
import org.jboss.seam.spreadsheet.SpreadsheetWriter;
-import org.jboss.seam.spreadsheet.jxl.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Range;
@@ -16,10 +16,10 @@
import org.jboss.seam.spreadsheet.model.Worksheet;
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
import org.jboss.seam.spreadsheet.model.formatting.Colour;
import org.jboss.seam.spreadsheet.model.formatting.Font;
-import org.jboss.seam.spreadsheet.model.formatting.RangeCellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.RangeCellFormatRule;
import org.jboss.seam.spreadsheet.util.Person;
import org.junit.Test;
@@ -123,7 +123,7 @@
public void addWorkbookCellFormatRuleTest()
{
WorkbookBuilder wbb = new WorkbookBuilder();
- wbb.addWorkbookCellFormatRule(RangeCellFormatRule.of(new CellFormat(), Range.of(1, 1, 10, 10)));
+ wbb.addWorkbookCellFormatRule(RangeCellFormatRule.of(Range.of(1, 1, 10, 10), new CellFormat()));
Workbook wb = wbb.getWorkbook();
Assert.assertFalse(wb.getCellFormatRules().isEmpty());
}
@@ -132,7 +132,7 @@
public void addWorksheetCellFormatRuleTest()
{
WorkbookBuilder wbb = new WorkbookBuilder();
- wbb.addWorksheetCellFormatRule(RangeCellFormatRule.of(new CellFormat(), Range.of(1, 1, 10, 10)));
+ wbb.addWorksheetCellFormatRule(RangeCellFormatRule.of(Range.of(1, 1, 10, 10), new CellFormat()));
Workbook wb = wbb.getWorkbook();
Assert.assertFalse(wb.getWorksheets().iterator().next().getCellFormatRules().isEmpty());
}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,6 +1,8 @@
package org.jboss.seam.spreadsheet.model.formatting;
import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -9,7 +11,9 @@
import jxl.read.biff.BiffException;
+import org.jboss.seam.spreadsheet.SpreadsheetException;
import org.jboss.seam.spreadsheet.SpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Range;
@@ -22,16 +26,28 @@
import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.RangeCellFormatRule;
public abstract class SpreadsheetTest
{
- @Inject SpreadsheetWriter sw;
+ @Inject
+ SpreadsheetWriter sw;
+ private SpreadsheetWriter getSpreadsheetWriter()
+ {
+ if (sw == null)
+ {
+ sw = new JXLSpreadsheetWriter();
+ }
+ return sw;
+ }
+
protected jxl.Workbook getWorkbook(Workbook workbook)
{
try
{
- byte[] data = sw.writeWorkbook(workbook);
+ byte[] data = getSpreadsheetWriter().writeWorkbook(workbook);
return jxl.Workbook.getWorkbook(new ByteArrayInputStream(data));
}
catch (BiffException e)
@@ -112,6 +128,21 @@
protected CellFormatRule getSampleCellFormatRule()
{
- return new RangeCellFormatRule(new CellFormat(), Range.of(10, 10, 20, 20));
+ return RangeCellFormatRule.of(Range.of(10, 10, 20, 20), new CellFormat());
}
+
+ protected void workbookToFile(Workbook workbook, String fileName)
+ {
+ try
+ {
+ FileOutputStream out = new FileOutputStream(fileName);
+ out.write(sw.writeWorkbook(workbook));
+ out.flush();
+ out.close();
+ }
+ catch (Exception e)
+ {
+ throw new SpreadsheetException(String.format("Could not write to file %s", fileName), e);
+ }
+ }
}
14 years, 5 months
Seam SVN: r13468 - in modules/persistence/trunk: impl/src/main/java/org/jboss/seam/persistence/transaction and 1 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-07-22 02:28:55 -0400 (Thu, 22 Jul 2010)
New Revision: 13468
Removed:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/event/
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
Log:
removed transaction events, they were not documented in seam 2 and cannot really be made to work reliably
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java 2010-07-22 05:35:50 UTC (rev 13467)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java 2010-07-22 06:28:55 UTC (rev 13468)
@@ -28,8 +28,6 @@
import javax.transaction.Status;
import javax.transaction.Synchronization;
-import org.jboss.seam.persistence.transaction.event.AfterTransactionCompletion;
-import org.jboss.seam.persistence.transaction.event.BeforeTransactionCompletion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,7 +60,6 @@
void afterTransactionCompletion(boolean success)
{
- beanManager.fireEvent(new AfterTransactionCompletion(success));
for (Synchronization sync : synchronizations)
{
try
@@ -79,7 +76,6 @@
void beforeTransactionCompletion()
{
- beanManager.fireEvent(new BeforeTransactionCompletion());
for (Synchronization sync : synchronizations)
{
try
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-22 05:35:50 UTC (rev 13467)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-22 06:28:55 UTC (rev 13468)
@@ -1,3 +1,24 @@
+/*
+ * 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.transactions.test;
import java.util.List;
@@ -30,6 +51,12 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+/**
+ * Tests the @Transactional interceptor
+ *
+ * @author stuart
+ *
+ */
@RunWith(Arquillian.class)
public class TransactionInterceptorTest
{
@@ -41,7 +68,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(Transaction.class.getPackage());
- war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class, TransactionObserver.class);
+ war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(("<beans><interceptors><class>" + TransactionInterceptor.class.getName() + "</class></interceptors></beans>").getBytes()), "beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
@@ -57,50 +84,28 @@
@PersistenceContext
EntityManager em;
- @Inject
- TransactionObserver observer;
-
@Test
public void testTransactionInterceptor() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
{
- observer.setEnabled(true);
+
+ bean.addHotel();
+ assertHotels(1);
try
{
- observer.reset(true);
- bean.addHotel();
- assertHotels(1);
- observer.verify();
- observer.reset(false);
- try
- {
- bean.failToAddHotel();
- }
- catch (Exception e)
- {
- }
- assertHotels(1);
- observer.verify();
- observer.reset(true);
- try
- {
- bean.addHotelWithApplicationException();
- }
- catch (DontRollBackException e)
- {
- }
- observer.setEnabled(false);
- assertHotels(2);
- observer.verify();
+ bean.failToAddHotel();
}
catch (Exception e)
{
- throw new RuntimeException(e);
}
- finally
+ assertHotels(1);
+ try
{
- observer.setEnabled(false);
+ bean.addHotelWithApplicationException();
}
-
+ catch (DontRollBackException e)
+ {
+ }
+ assertHotels(2);
}
public void assertHotels(int count) throws NotSupportedException, SystemException
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java 2010-07-22 05:35:50 UTC (rev 13467)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java 2010-07-22 06:28:55 UTC (rev 13468)
@@ -1,66 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-
-import org.jboss.seam.persistence.transaction.event.AfterTransactionCompletion;
-import org.jboss.seam.persistence.transaction.event.BeforeTransactionCompletion;
-
-@ApplicationScoped
-public class TransactionObserver
-{
- private boolean expectSuccess, beforeTransaction, afterTransaction;
- private boolean enabled = false;
-
- public boolean isEnabled()
- {
- return enabled;
- }
-
- public void setEnabled(boolean enabled)
- {
- this.enabled = enabled;
- }
-
- public void reset(boolean expected)
- {
- beforeTransaction = false;
- afterTransaction = false;
- expectSuccess = expected;
- }
-
- public boolean isBeforeTransaction()
- {
- return beforeTransaction;
- }
-
- public boolean isAfterTransaction()
- {
- return afterTransaction;
- }
-
- public void observeBeforeTransactionCommit(@Observes BeforeTransactionCompletion event)
- {
- beforeTransaction = true;
- }
-
- public void observeBeforeTransactionCommit(@Observes AfterTransactionCompletion event)
- {
- afterTransaction = true;
- if (enabled)
- {
- if (expectSuccess != event.success())
- {
- throw new RuntimeException("Expected success to be " + expectSuccess);
- }
- }
- }
-
- public void verify()
- {
- if (!((beforeTransaction || !expectSuccess) && afterTransaction))
- {
- throw new RuntimeException("Events not recieved before:" + beforeTransaction + " after:" + afterTransaction);
- }
- }
-}
14 years, 5 months