Replace validators code duplications with macro

The code implementing the functionality of caching validators
and getting them was duplicated all over the validator classes.
These duplications are now replaced by a respective macro defined
in the validators base class.

Change-Id: I3d44811b75159b48769a65f37e14c6ea99f434d0

git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1679584 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorBoolean.h b/binding-cpp/runtime/include/serialization/EtchValidatorBoolean.h
index aea4b4d..d8aecaf 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorBoolean.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorBoolean.h
@@ -58,17 +58,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorBoolean(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 };
 
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorByte.h b/binding-cpp/runtime/include/serialization/EtchValidatorByte.h
index b282c21..89b7c3b 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorByte.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorByte.h
@@ -62,17 +62,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorByte(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
   
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h b/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h
index 3570da1..f619fe6 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h
@@ -60,17 +60,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorDouble(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h b/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h
index ba4bddf..f44bc3c 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h
@@ -59,17 +59,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorFloat(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorInt.h b/binding-cpp/runtime/include/serialization/EtchValidatorInt.h
index 1a8e9a4..08a5223 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorInt.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorInt.h
@@ -63,19 +63,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
-
-
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorInt(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorLong.h b/binding-cpp/runtime/include/serialization/EtchValidatorLong.h
index fa734e0..4cdb1a5 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorLong.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorLong.h
@@ -61,17 +61,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorLong(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorNone.h b/binding-cpp/runtime/include/serialization/EtchValidatorNone.h
index 7408478..cf69774 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorNone.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorNone.h
@@ -63,7 +63,7 @@
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorObject.h b/binding-cpp/runtime/include/serialization/EtchValidatorObject.h
index 0bec1be..2e88549 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorObject.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorObject.h
@@ -57,17 +57,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorObject(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorRuntimeException.h b/binding-cpp/runtime/include/serialization/EtchValidatorRuntimeException.h
index a3904c7..b934c3c 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorRuntimeException.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorRuntimeException.h
@@ -66,7 +66,7 @@
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 };
 
 #endif
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorShort.h b/binding-cpp/runtime/include/serialization/EtchValidatorShort.h
index 14b49fe..dbb3447 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorShort.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorShort.h
@@ -62,10 +62,7 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
 
@@ -73,7 +70,7 @@
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/include/serialization/EtchValidatorString.h b/binding-cpp/runtime/include/serialization/EtchValidatorString.h
index 0885713..f059163 100644
--- a/binding-cpp/runtime/include/serialization/EtchValidatorString.h
+++ b/binding-cpp/runtime/include/serialization/EtchValidatorString.h
@@ -58,17 +58,14 @@
    */
   virtual status_t validateValue(capu::SmartPointer<EtchObject> value, capu::SmartPointer<EtchObject>& result);
 
-  /**
-   * @see EtchValidator
-   */
-  static status_t Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+  VALIDATOR_GET_DEF()
 
 protected:
   EtchValidatorString(EtchRuntime* runtime, capu::uint32_t ndim);
 
 private:
   EtchRuntime* mRuntime;
-  static capu::SmartPointer<EtchValidator>* Validators(EtchRuntime* runtime);
+  VALIDATOR_CACHE_DEF()
 
 };
 
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorBoolean.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorBoolean.cpp
index bad77ce..ecfcdfc 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorBoolean.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorBoolean.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorBoolean.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorBoolean::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorBoolean)
 
 const EtchObjectType* EtchValidatorBoolean::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_BOOLEAN, NULL);
@@ -76,23 +73,9 @@
   }
 }
 
-status_t EtchValidatorBoolean::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorBoolean(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorBoolean(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorBoolean has been created");
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorBoolean::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorBoolean::Get(mRuntime, mNDims - 1, val);
 }
 
+VALIDATOR_GET_IMPL(EtchValidatorBoolean)
+
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp
index 92ca44e..b80a7c7 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorByte.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorByte::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorByte)
 
 const EtchObjectType* EtchValidatorByte::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_BYTE, NULL);
@@ -120,23 +117,8 @@
   }
 }
 
-status_t EtchValidatorByte::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorByte(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorByte(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorByte has been created");
-
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorByte::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorByte::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorByte)
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp
index d10a6e5..2d6e1a5 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp
@@ -19,10 +19,8 @@
 #include "serialization/EtchValidatorDouble.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorDouble::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorDouble)
+
 const EtchObjectType* EtchValidatorDouble::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_DOUBLE, NULL);
   return &TYPE;
@@ -74,22 +72,8 @@
   }
 }
 
-status_t EtchValidatorDouble::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorDouble(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorDouble(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorDouble has been created");
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorDouble::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorDouble::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorDouble)
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp
index e0c01ed..72fc19e 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorFloat.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorFloat::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorFloat)
 
 const EtchObjectType* EtchValidatorFloat::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_FLOAT, NULL);
@@ -74,22 +71,8 @@
   }
 }
 
-status_t EtchValidatorFloat::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorFloat(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorFloat(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorFloat has been created");
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorFloat::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorFloat::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorFloat)
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorInt.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorInt.cpp
index 756f62d..07183a6 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorInt.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorInt.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorInt.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorInt::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorInt)
 
 const EtchObjectType* EtchValidatorInt::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_INT, NULL);
