You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2017/06/04 10:20:28 UTC

[1/4] polygene-java git commit: More documentation

Repository: polygene-java
Updated Branches:
  refs/heads/develop e21738bb2 -> 05ddab16a


More documentation

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/14125f65
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/14125f65
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/14125f65

Branch: refs/heads/develop
Commit: 14125f658eb461843f25f1f0f08811e42dcee68a
Parents: e21738b
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 4 17:23:52 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 4 17:23:52 2017 +0800

----------------------------------------------------------------------
 core/api/src/docs/api.txt                       |   2 +-
 core/api/src/docs/composition.txt               |  10 +-
 core/api/src/docs/dependency-injection.txt      | 136 +++++++++++++++++++
 core/api/src/docs/fragment.txt                  |  10 +-
 core/api/src/docs/layer.txt                     |  24 ++++
 core/api/src/docs/module.txt                    |  12 ++
 core/api/src/docs/structure.txt                 |  35 +----
 core/api/src/docs/visibility.txt                |  16 +++
 .../runtime/composite/CompositeMethodModel.java |   2 +-
 manual/src/docs/userguide/extensions.txt        |   4 +
 manual/src/docs/userguide/glossary.txt          |   8 ++
 11 files changed, 215 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/api.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/api.txt b/core/api/src/docs/api.txt
index fa7188e..0523cb6 100644
--- a/core/api/src/docs/api.txt
+++ b/core/api/src/docs/api.txt
@@ -62,7 +62,7 @@ include::objects.txt[]
 
 :leveloffset: {level3}
 
-// include::dependency-injection.txt[]
+include::dependency-injection.txt[]
 
 :leveloffset: {level3}
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/composition.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/composition.txt b/core/api/src/docs/composition.txt
index 1a60a3a..895cca0 100644
--- a/core/api/src/docs/composition.txt
+++ b/core/api/src/docs/composition.txt
@@ -23,15 +23,7 @@ In Polygene, we use the term Assembly for the second case of composition. See se
 Composition will allow library authors a new level of flexibility in how functionality is provided to client code. More
 on that later.
 
-== Fragments ==
-
-There are 4 types of Fragments in Polygene;
-
-    * <<core-api-mixin>> - The state carrying part of a Composite.
-    * <<core-api-constraint>> - Rules for in and out arguments, typically used for validation.
-    * <<core-api-concern>> - Interceptor of method calls. General purpose use, often for cross-cutting behaviors.
-    * <<core-api-sideeffect>> - Executed after the method call has been completed, and unable to influence the
-    outcome of the method call.
+include::fragment.txt[]
 
 == Composites ==
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/dependency-injection.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/dependency-injection.txt b/core/api/src/docs/dependency-injection.txt
index fc7aac6..d9fabca 100644
--- a/core/api/src/docs/dependency-injection.txt
+++ b/core/api/src/docs/dependency-injection.txt
@@ -16,3 +16,139 @@
  * specific language governing permissions and limitations
  * under the License.
 ///////////////////////////////////////////////////////////////
