Seam SVN: r12381 - modules/faces/trunk/src/test/java/org/jboss/seam/faces/event.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-05 07:15:13 -0400 (Mon, 05 Apr 2010)
New Revision: 12381
Modified:
modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java
Log:
test tunings
Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java 2010-04-05 08:58:08 UTC (rev 12380)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java 2010-04-05 11:15:13 UTC (rev 12381)
@@ -1,7 +1,21 @@
package org.jboss.seam.faces.event;
-import static org.junit.Assert.assertEquals;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_APPLY_VALUES;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_INVOKE_APPLICATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_PROCESS_VALIDATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_RENDER_RESPONSE;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_RESTORE_VIEW;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_UPDATE_MODEL_VALUES;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_APPLY_VALUES;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_INVOKE_APPLICATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_PROCESS_VALIDATION;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_RENDER_RESPONSE;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_RESTORE_VIEW;
+import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_UPDATE_MODEL_VALUES;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.inject.Inject;
@@ -22,6 +36,20 @@
@RunWith(Arquillian.class)
public class PhaseEventBridgeTest
{
+ private static List<PhaseId> ALL_PHASES = new ArrayList<PhaseId>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ {
+ add(PhaseId.APPLY_REQUEST_VALUES);
+ add(PhaseId.INVOKE_APPLICATION);
+ add(PhaseId.PROCESS_VALIDATIONS);
+ add(PhaseId.RENDER_RESPONSE);
+ add(PhaseId.RESTORE_VIEW);
+ add(PhaseId.UPDATE_MODEL_VALUES);
+ }
+ };
+
@Deployment
public static JavaArchive createTestArchive()
{
@@ -30,6 +58,8 @@
@Inject
PhaseEventBridge phaseEventBridge;
+ @Inject
+ PhaseEventObserver observer;
private final MockFacesContext facesContext = new MockFacesContext();
private final MockLifecycle lifecycle = new MockLifecycle();
@@ -37,103 +67,149 @@
@Test
public void testBeforeAnyPhaseObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assertEquals(3, PhaseEventObserver.beforeAnyPhaseCount);
+ observer.reset();
+ fireAllBeforePhases();
+ observer.assertAllBeforePhasesObserved();
}
+ private void fireAllBeforePhases()
+ {
+ fireBeforePhases(ALL_PHASES);
+ }
+
+ private void fireBeforePhases(List<PhaseId> phases)
+ {
+ for (PhaseId phaseId : phases)
+ {
+ fireBeforePhase(phaseId);
+ }
+ }
+
+ private void fireBeforePhase(PhaseId phaseId)
+ {
+ phaseEventBridge.beforePhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+ }
+
@Test
public void testAfterAnyPhaseObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assertEquals(3, PhaseEventObserver.afterAnyPhaseCount);
+ observer.reset();
+ fireAllAfterPhases();
+ observer.assertAllAfterPhasesObserved();
}
+ private void fireAllAfterPhases()
+ {
+ fireAfterPhases(ALL_PHASES);
+ }
+
+ private void fireAfterPhases(List<PhaseId> phases)
+ {
+ for (PhaseId phaseId : phases)
+ {
+ fireAfterPhase(phaseId);
+ }
+ }
+
+ private void fireAfterPhase(PhaseId phaseId)
+ {
+ phaseEventBridge.afterPhase(new PhaseEvent(facesContext, phaseId, lifecycle));
+ }
+
@Test
public void testBeforeRenderResponseObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- assert PhaseEventObserver.observeBeforeRenderResponse;
+ observer.reset();
+ fireBeforePhase(PhaseId.RENDER_RESPONSE);
+ observer.assertSingleObservation(BEFORE_RENDER_RESPONSE);
}
@Test
public void testAfterRenderResponseObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.RENDER_RESPONSE, lifecycle));
- assert PhaseEventObserver.observeAfterRenderResponse;
+ observer.reset();
+ fireAfterPhase(PhaseId.RENDER_RESPONSE);
+ observer.assertSingleObservation(AFTER_RENDER_RESPONSE);
}
@Test
public void testBeforeApplyRequestValuesObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- assert PhaseEventObserver.observeBeforeApplyRequestValues;
+ observer.reset();
+ fireBeforePhase(PhaseId.APPLY_REQUEST_VALUES);
+ observer.assertSingleObservation(BEFORE_APPLY_VALUES);
}
@Test
public void testAfterApplyRequestValuesObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.APPLY_REQUEST_VALUES, lifecycle));
- assert PhaseEventObserver.observeAfterApplyRequestValues;
+ observer.reset();
+ fireAfterPhase(PhaseId.APPLY_REQUEST_VALUES);
+ observer.assertSingleObservation(AFTER_APPLY_VALUES);
}
@Test
public void testBeforeInvokeApplicationObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, lifecycle));
- assert PhaseEventObserver.observeBeforeInvokeApplication;
+ observer.reset();
+ fireBeforePhase(PhaseId.INVOKE_APPLICATION);
+ observer.assertSingleObservation(BEFORE_INVOKE_APPLICATION);
}
@Test
public void testAfterInvokeApplicationObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.INVOKE_APPLICATION, lifecycle));
- assert PhaseEventObserver.observeAfterInvokeApplication;
+ observer.reset();
+ fireAfterPhase(PhaseId.INVOKE_APPLICATION);
+ observer.assertSingleObservation(AFTER_INVOKE_APPLICATION);
}
@Test
public void testBeforeProcessValidationsObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assert PhaseEventObserver.observeBeforeProcessValidations;
+ observer.reset();
+ fireBeforePhase(PhaseId.PROCESS_VALIDATIONS);
+ observer.assertSingleObservation(BEFORE_PROCESS_VALIDATION);
}
@Test
public void testAfterProcessValidationsObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.PROCESS_VALIDATIONS, lifecycle));
- assert PhaseEventObserver.observeAfterProcessValidations;
+ observer.reset();
+ fireAfterPhase(PhaseId.PROCESS_VALIDATIONS);
+ observer.assertSingleObservation(AFTER_PROCESS_VALIDATION);
}
@Test
public void testBeforeRestoreViewObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, lifecycle));
- assert PhaseEventObserver.observeBeforeRestoreView;
+ observer.reset();
+ fireBeforePhase(PhaseId.RESTORE_VIEW);
+ observer.assertSingleObservation(BEFORE_RESTORE_VIEW);
}
@Test
public void testAfterRestoreViewObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.RESTORE_VIEW, lifecycle));
- assert PhaseEventObserver.observeAfterRestoreView;
+ observer.reset();
+ fireAfterPhase(PhaseId.RESTORE_VIEW);
+ observer.assertSingleObservation(AFTER_RESTORE_VIEW);
}
@Test
public void testBeforeUpdateModelValuesObserver()
{
- phaseEventBridge.beforePhase(new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, lifecycle));
- assert PhaseEventObserver.observeBeforeUpdateModelValues;
+ observer.reset();
+ fireBeforePhase(PhaseId.UPDATE_MODEL_VALUES);
+ observer.assertSingleObservation(BEFORE_UPDATE_MODEL_VALUES);
}
@Test
public void testAfterUpdateModelValuesObserver()
{
- phaseEventBridge.afterPhase(new PhaseEvent(facesContext, PhaseId.UPDATE_MODEL_VALUES, lifecycle));
- assert PhaseEventObserver.observeAfterUpdateModelValues;
+ observer.reset();
+ fireAfterPhase(PhaseId.UPDATE_MODEL_VALUES);
+ observer.assertSingleObservation(AFTER_UPDATE_MODEL_VALUES);
}
}
Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java 2010-04-05 08:58:08 UTC (rev 12380)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java 2010-04-05 11:15:13 UTC (rev 12381)
@@ -1,5 +1,8 @@
package org.jboss.seam.faces.event;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.faces.event.PhaseEvent;
@@ -17,89 +20,169 @@
@ApplicationScoped
public class PhaseEventObserver
{
- public static boolean observeBeforeRenderResponse;
- public static boolean observeAfterRenderResponse;
- public static boolean observeBeforeApplyRequestValues;
- public static boolean observeAfterApplyRequestValues;
- public static boolean observeBeforeInvokeApplication;
- public static boolean observeAfterInvokeApplication;
- public static boolean observeBeforeProcessValidations;
- public static boolean observeAfterProcessValidations;
- public static boolean observeBeforeRestoreView;
- public static boolean observeAfterRestoreView;
- public static boolean observeBeforeUpdateModelValues;
- public static boolean observeAfterUpdateModelValues;
- public static int beforeAnyPhaseCount;
- public static int afterAnyPhaseCount;
+ public static enum Observation
+ {
+ BEFORE_RENDER_RESPONSE, AFTER_RENDER_RESPONSE, BEFORE_APPLY_VALUES, AFTER_APPLY_VALUES, BEFORE_INVOKE_APPLICATION, AFTER_INVOKE_APPLICATION, BEFORE_PROCESS_VALIDATION, BEFORE_RESTORE_VIEW, AFTER_RESTORE_VIEW, AFTER_UPDATE_MODEL_VALUES, AFTER_PROCESS_VALIDATION, BEFORE_UPDATE_MODEL_VALUES
+ }
+ private static final List<Observation> ALL_BEFORE_OBSERVATIONS = new ArrayList<Observation>()
+ {
+ private static final long serialVersionUID = 1L;
+ {
+ add(Observation.BEFORE_APPLY_VALUES);
+ add(Observation.BEFORE_INVOKE_APPLICATION);
+ add(Observation.BEFORE_PROCESS_VALIDATION);
+ add(Observation.BEFORE_RENDER_RESPONSE);
+ add(Observation.BEFORE_RESTORE_VIEW);
+ add(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ }
+ };
+
+ private static final List<Observation> ALL_AFTER_OBSERVATIONS = new ArrayList<Observation>()
+ {
+ private static final long serialVersionUID = 1L;
+ {
+ add(Observation.AFTER_APPLY_VALUES);
+ add(Observation.AFTER_INVOKE_APPLICATION);
+ add(Observation.AFTER_PROCESS_VALIDATION);
+ add(Observation.AFTER_RENDER_RESPONSE);
+ add(Observation.AFTER_RESTORE_VIEW);
+ add(Observation.AFTER_UPDATE_MODEL_VALUES);
+ }
+ };
+
+ private List<Observation> observations = new ArrayList<Observation>();
+ private List<Observation> beforeAnyObservations = new ArrayList<Observation>();
+ private List<Observation> afterAnyObservations = new ArrayList<Observation>();
+
+ public void reset()
+ {
+ observations.clear();
+ beforeAnyObservations.clear();
+ afterAnyObservations.clear();
+ }
+
+ public void assertSingleObservation(Observation observation)
+ {
+ assert observations.size() == 1;
+ assert observation.equals(observations.iterator().next());
+ }
+
+ private void recordObservation(Observation observation)
+ {
+ observations.add(observation);
+ }
+
public void observeBeforeAnyPhase(@Observes @Before @AnyPhase final PhaseEvent e)
{
- beforeAnyPhaseCount++;
+ recordBeforeAnyObservations();
}
+ private void recordBeforeAnyObservations()
+ {
+ recordBeforeAnyObservation(Observation.BEFORE_APPLY_VALUES);
+ recordBeforeAnyObservation(Observation.BEFORE_INVOKE_APPLICATION);
+ recordBeforeAnyObservation(Observation.BEFORE_PROCESS_VALIDATION);
+ recordBeforeAnyObservation(Observation.BEFORE_RENDER_RESPONSE);
+ recordBeforeAnyObservation(Observation.BEFORE_RESTORE_VIEW);
+ recordBeforeAnyObservation(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ }
+
+ private void recordBeforeAnyObservation(Observation observation)
+ {
+ beforeAnyObservations.add(observation);
+ }
+
public void observeAfterAnyPhase(@Observes @After @AnyPhase final PhaseEvent e)
{
- afterAnyPhaseCount++;
+ recordAfterAnyObservations();
}
+ private void recordAfterAnyObservations()
+ {
+ recordAfterAnyObservation(Observation.AFTER_APPLY_VALUES);
+ recordAfterAnyObservation(Observation.AFTER_INVOKE_APPLICATION);
+ recordAfterAnyObservation(Observation.AFTER_PROCESS_VALIDATION);
+ recordAfterAnyObservation(Observation.AFTER_RENDER_RESPONSE);
+ recordAfterAnyObservation(Observation.AFTER_RESTORE_VIEW);
+ recordAfterAnyObservation(Observation.AFTER_UPDATE_MODEL_VALUES);
+ }
+
+ private void recordAfterAnyObservation(Observation observation)
+ {
+ afterAnyObservations.add(observation);
+ }
+
public void observeBeforeRenderResponse(@Observes @Before @RenderResponse final PhaseEvent e)
{
- observeBeforeRenderResponse = true;
+ recordObservation(Observation.BEFORE_RENDER_RESPONSE);
}
public void observeAfterRenderResponse(@Observes @After @RenderResponse final PhaseEvent e)
{
- observeAfterRenderResponse = true;
+ recordObservation(Observation.AFTER_RENDER_RESPONSE);
}
public void observeBeforeApplyRequestValues(@Observes @Before @ApplyRequestValues final PhaseEvent e)
{
- observeBeforeApplyRequestValues = true;
+ recordObservation(Observation.BEFORE_APPLY_VALUES);
}
public void observeAfterApplyRequestValues(@Observes @After @ApplyRequestValues final PhaseEvent e)
{
- observeAfterApplyRequestValues = true;
+ recordObservation(Observation.AFTER_APPLY_VALUES);
}
public void observeBeforeInvokeApplication(@Observes @Before @InvokeApplication final PhaseEvent e)
{
- observeBeforeInvokeApplication = true;
+ recordObservation(Observation.BEFORE_INVOKE_APPLICATION);
}
public void observeAfterInvokeApplication(@Observes @After @InvokeApplication final PhaseEvent e)
{
- observeAfterInvokeApplication = true;
+ recordObservation(Observation.AFTER_INVOKE_APPLICATION);
}
public void observeBeforeProcessValidations(@Observes @Before @ProcessValidations final PhaseEvent e)
{
- observeBeforeProcessValidations = true;
+ recordObservation(Observation.BEFORE_PROCESS_VALIDATION);
}
public void observeAfterProcessValidations(@Observes @After @ProcessValidations final PhaseEvent e)
{
- observeAfterProcessValidations = true;
+ recordObservation(Observation.AFTER_PROCESS_VALIDATION);
}
public void observeBeforeRestoreView(@Observes @Before @RestoreView final PhaseEvent e)
{
- observeBeforeRestoreView = true;
+ recordObservation(Observation.BEFORE_RESTORE_VIEW);
}
public void observeAfterRestoreView(@Observes @After @RestoreView final PhaseEvent e)
{
- observeAfterRestoreView = true;
+ recordObservation(Observation.AFTER_RESTORE_VIEW);
}
public void observeBeforeUpdateModelValues(@Observes @Before @UpdateModelValues final PhaseEvent e)
{
- observeBeforeUpdateModelValues = true;
+ recordObservation(Observation.BEFORE_UPDATE_MODEL_VALUES);
}
public void observeAfterUpdateModelValues(@Observes @After @UpdateModelValues final PhaseEvent e)
{
- observeAfterUpdateModelValues = true;
+ recordObservation(Observation.AFTER_UPDATE_MODEL_VALUES);
}
+ public void assertAllAfterPhasesObserved()
+ {
+// assert afterAnyObservations.size() == ALL_AFTER_OBSERVATIONS.size();
+ assert afterAnyObservations.containsAll(ALL_AFTER_OBSERVATIONS);
+ }
+
+ public void assertAllBeforePhasesObserved()
+ {
+// assert beforeAnyObservations.size() == ALL_BEFORE_OBSERVATIONS.size();
+ assert beforeAnyObservations.containsAll(ALL_BEFORE_OBSERVATIONS);
+ }
+
}
14 years, 8 months
Seam SVN: r12380 - in modules/xml/trunk/core/src: main/java/org/jboss/seam/xml/parser/namespace and 2 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-04-05 04:58:08 -0400 (Mon, 05 Apr 2010)
New Revision: 12380
Added:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
Modified:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml
Log:
allow setting of values for getter/setter pairs that don't have an underlying field
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-04-04 19:11:04 UTC (rev 12379)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-04-05 08:58:08 UTC (rev 12380)
@@ -121,6 +121,14 @@
fields.add(f);
}
}
+ for (PropertyXmlItem xi : rb.getChildrenOfType(PropertyXmlItem.class))
+ {
+ FieldValueObject f = xi.getFieldValue();
+ if (f != null)
+ {
+ fields.add(f);
+ }
+ }
if (!fields.isEmpty())
{
ret.getFieldValues().put(tp, fields);
Added: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java (rev 0)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java 2010-04-05 08:58:08 UTC (rev 12380)
@@ -0,0 +1,123 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.fieldset.ArrayFieldSet;
+import org.jboss.seam.xml.fieldset.CollectionFieldSet;
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.fieldset.FieldValueSetter;
+import org.jboss.seam.xml.fieldset.MapFieldSet;
+import org.jboss.seam.xml.fieldset.MethodFieldSetter;
+import org.jboss.seam.xml.fieldset.SimpleFieldValue;
+import org.jboss.seam.xml.util.XmlConfigurationException;
+
+public class PropertyXmlItem extends AbstractXmlItem
+{
+
+ FieldValueSetter fieldSetter;
+ FieldValueObject fieldValue;
+ String name;
+ Class<?> type;
+ HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ public PropertyXmlItem(XmlItem parent, String name, Method setter, String innerText, String document, int lineno)
+ {
+ super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null, document, lineno);
+ this.name = name;
+ this.type = setter.getParameterTypes()[0];
+ this.fieldSetter = new MethodFieldSetter(setter);
+ if (innerText != null && innerText.length() > 0)
+ {
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter, innerText);
+ }
+ allowed.add(XmlItemType.VALUE);
+ }
+
+ public FieldValueObject getFieldValue()
+ {
+ return fieldValue;
+ }
+
+ @Override
+ public boolean resolveChildren()
+ {
+ List<EntryXmlItem> mapEntries = new ArrayList<EntryXmlItem>();
+ List<XmlItem> valueEntries = new ArrayList<XmlItem>();
+ if (fieldValue == null)
+ {
+ for (XmlItem i : children)
+ {
+ if (i.getType() == XmlItemType.VALUE)
+ {
+ valueEntries.add(i);
+ }
+ else if (i.getType() == XmlItemType.ENTRY)
+ {
+ mapEntries.add((EntryXmlItem) i);
+ }
+
+ }
+ }
+ if (!mapEntries.isEmpty() || !valueEntries.isEmpty())
+ {
+ if (Map.class.isAssignableFrom(type))
+ {
+ if (!valueEntries.isEmpty())
+ {
+ throw new XmlConfigurationException("Map fields cannot have <value> elements as children,only <entry> elements Field:" + parent.getJavaClass().getName() + '.' + name, getDocument(), getLineno());
+ }
+ if (!mapEntries.isEmpty())
+ {
+ fieldValue = new MapFieldSet(fieldSetter, mapEntries);
+ }
+ }
+ else if (Collection.class.isAssignableFrom(type) || type.isArray())
+ {
+ if (!mapEntries.isEmpty())
+ {
+ throw new XmlConfigurationException("Collection fields must be set using <value> not <entry> Field:" + parent.getJavaClass().getName() + '.' + name, getDocument(), getLineno());
+ }
+ if (!valueEntries.isEmpty())
+ {
+ if (type.isArray())
+ {
+ fieldValue = new ArrayFieldSet(fieldSetter, valueEntries);
+ }
+ else
+ {
+ fieldValue = new CollectionFieldSet(fieldSetter, valueEntries);
+ }
+ }
+ }
+ else
+ {
+ if (!mapEntries.isEmpty())
+ {
+ throw new XmlConfigurationException("Only Map fields can be set using <entry> Field:" + parent.getJavaClass().getName() + '.' + name, getDocument(), getLineno());
+ }
+ if (valueEntries.size() != 1)
+ {
+ throw new XmlConfigurationException("Non collection fields can only have a single <value> element Field:" + parent.getJavaClass().getName() + '.' + name, getDocument(), getLineno());
+ }
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter, valueEntries.get(0).getInnerText());
+ }
+ }
+ return true;
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+
+}
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-04-04 19:11:04 UTC (rev 12379)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-04-05 08:58:08 UTC (rev 12380)
@@ -5,6 +5,7 @@
package org.jboss.seam.xml.parser.namespace;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -15,6 +16,7 @@
import org.jboss.seam.xml.model.FieldXmlItem;
import org.jboss.seam.xml.model.MethodXmlItem;
import org.jboss.seam.xml.model.ParameterXmlItem;
+import org.jboss.seam.xml.model.PropertyXmlItem;
import org.jboss.seam.xml.model.XmlItem;
import org.jboss.seam.xml.model.XmlItemType;
import org.jboss.seam.xml.parser.SaxNode;
@@ -117,6 +119,19 @@
{
return new FieldXmlItem(parent, f, innerText, document, lineno);
}
+
+ String methodName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
+ if (ReflectionUtils.methodExists(p, methodName))
+ {
+ Set<Method> methods = ReflectionUtils.getMethods(p);
+ for (Method m : methods)
+ {
+ if (m.getName().equals(methodName) && m.getParameterTypes().length == 1)
+ {
+ return new PropertyXmlItem(parent, name, m, innerText, document, lineno);
+ }
+ }
+ }
return null;
}
}
Modified: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-04-04 19:11:04 UTC (rev 12379)
+++ modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-04-05 08:58:08 UTC (rev 12380)
@@ -15,7 +15,7 @@
{
assert ivalue != 20;
}
-
+
private int ivalue = 20;
public String stringValue;
@@ -34,6 +34,8 @@
public long lvalue;
+ int noFieldValue;
+
public void setIvalue(int value)
{
this.ivalue = value + 1;
@@ -44,4 +46,14 @@
return ivalue;
}
+ public int getNoField()
+ {
+ return noFieldValue;
+ }
+
+ public void setNoField(int value)
+ {
+ noFieldValue = value;
+ }
+
}
Modified: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-04-04 19:11:04 UTC (rev 12379)
+++ modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-04-05 08:58:08 UTC (rev 12380)
@@ -31,6 +31,7 @@
assert x.getIvalue() == 11;
assert x.lvalue == 23;
assert x.svalue == 4;
+ assert x.noFieldValue == 7;
}
Modified: modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml 2010-04-04 19:11:04 UTC (rev 12379)
+++ modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml 2010-04-05 08:58:08 UTC (rev 12380)
@@ -16,7 +16,10 @@
<test:lvalue>23</test:lvalue>
<test:svalue>4</test:svalue>
<test:bigDecimalValue>10</test:bigDecimalValue>
+ <test:noField>7</test:noField>
</test:FieldValueBean>
+
+
</beans>
\ No newline at end of file
14 years, 8 months
Seam SVN: r12379 - in modules/faces/trunk/src: main/java/org/jboss/seam/faces/event/qualifier and 1 other directories.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-04 15:11:04 -0400 (Sun, 04 Apr 2010)
New Revision: 12379
Removed:
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ComponentSystemEvent.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ExceptionQueuedEvent.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructApplicationEvent.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructCustomScopeEvent.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyApplicationEvent.java
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyCustomScopeEvent.java
Modified:
modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/SystemEventBridge.java
modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java
Log:
Drop extra qualifiers
Modified: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/SystemEventBridge.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/SystemEventBridge.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/SystemEventBridge.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,21 +1,12 @@
package org.jboss.seam.faces.event;
-import java.lang.annotation.Annotation;
-
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
-import javax.enterprise.util.AnnotationLiteral;
import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ComponentSystemEvent;
-import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.PostConstructApplicationEvent;
-import javax.faces.event.PostConstructCustomScopeEvent;
-import javax.faces.event.PreDestroyApplicationEvent;
-import javax.faces.event.PreDestroyCustomScopeEvent;
import javax.faces.event.SystemEvent;
import javax.faces.event.SystemEventListener;
-import org.jboss.seam.faces.SeamFacesException;
import org.jboss.seam.faces.cdi.BeanManagerAware;
/**
@@ -53,69 +44,8 @@
public void processEvent(final SystemEvent e) throws AbortProcessingException
{
Object payload = e.getClass().cast(e);
- Annotation qualifier = null;
-
- if (e instanceof ComponentSystemEvent)
- {
- qualifier = COMPONENT_SYSTEM_EVENT;
- }
- else if (e instanceof ExceptionQueuedEvent)
- {
- qualifier = EXCEPTION_QUEUED_EVENT;
- }
- else if (e instanceof PostConstructApplicationEvent)
- {
- qualifier = POST_CONSTRUCT_APPLICATION_EVENT;
- }
- else if (e instanceof PostConstructCustomScopeEvent)
- {
- qualifier = POST_CONSTRUCT_CUSTOM_SCOPE_EVENT;
- }
- else if (e instanceof PreDestroyApplicationEvent)
- {
- qualifier = PRE_DESTROY_APPLICATION_EVENT;
- }
- else if (e instanceof PreDestroyCustomScopeEvent)
- {
- qualifier = PRE_DESTROY_CUSTOM_SCOPE_EVENT;
- }
- else
- {
- throw new SeamFacesException("Unknown JSF System Event detected during CDI event broadcasting");
- }
-
- /*
- * This propagates the event to CDI
- */
- getBeanManager().fireEvent(payload, qualifier);
+ getBeanManager().fireEvent(payload);
}
- /*
- * System Event Annotations
- */
- private static final AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PreDestroyCustomScopeEvent> PRE_DESTROY_CUSTOM_SCOPE_EVENT = new AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PreDestroyCustomScopeEvent>()
- {
- private static final long serialVersionUID = -7243409955575081242L;
- };
- private static final AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PreDestroyApplicationEvent> PRE_DESTROY_APPLICATION_EVENT = new AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PreDestroyApplicationEvent>()
- {
- private static final long serialVersionUID = -7448942843812054204L;
- };
- private static final AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PostConstructCustomScopeEvent> POST_CONSTRUCT_CUSTOM_SCOPE_EVENT = new AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PostConstructCustomScopeEvent>()
- {
- private static final long serialVersionUID = 6194794712139598271L;
- };
- private static final AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PostConstructApplicationEvent> POST_CONSTRUCT_APPLICATION_EVENT = new AnnotationLiteral<org.jboss.seam.faces.event.qualifier.PostConstructApplicationEvent>()
- {
- private static final long serialVersionUID = -7119316486394672512L;
- };
- private static final AnnotationLiteral<org.jboss.seam.faces.event.qualifier.ExceptionQueuedEvent> EXCEPTION_QUEUED_EVENT = new AnnotationLiteral<org.jboss.seam.faces.event.qualifier.ExceptionQueuedEvent>()
- {
- private static final long serialVersionUID = -2694169811275854595L;
- };
- private static final AnnotationLiteral<org.jboss.seam.faces.event.qualifier.ComponentSystemEvent> COMPONENT_SYSTEM_EVENT = new AnnotationLiteral<org.jboss.seam.faces.event.qualifier.ComponentSystemEvent>()
- {
- private static final long serialVersionUID = -8018221003951485295L;
- };
}
Deleted: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ComponentSystemEvent.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ComponentSystemEvent.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ComponentSystemEvent.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,24 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select JSF component system events
- * The event parameter is a
- * {@link javax.faces.event.ComponentSystemEvent.ComponentSystemEvent}.
- *
- * @author Nicklas Karlsson
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface ComponentSystemEvent
-{
-}
\ No newline at end of file
Deleted: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ExceptionQueuedEvent.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ExceptionQueuedEvent.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/ExceptionQueuedEvent.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,23 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select JSF exception queued events
- * The event parameter is a {@link javax.faces.event.ExceptionQueuedEvent}.
- *
- * @author Nicklas Karlsson
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface ExceptionQueuedEvent
-{
-}
\ No newline at end of file
Deleted: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructApplicationEvent.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructApplicationEvent.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructApplicationEvent.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,24 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select JSF post-construct application
- * events The event parameter is a
- * {@link javax.faces.event.PostConstructApplicationEvent}.
- *
- * @author Nicklas Karlsson
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface PostConstructApplicationEvent
-{
-}
\ No newline at end of file
Deleted: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructCustomScopeEvent.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructCustomScopeEvent.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PostConstructCustomScopeEvent.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,24 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select JSF post-construct custom
- * scope events The event parameter is a
- * {@link javax.faces.event.javax.faces.event.PostConstructCustomScopeEvent}.
- *
- * @author Nicklas Karlsson
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface PostConstructCustomScopeEvent
-{
-}
\ No newline at end of file
Deleted: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyApplicationEvent.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyApplicationEvent.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyApplicationEvent.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,24 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select JSF pre-destroy application
- * events The event parameter is a
- * {@link javax.faces.event.javax.faces.event.PreDestroyApplicationEvent}.
- *
- * @author Nicklas Karlsson
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface PreDestroyApplicationEvent
-{
-}
\ No newline at end of file
Deleted: modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyCustomScopeEvent.java
===================================================================
--- modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyCustomScopeEvent.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/main/java/org/jboss/seam/faces/event/qualifier/PreDestroyCustomScopeEvent.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -1,24 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select JSF pre-destroy custom scope
- * events The event parameter is a
- * {@link javax.faces.event.javax.faces.event.PreDestroyCustomScopeEvent}.
- *
- * @author Nicklas Karlsson
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface PreDestroyCustomScopeEvent
-{
-}
\ No newline at end of file
Modified: modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java
===================================================================
--- modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java 2010-04-03 14:41:03 UTC (rev 12378)
+++ modules/faces/trunk/src/test/java/org/jboss/seam/faces/event/SystemEventObserver.java 2010-04-04 19:11:04 UTC (rev 12379)
@@ -2,14 +2,13 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PostConstructCustomScopeEvent;
+import javax.faces.event.PreDestroyApplicationEvent;
+import javax.faces.event.PreDestroyCustomScopeEvent;
-import org.jboss.seam.faces.event.qualifier.ComponentSystemEvent;
-import org.jboss.seam.faces.event.qualifier.ExceptionQueuedEvent;
-import org.jboss.seam.faces.event.qualifier.PostConstructApplicationEvent;
-import org.jboss.seam.faces.event.qualifier.PostConstructCustomScopeEvent;
-import org.jboss.seam.faces.event.qualifier.PreDestroyApplicationEvent;
-import org.jboss.seam.faces.event.qualifier.PreDestroyCustomScopeEvent;
-
@ApplicationScoped
public class SystemEventObserver
{
@@ -20,32 +19,32 @@
public static boolean preDestroyApplicationEvent;
public static boolean preDestroyCustomScopeEvent;
- public void observeComponentSystemEvent(@Observes @ComponentSystemEvent javax.faces.event.ComponentSystemEvent e)
+ public void observeComponentSystemEvent(@Observes ComponentSystemEvent e)
{
componentSystemEvent = true;
}
- public void observeExceptionQueuedEvent(@Observes @ExceptionQueuedEvent javax.faces.event.ExceptionQueuedEvent e)
+ public void observeExceptionQueuedEvent(@Observes ExceptionQueuedEvent e)
{
excecptionQueuedEvent = true;
}
- public void observePostConstructApplicationEvent(@Observes @PostConstructApplicationEvent javax.faces.event.PostConstructApplicationEvent e)
+ public void observePostConstructApplicationEvent(@Observes PostConstructApplicationEvent e)
{
postConstructApplicationEvent = true;
}
- public void observePreDestroyApplicationEvent(@Observes @PreDestroyApplicationEvent javax.faces.event.PreDestroyApplicationEvent e)
+ public void observePreDestroyApplicationEvent(@Observes PreDestroyApplicationEvent e)
{
preDestroyApplicationEvent = true;
}
- public void observePostConstructCustomScopeEvent(@Observes @PostConstructCustomScopeEvent javax.faces.event.PostConstructCustomScopeEvent e)
+ public void observePostConstructCustomScopeEvent(@Observes PostConstructCustomScopeEvent e)
{
postConstructCustomScopeEvent = true;
}
- public void observePreDestroyCustomScopeEvent(@Observes @PreDestroyCustomScopeEvent javax.faces.event.PreDestroyCustomScopeEvent e)
+ public void observePreDestroyCustomScopeEvent(@Observes PreDestroyCustomScopeEvent e)
{
preDestroyCustomScopeEvent = true;
}
14 years, 9 months
Seam SVN: r12378 - in modules/security/trunk/examples/seamspace/src/main/webapp: WEB-INF and 1 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-04-03 10:41:03 -0400 (Sat, 03 Apr 2010)
New Revision: 12378
Added:
modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/kbaseconfig.properties
modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/kbuilderconfig.properties
Modified:
modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/classes/seam-beans.xml
modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/security-rules.drl
modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml
Log:
got security rules working, user manager view
Modified: modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/classes/seam-beans.xml
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/classes/seam-beans.xml 2010-04-03 14:39:33 UTC (rev 12377)
+++ modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/classes/seam-beans.xml 2010-04-03 14:41:03 UTC (rev 12378)
@@ -7,7 +7,6 @@
xmlns:permission="urn:java:org.jboss.seam.security.permission"
xmlns:drools="urn:java:org.jboss.seam.drools"
xmlns:seamspace="urn:java:org.jboss.seam.security.examples.seamspace"
- xmlns:drools="urn:java:org.jboss.seam.drools"
xmlns:drools-config="urn:java:org.jboss.seam.drools.config"
xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
@@ -36,7 +35,7 @@
<drools-config:KnowledgeBaseConfig>
<s:overrides/>
- <drools-qualifier:KBaseConfig name="security-rules-config"/>
+ <drools-qualifier:KBaseConfig value="security-rules-config"/>
<drools-config:knowledgeBuilderConfig>kbuilderconfig.properties</drools-config:knowledgeBuilderConfig>
<drools-config:knowledgeBaseConfig>kbaseconfig.properties</drools-config:knowledgeBaseConfig>
<drools-config:ruleResources>
@@ -48,19 +47,23 @@
</drools-config:KnowledgeBaseConfig>
<drools:KnowledgeBaseProducer>
- <s:specializes/>
- <drools:produceKBase>
- <drools-qualifier:KBase name="permission-rules"/>
- <s:Inject/>
- <drools-qualifier:KBaseConfig name="security-rules-config"/>
- </drools:produceKBase>
+ <s:specializes/>
+ <drools:produceKBase>
+ <drools-qualifier:KBase value="permission-rules"/>
+ <s:parameters>
+ <drools-config:KnowledgeBaseConfig>
+ <s:Inject/>
+ <drools-qualifier:KBaseConfig value="security-rules-config"/>
+ </drools-config:KnowledgeBaseConfig>
+ </s:parameters>
+ </drools:produceKBase>
</drools:KnowledgeBaseProducer>
<permission:RuleBasedPermissionResolver>
<s:specializes/>
<permission:securityRules>
+ <drools-qualifier:KBase value="permission-rules"/>
<s:Inject/>
- <drools-qualifier:KBase name="permission-rules"/>
</permission:securityRules>
</permission:RuleBasedPermissionResolver>
Added: modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/kbaseconfig.properties
===================================================================
Added: modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/kbuilderconfig.properties
===================================================================
Modified: modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/security-rules.drl
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/security-rules.drl 2010-04-03 14:39:33 UTC (rev 12377)
+++ modules/security/trunk/examples/seamspace/src/main/webapp/WEB-INF/security-rules.drl 2010-04-03 14:41:03 UTC (rev 12378)
@@ -8,12 +8,12 @@
import org.jboss.seam.security.permission.RoleCheck;
import org.jboss.seam.security.Role;
-import org.jboss.seam.example.seamspace.BlogComment;
-import org.jboss.seam.example.seamspace.Member;
-import org.jboss.seam.example.seamspace.MemberAccount;
-import org.jboss.seam.example.seamspace.MemberBlog;
-import org.jboss.seam.example.seamspace.MemberFriend;
-import org.jboss.seam.example.seamspace.MemberImage;
+import org.jboss.seam.security.examples.seamspace.model.BlogComment;
+import org.jboss.seam.security.examples.seamspace.model.Member;
+import org.jboss.seam.security.examples.seamspace.model.MemberAccount;
+import org.jboss.seam.security.examples.seamspace.model.MemberBlog;
+import org.jboss.seam.security.examples.seamspace.model.MemberFriend;
+import org.jboss.seam.security.examples.seamspace.model.MemberImage;
# These rules allow members to manage permissions on their own images
Modified: modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml 2010-04-03 14:39:33 UTC (rev 12377)
+++ modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml 2010-04-03 14:41:03 UTC (rev 12378)
@@ -11,6 +11,8 @@
</ui:define>
<ui:define name="content">
+
+ <f:event type="preRenderView" listener="#{userSearch.loadUsers}"/>
<script type="text/javascript">
function confirmDelete() {
@@ -26,7 +28,7 @@
<h:dataTable
id="threads"
- value="#{users}"
+ value="#{userSearch.users}"
var="user"
styleClass="security"
cellspacing="0"
14 years, 9 months
Seam SVN: r12377 - in modules/security/trunk/core: src/main/java/org/jboss/seam/security/management/action and 1 other directories.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-04-03 10:39:33 -0400 (Sat, 03 Apr 2010)
New Revision: 12377
Modified:
modules/security/trunk/core/pom.xml
modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
modules/security/trunk/core/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java
Log:
got rule-based permissions working
Modified: modules/security/trunk/core/pom.xml
===================================================================
--- modules/security/trunk/core/pom.xml 2010-04-03 03:32:15 UTC (rev 12376)
+++ modules/security/trunk/core/pom.xml 2010-04-03 14:39:33 UTC (rev 12377)
@@ -43,8 +43,8 @@
</dependency>
<dependency>
- <groupId>org.drools</groupId>
- <artifactId>drools-core</artifactId>
+ <groupId>org.jboss.seam.drools</groupId>
+ <artifactId>seam-drools-core</artifactId>
</dependency>
<dependency>
Modified: modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
===================================================================
--- modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java 2010-04-03 03:32:15 UTC (rev 12376)
+++ modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java 2010-04-03 14:39:33 UTC (rev 12377)
@@ -1,24 +1,26 @@
package org.jboss.seam.security.management.action;
import java.io.Serializable;
+import java.util.List;
import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
import javax.inject.Named;
+import org.jboss.seam.security.management.IdentityManager;
+
@Named
@SessionScoped
public class UserSearch implements Serializable
{
private static final long serialVersionUID = 8592034786339372510L;
- /*
- @DataModel
List<String> users;
- @DataModelSelection
- String selectedUser;
+ //@DataModelSelection
+ //String selectedUser;
- @Current IdentityManager identityManager;
+ @Inject IdentityManager identityManager;
public void loadUsers()
{
@@ -41,10 +43,14 @@
return sb.toString();
}
- public String getSelectedUser()
+ //public String getSelectedUser()
+ //{
+ //return selectedUser;
+ //}
+
+ public List<String> getUsers()
{
- return selectedUser;
- }
+ return users;
+ }
- */
}
\ No newline at end of file
Modified: modules/security/trunk/core/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java
===================================================================
--- modules/security/trunk/core/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java 2010-04-03 03:32:15 UTC (rev 12376)
+++ modules/security/trunk/core/src/main/java/org/jboss/seam/security/permission/RuleBasedPermissionResolver.java 2010-04-03 14:39:33 UTC (rev 12377)
@@ -14,10 +14,12 @@
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.event.Observes;
-import org.drools.FactHandle;
+import org.drools.KnowledgeBase;
import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.ClassObjectFilter;
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.rule.FactHandle;
//import org.jboss.seam.drools.SeamGlobalResolver;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.Role;
@@ -38,9 +40,9 @@
private Logger log = LoggerFactory.getLogger(RuleBasedPermissionResolver.class);
- private StatefulSession securityContext;
+ private StatefulKnowledgeSession securityContext;
- private RuleBase securityRules;
+ private KnowledgeBase securityRules;
@Inject BeanManager manager;
@Inject Identity identity;
@@ -56,7 +58,7 @@
{
if (getSecurityRules() != null)
{
- setSecurityContext(getSecurityRules().newStatefulSession(false));
+ setSecurityContext(getSecurityRules().newStatefulKnowledgeSession());
//getSecurityContext().setGlobalResolver(new SeamGlobalResolver(getSecurityContext().getGlobalResolver()));
}
}
@@ -70,7 +72,7 @@
*/
public boolean hasPermission(Object target, String action)
{
- StatefulSession securityContext = getSecurityContext();
+ StatefulKnowledgeSession securityContext = getSecurityContext();
if (securityContext == null) return false;
@@ -125,7 +127,7 @@
public boolean checkConditionalRole(String roleName, Object target, String action)
{
- StatefulSession securityContext = getSecurityContext();
+ StatefulKnowledgeSession securityContext = getSecurityContext();
if (securityContext == null) return false;
RoleCheck roleCheck = new RoleCheck(roleName);
@@ -214,11 +216,10 @@
Principal role = (Principal) e.nextElement();
boolean found = false;
- Iterator<Role> iter = (Iterator<Role>) getSecurityContext()
- .iterateObjects(new ClassObjectFilter(Role.class));
+ Iterator<?> iter = getSecurityContext().getObjects(new ClassObjectFilter(Role.class)).iterator();
while (iter.hasNext())
{
- Role r = iter.next();
+ Role r = (Role) iter.next();
if (r.getName().equals(role.getName()))
{
found = true;
@@ -235,11 +236,10 @@
}
}
- Iterator<Role> iter = (Iterator<Role>) getSecurityContext()
- .iterateObjects(new ClassObjectFilter(Role.class));
+ Iterator<?> iter = getSecurityContext().getObjects(new ClassObjectFilter(Role.class)).iterator();
while (iter.hasNext())
{
- Role r = iter.next();
+ Role r = (Role) iter.next();
if (!identity.hasRole(r.getName()))
{
FactHandle fh = getSecurityContext().getFactHandle(r);
@@ -250,23 +250,23 @@
}
- public StatefulSession getSecurityContext()
+ public StatefulKnowledgeSession getSecurityContext()
{
return securityContext;
}
- public void setSecurityContext(StatefulSession securityContext)
+ public void setSecurityContext(StatefulKnowledgeSession securityContext)
{
this.securityContext = securityContext;
}
- public RuleBase getSecurityRules()
+ public KnowledgeBase getSecurityRules()
{
return securityRules;
}
- public void setSecurityRules(RuleBase securityRules)
+ public void setSecurityRules(KnowledgeBase securityRules)
{
this.securityRules = securityRules;
}
14 years, 9 months
Seam SVN: r12376 - in modules/drools/trunk/core: src/main/java/org/jboss/seam/drools and 2 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-02 23:32:15 -0400 (Fri, 02 Apr 2010)
New Revision: 12376
Added:
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
Modified:
modules/drools/trunk/core/pom.xml
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java
Log:
add classes to support ResourceProvider
temporarily depend on weld-extensions 1.0.0-SNAPSHOT
reintroduce XML bean config for KBaseTest
Modified: modules/drools/trunk/core/pom.xml
===================================================================
--- modules/drools/trunk/core/pom.xml 2010-04-03 03:17:56 UTC (rev 12375)
+++ modules/drools/trunk/core/pom.xml 2010-04-03 03:32:15 UTC (rev 12376)
@@ -78,6 +78,7 @@
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-extensions</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-03 03:17:56 UTC (rev 12375)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-03 03:32:15 UTC (rev 12376)
@@ -3,8 +3,6 @@
import java.io.InputStream;
import java.util.Properties;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
Modified: modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java
===================================================================
--- modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java 2010-04-03 03:17:56 UTC (rev 12375)
+++ modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java 2010-04-03 03:32:15 UTC (rev 12376)
@@ -3,7 +3,6 @@
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import static org.junit.Assert.assertNotNull;
-import static org.jboss.shrinkwrap.api.formatter.Formatters.VERBOSE;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
@@ -31,18 +30,15 @@
public static JavaArchive createTestArchive()
{
String pkgPath = KBaseTest.class.getPackage().getName().replaceAll("\\.", "/");
- JavaArchive archive = Archives.create("test.jar", JavaArchive.class)
+ JavaArchive archive = Archives.create("test.jar", JavaArchive.class)
.addPackages(true, KnowledgeBaseProducer.class.getPackage())
- .addClass(ResourceProvider.class)
+ .addPackages(true, ResourceProvider.class.getPackage())
.addResource(pkgPath + "/kbasetest.drl", ArchivePaths.create("kbasetest.drl"))
- .addResource(pkgPath + "/kbuilderconfig.properties", ArchivePaths.create("kbuilderconfig.properties"))
+ .addResource(pkgPath + "/kbuilderconfig.properties", ArchivePaths.create("kbuilderconfig.properties"))
.addResource(pkgPath + "/kbaseconfig.properties", ArchivePaths.create("kbaseconfig.properties"))
- .addManifestResource("META-INF/beans.xml", ArchivePaths.create("beans.xml"));
- // the XML bean config module doesn't pick up the beans.xml unless it's located at src/test/resources/META-INF/beans.xml
- //.addManifestResource(pkgPath + "/KBaseTest-beans.xml", ArchivePaths.create("beans.xml"));
- System.out.println(archive.toString(VERBOSE));
-
- return archive;
+ .addManifestResource(pkgPath + "/KBaseTest-beans.xml", ArchivePaths.create("beans.xml"));
+ System.out.println(archive.toString(Formatters.VERBOSE));
+ return archive;
}
@Inject @Any Instance<KnowledgeBaseConfig> kbaseConfigResolver;
@@ -63,8 +59,6 @@
assertNotNull(kbase);
}
-
-
static class KBaseConfigBinding extends AnnotationLiteral<KBaseConfig> implements KBaseConfig
{
private String value = null;
@@ -78,4 +72,3 @@
}
}
}
-
Added: modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml (rev 0)
+++ modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml 2010-04-03 03:32:15 UTC (rev 12376)
@@ -0,0 +1,32 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:s="urn:java:seam:core"
+ xmlns:drools="urn:java:org.jboss.seam.drools:org.jboss.seam.drools.config:org.jboss.seam.drools.qualifier">
+
+ <drools:KnowledgeBaseConfig>
+ <s:overrides/>
+ <drools:KBaseConfig value="kbaseconfig1"/>
+ <drools:knowledgeBuilderConfig>kbuilderconfig.properties</drools:knowledgeBuilderConfig>
+ <drools:knowledgeBaseConfig>kbaseconfig.properties</drools:knowledgeBaseConfig>
+ <drools:ruleResources>
+ <s:value>classpath:kbasetest.drl:DRL</s:value>
+ </drools:ruleResources>
+ <drools:eventListeners>
+ <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</s:value>
+ </drools:eventListeners>
+ </drools:KnowledgeBaseConfig>
+
+ <drools:KnowledgeBaseProducer>
+ <s:specializes/>
+ <drools:produceKBase>
+ <drools:KBase value="kbase1"/>
+ <s:parameters>
+ <drools:KnowledgeBaseConfig>
+ <s:Inject/>
+ <drools:KBaseConfig value="kbaseconfig1"/>
+ </drools:KnowledgeBaseConfig>
+ </s:parameters>
+ </drools:produceKBase>
+ </drools:KnowledgeBaseProducer>
+
+</beans>
14 years, 9 months
Seam SVN: r12375 - modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-02 23:17:56 -0400 (Fri, 02 Apr 2010)
New Revision: 12375
Modified:
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java
Log:
add type and parameter targets
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java 2010-04-02 20:53:40 UTC (rev 12374)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java 2010-04-03 03:17:56 UTC (rev 12375)
@@ -2,6 +2,8 @@
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.FIELD;
+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.Documented;
@@ -12,7 +14,7 @@
import javax.inject.Qualifier;
@Qualifier
-@Target({METHOD, FIELD})
+@Target({TYPE, METHOD, FIELD, PARAMETER})
@Documented
@Retention(RUNTIME)
@Inherited
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java 2010-04-02 20:53:40 UTC (rev 12374)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java 2010-04-03 03:17:56 UTC (rev 12375)
@@ -2,6 +2,8 @@
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.Documented;
@@ -12,7 +14,7 @@
import javax.inject.Qualifier;
@Qualifier
-@Target({METHOD, FIELD})
+@Target({TYPE, METHOD, FIELD, PARAMETER})
@Documented
@Retention(RUNTIME)
@Inherited
14 years, 9 months
Seam SVN: r12374 - modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-02 16:53:40 -0400 (Fri, 02 Apr 2010)
New Revision: 12374
Modified:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java
Log:
use context class loader to load resource
don't break iterator on first empty file, rather continue
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java 2010-04-02 17:57:34 UTC (rev 12373)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java 2010-04-02 20:53:40 UTC (rev 12374)
@@ -27,7 +27,7 @@
public class ClassPathXmlDocumentProvider implements XmlDocumentProvider
{
- static final String[] DEFAULT_RESOURCES = { "seam-beans.xml", "META-INF/seam-beans.xml", "WEB-INF/seam-beans.xml" , "META-INF/beans.xml", "WEB-INF/beans.xml"};
+ static final String[] DEFAULT_RESOURCES = { "seam-beans.xml", "META-INF/seam-beans.xml", "META-INF/beans.xml"};
final String[] resources;
@@ -52,7 +52,6 @@
public void open()
{
-
factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setIgnoringComments(true);
@@ -66,11 +65,16 @@
throw new RuntimeException(e1);
}
docs = new ArrayList<URL>();
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null)
+ {
+ cl = getClass().getClassLoader();
+ }
for (String i : resources)
{
try
{
- Enumeration<URL> e = getClass().getClassLoader().getResources(i);
+ Enumeration<URL> e = cl.getResources(i);
while (e.hasMoreElements())
{
docs.add(e.nextElement());
@@ -126,7 +130,7 @@
test = url.openStream();
if(test.available() == 0)
{
- break;
+ continue;
}
}
finally
14 years, 9 months
Seam SVN: r12373 - in modules/drools/trunk/core: src/main/java/org/jboss/seam/drools and 5 other directories.
by seam-commits@lists.jboss.org
Author: tsurdilovic
Date: 2010-04-02 13:57:34 -0400 (Fri, 02 Apr 2010)
New Revision: 12373
Added:
modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
Removed:
modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
Modified:
modules/drools/trunk/core/pom.xml
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java
modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java
modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java
Log:
added resource management
Modified: modules/drools/trunk/core/pom.xml
===================================================================
--- modules/drools/trunk/core/pom.xml 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/pom.xml 2010-04-02 17:57:34 UTC (rev 12373)
@@ -75,6 +75,10 @@
<groupId>org.drools</groupId>
<artifactId>drools-workitems</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions</artifactId>
+ </dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/KnowledgeBaseProducer.java 2010-04-02 17:57:34 UTC (rev 12373)
@@ -4,6 +4,7 @@
import java.util.Properties;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
@@ -22,6 +23,7 @@
import org.jboss.seam.drools.config.KnowledgeBaseConfig;
import org.jboss.seam.drools.events.KnowledgeBuilderErrorsEvent;
import org.jboss.seam.drools.events.RuleResourceAddedEvent;
+import org.jboss.weld.extensions.resources.ResourceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,12 +34,13 @@
public class KnowledgeBaseProducer
{
private static final Logger log = LoggerFactory.getLogger(KnowledgeBaseProducer.class);
+
@Inject BeanManager manager;
-
- @Produces //@ApplicationScoped
+ @Inject ResourceProvider resourceProvider;
+
+ @Produces
public KnowledgeBase produceKBase(KnowledgeBaseConfig kbaseConfig) throws Exception
{
- System.out.println("***KBASEPRODUCER CONFIG IS: " + kbaseConfig);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getKnowledgeBuilderConfiguration(kbaseConfig));
for (String nextResource : kbaseConfig.getRuleResources())
@@ -74,7 +77,7 @@
if (kbaseConfig.getKnowledgeBuilderConfig() != null && kbaseConfig.getKnowledgeBuilderConfig().endsWith(".properties"))
{
Properties kbuilderProp = new Properties();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(kbaseConfig.getKnowledgeBuilderConfig());
+ InputStream in = resourceProvider.loadResourceStream(kbaseConfig.getKnowledgeBuilderConfig());
if (in == null)
{
throw new IllegalStateException("Could not locate knowledgeBuilderConfig: " + kbaseConfig.getKnowledgeBuilderConfig());
@@ -93,7 +96,7 @@
if (kbaseConfig.getKnowledgeBaseConfig() != null && kbaseConfig.getKnowledgeBaseConfig().endsWith(".properties"))
{
Properties kbaseProp = new Properties();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(kbaseConfig.getKnowledgeBaseConfig());
+ InputStream in = resourceProvider.loadResourceStream(kbaseConfig.getKnowledgeBaseConfig());
if (in == null)
{
throw new IllegalStateException("Could not locate knowledgeBaseConfig: " + kbaseConfig.getKnowledgeBaseConfig());
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/config/KnowledgeBaseConfig.java 2010-04-02 17:57:34 UTC (rev 12373)
@@ -46,6 +46,22 @@
private String knowledgeBaseConfig;
private String[] ruleResources;
private String[] eventListeners;
+
+ public String toString() {
+ StringBuffer buff = new StringBuffer();
+ buff.append("knowledgeBuilderConfig: " + getKnowledgeBuilderConfig() + "\n")
+ .append("knowledgeBaseConfig: " + getKnowledgeBaseConfig() + "\n")
+ .append("Rule Resources:\n");
+ for(String rr : getRuleResources()) {
+ buff.append("\t" + rr);
+ }
+ buff.append("\nEvent Listeners: \n");
+ for(String el : getEventListeners()) {
+ buff.append("\t" + el);
+ }
+
+ return buff.toString();
+ }
public String getKnowledgeBuilderConfig()
{
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBase.java 2010-04-02 17:57:34 UTC (rev 12373)
@@ -18,5 +18,5 @@
@Inherited
public @interface KBase
{
- String name();
+ String value() default "";
}
Modified: modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java
===================================================================
--- modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/main/java/org/jboss/seam/drools/qualifier/KBaseConfig.java 2010-04-02 17:57:34 UTC (rev 12373)
@@ -18,5 +18,5 @@
@Inherited
public @interface KBaseConfig
{
- String name();
+ String value() default "";
}
Modified: modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java
===================================================================
--- modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/test/java/org/jboss/seam/drools/kbase/KBaseTest.java 2010-04-02 17:57:34 UTC (rev 12373)
@@ -3,19 +3,24 @@
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import static org.junit.Assert.assertNotNull;
+import static org.jboss.shrinkwrap.api.formatter.Formatters.VERBOSE;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import junit.framework.Assert;
+import org.drools.KnowledgeBase;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.drools.KnowledgeBaseProducer;
import org.jboss.seam.drools.config.KnowledgeBaseConfig;
+import org.jboss.seam.drools.qualifier.KBase;
import org.jboss.seam.drools.qualifier.KBaseConfig;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.formatter.Formatters;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.weld.extensions.resources.ResourceProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,37 +31,50 @@
public static JavaArchive createTestArchive()
{
String pkgPath = KBaseTest.class.getPackage().getName().replaceAll("\\.", "/");
- return Archives.create("test.jar", JavaArchive.class)
+ JavaArchive archive = Archives.create("test.jar", JavaArchive.class)
.addPackages(true, KnowledgeBaseProducer.class.getPackage())
- .addResource(pkgPath + "/kbasetest.drl")
- .addResource(pkgPath + "/kbuilderconfig.properties")
- .addResource(pkgPath + "/kbaseconfig.properties")
+ .addClass(ResourceProvider.class)
+ .addResource(pkgPath + "/kbasetest.drl", ArchivePaths.create("kbasetest.drl"))
+ .addResource(pkgPath + "/kbuilderconfig.properties", ArchivePaths.create("kbuilderconfig.properties"))
+ .addResource(pkgPath + "/kbaseconfig.properties", ArchivePaths.create("kbaseconfig.properties"))
.addManifestResource("META-INF/beans.xml", ArchivePaths.create("beans.xml"));
// the XML bean config module doesn't pick up the beans.xml unless it's located at src/test/resources/META-INF/beans.xml
//.addManifestResource(pkgPath + "/KBaseTest-beans.xml", ArchivePaths.create("beans.xml"));
+ System.out.println(archive.toString(VERBOSE));
+
+ return archive;
}
@Inject @Any Instance<KnowledgeBaseConfig> kbaseConfigResolver;
- @Inject @KBaseConfig(name = "kbaseconfig1") KnowledgeBaseConfig config;
+ @Inject @KBaseConfig("kbaseconfig1") KnowledgeBaseConfig config;
+ @Inject @KBase("kbase1") KnowledgeBase kbase;
+
@Test
public void testKBaseConfig() {
Assert.assertFalse(kbaseConfigResolver.select(new KBaseConfigBinding("kbaseconfig1")).isUnsatisfied());
KnowledgeBaseConfig kbaseConfig = kbaseConfigResolver.select(new KBaseConfigBinding("kbaseconfig1")).get();
assertNotNull(kbaseConfig);
- System.out.println("**** " + kbaseConfig.getEventListeners());
+ System.out.println("\n\n\n**** " + kbaseConfig.toString() + "********\n\n\n");
}
+ @Test
+ public void testKBase() {
+ assertNotNull(kbase);
+ }
+
+
+
static class KBaseConfigBinding extends AnnotationLiteral<KBaseConfig> implements KBaseConfig
{
- private String name = null;
- public KBaseConfigBinding(String name)
+ private String value = null;
+ public KBaseConfigBinding(String value)
{
- this.name = name;
+ this.value = value;
}
- public String name() {
- return name;
+ public String value() {
+ return value;
}
}
}
Deleted: modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/META-INF/beans.xml 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/test/resources/META-INF/beans.xml 2010-04-02 17:57:34 UTC (rev 12373)
@@ -1,35 +0,0 @@
-<beans xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:s="urn:java:seam:core"
- xmlns:drools="urn:java:org.jboss.seam.drools:org.jboss.seam.drools.config"
- xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
- xmlns:drools-test="urn:java:org.jboss.seam.drools.kbase">
-
- <drools:KnowledgeBaseConfig>
- <s:overrides/>
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- <drools:knowledgeBuilderConfig>kbuilderconfig.properties</drools:knowledgeBuilderConfig>
- <drools:knowledgeBaseConfig>kbaseconfig.properties</drools:knowledgeBaseConfig>
- <drools:ruleResources>
- <s:value>classpath:kbasetest.drl:DRL</s:value>
- </drools:ruleResources>
- <drools:eventListeners>
- <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener
- </s:value>
- </drools:eventListeners>
- </drools:KnowledgeBaseConfig>
-
- <drools:KnowledgeBaseProducer>
- <s:specializes />
- <drools:produceKBase>
- <drools-qualifier:KBase name="kbase1" />
- <s:parameters>
- <drools:KnowledgeBaseConfig>
- <s:Inject />
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- </drools:KnowledgeBaseConfig>
- </s:parameters>
- </drools:produceKBase>
- </drools:KnowledgeBaseProducer>
-
-</beans>
\ No newline at end of file
Added: modules/drools/trunk/core/src/test/resources/META-INF/beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/META-INF/beans.xml (rev 0)
+++ modules/drools/trunk/core/src/test/resources/META-INF/beans.xml 2010-04-02 17:57:34 UTC (rev 12373)
@@ -0,0 +1,38 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:s="urn:java:seam:core"
+ xmlns:drools="urn:java:org.jboss.seam.drools:org.jboss.seam.drools.config"
+ xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
+ xmlns:drools-test="urn:java:org.jboss.seam.drools.kbase">
+
+ <drools:KnowledgeBaseConfig>
+ <s:overrides/>
+ <drools-qualifier:KBaseConfig value="kbaseconfig1" />
+ <drools:knowledgeBuilderConfig>
+ <s:value>/kbuilderconfig.properties</s:value>
+ </drools:knowledgeBuilderConfig>
+ <drools:knowledgeBaseConfig>
+ <s:value>/kbaseconfig.properties</s:value>
+ </drools:knowledgeBaseConfig>
+ <drools:ruleResources>
+ <s:value>classpath:kbasetest.drl:DRL</s:value>
+ </drools:ruleResources>
+ <drools:eventListeners>
+ <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener</s:value>
+ </drools:eventListeners>
+ </drools:KnowledgeBaseConfig>
+
+ <drools:KnowledgeBaseProducer>
+ <s:specializes />
+ <drools:produceKBase>
+ <drools-qualifier:KBase value="kbase1" />
+ <s:parameters>
+ <drools:KnowledgeBaseConfig>
+ <s:Inject />
+ <drools-qualifier:KBaseConfig value="kbaseconfig1" />
+ </drools:KnowledgeBaseConfig>
+ </s:parameters>
+ </drools:produceKBase>
+ </drools:KnowledgeBaseProducer>
+
+</beans>
\ No newline at end of file
Deleted: modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml
===================================================================
--- modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml 2010-04-02 13:38:51 UTC (rev 12372)
+++ modules/drools/trunk/core/src/test/resources/org/jboss/seam/drools/kbase/KBaseTest-beans.xml 2010-04-02 17:57:34 UTC (rev 12373)
@@ -1,35 +0,0 @@
-<beans xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:s="urn:java:seam:core"
- xmlns:drools="urn:java:org.jboss.seam.drools:org.jboss.seam.drools.config"
- xmlns:drools-qualifier="urn:java:org.jboss.seam.drools.qualifier"
- xmlns:drools-test="urn:java:org.jboss.seam.drools.kbase">
-
- <drools:KnowledgeBaseConfig>
- <s:overrides/>
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- <drools:knowledgeBuilderConfig>kbuilderconfig.properties</drools:knowledgeBuilderConfig>
- <drools:knowledgeBaseConfig>kbaseconfig.properties</drools:knowledgeBaseConfig>
- <drools:ruleResources>
- <s:value>classpath:kbasetest.drl:DRL</s:value>
- </drools:ruleResources>
- <drools:eventListeners>
- <s:value>org.drools.event.knowledgebase.DefaultKnowledgeBaseEventListener
- </s:value>
- </drools:eventListeners>
- </drools:KnowledgeBaseConfig>
-
- <drools:KnowledgeBaseProducer>
- <s:specializes />
- <drools:produceKBase>
- <drools-qualifier:KBase name="kbase1" />
- <s:parameters>
- <drools:KnowledgeBaseConfig>
- <s:Inject />
- <drools-qualifier:KBaseConfig name="kbaseconfig1" />
- </drools:KnowledgeBaseConfig>
- </s:parameters>
- </drools:produceKBase>
- </drools:KnowledgeBaseProducer>
-
-</beans>
\ No newline at end of file
14 years, 9 months
Seam SVN: r12372 - in modules/international/trunk: core and 19 other directories.
by seam-commits@lists.jboss.org
Author: kenfinni
Date: 2010-04-02 09:38:51 -0400 (Fri, 02 Apr 2010)
New Revision: 12372
Added:
modules/international/trunk/core/
modules/international/trunk/core/pom.xml
modules/international/trunk/core/src/
modules/international/trunk/core/src/main/
modules/international/trunk/core/src/main/java/
modules/international/trunk/core/src/main/java/org/
modules/international/trunk/core/src/main/java/org/jboss/
modules/international/trunk/core/src/main/java/org/jboss/seam/
modules/international/trunk/core/src/main/java/org/jboss/seam/international/
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/AvailableTimeZones.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZone.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZoneProducer.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZoneWrapper.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZones.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZone.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZoneProducer.java
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/events/
modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/events/TimeZoneSelectedEvent.java
modules/international/trunk/core/src/main/resources/
modules/international/trunk/core/src/main/resources/META-INF/
modules/international/trunk/core/src/main/resources/META-INF/beans.xml
modules/international/trunk/core/src/test/
modules/international/trunk/core/src/test/java/
modules/international/trunk/core/src/test/java/org/
modules/international/trunk/core/src/test/java/org/jboss/
modules/international/trunk/core/src/test/java/org/jboss/seam/
modules/international/trunk/core/src/test/java/org/jboss/seam/international/
modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/
modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZoneBean.java
modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZonesTest.java
modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/DefaultTimeZoneTest.java
modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/UserTimeZoneTest.java
modules/international/trunk/core/src/test/jboss-resources/
modules/international/trunk/core/src/test/jboss-resources/jndi.properties
modules/international/trunk/core/src/test/resources/
modules/international/trunk/docs/
modules/international/trunk/examples/
Removed:
modules/international/trunk/src/
Modified:
modules/international/trunk/pom.xml
Log:
Restructured International module to follow pattern of others
Property changes on: modules/international/trunk/core
___________________________________________________________________
Name: svn:ignore
+ .settings
.classpath
.project
target
Added: modules/international/trunk/core/pom.xml
===================================================================
--- modules/international/trunk/core/pom.xml (rev 0)
+++ modules/international/trunk/core/pom.xml 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,41 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.seam.international</groupId>
+ <artifactId>seam-international-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jboss.seam.international</groupId>
+ <artifactId>seam-international-core</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Seam International Core</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-embedded</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/AvailableTimeZones.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/AvailableTimeZones.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/AvailableTimeZones.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,65 @@
+package org.jboss.seam.international.timezone;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+/**
+ * <p>Seam component that provides a list of time zones, limited to time zones
+ * with IDs in the form Continent/Place, excluding deprecated three-letter time
+ * zone IDs. The time zones returned have a fixed offset from UTC, which takes
+ * daylight savings time into account. For example, Europe/Amsterdam is UTC+1;
+ * in winter this is GMT+1 and in summer GMT+2.</p>
+ *
+ * <p>The time zone objects returned are wrapped in an implementation of
+ * TimeZone that provides a more friendly interface for accessing the time zone
+ * information. In particular, this type provides a more bean-friend property
+ * for the time zone id (id than ID) and provides a convenience property named
+ * label that formats the time zone for display in the UI. This wrapper can be
+ * disabled by setting the component property wrap to false.</p>
+ *
+ * @author Peter Hilton, Lunatech Research
+ * @author Dan Allen
+ */
+@ApplicationScoped
+public class AvailableTimeZones
+{
+ private static final String TIMEZONE_ID_PREFIXES =
+ "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";
+
+ private boolean wrap = true;
+
+ @Produces
+ @TimeZones
+ private List<TimeZone> timeZones = null;
+
+ @Inject
+ public void init() {
+ timeZones = new ArrayList<TimeZone>();
+ final String[] timeZoneIds = TimeZone.getAvailableIDs();
+ for (final String id : timeZoneIds) {
+ if (id.matches(TIMEZONE_ID_PREFIXES)) {
+ timeZones.add(wrap ? new TimeZoneWrapper(TimeZone.getTimeZone(id)) : TimeZone.getTimeZone(id));
+ }
+ }
+ Collections.sort(timeZones, new Comparator<TimeZone>() {
+ public int compare(final TimeZone a, final TimeZone b) {
+ return a.getID().compareTo(b.getID());
+ }
+ });
+ }
+
+ public boolean isWrap() {
+ return wrap;
+ }
+
+ public void setWrap(boolean wrap) {
+ this.wrap = wrap;
+ }
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZone.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZone.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZone.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,27 @@
+package org.jboss.seam.international.timezone;
+
+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.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Default Application TimeZone
+ *
+ * @author Ken Finnigan
+ */
+@Target( { METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@Inherited
+public @interface DefaultTimeZone
+{
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZoneProducer.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZoneProducer.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/DefaultTimeZoneProducer.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,32 @@
+package org.jboss.seam.international.timezone;
+
+import java.io.Serializable;
+import java.util.TimeZone;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * Default TimeZone of the application. If configuration of the default
+ * TimeZone is found that will be used, otherwise the JVM default TimeZone
+ * otherwise.
+ *
+ * @author Ken Finnigan
+ */
+
+@ApplicationScoped
+public class DefaultTimeZoneProducer implements Serializable
+{
+ private static final long serialVersionUID = 6181892144731122500L;
+
+ @Produces @DefaultTimeZone @Named
+ private TimeZone defaultTimeZone;
+
+ @Inject
+ public void init()
+ {
+ defaultTimeZone = TimeZone.getDefault();
+ }
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZoneWrapper.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZoneWrapper.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZoneWrapper.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,104 @@
+package org.jboss.seam.international.timezone;
+
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * A wrapper around a TimeZone that provides a more convenience interface to
+ * access the time zone information in the UI, in particular in the options of
+ * a select menu.
+ *
+ * @author Dan Allen
+ */
+public class TimeZoneWrapper extends TimeZone
+{
+ private static final long serialVersionUID = 8504687846433050650L;
+
+ private static final int MILLISECONDS_PER_HOUR = 1000 * 60 * 60;
+
+ private TimeZone timeZone;
+
+ public TimeZoneWrapper(TimeZone tz) {
+ timeZone = tz;
+ setID(tz.getID());
+ }
+
+ @Override
+ public void setID(String id) {
+ super.setID(id);
+ timeZone = TimeZone.getTimeZone(id);
+ }
+
+ public String getId() {
+ return timeZone.getID();
+ }
+
+ public String getLabel() {
+ StringBuilder label = new StringBuilder(50);
+ label.append(getId().replace("_", " "));
+ label.append(" (UTC");
+ label.append(timeZone.getRawOffset() > 0 ? "+" : "-");
+ if (Math.abs(timeZone.getRawOffset()) < MILLISECONDS_PER_HOUR * 10) {
+ label.append("0");
+ }
+ label.append(Math.abs(timeZone.getRawOffset())/MILLISECONDS_PER_HOUR);
+ label.append(":00)");
+ return label.toString();
+ }
+
+ public TimeZone getTimeZone() {
+ return timeZone;
+ }
+
+ @Override
+ public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) {
+ return timeZone.getOffset(era, year, month, day, dayOfWeek, millis);
+ }
+
+ @Override
+ public void setRawOffset(int offset) {
+ timeZone.setRawOffset(offset);
+ }
+
+ @Override
+ public int getRawOffset() {
+ return timeZone.getRawOffset();
+ }
+
+ @Override
+ public boolean useDaylightTime() {
+ return timeZone.useDaylightTime();
+ }
+
+ @Override
+ public boolean inDaylightTime(Date date) {
+ return timeZone.inDaylightTime(date);
+ }
+
+ @Override
+ public Object clone() {
+ return timeZone.clone();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final TimeZoneWrapper other = (TimeZoneWrapper) obj;
+ if (timeZone != other.timeZone && (timeZone == null || !timeZone.equals(other.timeZone))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 79 * hash + (timeZone != null ? timeZone.hashCode() : 0);
+ return hash;
+ }
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZones.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZones.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/TimeZones.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,27 @@
+package org.jboss.seam.international.timezone;
+
+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.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Qualifier for Time Zones
+ *
+ * @author Ken Finnigan
+ */
+@Target( { METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@Inherited
+public @interface TimeZones
+{
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZone.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZone.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZone.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,27 @@
+package org.jboss.seam.international.timezone;
+
+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.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * User TimeZone
+ *
+ * @author Ken Finnigan
+ */
+@Target( { METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@Qualifier
+@Inherited
+public @interface UserTimeZone
+{
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZoneProducer.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZoneProducer.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/UserTimeZoneProducer.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,40 @@
+package org.jboss.seam.international.timezone;
+
+import java.io.Serializable;
+import java.util.TimeZone;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jboss.seam.international.timezone.events.TimeZoneSelectedEvent;
+
+/**
+ * TimeZone for a User Session. Defaults to the TimeZone within
+ * DefaultTimeZone and is altered when it receives the
+ * TimeZoneSelectedEvent.
+ *
+ * @author Ken Finnigan
+ */
+
+@SessionScoped
+public class UserTimeZoneProducer implements Serializable
+{
+ private static final long serialVersionUID = -9008203923830420841L;
+
+ @Produces @UserTimeZone @Named
+ private TimeZone userTimeZone;
+
+ @Inject
+ public void init(@DefaultTimeZone TimeZone defaultTimeZone)
+ {
+ this.userTimeZone = defaultTimeZone;
+ }
+
+ public void afterTimeZoneUpdate(@Observes TimeZoneSelectedEvent event)
+ {
+ this.userTimeZone = TimeZone.getTimeZone(event.getTimeZoneId());
+ }
+}
Added: modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/events/TimeZoneSelectedEvent.java
===================================================================
--- modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/events/TimeZoneSelectedEvent.java (rev 0)
+++ modules/international/trunk/core/src/main/java/org/jboss/seam/international/timezone/events/TimeZoneSelectedEvent.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,21 @@
+package org.jboss.seam.international.timezone.events;
+
+/**
+ * Event raised when TimeZone selected.
+ *
+ * @author Ken Finnigan
+ */
+public class TimeZoneSelectedEvent
+{
+ private String timeZoneId;
+
+ public TimeZoneSelectedEvent(String timeZoneId)
+ {
+ this.timeZoneId = timeZoneId;
+ }
+
+ public String getTimeZoneId()
+ {
+ return timeZoneId;
+ }
+}
Added: modules/international/trunk/core/src/main/resources/META-INF/beans.xml
===================================================================
Added: modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZoneBean.java
===================================================================
--- modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZoneBean.java (rev 0)
+++ modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZoneBean.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,24 @@
+package org.jboss.seam.international.timezone;
+
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+@ApplicationScoped
+public class AvailableTimeZoneBean
+{
+ @Inject
+ @TimeZones
+ private List<TimeZone> timeZones;
+
+ public AvailableTimeZoneBean()
+ {
+ }
+
+ public List<TimeZone> getAvailTimeZones()
+ {
+ return timeZones;
+ }
+}
Added: modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZonesTest.java
===================================================================
--- modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZonesTest.java (rev 0)
+++ modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/AvailableTimeZonesTest.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,52 @@
+package org.jboss.seam.international.timezone;
+
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.timezone.events.TimeZoneSelectedEvent;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class AvailableTimeZonesTest
+{
+ @Deployment
+ public static JavaArchive createTestArchive()
+ {
+ return Archives.create("availabletimezonetest.jar", JavaArchive.class).addClasses(AvailableTimeZones.class, AvailableTimeZoneBean.class, TimeZoneWrapper.class, TimeZoneSelectedEvent.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ Instance<AvailableTimeZoneBean> availBean;
+ @Inject
+ @TimeZones
+ List<TimeZone> timeZones;
+
+ @Test
+ public void testAvailableTimeZonesProducerViaBean()
+ {
+ Assert.assertNotNull(availBean);
+ List<TimeZone> list = availBean.get().getAvailTimeZones();
+ Assert.assertNotNull(list);
+ Assert.assertTrue(!list.isEmpty());
+ Assert.assertTrue(list.size() > 0);
+ }
+
+ @Test
+ public void testAvailableTimeZonesProducerDirect()
+ {
+ Assert.assertNotNull(timeZones);
+ Assert.assertTrue(!timeZones.isEmpty());
+ Assert.assertTrue(timeZones.size() > 0);
+ }
+}
Added: modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/DefaultTimeZoneTest.java
===================================================================
--- modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/DefaultTimeZoneTest.java (rev 0)
+++ modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/DefaultTimeZoneTest.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,35 @@
+package org.jboss.seam.international.timezone;
+
+import java.util.TimeZone;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class DefaultTimeZoneTest
+{
+ @Deployment
+ public static JavaArchive createTestArchive()
+ {
+ return Archives.create("defaulttimezonetest.jar", JavaArchive.class).addClasses(DefaultTimeZoneProducer.class, DefaultTimeZone.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ @DefaultTimeZone
+ TimeZone timeZone;
+
+ @Test
+ public void testDefaultTimeZoneProducerDirect()
+ {
+ Assert.assertNotNull(timeZone);
+ }
+}
Added: modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/UserTimeZoneTest.java
===================================================================
--- modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/UserTimeZoneTest.java (rev 0)
+++ modules/international/trunk/core/src/test/java/org/jboss/seam/international/timezone/UserTimeZoneTest.java 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,55 @@
+package org.jboss.seam.international.timezone;
+
+import java.util.TimeZone;
+
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.timezone.events.TimeZoneSelectedEvent;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class UserTimeZoneTest
+{
+ @Deployment
+ public static JavaArchive createTestArchive()
+ {
+ return Archives.create("usertimezonetest.jar", JavaArchive.class).addClasses(UserTimeZoneProducer.class, UserTimeZone.class, TimeZoneSelectedEvent.class, DefaultTimeZone.class, DefaultTimeZoneProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject
+ @UserTimeZone
+ TimeZone timeZone;
+ @Inject
+ Event<TimeZoneSelectedEvent> timeZoneEvent;
+ @Inject
+ @UserTimeZone
+ Instance<TimeZone> timeZoneSource;
+
+ @Test
+ public void testUserTimeZoneProducerDirect()
+ {
+ Assert.assertNotNull(timeZone);
+ }
+
+ @Test
+ public void testUserTimeZoneEvent()
+ {
+ TimeZone tijuana = TimeZone.getTimeZone("America/Tijuana");
+ Assert.assertNotNull(timeZone);
+ Assert.assertFalse(timeZone.equals(tijuana));
+ timeZoneEvent.fire(new TimeZoneSelectedEvent("America/Tijuana"));
+ TimeZone tz = timeZoneSource.get();
+ Assert.assertNotNull(tz);
+ Assert.assertTrue(tz.equals(tijuana));
+ }
+}
Added: modules/international/trunk/core/src/test/jboss-resources/jndi.properties
===================================================================
--- modules/international/trunk/core/src/test/jboss-resources/jndi.properties (rev 0)
+++ modules/international/trunk/core/src/test/jboss-resources/jndi.properties 2010-04-02 13:38:51 UTC (rev 12372)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+java.naming.provider.url=jnp://localhost:1099
Modified: modules/international/trunk/pom.xml
===================================================================
--- modules/international/trunk/pom.xml 2010-04-02 08:49:51 UTC (rev 12371)
+++ modules/international/trunk/pom.xml 2010-04-02 13:38:51 UTC (rev 12372)
@@ -1,53 +1,90 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
-
+
<parent>
<artifactId>seam-parent</artifactId>
<groupId>org.jboss.seam</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
+ <groupId>org.jboss.seam.international</groupId>
+ <artifactId>seam-international-parent</artifactId>
+ <packaging>pom</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>Seam International Parent</name>
+
+ <modules>
+ <module>core</module>
+ <!--module>docs</module-->
+ <!--module>examples/??</module-->
+ </modules>
+
<properties>
<arquillian.version>1.0.0.Alpha1</arquillian.version>
</properties>
- <artifactId>seam-international</artifactId>
- <packaging>jar</packaging>
- <version>3.0.0-SNAPSHOT</version>
- <name>Seam Internationalization Module</name>
+ <dependencyManagement>
+ <dependencies>
- <dependencies>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>2.2</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>1.0.0.GA</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.0-SP1</version>
+ </dependency>
- <dependency>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- <version>1.0-SP1</version>
- </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.10</version>
+ <scope>provided</scope>
+ </dependency>
- <dependency>
- <groupId>org.jboss.arquillian</groupId>
- <artifactId>arquillian-junit</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <version>${arquillian.version}</version>
+ <scope>test</scope>
+ </dependency>
- <dependency>
- <groupId>org.jboss.arquillian.container</groupId>
- <artifactId>arquillian-weld-embedded</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-embedded</artifactId>
+ <version>${arquillian.version}</version>
+ <scope>test</scope>
+ </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.8.1</version>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
- </dependencies>
-
+ </dependencies>
+ </dependencyManagement>
+
<scm>
<connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/international/trunk</connection>
<developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/international/trunk</developerConnection>
14 years, 9 months