public ConfigurationBuilder read(Configuration template) {
    this.classLoader = new WeakReference<ClassLoader>(template.classLoader());
    this.clustering.read(template.clustering());
    this.customInterceptors.read(template.customInterceptors());
    this.dataContainer.read(template.dataContainer());
    this.deadlockDetection.read(template.deadlockDetection());
    this.eviction.read(template.eviction());
    this.expiration.read(template.expiration());
    this.indexing.read(template.indexing());
    this.invocationBatching.read(template.invocationBatching());
    this.jmxStatistics.read(template.jmxStatistics());
    this.persistence.read(template.persistence());
    this.locking.read(template.locking());
    this.storeAsBinary.read(template.storeAsBinary());
    this.transaction.read(template.transaction());
    this.unsafe.read(template.unsafe());
    this.sites.read(template.sites());
    this.versioning.read(template.versioning());
    this.compatibility.read(template.compatibility());

    for (Object c : template.modules().values()) {
      Builder<Object> builder = this.addModule(ConfigurationUtils.builderFor(c));
      builder.read(c);
    }

    return this;
  }
 public Configuration build(boolean validate) {
   if (validate) {
     validate();
   }
   List<Object> modulesConfig = new LinkedList<Object>();
   for (Builder<?> module : modules) modulesConfig.add(module.create());
   return new Configuration(
       clustering.create(),
       customInterceptors.create(),
       dataContainer.create(),
       deadlockDetection.create(),
       eviction.create(),
       expiration.create(),
       indexing.create(),
       invocationBatching.create(),
       jmxStatistics.create(),
       persistence.create(),
       locking.create(),
       storeAsBinary.create(),
       transaction.create(),
       unsafe.create(),
       versioning.create(),
       sites.create(),
       compatibility.create(),
       modulesConfig,
       classLoader == null ? null : classLoader.get());
 }
  @SuppressWarnings("unchecked")
  public void validate() {
    for (Builder<?> validatable :
        asList(
            clustering,
            customInterceptors,
            dataContainer,
            deadlockDetection,
            eviction,
            expiration,
            indexing,
            invocationBatching,
            jmxStatistics,
            persistence,
            locking,
            storeAsBinary,
            transaction,
            versioning,
            unsafe,
            sites,
            compatibility)) {
      validatable.validate();
    }
    for (Builder<?> m : modules) {
      m.validate();
    }

    // TODO validate that a transport is set if a singleton store is set
  }
 @Override
 public GlobalConfiguration build() {
   validate();
   List<Object> modulesConfig = new LinkedList<Object>();
   for (Builder<?> module : modules) modulesConfig.add(module.create());
   return new GlobalConfiguration(
       asyncListenerExecutor.create(),
       asyncTransportExecutor.create(),
       remoteCommandsExecutor.create(),
       evictionScheduledExecutor.create(),
       replicationQueueScheduledExecutor.create(),
       globalJmxStatistics.create(),
       transport.create(),
       serialization.create(),
       shutdown.create(),
       modulesConfig,
       site.create(),
       cl.get(),
       totalOrderExecutor.create());
 }
 @SuppressWarnings("unchecked")
 public void validate() {
   for (AbstractGlobalConfigurationBuilder<?> validatable :
       asList(
           asyncListenerExecutor,
           asyncTransportExecutor,
           remoteCommandsExecutor,
           evictionScheduledExecutor,
           replicationQueueScheduledExecutor,
           globalJmxStatistics,
           transport,
           serialization,
           shutdown,
           site,
           totalOrderExecutor)) {
     validatable.validate();
   }
   for (Builder<?> m : modules) {
     m.validate();
   }
 }
  public GlobalConfigurationBuilder read(GlobalConfiguration template) {
    this.cl = new WeakReference<ClassLoader>(template.classLoader());

    for (Object c : template.modules().values()) {
      BuiltBy builtBy = c.getClass().getAnnotation(BuiltBy.class);
      Builder<Object> builder = (Builder<Object>) this.addModule(builtBy.value());
      builder.read(c);
    }

    asyncListenerExecutor.read(template.asyncListenerExecutor());
    asyncTransportExecutor.read(template.asyncTransportExecutor());
    remoteCommandsExecutor.read(template.remoteCommandsExecutor());
    evictionScheduledExecutor.read(template.evictionScheduledExecutor());
    globalJmxStatistics.read(template.globalJmxStatistics());
    replicationQueueScheduledExecutor.read(template.replicationQueueScheduledExecutor());
    serialization.read(template.serialization());
    shutdown.read(template.shutdown());
    transport.read(template.transport());
    site.read(template.sites());
    totalOrderExecutor.read(template.totalOrderExecutor());
    return this;
  }