+
+[[core-api-dependency-injection,Dependency Injection]]
+= Dependency Injection =
+
+Polygene has a rather sophisticated dependency injection system, which is based around the <<core-api-modules>>
+and <<core-api-visibility>> concepts. The dependency injection system also need help to keep the injection scopes
+separated. The following injection scopes exists, some more common than others;
+
+    * ++@This++ - injection of fragment from the same Composite instance.
+    * ++@Structure++ - injection of <<core-api-structure>> organized types.
+    * ++@Service++ - injection of services.
+    * ++@Uses++ - injection of construction injected objects
+    * ++@Invocation++ - injection of parts related to the current method invocation.
+    * ++@State++ - injection of state of the composite instance
+    * Custom injection scopes - managed through ++@AppliesTo++ and ++AppliesToFilter++ declarations.
+
+[[core-api-this,@This]]
+== @This ==
+++@This++ is equivalent to the ++this++ pointer in the Java language, but refers to any part of the current
+<<core-api-composite>>. This can either be a declared mixin type, or if not declared will be a <<def-private-mixin>>.
+
+=== Example ===
+
+We can simply request the injection of any type of the composite that we belong to, such as;
+
+[source,java]
+--------------
+@Mixins( { OrderMixin.class, ShippingMixin.class } )
+public interface Order extends HasShippingInformation
+{
+   :
+}
+
+public abstract class OrderMixin
+    implements Order
+{
+    @This
+    private HasShippingInformation shipping;
+}
+--------------
+
+But we can have <<def-private-mixin>> instead, where the injected mixin type will be automatically added to the
+composite.
+
+[source,java]
+--------------
+@MIxins( OrderMixin.class )
+public interface Order
+{
+   :
+}
+
+public class OrderMixin
+    implements Order
+{
+    @This
+    private DiscountRate discount;
+--------------
+
+[[core-api-structure-injection,@Structure]]
+== @Structure ==
+The ++@Structure++ injection scope is all about the types involved in the Application <<core-api-structure>> system.
+The possible types are;
+
+    * Application
+    * ApplicationDescriptor
+    * Layer
+    * LayerDescriptor
+    * Module
+    * ModuleDescriptor
+    * ModuleSPI
+    * UnitOfWorkFactory
+    * EntityBuilderFactory
+    * ValueBuilderFactory
+    * TransientBuilderFactory
+    * ObjectFactory
+    * QueryBuilderFactory
+    * ServiceFinder
+    * PolygeneAPI
+    * PolygeneSPI
+
+[[core-api-service,@Service]]
+== @Service ==
+Services are injected either in a number of ways, either direct, via List or via ServiceReference types. The following
+combinations are allowed;
+
+[source,java]
+--------------
+    @Service
+    private MyService service;
+
+    @Service
+    private Iterable<MyService> services;
+
+    @Service
+    private ServiceReference<MyService> service;
+
+    @Service
+    private Iterable<ServiceReference<MyService>> services;
+--------------
+
+If service is not declared ++instantiateOnStartup++ during assembly, then the service will be activated on first
+method invocation, and not on injection. This means that any reflection on the injected instance, may result in
+unexpected behavior.
+
+[[core-api-uses,@Uses]]
+== @Uses ==
+<<def-object>> and <<def-valuecomposite>> can be created with ++uses()++ declarations. This allows injection of
+arbitrary types to these meta types. Only type matching will occur, so for instance only one String can be injected
+this way.
+
+If a ++@Uses++ declaration can not be satisfied from the injected objects via ++uses()++ builder method, then
+if the ++@Uses++ injection is not ++@Optional++ the Polygene runtime will attempt to (in this order)
+
+    * Instantiate a visible <<def-transientcomposite>>
+    * Instantiate a visible <<def-object>>
+    * Instantiate a plain object with this Composite instance as a single constructor argument.
+
+If the ++@Uses++ is ++@Optional++ then no implict object creation will take place.
+
+[[core-api-invocation,@Invocation]]
+== @Invocation ==
+++@Invocation++ injection scope is all about the current method call. It is possible to inject the following types;
+
+    * The ++Method++ being executed.
+    * Any annotation type that the method is annotated with.
+    * An ++Iterable++ of either of the above
+
+[[core-api-state,@State]]
+== @State ==
+This injection scope can inject either a ++StateHolder++ which allows inspection of current state of the Composite,
+or it can inject any declared <<def-property>>, <<def-assocation>>, <<def-manyassociation>> or
+<<def-namedassociation>>.
+
+[[core-api-custom-injection,Custom Injection Scopes]]
+== Custom Injection Scopes ==

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/fragment.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/fragment.txt b/core/api/src/docs/fragment.txt
index 3edbf3b..ef68223 100644
--- a/core/api/src/docs/fragment.txt
+++ b/core/api/src/docs/fragment.txt
@@ -12,7 +12,8 @@
 //////////////////////
 
 [[core-api-fragment,Fragment]]
-= Fragment =
+== Fragment ==
+
 Composites should be perceived as single units, although they consist of many Java classes and instances. Some of
 those Java instances are not even belonging to a particular instance in runtime, but such details can and should
 be ignored by the developer. Developers should think of the Composite as a single concept, and not be concerned
@@ -21,6 +22,13 @@ about its internal structure.
 The Composite is composed by declaring the parts it forms in the Composite Type interface declaration. Technically
 speaking, Composite Type is the only Fragment that is required to exist. The other Fragments are optional.
 
+There are 4 types of Fragments in Polygene;
+
+    * <<core-api-mixin>> - The state carrying part of a Composite.
+    * <<core-api-constraint>> - Rules for in and out arguments, typically used for validation.
+    * <<core-api-concern>> - Interceptor of method calls. General purpose use, often for cross-cutting behaviors.
+    * <<core-api-sideeffect>> - Executed after the method call has been completed, and unable to influence the outcome of the method call.
+
 There are one very important thing to know about Fragments;
 
 *ONLY Mixins can maintain inter-method state.*

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/layer.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/layer.txt b/core/api/src/docs/layer.txt
new file mode 100644
index 0000000..d3484f4
--- /dev/null
+++ b/core/api/src/docs/layer.txt
@@ -0,0 +1,24 @@
+//////////////////////
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+//////////////////////
+
+[[core-api-layer,Layer]]
+= Layer =
+A Polygene™ Application must consist of at least one layer. More layers are common, often dividing the application along the
+common architectural diagrams used on whiteboards, perhaps with a UI layer at the top, followed by a service or application
+layer, then with a domain layer and finally some persistence layer at the bottom.
+
+Polygene™ enforces this layering by requiring the <<core-bootstrap-assembly>> to declare which layer uses which other layer. And
+<<core-api-visibility>> rules define that layers below can not locate composites in layers above. Also, defining that
+"Layer1 uses Layer2" and "Layer2 uses Layer3" does NOT imply that Layer1 has <<core-api-visibility>> to Layer3. If that
+is wanted, then it must be declared explicitly.
+

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/module.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/module.txt b/core/api/src/docs/module.txt
index eb191a9..4fd9fbf 100644
--- a/core/api/src/docs/module.txt
+++ b/core/api/src/docs/module.txt
@@ -11,3 +11,15 @@
  * and limitations under the License.
 //////////////////////
 
+[[core-api-module,Module]]
+= Module =
+Modules are logical compartments to assist developers in creating and maintaining well modularized code. A Module only
+belongs to a single Layer, but many Modules can exist in the same Layer. Composite access is limited to;
+
+    * Composites within the same Module, with Visibility set to Visibility.module (default).
+    * Composites from Modules in the same Layer, with Visibility set to Visibility.layer
+    * Composites from Modules in Layers below, with Visibility set to Visibility.application
+
+Modules contains a lot of the Polygene™ infrastructure, which are the enforcers of these wise modularization principles.
+
+It is not possible to modify the Modules, their resolution nor binding in any way after the application starts.

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/structure.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/structure.txt b/core/api/src/docs/structure.txt
index 04952fe..2c91e77 100644
--- a/core/api/src/docs/structure.txt
+++ b/core/api/src/docs/structure.txt
@@ -29,38 +29,9 @@ in Modules (including itself) of the same or lower Layers.
 Each Layer has to be declared which lower Layer(s) it uses, and it is not allowed that a lower Layer uses a higher
 Layer, i.e. cyclic references.
 
-[[core-api-application,Application]]
-= Application =
-Every Polygene™ runtime has _one and only one_ Application in it. It is possible to run multiple Polygene™ runtimes in the same
-JVM, and it is even possible to embed a Polygene™ runtime within a Polygene™ Application, but there can only be one Application
-in a Polygene™ runtime.
+include::application.txt[]
 
-An Application is then broken into layers and modules are placed within those layers. Composites are placed within
-modules. This forms the Application Structure and is enforced by the Polygene™ runtime.
+include::layer.txt[]
 
-[[core-api-layer,Layer]]
-= Layer =
-A Polygene™ Application must consist of at least one layer. More layers are common, often dividing the application along the
-common architectural diagrams used on whiteboards, perhaps with a UI layer at the top, followed by a service or application
-layer, then with a domain layer and finally some persistence layer at the bottom.
+include::module.txt[]
 
-Polygene™ enforces this layering by requiring the <<core-bootstrap-assembly>> to declare which layer uses which other layer. And
-<<core-api-visibility>> rules define that layers below can not locate composites in layers above. Also, defining that
-"Layer1 uses Layer2" and "Layer2 uses Layer3" does NOT imply that Layer1 has <<core-api-visibility>> to Layer3. If that
-is wanted, then it must be declared explicitly.
-
-[[core-api-module,Module]]
-= Module =
-Modules are logical compartments to assist developers in creating and maintaining well modularized code. A Module only
-belongs to a single Layer, but many Modules can exist in the same Layer. Composite access is limited to;
-
-    * Composites within the same Module, with Visibility set to Visibility.module (default).
-    * Composites from Modules in the same Layer, with Visibility set to Visibility.layer
-    * Composites from Modules in Layers below, with Visibility set to Visibility.application
-
-Modules contains a lot of the Polygene™ infrastructure, which are the enforcers of these wise modularization principles.
-
-It is not possible to modify the Modules, their resolution nor binding in any way after the application starts.
-
-[[core-api-visibility,Visibility]]
-= Visibility =

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/api/src/docs/visibility.txt
----------------------------------------------------------------------
diff --git a/core/api/src/docs/visibility.txt b/core/api/src/docs/visibility.txt
new file mode 100644
index 0000000..c0dad46
--- /dev/null
+++ b/core/api/src/docs/visibility.txt
@@ -0,0 +1,16 @@
+//////////////////////
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+//////////////////////
+
+[[core-api-visibility,Visibility]]
+= Visibility =
+

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/core/runtime/src/main/java/org/apache/polygene/runtime/composite/CompositeMethodModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/CompositeMethodModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/CompositeMethodModel.java
index d290f97..ec6de3b 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/CompositeMethodModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/CompositeMethodModel.java
@@ -52,7 +52,7 @@ public final class CompositeMethodModel
     private final ConcernsModel concerns;
     private final SideEffectsModel sideEffects;
     private final MixinsModel mixins;
-    private AnnotatedElement annotations;
+    private final AnnotatedElement annotations;
 
     // Context
 //    private final SynchronizedCompositeMethodInstancePool instancePool = new SynchronizedCompositeMethodInstancePool();

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/manual/src/docs/userguide/extensions.txt
----------------------------------------------------------------------
diff --git a/manual/src/docs/userguide/extensions.txt b/manual/src/docs/userguide/extensions.txt
index 433bd47..44bfd3f 100644
--- a/manual/src/docs/userguide/extensions.txt
+++ b/manual/src/docs/userguide/extensions.txt
@@ -61,6 +61,10 @@ include::../../../../extensions/entitystore-memory/src/docs/es-memory.txt[]
 
 :leveloffset: 2
 
+include::../../../../extensions/entitystore-file/src/docs/es-cassandra.txt[]
+
+:leveloffset: 2
+
 include::../../../../extensions/entitystore-file/src/docs/es-file.txt[]
 
 :leveloffset: 2

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14125f65/manual/src/docs/userguide/glossary.txt
----------------------------------------------------------------------
diff --git a/manual/src/docs/userguide/glossary.txt b/manual/src/docs/userguide/glossary.txt
index ffef798..f2fb326 100644
--- a/manual/src/docs/userguide/glossary.txt
+++ b/manual/src/docs/userguide/glossary.txt
@@ -321,6 +321,14 @@ This term has no definition yet. Learn how to contribute in <<community-docs>>.
 --
 
 
+[[def-object,Object]]Object::
++
+--
+Polygene can manage Java classes that are not Composites, and injections can be made on these objects. Read more
+in the user guide about <<core-api-object>>.
+--
+
+
 [[def-private-mixin,Private Mixin]]Private Mixin::
 +
 --


[3/4] polygene-java git commit: Configuration can not be Optional, although the individual elements can be.

Posted by ni...@apache.org.
Configuration can not be Optional, although the individual elements can be.

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/c782f071
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/c782f071
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/c782f071

Branch: refs/heads/develop
Commit: c782f0713212792eb39b5a73265ab53e1327f078
Parents: 7e83d0b
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 4 17:30:03 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 4 17:30:03 2017 +0800

----------------------------------------------------------------------
 .../cache/memcache/MemcachePoolMixin.java       |  69 ++++-----
 tools/generator-polygene/app/index.js           | 147 ++++++++++++-------
 .../DomainLayer/DomainModule/Configuration.tmpl |  10 +-
 .../DomainLayer/DomainModule/bootstrap.tmpl     |  19 ++-
 .../DomainModule/config.properties.tmpl         |  22 +++
 .../DomainLayer/DomainModule/config.yaml.tmpl   |  23 ---
 .../DomainLayer/DomainModule/module.js          |  12 +-
 .../DomainLayer/JmxModule/bootstrap.tmpl        |   2 +-
 .../StorageModule/bootstrap.tmpl                |  13 +-
 .../InfrastructureLayer/StorageModule/module.js |  13 +-
 .../DevelopmentKeyManagement.java.tmpl          |  28 +++-
 .../RestAPIApplication/Launcher.java.tmpl       |   6 +
 .../app/templates/RestAPIApplication/app.js     |   4 +-
 .../RestAPIApplication/bootstrap-test.tmpl      |  17 ++-
 .../app/templates/buildtool/gradle-app.tmpl     |  37 +++++
 .../app/templates/buildtool/gradle-root.tmpl    |   4 +
 .../src/docs/yeoman_polygene.txt                |  76 ++++++++--
 17 files changed, 329 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java
----------------------------------------------------------------------
diff --git a/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java b/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java
index dabaea0..3184865 100644
--- a/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java
+++ b/extensions/cache-memcache/src/main/java/org/apache/polygene/cache/memcache/MemcachePoolMixin.java
@@ -28,7 +28,6 @@ import net.spy.memcached.ConnectionFactoryBuilder.Protocol;
 import net.spy.memcached.MemcachedClient;
 import net.spy.memcached.auth.AuthDescriptor;
 import net.spy.memcached.auth.PlainCallbackHandler;
-import org.apache.polygene.api.common.Optional;
 import org.apache.polygene.api.configuration.Configuration;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.spi.cache.Cache;
@@ -40,8 +39,10 @@ public class MemcachePoolMixin
     implements MemcachePoolService
 {
     private final Map<String, MemcacheImpl<?>> caches = new HashMap<>();
-    @This @Optional
+
+    @This
     private Configuration<MemcacheConfiguration> configuration;
+
     private MemcachedClient client;
     private int expiration;
 
@@ -49,41 +50,32 @@ public class MemcachePoolMixin
     public void activateService()
         throws Exception
     {
-        if( configuration != null )
-        {
-            MemcacheConfiguration config = configuration.get();
-            expiration = ( config.expiration().get() == null )
-                         ? 3600
-                         : config.expiration().get();
-            String addresses = ( config.addresses().get() == null )
-                               ? "localhost:11211"
-                               : config.addresses().get();
-            Protocol protocol = ( config.protocol().get() == null )
-                                ? Protocol.TEXT
-                                : Protocol.valueOf( config.protocol().get().toUpperCase() );
-            String username = config.username().get();
-            String password = config.password().get();
-            String authMech = config.authMechanism().get() == null
-                              ? "PLAIN"
-                              : config.authMechanism().get();
-
-            ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
-            builder.setProtocol( protocol );
-            if( username != null && !username.isEmpty() )
-            {
-                builder.setAuthDescriptor(
-                    new AuthDescriptor(
-                        new String[]
-                        {
-                            authMech
-                        },
-                        new PlainCallbackHandler( username, password )
-                    )
-                );
-            }
+        MemcacheConfiguration config = configuration.get();
+        expiration = ( config.expiration().get() == null )
+                     ? 3600
+                     : config.expiration().get();
+        String addresses = ( config.addresses().get() == null )
+                           ? "localhost:11211"
+                           : config.addresses().get();
+        Protocol protocol = ( config.protocol().get() == null )
+                            ? Protocol.TEXT
+                            : Protocol.valueOf( config.protocol().get().toUpperCase() );
+        String username = config.username().get();
+        String password = config.password().get();
+        String authMech = config.authMechanism().get() == null
+                          ? "PLAIN"
+                          : config.authMechanism().get();
 
-            client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) );
+        ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
+        builder.setProtocol( protocol );
+        if( username != null && !username.isEmpty() )
+        {
+            String[] authType = { authMech };
+            AuthDescriptor to = new AuthDescriptor( authType, new PlainCallbackHandler( username, password ) );
+            builder.setAuthDescriptor( to );
         }
+
+        client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) );
     }
 
     @Override
