commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1133168 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
Date Tue, 07 Jun 2011 21:47:55 GMT
Author: mbenson
Date: Tue Jun  7 21:47:55 2011
New Revision: 1133168

URL: http://svn.apache.org/viewvc?rev=1133168&view=rev
Log:
add an optional NodePointerFactory whose (indirectly) returned PropertyPointers are 'strict'
for LazyDynaBeans (JXPathNotFoundException on unset lazy properties)

Added:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java
  (with props)
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
  (with props)

Added: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java?rev=1133168&view=auto
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java
(added)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java
Tue Jun  7 21:47:55 2011
@@ -0,0 +1,76 @@
+package org.apache.commons.jxpath.ri.model.dynabeans;
+
+import java.util.Locale;
+
+import org.apache.commons.beanutils.LazyDynaBean;
+import org.apache.commons.beanutils.LazyDynaClass;
+import org.apache.commons.jxpath.ri.QName;
+import org.apache.commons.jxpath.ri.model.NodePointer;
+import org.apache.commons.jxpath.ri.model.NodePointerFactory;
+import org.apache.commons.jxpath.ri.model.beans.PropertyPointer;
+
+/**
+ * Implemented in response to [JXPATH-144]. Optionally pluggable
+ * <code>NodePointerFactory</code> that returns a special type of
+ * <code>NodePointer</code> for <code>LazyDynaBean</code>s. The
+ * <code>PropertyPointer</code>s returned by these will respect
+ * {@link LazyDynaClass#isDynaProperty(String)} when determining
+ * {@link PropertyPointer#isActual()}
+ */
+public class StrictLazyDynaBeanPointerFactory implements NodePointerFactory {
+    private static class StrictLazyDynaBeanPointer extends DynaBeanPointer {
+        private static final long serialVersionUID = 1L;
+
+        private final LazyDynaBean lazyDynaBean;
+
+        /**
+         * Create a new StrictLazyDynaBeanPointer instance.
+         * 
+         * @param parent
+         * @param name
+         * @param lazyDynaBean
+         */
+        public StrictLazyDynaBeanPointer(NodePointer parent, QName name, LazyDynaBean lazyDynaBean)
{
+            super(parent, name, lazyDynaBean);
+            this.lazyDynaBean = lazyDynaBean;
+        }
+
+        /**
+         * Create a new StrictLazyDynaBeanPointer instance.
+         * 
+         * @param name
+         * @param lazyDynaBean
+         * @param locale
+         */
+        public StrictLazyDynaBeanPointer(QName name, LazyDynaBean lazyDynaBean, Locale locale)
{
+            super(name, lazyDynaBean, locale);
+            this.lazyDynaBean = lazyDynaBean;
+        }
+
+        public PropertyPointer getPropertyPointer() {
+            return new DynaBeanPropertyPointer(this, lazyDynaBean) {
+                private static final long serialVersionUID = 1L;
+
+                protected boolean isActualProperty() {
+                    return ((LazyDynaClass) lazyDynaBean.getDynaClass())
+                            .isDynaProperty(getPropertyName());
+                }
+            };
+        }
+    }
+
+    public int getOrder() {
+        return DynaBeanPointerFactory.DYNA_BEAN_POINTER_FACTORY_ORDER - 1;
+    }
+
+    public NodePointer createNodePointer(QName name, Object object, Locale locale) {
+        return object instanceof LazyDynaBean ? new StrictLazyDynaBeanPointer(name,
+                (LazyDynaBean) object, locale) : null;
+    }
+
+    public NodePointer createNodePointer(NodePointer parent, QName name, Object object) {
+        return object instanceof LazyDynaBean ? new StrictLazyDynaBeanPointer(parent, name,
+                (LazyDynaBean) object) : null;
+    }
+
+}

Propchange: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dynabeans/StrictLazyDynaBeanPointerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java?rev=1133168&view=auto
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
(added)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
Tue Jun  7 21:47:55 2011
@@ -0,0 +1,26 @@
+package org.apache.commons.jxpath.ri.model.dynabeans;
+
+import org.apache.commons.beanutils.LazyDynaBean;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathNotFoundException;
+import org.apache.commons.jxpath.JXPathTestCase;
+import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
+
+public class LazyDynaBeanTest extends JXPathTestCase {
+
+    public void testLazyProperty() throws JXPathNotFoundException {
+        LazyDynaBean bean = new LazyDynaBean();
+        JXPathContext context = JXPathContext.newContext(bean);
+        context.getValue("nosuch");
+    }
+
+    public void testStrictLazyDynaBeanPropertyFactory() {
+        JXPathContextReferenceImpl.addNodePointerFactory(new StrictLazyDynaBeanPointerFactory());
+        try {
+            testLazyProperty();
+            fail();
+        } catch (JXPathNotFoundException e) {
+            //okay
+        }
+    }
+}

Propchange: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/dynabeans/LazyDynaBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message