@@ -112,22 +109,8 @@
   }
 }
 
-status_t EtchValidatorInt::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorInt(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorInt(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorInt has been created");
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorInt::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorInt::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorInt)
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp
index 0bc9ff2..33b5566 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorLong.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorLong::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorLong)
 
 const EtchObjectType* EtchValidatorLong::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_LONG, NULL);
@@ -105,22 +102,8 @@
   }
 }
 
-status_t EtchValidatorLong::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorLong(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorLong(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorLong has been created");
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorLong::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorLong::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorLong)
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorNone.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorNone.cpp
index a6005f6..48fb6da 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorNone.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorNone.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorNone.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorNone::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorNone)
 
 const EtchObjectType* EtchValidatorNone::TYPE() {
   static const EtchObjectType TYPE(EOTID_VALIDATOR_NONE, NULL);
@@ -59,6 +56,7 @@
 status_t EtchValidatorNone::Get(EtchRuntime* runtime, capu::SmartPointer<EtchValidator> &val) {
   if (Validators(runtime)[0].get() == NULL) {
     Validators(runtime)[0] = new EtchValidatorNone(runtime);
+    runtime->registerListener(&SRuntimeChangedListener);
     ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorNone has been created");
   }
   val = Validators(runtime)[0];
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp
index f884846..1fdbc89 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorObject.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorObject::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorObject)
 
 const EtchObjectType* EtchValidatorObject::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_OBJECT, NULL);
@@ -63,22 +60,6 @@
   }
 }
 
-status_t EtchValidatorObject::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS)
-    return ETCH_EINVAL;
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorObject(runtime, ndim);
-    return ETCH_OK;
-  }
-  //TODO thread safety
-  if (Validators(runtime)[ndim].get() == NULL) {
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorObject has been created");
-    Validators(runtime)[ndim] = new EtchValidatorObject(runtime, ndim);
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorObject::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   if (mNDims > 0) {
     return EtchValidatorObject::Get(mRuntime, mNDims - 1, val);
@@ -86,3 +67,8 @@
     return EtchValidatorObject::Get(mRuntime, 0, val);
   }
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorObject)
+
+
+
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorRuntimeException.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorRuntimeException.cpp
index bd0b034..5761334 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorRuntimeException.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorRuntimeException.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorRuntimeException.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorRuntimeException::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorRuntimeException)
 
 const EtchObjectType* EtchValidatorRuntimeException::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_RUNTIME_EXCEPTION, NULL);
@@ -61,6 +58,7 @@
 status_t EtchValidatorRuntimeException::Get(EtchRuntime* runtime, capu::SmartPointer<EtchValidator> &val) {
   if (Validators(runtime)[0].get() == NULL) {
     Validators(runtime)[0] = new EtchValidatorRuntimeException(runtime);
+    runtime->registerListener(&SRuntimeChangedListener);
     ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(),"EtchValidatorRuntimeException has been created");
   }
   val = Validators(runtime)[0];
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorShort.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorShort.cpp
index fb3fb28..d8bdc58 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorShort.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorShort.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorShort.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorShort::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorShort)
 
 const EtchObjectType* EtchValidatorShort::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_SHORT, NULL);
@@ -114,22 +111,8 @@
   }
 }
 
-status_t EtchValidatorShort::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorShort(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorShort has been created");
-    Validators(runtime)[ndim] = new EtchValidatorShort(runtime, ndim);
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorShort::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorShort::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorShort)
diff --git a/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp b/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp
index 706af3c..0346ced 100644
--- a/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp
+++ b/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp
@@ -19,10 +19,7 @@
 #include "serialization/EtchValidatorString.h"
 #include "support/EtchRuntime.h"
 
-capu::SmartPointer<EtchValidator>* EtchValidatorString::Validators(EtchRuntime* runtime) {
-  static EtchValidatorCaches validators;
-  return validators.get(runtime);
-}
+VALIDATOR_CACHE_IMPL(EtchValidatorString)
 
 const EtchObjectType* EtchValidatorString::TYPE() {
   const static EtchObjectType TYPE(EOTID_VALIDATOR_STRING, NULL);
@@ -72,22 +69,8 @@
   }
 }
 
-status_t EtchValidatorString::Get(EtchRuntime* runtime, capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
-  if (ndim > MAX_NDIMS) {
-    return ETCH_EINVAL;
-  }
-  if (ndim >= MAX_CACHED) {
-    val = new EtchValidatorString(runtime, ndim);
-    return ETCH_OK;
-  }
-  if (Validators(runtime)[ndim].get() == NULL) {
-    Validators(runtime)[ndim] = new EtchValidatorString(runtime, ndim);
-    ETCH_LOG_TRACE(runtime->getLogger(), runtime->getLogger().getValidatorContext(), "EtchValidatorString has been created");
-  }
-  val = Validators(runtime)[ndim];
-  return ETCH_OK;
-}
-
 status_t EtchValidatorString::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
   return EtchValidatorString::Get(mRuntime, mNDims - 1, val);
 }
+
+VALIDATOR_GET_IMPL(EtchValidatorString)