@@ -107,12 +99,7 @@ public class MemcachePoolMixin
         }
         synchronized( caches )
         {
-            MemcacheImpl<?> cache = caches.get( cacheId );
-            if( cache == null )
-            {
-                cache = new MemcacheImpl<>( client, cacheId, valueType, expiration );
-                caches.put( cacheId, cache );
-            }
+            MemcacheImpl<?> cache = caches.computeIfAbsent( cacheId, identity -> new MemcacheImpl<>( client, identity, valueType, expiration ) );
             cache.incRefCount();
             return (Cache<T>) cache;
         }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/index.js
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/index.js b/tools/generator-polygene/app/index.js
index cb9d214..b933c27 100644
--- a/tools/generator-polygene/app/index.js
+++ b/tools/generator-polygene/app/index.js
@@ -130,9 +130,8 @@ module.exports = generators.Base.extend(
                             choices: [
                                 'BoneCP',
                                 'DBCP'
-                                // 'HikariCP'
                             ],
-                            message: 'Which entity store do you want to use?',
+                            message: 'Which connection pool do you want to use?',
                             default: polygene.dbpool ? polygene.dbpool : "DBCP",
                             when: function (answers) {
                                 return answers.entitystore.indexOf('SQL') > -1;
@@ -245,7 +244,7 @@ module.exports = generators.Base.extend(
                 if (this.options.export) {
                     exportModel(this.options.export);
                 }
-            } catch( exception ) {
+            } catch (exception) {
                 console.log(exception);
                 throw exception;
             }
@@ -282,6 +281,21 @@ function assignFunctions(polygene) {
         return polygene.features.indexOf(feature) >= 0;
     };
 
+    polygene.copyToConfig = function (ctx, from, toName) {
+        polygene.copyTemplate(ctx,
+            from,
+            'app/src/main/config/development/' + toName);
+        polygene.copyTemplate(ctx,
+            from,
+            'app/src/main/config/qa/' + toName);
+        polygene.copyTemplate(ctx,
+            from,
+            'app/src/main/config/staging/' + toName);
+        polygene.copyTemplate(ctx,
+            from,
+            'app/src/main/config/production/' + toName);
+    };
+
     polygene.copyTemplate = function (ctx, from, to) {
         try {
 
@@ -347,12 +361,16 @@ function assignFunctions(polygene) {
         var state = [];
         var imported = {};
         var props = current.clazz.properties;
+        var idx;
+        var assoc;
         if (props) {
             imported["org.apache.polygene.api.property.Property"] = true;
-            for (var idx in props) {
-                var prop = props[idx];
-                state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();");
-                imported[prop.type] = true;
+            for (idx in props) {
+                if( props.hasOwnProperty(idx)) {
+                    var prop = props[idx];
+                    state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();");
+                    imported[prop.type] = true;
+                }
             }
         } else {
             imported["org.apache.polygene.api.property.Property"] = true;
@@ -361,76 +379,101 @@ function assignFunctions(polygene) {
         var assocs = current.clazz.associations;
         if (assocs) {
             imported["org.apache.polygene.api.association.Association"] = true;
-            for (var idx in assocs) {
-                var assoc = assocs[idx];
-                state.push("Association" + '<' + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();");
-                imported[assoc.type] = true;
+            for (idx in assocs) {
+                if( assocs.hasOwnProperty(idx)) {
+                    assoc = assocs[idx];
+                    state.push("Association" + '<' + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();");
+                    imported[assoc.type] = true;
+                }
             }
         }
         assocs = current.clazz.manyassociations;
         if (assocs) {
             imported["org.apache.polygene.api.association.ManyAssociation"] = true;
-            for (var idx in assocs) {
-                var assoc = assocs[idx];
-                state.push("ManyAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();");
-                imported[assoc.type] = true;
+            for (idx in assocs) {
+                if( assocs.hasOwnProperty(idx)) {
+                    assoc = assocs[idx];
+                    state.push("ManyAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();");
+                    imported[assoc.type] = true;
+                }
             }
         }
         assocs = current.clazz.namedassociations;
         if (assocs) {
             imported["org.apache.polygene.api.association.NamedAssociation"] = true;
-            for (var idx in assocs) {
-                var assoc = assocs[idx];
-                state.push("NamedAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();");
-                imported[assoc.type] = true;
+            for (idx in assocs) {
+                if( assocs.hasOwnProperty(idx)){
+                    assoc = assocs[idx];
+                    state.push("NamedAssociation<" + polygene.typeNameOnly(assoc.type) + "> " + assoc.name + "();");
+                    imported[assoc.type] = true;
+                }
             }
         }
         current.state = state;
         current.imported = imported;
     };
 
-    polygene.prepareConfigClazz = function (current) {
+    polygene.prepareConfigClazz = function (currentModule, composite) {
         var state = [];
-        var yaml = [];
+        var propertyFile = [];
         var imported = {};
-        var props = current.clazz.configuration;
+        var props = composite.configuration;
         if (props) {
             imported["org.apache.polygene.api.property.Property"] = true;
             for (var idx in props) {
-                var prop = props[idx];
-                state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();");
-                imported[prop.type] = true;
-                var yamlDefault;
-                if (prop.type === "java.lang.String") {
-                    yamlDefault = '""';
-                }
-                else if (prop.type === "java.lang.Boolean") {
-                    yamlDefault = 'false';
-                }
-                else if (prop.type === "java.lang.Long") {
-                    yamlDefault = '0';
-                }
-                else if (prop.type === "java.lang.Integer") {
-                    yamlDefault = '0';
-                }
-                else if (prop.type === "java.lang.Double") {
-                    yamlDefault = '0.0';
-                }
-                else if (prop.type === "java.lang.Float") {
-                    yamlDefault = '0.0';
-                }
-                else {
-                    yamlDefault = '\n    # TODO: complex configuration type. ';
+                if (props.hasOwnProperty(idx)) {
+                    var prop = props[idx];
+                    imported[prop.type] = true;
+                    var propertyDefault;
+                    if (prop.default !== undefined) {
+                        propertyDefault = prop.default;
+                    } else {
+                        if (prop.type === "java.lang.String") {
+                            propertyDefault = '';
+                        }
+                        else if (prop.type === "java.lang.Boolean") {
+                            propertyDefault = 'false';
+                        }
+                        else if (prop.type === "java.lang.Long") {
+                            propertyDefault = '0';
+                        }
+                        else if (prop.type === "java.lang.Integer") {
+                            propertyDefault = '0';
+                        }
+                        else if (prop.type === "java.lang.Double") {
+                            propertyDefault = '0.0';
+                        }
+                        else if (prop.type === "java.lang.Float") {
+                            propertyDefault = '0.0';
+                        }
+                        else {
+                            propertyDefault = '\n    # TODO: complex configuration type. ';
+                        }
+                    }
+                    state.push("/**");
+                    for( var idxDesc in prop.description ){
+                        if( prop.description.hasOwnProperty(idxDesc)){
+                            var desc = prop.description[idxDesc];
+                            propertyFile.push("# " + desc);
+                            state.push(" * " + desc )
+                        }
+                    }
+                    state.push(" */");
+                    propertyFile.push(prop.name + "=" + propertyDefault +"\n");
+                    state.push('Property' + '<' + polygene.typeNameOnly(prop.type) + "> " + prop.name + "();\n");
                 }
-                yaml.push(prop.name + " : " + yamlDefault);
             }
         } else {
             imported["org.apache.polygene.api.property.Property"] = true;
-            state.push('Property<String> name();    // TODO: remove sample property');
-            yaml.push('name : "sample config value"');
+            state.push('/** TODO: remove sample property');
+            state.push(' */');
+            state.push('Property<String> name();');
+            propertyFile.push("# This is just the sample configuration value. " );
+            propertyFile.push("# TODO: Remove this config value " );
+            propertyFile.push('name=sample config value');
         }
-        current.state = state;
-        current.yaml = yaml;
-        current.imported = imported;
+        currentModule.state = state;
+        currentModule.propertyLines = propertyFile;
+        currentModule.imported = imported;
     };
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl
index b7acd94..e36bffb 100644
--- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl
+++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/Configuration.tmpl
@@ -18,6 +18,7 @@
  *
 -%>
 package <%= polygene.packageName %>.model.<%= polygene.current.name %>;
+
 <%
 for( var imp in polygene.current.imported ) {
     if( !imp.startsWith( "java.lang" )
@@ -26,10 +27,11 @@ for( var imp in polygene.current.imported ) {
 <%
     }
 } %>
-
 public interface <%= polygene.current.clazz.name %>
 {
-<% for( var idx in polygene.current.state ) {
-%>    <%- polygene.current.state[idx]; %>
-<% } %>
+<%
+for( var idx in polygene.current.state ) {
+%>
+    <%- polygene.current.state[idx]; %><%
 }
+%>}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl
index 092d683..5afbdd7 100644
--- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl
+++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/bootstrap.tmpl
@@ -69,8 +69,8 @@ if( polygene.current.cruds ) {
     for( var value in polygene.current.cruds ) {
         var crud = polygene.current.cruds[value];
 %>
-        <%- "module.values( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn(" + crud.visibility +")" : "" ) %>;
-        <%- "module.entities( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn(" + crud.visibility +")" : "" ) %>;
+        <%- "module.values( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn( " + crud.visibility +" )" : "" ) %>;
+        <%- "module.entities( " + crud.name + ".class )" + (crud.visibility ? ".visibleIn( " + crud.visibility +" )" : "" ) %>;
 <%
     }
 }
@@ -78,7 +78,7 @@ if( polygene.current.values ) {
     for( var value in polygene.current.values ) {
         var v = polygene.current.values[value];
 %>
-        <%- "module.values( " + v.name + ".class )" + (v.visibility ? ".visibleIn(" + v.visibility +")" : "" ) %>;
+        <%- "module.values( " + v.name + ".class )" + (v.visibility ? ".visibleIn(" + v.visibility +" )" : "" ) %>;
 <%
     }
 }
@@ -86,7 +86,7 @@ if( polygene.current.entities ) {
     for( var value in polygene.current.entities ) {
         var entity = polygene.current.entities[value];
 %>
-        <%- "module.entities( " + entity.name + ".class )" + (entity.visibility ? ".visibleIn(" + entity.visibility +")" : "" ) %>;
+        <%- "module.entities( " + entity.name + ".class )" + (entity.visibility ? ".visibleIn( " + entity.visibility +" )" : "" ) %>;
 <%
     }
 }
@@ -94,7 +94,7 @@ if( polygene.current.transients ) {
     for( var value in polygene.current.transients ) {
         var trans = polygene.current.transients[value];
 %>
-        <%- "module.transients( " + trans.name + ".class )" + (trans.visibility ? ".visibleIn(" + trans.visibility +")" : "" ) %>;
+        <%- "module.transients( " + trans.name + ".class )" + (trans.visibility ? ".visibleIn( " + trans.visibility +" )" : "" ) %>;
 <%
     }
 }
@@ -102,7 +102,7 @@ if( polygene.current.objects ) {
     for( var value in polygene.current.objects ) {
         var obj = polygene.current.objects[value];
 %>
-        <%- "module.objects( " + obj.name + ".class )" + (obj.visibility ? ".visibleIn(" + obj.visibility +")" : "" ) %>;
+        <%- "module.objects( " + obj.name + ".class )" + (obj.visibility ? ".visibleIn( " + obj.visibility +" )" : "" ) %>;
 <%
     }
 }
@@ -110,8 +110,11 @@ if( polygene.current.services ) {
     for( var value in polygene.current.services ) {
         var service = polygene.current.services[value];
 %>
-        <%- "module.services( " + service.name + ".class )" + (service.visibility ? ".visibleIn(" + service.visibility + ")" : "" ) %>;
-        <%- "module.entities( " + polygene.configurationClassName(service.name) + ".class )" %>;
+        module.services( <%- service.name %>.class )
+            .identifiedBy("<%- service.name %>")
+        <%- (service.visibility ? "    .visibleIn( " + service.visibility + " )" : "" )
+%>;
+        <%- "module.configurations( " + polygene.configurationClassName(service.name) + ".class )" %>;
 <%
     }
 } %>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl
new file mode 100644
index 0000000..a20c784
--- /dev/null
+++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.properties.tmpl
@@ -0,0 +1,22 @@
+<%#
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+-%>
+<% for( var idx in polygene.current.propertyLines ) {
+%><%- polygene.current.propertyLines[idx]; %>
+<% } %>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl
deleted file mode 100644
index e2629d5..0000000
--- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/config.yaml.tmpl
+++ /dev/null
@@ -1,23 +0,0 @@
-<%#
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *
--%>
--
-<% for( var idx in polygene.current.yaml ) {
-%>    <%- polygene.current.yaml[idx]; %>
-<% } %>

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js
index 8855bc3..f511c0f 100644
--- a/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js
+++ b/tools/generator-polygene/app/templates/DomainLayer/DomainModule/module.js
@@ -49,7 +49,7 @@ function copyPolygeneDomainModule(p, moduleName, moduleDef) {
     copyComposites(p, moduleDef.plainTypes, "Plain");
     copyComposites(p, moduleDef.services, "Configuration");
 
-    copyConfigurationYaml(p, moduleDef.services )
+    copyConfigurationPropertiesFile(p, moduleDef.services )
 }
 
 function copyComposites(p, composites, type) {
@@ -57,7 +57,9 @@ function copyComposites(p, composites, type) {
         if (composites.hasOwnProperty(idx)) {
             if( type === "Configuration"){
                 p.current.clazz.name = p.configurationClassName(composites[idx].name);
-                p.prepareConfigClazz(p.current);
+                delete p.current.type;
+                delete p.current.value;
+                p.prepareConfigClazz(p.current, composites[idx]);
             } else {
                 p.current.clazz = composites[idx];
                 p.prepareClazz(p.current);
@@ -69,14 +71,12 @@ function copyComposites(p, composites, type) {
     }
 }
 
-function copyConfigurationYaml(p, composites) {
+function copyConfigurationPropertiesFile(p, composites) {
     for (var idx in composites) {
         if (composites.hasOwnProperty(idx)) {
             p.current.clazz = composites[idx];
             p.prepareClazz(p.current);
-            p.copyTemplate(p.ctx,
-                'DomainLayer/DomainModule/config.yaml.tmpl',
-                'model/src/main/resources/' + p.javaPackageDir + '/model/' + p.current.name + '/' + p.current.clazz.name + '.yaml');
+            p.copyToConfig(p.ctx,'DomainLayer/DomainModule/config.properties.tmpl', p.current.clazz.name + '.properties');
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl
index 8a9a96f..b53529f 100644
--- a/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl
+++ b/tools/generator-polygene/app/templates/DomainLayer/JmxModule/bootstrap.tmpl
@@ -36,7 +36,7 @@ public class JmxModule
     {
         new JMXAssembler().assemble( module );
         module.services( JMXConnectorService.class ).instantiateOnStartup();
-        module.entities( JMXConnectorConfiguration.class );
+        module.configurations( JMXConnectorConfiguration.class );
         module.forMixin( JMXConnectorConfiguration.class ).declareDefaults().port().set( 1099 );
         return module;
     }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl
index b2ebb64..ce33d13 100644
--- a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl
+++ b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/bootstrap.tmpl
@@ -26,6 +26,7 @@ import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.LayerAssembly;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.bootstrap.layered.ModuleAssembler;
+import org.apache.polygene.entitystore.<%- polygene.entitystoremodule %>.<%- polygene.entitystore %>EntityStoreConfiguration;
 import org.apache.polygene.entitystore.<%- polygene.entitystoremodule %>.assembly.<%- polygene.entitystore %>EntityStoreAssembler;
 <%
 if( polygene.entitystore.indexOf('SQL') >= 0 ) {
@@ -73,9 +74,17 @@ if( polygene.entitystore.indexOf( 'SQL' ) >= 0 ) {
             .withConfig( configModule, Visibility.application )
             .identifiedBy( "es-<%- polygene.entitystore.toLowerCase() %>" )
             .assemble( module );
+<%
+if( polygene.entitystore === 'Cassandra' ) {
+%>        configModule.forMixin( CassandraEntityStoreConfiguration.class )
+            .declareDefaults()
+            .createIfMissing().set( true );
+<%
+}
+%>
         module.services( IdentityGenerator.class )
-              .visibleIn( Visibility.application )
-              .withMixins( UuidGeneratorMixin.class );
+            .visibleIn( Visibility.application )
+            .withMixins( UuidGeneratorMixin.class );
         return module;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js
index a9790bb..d26c454 100644
--- a/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js
+++ b/tools/generator-polygene/app/templates/InfrastructureLayer/StorageModule/module.js
@@ -31,21 +31,14 @@ module.exports = {
         if (p.entitystore.indexOf('SQL') < 0) {
             fs.stat(__dirname + "/../../" + configurationFile, function (err, stat) {
                 if (err === null) {
-                    p.copyTemplate(p.ctx,
-                        configurationFile,
-                        'app/src/main/resources/' + esFileName);
+                    p.copyToConfig(p.ctx, configurationFile, esFileName);
                 }
             });
         } else {
-            p.copyTemplate(p.ctx,
-                'InfrastructureLayer/StorageModule/storage/es-sql.properties',
-                'app/src/main/resources/' + esFileName);
-
+            p.copyToConfig(p.ctx, 'InfrastructureLayer/StorageModule/storage/es-sql.properties', esFileName);
             var dsFileName = 'ds-es-' + p.entitystore.toLowerCase() + '.properties';
             var datasourceFile = 'InfrastructureLayer/StorageModule/storage/' + dsFileName;
-            p.copyTemplate(p.ctx,
-                datasourceFile,
-                'app/src/main/resources/' + dsFileName);
+            p.copyToConfig(p.ctx, datasourceFile, dsFileName);
         }
     }
 };

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl
index d82eec5..d724253 100644
--- a/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl
+++ b/tools/generator-polygene/app/templates/RestAPIApplication/DevelopmentKeyManagement.java.tmpl
@@ -71,16 +71,17 @@ class DevelopmentKeyManagement
         @SuppressWarnings( "unused" )
         KeyStore trustStore = loadKeyStore( new File(TRUSTSTORE_FILENAME), TRUSTSTORE_TYPE, KS_PASSWORD );
 
-        KeyStore keyStore = loadKeyStore( new File(SERVER_KEYSTORE_FILENAME), SERVER_KEYSTORE_TYPE, KS_PASSWORD );
+        File keyFile = new File( SERVER_KEYSTORE_FILENAME );
+        KeyStore keyStore = loadKeyStore( keyFile, SERVER_KEYSTORE_TYPE, KS_PASSWORD );
         initializeKeyManager( keyStore, KS_PASSWORD );
-        createKeyStoreData( keyStore );
+        createKeyStoreData( keyStore, keyFile, SERVER_KEYSTORE_TYPE, KS_PASSWORD );
     }
 
     private static KeyStore loadKeyStore( File keyFile, String type, String password )
     {
         if( !keyFile.exists() )
         {
-            return createKeyStore(keyFile, type, password);
+            createKeyStore(keyFile, type, password);
         }
         try( FileInputStream fis = new FileInputStream( keyFile ) )
         {
@@ -96,7 +97,7 @@ class DevelopmentKeyManagement
     }
 
     @SuppressWarnings( "ResultOfMethodCallIgnored" )
-    private static KeyStore createKeyStore( File keyFile, String type, String password )
+    private static void createKeyStore( File keyFile, String type, String password )
         throws AssemblyException
     {
         if( !keyFile.getParentFile().exists() )
@@ -109,7 +110,6 @@ class DevelopmentKeyManagement
             char[] pwd = password.toCharArray();
             ks.load( null, pwd );
             ks.store( fos, pwd );
-            return ks;
         }
         catch( Exception e )
         {
@@ -130,7 +130,7 @@ class DevelopmentKeyManagement
         }
     }
 
-    private static void createKeyStoreData( KeyStore keyStore )
+    private static void createKeyStoreData( KeyStore keyStore, File keyFile, String type, String password )
     {
         try
         {
@@ -141,6 +141,7 @@ class DevelopmentKeyManagement
             KeyPair keyPair = generateKeyPair();
             X509Certificate certificate = selfSignedCertificate( keyPair, COMMON_NAME, 30 );
             keyStore.setCertificateEntry( COMMON_NAME, certificate );
+            storeKeyStore(keyStore, keyFile, password, type);
 
             System.out.println("Created Self-signed certificated:");
             System.out.println(convertCertificateToPEM( certificate ));
@@ -151,6 +152,21 @@ class DevelopmentKeyManagement
         }
     }
 
+    private static void storeKeyStore( KeyStore keyStore, File keyFile, String password, String type )
+    {
+        try( FileOutputStream fos = new FileOutputStream( keyFile ) )
+        {
+            KeyStore ks = KeyStore.getInstance( type );
+            char[] pwd = password.toCharArray();
+            ks.load( null, pwd );
+            ks.store( fos, pwd );
+        }
+        catch( Exception e )
+        {
+            throw new AssemblyException( "Unable to create keystore.", e );
+        }
+    }
+
     private static KeyPair generateKeyPair()
     {
         try

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl
index 3a66952..2acdca1 100644
--- a/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl
+++ b/tools/generator-polygene/app/templates/RestAPIApplication/Launcher.java.tmpl
@@ -54,6 +54,12 @@ public class <%= polygene.name %>Launcher extends PolygeneRestApplicationLaunche
 %>        return new <%= polygene.name %>ApplicationAssembler( name, version, mode, none -> {} );
     }
 
+    @Override
+    public void shutdown()
+    {
+        super.shutdown();
+    }
+
     protected String entryLayer()
     {
         return ConnectivityLayer.NAME;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/app.js
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/app.js b/tools/generator-polygene/app/templates/RestAPIApplication/app.js
index c016bec..ceed39e 100644
--- a/tools/generator-polygene/app/templates/RestAPIApplication/app.js
+++ b/tools/generator-polygene/app/templates/RestAPIApplication/app.js
@@ -36,9 +36,7 @@ module.exports = {
             p.copyTemplate(p.ctx,
                 'RestAPIApplication/DevelopmentKeyManagement.java.tmpl',
                 'app/src/main/java/' + p.javaPackageDir + '/app/DevelopmentKeyManagement.java');
-            p.copyTemplate(p.ctx,
-                'RestAPIApplication/web-shiro.ini.tmpl',
-                'app/src/main/resources/web-shiro.ini');
+            p.copyToConfig(p.ctx, 'RestAPIApplication/web-shiro.ini.tmpl', 'web-shiro.ini');
         }
 
         p.copyTemplate(p.ctx,

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl b/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl
index 0eac743..ae03cd6 100644
--- a/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl
+++ b/tools/generator-polygene/app/templates/RestAPIApplication/bootstrap-test.tmpl
@@ -35,6 +35,8 @@ import org.apache.polygene.bootstrap.layered.LayeredApplicationAssembler;
 import org.apache.polygene.tools.model.descriptor.ApplicationDetailDescriptor;
 import org.apache.polygene.tools.model.descriptor.ApplicationDetailDescriptorBuilder;
 <%
+polygene.needsDelayChecker = false;
+
 if(  polygene.entitystore === 'MySQL' ) {
 %>import java.util.HashMap;
 <%
@@ -89,6 +91,8 @@ public class BootstrapTest
         };
         launcher.initialize();
         System.out.println("Application Launched...");
+        // Thread.sleep( 3600000L );
+        launcher.shutdown();
     }
 
     private void setupTest( ApplicationAssembly assembly )
@@ -186,6 +190,7 @@ if(  polygene.entitystore === 'MongoDB' ) {
     }
 <% }
 if(  polygene.entitystore === 'MySQL' ) {
+    polygene.needsDelayChecker = true;
 %>
     private void entityStoreSetup(ApplicationAssembly assembly )
     {
@@ -205,6 +210,7 @@ if(  polygene.entitystore === 'MySQL' ) {
                                                          .build();
 <% }
 if(  polygene.entitystore === 'PostgreSQL' ) {
+    polygene.needsDelayChecker = true;
 %>
     private void entityStoreSetup(ApplicationAssembly assembly )
     {
@@ -264,6 +270,7 @@ if(  polygene.caching === 'Memcache' ) {
                                                             .imageName( "memcached:latest"  )
                                                             .expose( "11211", "11211" )
                                                             .waitForTimeout( 120 )
+                                                            .waitFor( WaitFor.tcpPort(11211) )
                                                             .build();
 
 <% }
@@ -272,8 +279,9 @@ if(  polygene.caching === 'EhCache' ) {
     @ClassRule
     public static final DockerRule CACHE_DOCKER = DockerRule.builder()
                                                             .imageName( "terracotta/terracotta-server-oss:latest"  )
-                                                            .publishAllPorts( true )
+                                                            .expose( "9510", "9510" )
                                                             .waitForTimeout( 120 )
+                                                            .waitFor( WaitFor.tcpPort(9510) )
                                                             .build();
 <% }
 if(  polygene.indexing === 'ElasticSearch' ) {
@@ -286,7 +294,8 @@ if(  polygene.indexing === 'ElasticSearch' ) {
                                                                .build();
 <%
 } %>
-
+<% if( polygene.needsDelayChecker ) {
+%>
     private static class DelayChecker
         implements StartCondition
     {
@@ -304,7 +313,6 @@ if(  polygene.indexing === 'ElasticSearch' ) {
         {
             return new StartConditionCheck()
             {
-
                 @Override
                 public boolean check()
                 {
@@ -324,4 +332,5 @@ if(  polygene.indexing === 'ElasticSearch' ) {
             };
         }
     }
-}
+<% }
+%>}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl b/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl
index 0d8431a..14b3510 100644
--- a/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl
+++ b/tools/generator-polygene/app/templates/buildtool/gradle-app.tmpl
@@ -18,6 +18,24 @@
  *
 -%>
 
+
+apply plugin: 'application'
+
+mainClassName="<%= polygene.packageName %>.app.<%= polygene.name %>Launcher"
+
+applicationDefaultJvmArgs=[]
+// GC Tuning strategies, see https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/
+// Strict memory bound
+// applicationDefaultJvmArgs << "-Xmx512M -Xms512M"
+//
+// Goal oriented, "throughput" and "max pause"
+// applicationDefaultJvmArgs << "-XX:MaxGCPauseMillis=300 -XX:GCTimeRatio=19"
+//
+// Garbage Collector
+// OneOf; -XX:+UseG1GC, -XX:+UseConcMarkSweepGC, -XX:-UseParallelOldGC, -XX:+UseSerialGC
+applicationDefaultJvmArgs << "-XX:+UseG1GC"
+
+
 dependencies {
   implementation project( ":bootstrap" )
   implementation project( ":model" )
@@ -89,3 +107,22 @@ if( polygene.entitystore == 'SQLite'  ) {
   testImplementation "org.apache.polygene.core:org.apache.polygene.core.testsupport:$polygeneVersion"
   testImplementation "com.github.tdomzal:junit-docker-rule:0.3"
 }
+
+
+task createConfigs {
+  def config = file("src/main/config")
+  outputs.dir config
+  doLast {
+    config.mkdirs()
+  }
+}
+
+distributions {
+  main {
+    contents {
+      from(createConfigs) {
+        into "config"
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl b/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl
index d8f215e..357b607 100644
--- a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl
+++ b/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl
@@ -25,7 +25,11 @@ if( project.version == 'unspecified' )
 
 rootProject.ext {
   polygeneVersion = "<%= polygene.version %>"
+<% if( polygene.applicationtype === "Rest API" ) {
+%>  jettyVersion = "9.2.17.v20160517"
+<%
 }
+%>}
 
 allprojects() {
   apply plugin: 'java-library'

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/c782f071/tools/generator-polygene/src/docs/yeoman_polygene.txt
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/src/docs/yeoman_polygene.txt b/tools/generator-polygene/src/docs/yeoman_polygene.txt
index cff7882..19cca52 100644
--- a/tools/generator-polygene/src/docs/yeoman_polygene.txt
+++ b/tools/generator-polygene/src/docs/yeoman_polygene.txt
@@ -19,8 +19,8 @@
 
 [[tools-shell,Command Line Shell]]
 = Polygene Generator =
-Apache Polygene comes with a Yeoman code generator, to quickly set up a development
-environment for Polygene applications.
+Apache Polygene comes with a Yeoman code generator, to quickly set up a
+project for Polygene applications.
 
 [source,shell]
 ----
@@ -90,6 +90,15 @@ number of implementations to choose from. Not that "memory" is not persistent, b
   SQLite
 ----
 
+If one of the SQL options are given, then a question of connection pool will pop up.
+
+[source,shell]
+----
+? Which connection pool do you want to use?
+  BoneCP
+> DBCP
+----
+
 === Indexing/Query system ===
 Select of a pluggable Indexing and Query subsystem.
 
@@ -272,7 +281,11 @@ where the content of the +../model.json+ is as follows,
           "visibility": "application",
           "configuration" : [
             { "name": "backend", "type": "java.lang.String" },
-            { "name": "connectString", "type": "java.lang.String" }
+            { "name": "connectString", "type": "java.lang.String",
+              "description": [
+                  "The connection string to the authentication and authorization backend system."
+              ]
+            }
           ]
         }
       ]
@@ -325,11 +338,19 @@ we will create a complete project, like this
 
 [source,shell]
 ----
-  create bootstrap/src/main/java/com/sensetif/sink/bootstrap/config/ConfigurationLayer.java
+   create bootstrap/src/main/java/com/sensetif/sink/bootstrap/config/ConfigurationLayer.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/InfrastructureLayer.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/DomainLayer.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/connectivity/ConnectivityLayer.java
-   create app/src/main/webapp/WEB-INF/web.xml
+   create rest/src/main/java/com/sensetif/sink/rest/FloodRestApplication.java
+   create app/src/main/java/com/sensetif/sink/app/FloodLauncher.java
+   create app/src/main/java/com/sensetif/sink/app/DevelopmentKeyManagement.java
+   create app/src/main/config/development/web-shiro.ini
+   create app/src/main/config/qa/web-shiro.ini
+   create app/src/main/config/staging/web-shiro.ini
+   create app/src/main/config/production/web-shiro.ini
+   create app/src/test/java/com/sensetif/sink/app/BootstrapTest.java
+   create bootstrap/src/main/java/com/sensetif/sink/bootstrap/FloodApplicationAssembler.java
    create app/build.gradle
    create bootstrap/build.gradle
    create model/build.gradle
@@ -343,34 +364,53 @@ we will create a complete project, like this
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/config/ConfigModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/MemcacheCachingModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/FileConfigurationModule.java
-   create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/SQLIndexingModule.java
+   create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/RdfIndexingModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/CodahaleMetricsModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/JavaxJsonSerializationModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/infrastructure/CassandraStorageModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/CrudModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/UserModule.java
-   create model/src/main/java/com/sensetif/sink/model/user/Users.java
-   create model/src/main/java/com/sensetif/sink/model/user/Roles.java
    create model/src/main/java/com/sensetif/sink/model/user/User.java
+   create model/src/main/java/com/sensetif/sink/model/user/Users.java
    create model/src/main/java/com/sensetif/sink/model/user/Role.java
+   create model/src/main/java/com/sensetif/sink/model/user/Roles.java
    create model/src/main/java/com/sensetif/sink/model/user/Permission.java
+   create model/src/main/java/com/sensetif/sink/model/user/Permissions.java
    create model/src/main/java/com/sensetif/sink/model/user/Group.java
    create model/src/main/java/com/sensetif/sink/model/user/Groups.java
    create model/src/main/java/com/sensetif/sink/model/user/AuthService.java
+   create model/src/main/java/com/sensetif/sink/model/user/AuthBackend.java
    create model/src/main/java/com/sensetif/sink/model/user/AuthConfiguration.java
-   create model/src/main/resources/com/sensetif/sink/model/user/AuthConfiguration.yaml
+   create app/src/main/config/development/AuthService.properties
+   create app/src/main/config/qa/AuthService.properties
+   create app/src/main/config/staging/AuthService.properties
+   create app/src/main/config/production/AuthService.properties
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/OrganizationModule.java
-   create model/src/main/java/com/sensetif/sink/model/organization/Organizations.java
    create model/src/main/java/com/sensetif/sink/model/organization/Organization.java
    create model/src/main/java/com/sensetif/sink/model/organization/Project.java
+   create model/src/main/java/com/sensetif/sink/model/organization/Contract.java
+   create model/src/main/java/com/sensetif/sink/model/organization/ContractPart.java
+   create model/src/main/java/com/sensetif/sink/model/organization/Order.java
+   create model/src/main/java/com/sensetif/sink/model/organization/OrderConfirmation.java
    create model/src/main/java/com/sensetif/sink/model/organization/Invoice.java
    create model/src/main/java/com/sensetif/sink/model/organization/CreditLimit.java
-   create model/src/main/java/com/sensetif/sink/model/organization/OrderConfirmation.java
+   create model/src/main/java/com/sensetif/sink/model/organization/Label.java
    create model/src/main/java/com/sensetif/sink/model/organization/PaypalNotification.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/SensorModule.java
-   create model/src/main/java/com/sensetif/sink/model/sensor/SensorData.java
-   create model/src/main/java/com/sensetif/sink/model/sensor/Sensor.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/SensorDetails.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/SensorPoll.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/Access.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/JsonDocumentAddress.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/XmlDocumentAddress.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/ModbusDeviceAddress.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/JsonPathSelector.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/XPathSelector.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/ModbusSelector.java
    create model/src/main/java/com/sensetif/sink/model/sensor/PollSchedule.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/AccessType.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/Address.java
+   create model/src/main/java/com/sensetif/sink/model/sensor/Selector.java
+   create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/JmxModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/domain/SecurityModule.java
    create model/src/main/java/com/sensetif/sink/model/security/CryptoConfiguration.java
    create model/src/main/java/com/sensetif/sink/model/security/CryptoException.java
@@ -381,8 +421,18 @@ we will create a complete project, like this
    create model/src/main/java/com/sensetif/sink/model/security/SecurityRepository.java
    create model/src/main/java/com/sensetif/sink/model/security/User.java
    create model/src/main/java/com/sensetif/sink/model/security/UserFactory.java
+   create bootstrap/src/main/java/com/sensetif/sink/bootstrap/connectivity/HttpServerModule.java
    create bootstrap/src/main/java/com/sensetif/sink/bootstrap/connectivity/RestApiModule.java
    create rest/src/main/java/com/sensetif/sink/rest/security/DefaultEnroler.java
    create rest/src/main/java/com/sensetif/sink/rest/security/DefaultVerifier.java
+   create app/src/main/config/development/es-cassandra.properties
+   create app/src/main/config/qa/es-cassandra.properties
+   create app/src/main/config/staging/es-cassandra.properties
+   create app/src/main/config/production/es-cassandra.properties
 ----
 
+Notice that there is a ++app/src/main/config++ directory with 4 sub-directories. Each of those subdirectories
+represents one of the modes in ++Application.Mode++. The start script will look for the environment variable
+SYS_ENVIRONMENT and select the ++Application.Mode++ accordingly and set the configuration directory
+(i.e. make it part of the CLASSPATH) to such.
+


[2/4] polygene-java git commit: One more test about configuration instantiation.

Posted by ni...@apache.org.
One more test about configuration instantiation.

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/7e83d0ba
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/7e83d0ba
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/7e83d0ba

Branch: refs/heads/develop
Commit: 7e83d0bafe70703f3cbf05587133c0188ddbf1ce
Parents: 14125f6
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 4 17:26:25 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 4 17:26:25 2017 +0800

----------------------------------------------------------------------
 .../ConfigurationInstantiationTest.java         | 94 ++++++++++++++++++++
 1 file changed, 94 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/7e83d0ba/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
new file mode 100644
index 0000000..404f793
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
@@ -0,0 +1,94 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.polygene.runtime.instantiation;
+
+import org.apache.polygene.api.configuration.Configuration;
+import org.apache.polygene.api.entity.Lifecycle;
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.entitystore.memory.MemoryEntityStoreService;
+import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Test;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+public class ConfigurationInstantiationTest extends AbstractPolygeneTest
+{
+
+    @Override
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        module.defaultServices();
+        module.services( MemoryEntityStoreService.class );
+        module.services( MyService.class ).instantiateOnStartup();
+        module.configurations( MyConfig.class );
+    }
+
+    @Test
+    public void givenSpecialInitializableWhenStartingExpectOsNameToBeSet()
+    {
+        MyService myService = serviceFinder.findService( MyService.class ).get();
+        assertThat( myService.osName(), equalTo(System.getProperty( "os.name" )));
+    }
+
+
+    @Mixins( MyMixin.class)
+    public interface MyService
+    {
+        String osName();
+    }
+
+    public class MyMixin
+        implements MyService, Lifecycle
+    {
+        @This
+        private Configuration<MyConfig> config;
+
+        @Override
+        public String osName()
+        {
+            return config.get().osName().get();
+        }
+
+        @Override
+        public void create()
+            throws Exception
+        {
+            config.get().osName().set( System.getProperty( "os.name" ) );
+        }
+
+        @Override
+        public void remove()
+            throws Exception
+        {
+
+        }
+    }
+
+    public interface MyConfig
+    {
+        Property<String> osName();
+    }
+}


[4/4] polygene-java git commit: Configuration default back to System Properties and Environment variables.

Posted by ni...@apache.org.
Configuration default back to System Properties and Environment variables.

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/05ddab16
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/05ddab16
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/05ddab16

Branch: refs/heads/develop
Commit: 05ddab16a0108b46ac71dd0f05f327f50dd81c1b
Parents: c782f07
Author: niclas <ni...@hedhman.org>
Authored: Sun Jun 4 18:14:54 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Sun Jun 4 18:14:54 2017 +0800

----------------------------------------------------------------------
 .../polygene/api/composite/PropertyMapper.java  |  2 +-
 .../api/configuration/Configuration.java        | 68 ++++++++++++++++----
 .../ConfigurationInstantiationTest.java         | 31 ++++++++-
 3 files changed, 85 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/05ddab16/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java b/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
index acff127..59e1f67 100644
--- a/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
+++ b/core/api/src/main/java/org/apache/polygene/api/composite/PropertyMapper.java
@@ -114,7 +114,7 @@ public final class PropertyMapper
             }
             catch( NoSuchMethodException e )
             {
-                throw new IllegalArgumentException( "Could not find any property named " + objectObjectEntry.getKey() );
+//                throw new IllegalArgumentException( "Could not find any property named " + objectObjectEntry.getKey() );
             }
             catch( IllegalAccessException e )
             {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/05ddab16/core/api/src/main/java/org/apache/polygene/api/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/configuration/Configuration.java b/core/api/src/main/java/org/apache/polygene/api/configuration/Configuration.java
index a47719f..bca886f 100644
--- a/core/api/src/main/java/org/apache/polygene/api/configuration/Configuration.java
+++ b/core/api/src/main/java/org/apache/polygene/api/configuration/Configuration.java
@@ -23,7 +23,10 @@ package org.apache.polygene.api.configuration;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Map;
 import java.util.Objects;
+import java.util.Properties;
+import java.util.stream.Stream;
 import org.apache.polygene.api.PolygeneAPI;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.PropertyMapper;
@@ -285,15 +288,19 @@ public interface Configuration<T>
                         config = tryLoadXmlFile( buildUow, entityDescriptor, identity );
                         if( config == null )
                         {
-                            try
+                            config = tryLoadSystemProperties( buildUow, entityDescriptor, identity );
+                            if( config == null )
                             {
-                                EntityBuilder<V> configBuilder = buildUow.newEntityBuilder(
-                                    serviceModel.<V>configurationType(), identity );
-                                configBuilder.newInstance();
-                            }
-                            catch( ConstraintViolationException e )
-                            {
-                                throw new NoSuchConfigurationException( configType, identity, e );
+                                try
+                                {
+                                    EntityBuilder<V> configBuilder =
+                                        buildUow.newEntityBuilder( serviceModel.<V>configurationType(), identity );
+                                    configBuilder.newInstance();
+                                }
+                                catch( ConstraintViolationException e )
+                                {
+                                    throw new NoSuchConfigurationException( configType, identity, e );
+                                }
                             }
                         }
                     }
@@ -317,10 +324,47 @@ public interface Configuration<T>
             }
         }
 
-        private <V> V tryLoadPropertiesFile( UnitOfWork buildUow,
-                                             EntityDescriptor configType,
-                                             Identity identity
-                                           )
+        private <V> V tryLoadSystemProperties( UnitOfWork buildUow, EntityDescriptor configType, Identity identity )
+            throws InstantiationException
+        {
+            @SuppressWarnings( "unchecked" )
+            EntityBuilder<V> configBuilder = buildUow.newEntityBuilder( (Class<V>) configType.primaryType(), identity );
+            PropertyMapper.map( systemProperties(), (Composite) configBuilder.instance() );
+            return configBuilder.newInstance();
+        }
+
+        private Properties systemProperties()
+        {
+            Stream<Map.Entry<?, ?>> allProps =
+                Stream.concat( System.getenv().entrySet().stream(), System.getProperties().entrySet().stream() );
+            Properties props = new Properties();
+            allProps.forEach( entry -> props.put( transform( (String) entry.getKey() ), entry.getValue() ) );
+            return props;
+        }
+
+        private String transform( String text )
+        {
+            boolean upper = false;
+            StringBuilder builder = new StringBuilder();
+            for( int i = 0; i < text.length(); i++ )
+            {
+                char ch = Character.toLowerCase( text.charAt( i ) );
+                if( ch == '.' )
+                {
+                    upper = true;
+                    continue;
+                }
+                if( upper )
+                {
+                    ch = Character.toUpperCase( ch );
+                    upper = false;
+                }
+                builder.append( ch );
+            }
+            return builder.toString();
+        }
+
+        private <V> V tryLoadPropertiesFile( UnitOfWork buildUow, EntityDescriptor configType, Identity identity )
             throws InstantiationException
         {
             @SuppressWarnings( "unchecked" )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/05ddab16/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
index 404f793..59b6880 100644
--- a/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/instantiation/ConfigurationInstantiationTest.java
@@ -44,20 +44,29 @@ public class ConfigurationInstantiationTest extends AbstractPolygeneTest
         module.services( MemoryEntityStoreService.class );
         module.services( MyService.class ).instantiateOnStartup();
         module.configurations( MyConfig.class );
+        System.setProperty( "path", "fakepath" );
     }
 
     @Test
     public void givenSpecialInitializableWhenStartingExpectOsNameToBeSet()
     {
         MyService myService = serviceFinder.findService( MyService.class ).get();
-        assertThat( myService.osName(), equalTo(System.getProperty( "os.name" )));
+        assertThat( myService.osName(), equalTo( System.getProperty( "os.name" ) ) );
+        if( myService.osName().equalsIgnoreCase( "Linux" ) )
+        {
+            assertThat( myService.home(), equalTo( System.getProperty( "user.home" ) ) );
+        }
+        assertThat( myService.path(), equalTo( System.getProperty( "path" ) ) );
     }
 
-
-    @Mixins( MyMixin.class)
+    @Mixins( MyMixin.class )
     public interface MyService
     {
         String osName();
+
+        String home();
+
+        String path();
     }
 
     public class MyMixin
@@ -73,6 +82,18 @@ public class ConfigurationInstantiationTest extends AbstractPolygeneTest
         }
 
         @Override
+        public String home()
+        {
+            return config.get().home().get();
+        }
+
+        @Override
+        public String path()
+        {
+            return config.get().path().get();
+        }
+
+        @Override
         public void create()
             throws Exception
         {
@@ -90,5 +111,9 @@ public class ConfigurationInstantiationTest extends AbstractPolygeneTest
     public interface MyConfig
     {
         Property<String> osName();
+
+        Property<String> home();
+
+        Property<String> path();
     }
 }