incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1073987 - in /incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic: DynamicMetaGraphManagerImpl.java DynamicModelManager.java DynamicValidatorFactory.java Timestamped.java
Date Wed, 23 Feb 2011 23:32:26 GMT
Author: mbenson
Date: Wed Feb 23 23:32:26 2011
New Revision: 1073987

URL: http://svn.apache.org/viewvc?rev=1073987&view=rev
Log:
carry timestamps throughout the meta-graph

Modified:
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModelManager.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorFactory.java
    incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/Timestamped.java

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java?rev=1073987&r1=1073986&r2=1073987&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicMetaGraphManagerImpl.java
Wed Feb 23 23:32:26 2011
@@ -42,6 +42,7 @@ import org.apache.bval.MetaBeanFinder;
 import org.apache.bval.jsr303.AnnotationProcessor;
 import org.apache.bval.jsr303.AppendValidationToMeta;
 import org.apache.bval.jsr303.UnknownPropertyException;
+import org.apache.bval.jsr303.dynamic.Timestamped.Context.Bean;
 import org.apache.bval.jsr303.util.ClassHelper;
 import org.apache.bval.jsr303.util.NodeImpl;
 import org.apache.bval.jsr303.util.PathImpl;
@@ -512,7 +513,7 @@ final class DynamicMetaGraphManagerImpl 
                 if (dynamicBeanInfo.containsKey(type)) {
                     return dynamicBeanInfo.get(type);
                 }
-                MetaBean result = timeContext.new Bean();
+                MetaBean result = new Bean(timeContext);
                 result.setBeanClass(type);
                 MetaBean faster = dynamicBeanInfo.putIfAbsent(type, result);
                 return faster == null ? result : faster;

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModelManager.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModelManager.java?rev=1073987&r1=1073986&r2=1073987&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModelManager.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicModelManager.java
Wed Feb 23 23:32:26 2011
@@ -125,7 +125,7 @@ public class DynamicModelManager {
             result = createMetaProperty(metaBean);
             result.setName(name);
             result.setType(new PropertyAccess(metaBean.getBeanClass(), name).getJavaType());
-            MetaBean propertyBean = createMetaBean();
+            MetaBean propertyBean = createPropertyMetaBean(result);
             propertyBean.setBeanClass(result.getTypeClass());
             result.setMetaBean(propertyBean);
             metaBean.putProperty(name, result);
@@ -144,15 +144,7 @@ public class DynamicModelManager {
     public MetaContainer<?> getRequiredContainer(FeaturesCapable meta) {
         MetaContainer<?> result = meta.getFeature(META_CONTAINER);
         if (result == null) {
-            Type type =
-                meta instanceof MetaProperty ? ((MetaProperty) meta).getType() : ((MetaBean)
meta).getBeanClass();
-            if (KeyedAccess.getJavaElementType(type) != null) {
-                result = createKeyedContainer(type);
-            } else if (IndexedAccess.getJavaElementType(type) != null) {
-                result = createIndexedContainer(type);
-            } else {
-                throw new IllegalArgumentException(String.format("don't know how to make
a container of %s", meta));
-            }
+            result = createContainer(meta);
             meta.putFeature(META_CONTAINER, result);
         }
         return result;
@@ -384,36 +376,72 @@ public class DynamicModelManager {
     }
 
     /**
-     * {@inheritDoc}
+     * Create a {@link MetaProperty} for <code>owner</code>.
+     * 
+     * @param owner
+     * @return MetaProperty
      */
     protected MetaProperty createMetaProperty(MetaBean owner) {
         return new MetaProperty();
     }
 
     /**
-     * {@inheritDoc}
+     * Create a {@link MetaBean}.
+     * 
+     * @return MetaBean
      */
     protected MetaBean createMetaBean() {
         return new MetaBean();
     }
 
     /**
-     * {@inheritDoc}
+     * Create a {@link MetaBean} to be assigned to a {@link MetaProperty}. 
+     * @param owner
+     * @return MetaBean
+     */
+    protected MetaBean createPropertyMetaBean(MetaProperty owner) {
+        return createMetaBean();
+    }
+
+    /**
+     * Create the appropriate {@link MetaContainer} for the specified meta-node.
+     * @param owner
+     * @return MetaContainer
      */
-    protected MetaContainer<Object> createKeyedContainer(Type type) {
-        return new MetaMap(type);
+    protected MetaContainer<?> createContainer(FeaturesCapable owner) {
+        Type type = getType(owner);
+        if (KeyedAccess.getJavaElementType(type) != null) {
+            return new MetaMap(type);
+        }
+        if (IndexedAccess.getJavaElementType(type) != null) {
+            return new MetaCollection(type);
+        }
+        throw new IllegalArgumentException(String.format("don't know how to make a container
of %s", owner));
     }
 
     /**
-     * {@inheritDoc}
+     * Get generic type information for the specified meta-node.
+     * 
+     * @param meta
+     * @return Type found
+     * @throws IllegalArgumentException
+     *             if <code>meta</code> is neither {@link MetaBean} nor {@link
MetaProperty}.
      */
-    protected MetaContainer<Integer> createIndexedContainer(Type type) {
-        return new MetaCollection(type);
+    protected Type getType(FeaturesCapable meta) {
+        if (meta instanceof MetaBean) {
+            return ((MetaBean) meta).getBeanClass();
+        }
+        if (meta instanceof MetaProperty) {
+            return ((MetaProperty) meta).getType();
+        }
+        throw new IllegalArgumentException(String.format("Cannot calculate type for %s",
meta));
     }
 
     /**
+     * Create the dynamic constraints collection for the specified meta-node.
      * 
-     * {@inheritDoc}
+     * @param owner
+     * @return Collection of Annotation
      */
     protected Collection<Annotation> createDynamicConstraintsCollection(FeaturesCapable
owner) {
         return Collections.synchronizedList(new ArrayList<Annotation>());

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorFactory.java?rev=1073987&r1=1073986&r2=1073987&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorFactory.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/DynamicValidatorFactory.java
Wed Feb 23 23:32:26 2011
@@ -28,6 +28,7 @@ import org.apache.bval.MetaBeanFinder;
 import org.apache.bval.MetaBeanManager;
 import org.apache.bval.jsr303.ApacheFactoryContext;
 import org.apache.bval.jsr303.ApacheValidatorFactory;
+import org.apache.bval.jsr303.dynamic.Timestamped.Context.Bean;
 import org.apache.bval.jsr303.xml.MetaConstraint;
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.util.AccessStrategy;
@@ -72,7 +73,7 @@ public class DynamicValidatorFactory ext
          */
         @Override
         public MetaBean buildForClass(Class<?> clazz) throws Exception {
-            final MetaBean result = timeContext == null ? new MetaBean() : timeContext.new
Bean();
+            final MetaBean result = timeContext == null ? new MetaBean() : new Bean(timeContext);
             if (clazz != null) { // local class here?
                 result.setBeanClass(clazz);
                 result.setId(clazz.getName()); // default id = full class name!
@@ -159,10 +160,10 @@ public class DynamicValidatorFactory ext
         if (cached != null) {
             cache.removeFromCache(cached);
         } else if (timeContext == null) {
-            //if there is no timeContext, don't create it on account of a noop cache removal:
+            // if there is no timeContext, don't create it on account of a noop cache removal:
             return;
         }
-        //double read to avoid unnecessary synchronization:
+        // double read to avoid unnecessary synchronization:
         if (timeContext == null) {
             synchronized (this) {
                 if (timeContext == null) {

Modified: incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/Timestamped.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/Timestamped.java?rev=1073987&r1=1073986&r2=1073987&view=diff
==============================================================================
--- incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/Timestamped.java
(original)
+++ incubator/bval/sandbox/lang3-work/bval-jsr303d/src/main/java/org/apache/bval/jsr303/dynamic/Timestamped.java
Wed Feb 23 23:32:26 2011
@@ -38,6 +38,8 @@ import org.apache.bval.model.FeaturesCap
 import org.apache.bval.model.MetaBean;
 import org.apache.bval.model.MetaProperty;
 import org.apache.bval.model.Validation;
+import org.apache.bval.util.IndexedAccess;
+import org.apache.bval.util.KeyedAccess;
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.ObjectUtils;
 
@@ -396,6 +398,7 @@ interface Timestamped {
         /**
          * {@inheritDoc}
          */
+        @Override
         protected MetaProperty createMetaProperty(MetaBean owner) {
             return owner instanceof Bean ? ((Bean) owner).new Property() : super.createMetaProperty(owner);
         }
@@ -403,27 +406,38 @@ interface Timestamped {
         /**
          * {@inheritDoc}
          */
+        @Override
         protected MetaBean createMetaBean() {
-            return new Bean();
+            return new Bean(this);
         }
 
         /**
          * {@inheritDoc}
          */
-        protected MetaContainer<Object> createKeyedContainer(Type type) {
-            return new AwareMap(type);
+        @Override
+        protected MetaBean createPropertyMetaBean(MetaProperty owner) {
+            return new Bean(owner);
         }
 
         /**
          * {@inheritDoc}
          */
-        protected MetaContainer<Integer> createIndexedContainer(Type type) {
-            return new AwareCollection(type);
+        @Override
+        protected MetaContainer<?> createContainer(FeaturesCapable owner) {
+            Type type = getType(owner);
+            if (KeyedAccess.getJavaElementType(type) != null) {
+                return new AwareMap(type, owner);
+            }
+            if (IndexedAccess.getJavaElementType(type) != null) {
+                return new AwareCollection(type, owner);
+            }
+            throw new IllegalArgumentException(String.format("don't know how to make a container
of %s", owner));
         }
 
         /**
          * {@inheritDoc}
          */
+        @Override
         protected Collection<Annotation> createDynamicConstraintsCollection(FeaturesCapable
owner) {
             Timestamped t = null;
             if (owner instanceof Timestamped) {
@@ -441,7 +455,7 @@ interface Timestamped {
         /**
          * {@link Timestamped} {@link MetaBean}.
          */
-        class Bean extends MetaBean implements Timestamped, CacheMeta<MetaBean> {
+        static class Bean extends MetaBean implements Timestamped, CacheMeta<MetaBean>
{
 
             private static final long serialVersionUID = 1L;
 
@@ -484,11 +498,17 @@ interface Timestamped {
             }
 
             private volatile long millis;
-
+            private final Object owner;
             private transient MetaBean cached;
 
-            {
-                touch();
+            /**
+             * Create a new Bean instance.
+             * 
+             * @param owner
+             */
+            Bean(Object owner) {
+                super();
+                this.owner = owner;
             }
 
             /**
@@ -502,8 +522,8 @@ interface Timestamped {
              * {@inheritDoc}
              */
             public void touch() {
-                Context.this.touch();
-                this.millis = Context.this.millis;
+                Timestamped.Utils.touch(owner);
+                this.millis = Timestamped.Utils.read(owner);
             }
 
             /**
@@ -670,14 +690,17 @@ interface Timestamped {
          */
         class AwareCollection extends MetaCollection {
             private final AwareContainerHelper helper = new AwareContainerHelper();
+            private final Object owner;
 
             /**
              * Create a new AwareCollection instance.
              * 
              * @param type
+             * @param owner
              */
-            public AwareCollection(Type type) {
+            private AwareCollection(Type type, Object owner) {
                 super(type);
+                this.owner = owner;
             }
 
             /**
@@ -694,7 +717,7 @@ interface Timestamped {
              */
             @Override
             protected MetaBean createMetaBean() {
-                return Context.this.new Bean();
+                return new Bean(owner);
             }
 
         }
@@ -704,14 +727,17 @@ interface Timestamped {
          */
         class AwareMap extends MetaMap {
             private final AwareContainerHelper helper = new AwareContainerHelper();
+            private final FeaturesCapable owner;
 
             /**
              * Create a new AwareMap instance.
              * 
              * @param type
+             * @param owner
              */
-            public AwareMap(Type type) {
+            private AwareMap(Type type, FeaturesCapable owner) {
                 super(type);
+                this.owner = owner;
             }
 
             /**
@@ -729,7 +755,7 @@ interface Timestamped {
              */
             @Override
             protected MetaBean createMetaBean() {
-                return Context.this.new Bean();
+                return new Bean(owner);
             }
 
         }
@@ -788,5 +814,16 @@ interface Timestamped {
         public static long read(Object o) {
             return o instanceof Timestamped ? ((Timestamped) o).millis() : Long.MIN_VALUE;
         }
+
+        /**
+         * Call {@link Timestamped#touch()} against a {@link Timestamped} argument.
+         * 
+         * @param o
+         */
+        public static void touch(Object o) {
+            if (o instanceof Timestamped) {
+                ((Timestamped) o).touch();
+            }
+        }
     }
 }



Mime
View raw message