polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [15/80] [partial] zest-java git commit: First round of changes to move to org.apache.zest namespace.
Date Thu, 30 Jul 2015 19:48:14 GMT
http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java
new file mode 100644
index 0000000..c199bee
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/LayerAssemblyImpl.java
@@ -0,0 +1,625 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.zest.api.activation.Activator;
+import org.apache.zest.api.common.MetaInfo;
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.api.service.ServiceImporter;
+import org.apache.zest.api.structure.Layer;
+import org.apache.zest.bootstrap.ApplicationAssembly;
+import org.apache.zest.bootstrap.AssemblyVisitor;
+import org.apache.zest.bootstrap.EntityAssembly;
+import org.apache.zest.bootstrap.EntityDeclaration;
+import org.apache.zest.bootstrap.ImportedServiceAssembly;
+import org.apache.zest.bootstrap.ImportedServiceDeclaration;
+import org.apache.zest.bootstrap.LayerAssembly;
+import org.apache.zest.bootstrap.ModuleAssembly;
+import org.apache.zest.bootstrap.ObjectAssembly;
+import org.apache.zest.bootstrap.ObjectDeclaration;
+import org.apache.zest.bootstrap.ServiceAssembly;
+import org.apache.zest.bootstrap.ServiceDeclaration;
+import org.apache.zest.bootstrap.TransientAssembly;
+import org.apache.zest.bootstrap.TransientDeclaration;
+import org.apache.zest.bootstrap.ValueAssembly;
+import org.apache.zest.bootstrap.ValueDeclaration;
+import org.apache.zest.functional.Specification;
+
+/**
+ * Assembly of a Layer. From here you can create more ModuleAssemblies for
+ * the Layer that is being assembled. It is also here that you define
+ * what other Layers this Layer is using by calling {@link org.apache.zest.runtime.bootstrap.LayerAssemblyImpl#uses()}.
+ */
+public final class LayerAssemblyImpl
+    implements LayerAssembly
+{
+    private final ApplicationAssembly applicationAssembly;
+    private final HashMap<String, ModuleAssemblyImpl> moduleAssemblies;
+    private final Set<LayerAssembly> uses;
+
+    private String name;
+    private final MetaInfo metaInfo = new MetaInfo();
+    private final List<Class<? extends Activator<Layer>>> activators = new ArrayList<>();
+
+    public LayerAssemblyImpl( ApplicationAssembly applicationAssembly, String name )
+    {
+        this.applicationAssembly = applicationAssembly;
+        this.name = name;
+
+        moduleAssemblies = new LinkedHashMap<>();
+        uses = new LinkedHashSet<>();
+    }
+
+    @Override
+    public ModuleAssembly module( String name )
+    {
+        if( name != null )
+        {
+            ModuleAssemblyImpl existing = moduleAssemblies.get( name );
+            if( existing != null )
+            {
+                return existing;
+            }
+        }
+        ModuleAssemblyImpl moduleAssembly = new ModuleAssemblyImpl( this, name );
+        moduleAssemblies.put( name, moduleAssembly );
+        return moduleAssembly;
+    }
+
+    @Override
+    public ApplicationAssembly application()
+    {
+        return applicationAssembly;
+    }
+
+    @Override
+    public LayerAssembly setName( String name )
+    {
+        this.name = name;
+        return this;
+    }
+
+    @Override
+    public LayerAssembly setMetaInfo( Object info )
+    {
+        metaInfo.set( info );
+        return this;
+    }
+
+    @Override
+    public LayerAssembly uses( LayerAssembly... layerAssembly )
+        throws IllegalArgumentException
+    {
+        uses.addAll( Arrays.asList( layerAssembly ) );
+        return this;
+    }
+
+    @Override
+    @SafeVarargs
+    public final LayerAssembly withActivators( Class<? extends Activator<Layer>>... activators )
+    {
+        this.activators.addAll( Arrays.asList( activators ) );
+        return this;
+    }
+
+    @Override
+    public <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType> visitor )
+        throws ThrowableType
+    {
+        visitor.visitLayer( this );
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            moduleAssembly.visit( visitor );
+        }
+    }
+
+    @Override
+    public EntityDeclaration entities( Specification<? super EntityAssembly> specification )
+    {
+        final List<EntityDeclaration> declarations = new ArrayList<>();
+
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            declarations.add( moduleAssembly.entities( specification ) );
+        }
+
+        return new EntityDeclaration()
+        {
+            @Override
+            public EntityDeclaration setMetaInfo( Object info )
+            {
+                for( EntityDeclaration declaration : declarations )
+                {
+                    declaration.setMetaInfo( info );
+                }
+                return this;
+            }
+
+            @Override
+            public EntityDeclaration visibleIn( Visibility visibility )
+            {
+                for( EntityDeclaration declaration : declarations )
+                {
+                    declaration.visibleIn( visibility );
+                }
+                return this;
+            }
+
+            @Override
+            public EntityDeclaration withConcerns( Class<?>... concerns )
+            {
+                for( EntityDeclaration declaration : declarations )
+                {
+                    declaration.withConcerns( concerns );
+                }
+                return this;
+            }
+
+            @Override
+            public EntityDeclaration withSideEffects( Class<?>... sideEffects )
+            {
+                for( EntityDeclaration declaration : declarations )
+                {
+                    declaration.withSideEffects( sideEffects );
+                }
+                return this;
+            }
+
+            @Override
+            public EntityDeclaration withMixins( Class<?>... mixins )
+            {
+                for( EntityDeclaration declaration : declarations )
+                {
+                    declaration.withMixins( mixins );
+                }
+                return this;
+            }
+
+            @Override
+            public EntityDeclaration withTypes( Class<?>... types )
+            {
+                for( EntityDeclaration declaration : declarations )
+                {
+                    declaration.withTypes( types );
+                }
+                return this;
+            }
+        };
+    }
+
+    @Override
+    public ServiceDeclaration services( Specification<? super ServiceAssembly> specification )
+    {
+        final List<ServiceDeclaration> declarations = new ArrayList<>();
+
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            declarations.add( moduleAssembly.services( specification ) );
+        }
+
+        return new ServiceDeclaration()
+        {
+            @Override
+            public ServiceDeclaration setMetaInfo( Object serviceAttribute )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.setMetaInfo( serviceAttribute );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration visibleIn( Visibility visibility )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.visibleIn( visibility );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration withConcerns( Class<?>... concerns )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.withConcerns( concerns );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration withSideEffects( Class<?>... sideEffects )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.withSideEffects( sideEffects );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration withMixins( Class<?>... mixins )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.withMixins( mixins );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration withTypes( Class<?>... types )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.withTypes( types );
+                }
+                return this;
+            }
+
+            @Override
+            @SafeVarargs
+            public final ServiceDeclaration withActivators( Class<? extends Activator<?>>... activators )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.withActivators( activators );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration identifiedBy( String identity )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.identifiedBy( identity );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration taggedWith( String... tags )
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.taggedWith( tags );
+                }
+                return this;
+            }
+
+            @Override
+            public ServiceDeclaration instantiateOnStartup()
+            {
+                for( ServiceDeclaration declaration : declarations )
+                {
+                    declaration.instantiateOnStartup();
+                }
+
+                return this;
+            }
+        };
+    }
+
+    @Override
+    public TransientDeclaration transients( Specification<? super TransientAssembly> specification )
+    {
+        final List<TransientDeclaration> declarations = new ArrayList<>();
+
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            declarations.add( moduleAssembly.transients( specification ) );
+        }
+
+        return new TransientDeclaration()
+        {
+            @Override
+            public TransientDeclaration setMetaInfo( Object info )
+            {
+                for( TransientDeclaration declaration : declarations )
+                {
+                    declaration.setMetaInfo( info );
+                }
+                return this;
+            }
+
+            @Override
+            public TransientDeclaration visibleIn( Visibility visibility )
+            {
+                for( TransientDeclaration declaration : declarations )
+                {
+                    declaration.visibleIn( visibility );
+                }
+                return this;
+            }
+
+            @Override
+            public TransientDeclaration withConcerns( Class<?>... concerns )
+            {
+                for( TransientDeclaration declaration : declarations )
+                {
+                    declaration.withConcerns( concerns );
+                }
+                return this;
+            }
+
+            @Override
+            public TransientDeclaration withSideEffects( Class<?>... sideEffects )
+            {
+                for( TransientDeclaration declaration : declarations )
+                {
+                    declaration.withSideEffects( sideEffects );
+                }
+                return this;
+            }
+
+            @Override
+            public TransientDeclaration withMixins( Class<?>... mixins )
+            {
+                for( TransientDeclaration declaration : declarations )
+                {
+                    declaration.withMixins( mixins );
+                }
+                return this;
+            }
+
+            @Override
+            public TransientDeclaration withTypes( Class<?>... types )
+            {
+                for( TransientDeclaration declaration : declarations )
+                {
+                    declaration.withTypes( types );
+                }
+                return this;
+            }
+        };
+    }
+
+    @Override
+    public ValueDeclaration values( Specification<? super ValueAssembly> specification )
+    {
+        final List<ValueDeclaration> declarations = new ArrayList<>();
+
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            declarations.add( moduleAssembly.values( specification ) );
+        }
+        return new ValueDeclaration()
+        {
+            @Override
+            public ValueDeclaration setMetaInfo( Object info )
+            {
+                for( ValueDeclaration declaration : declarations )
+                {
+                    declaration.setMetaInfo( info );
+                }
+                return this;
+            }
+
+            @Override
+            public ValueDeclaration visibleIn( Visibility visibility )
+            {
+                for( ValueDeclaration declaration : declarations )
+                {
+                    declaration.visibleIn( visibility );
+                }
+                return this;
+            }
+
+            @Override
+            public ValueDeclaration withConcerns( Class<?>... concerns )
+            {
+                for( ValueDeclaration declaration : declarations )
+                {
+                    declaration.withConcerns( concerns );
+                }
+                return this;
+            }
+
+            @Override
+            public ValueDeclaration withSideEffects( Class<?>... sideEffects )
+            {
+                for( ValueDeclaration declaration : declarations )
+                {
+                    declaration.withSideEffects( sideEffects );
+                }
+                return this;
+            }
+
+            @Override
+            public ValueDeclaration withMixins( Class<?>... mixins )
+            {
+                for( ValueDeclaration declaration : declarations )
+                {
+                    declaration.withMixins( mixins );
+                }
+                return this;
+            }
+
+            @Override
+            public ValueDeclaration withTypes( Class<?>... types )
+            {
+                for( ValueDeclaration declaration : declarations )
+                {
+                    declaration.withTypes( types );
+                }
+                return this;
+            }
+        };
+    }
+
+    @Override
+    public ObjectDeclaration objects( Specification<? super ObjectAssembly> specification )
+    {
+        final List<ObjectDeclaration> declarations = new ArrayList<>();
+
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            declarations.add( moduleAssembly.objects( specification ) );
+        }
+        return new ObjectDeclaration()
+        {
+            @Override
+            public ObjectDeclaration setMetaInfo( Object info )
+            {
+                for( ObjectDeclaration declaration : declarations )
+                {
+                    declaration.setMetaInfo( info );
+                }
+                return this;
+            }
+
+            @Override
+            public ObjectDeclaration visibleIn( Visibility visibility )
+                throws IllegalStateException
+            {
+                for( ObjectDeclaration declaration : declarations )
+                {
+                    declaration.visibleIn( visibility );
+                }
+                return this;
+            }
+        };
+    }
+
+    @Override
+    public ImportedServiceDeclaration importedServices( Specification<? super ImportedServiceAssembly> specification )
+    {
+        final List<ImportedServiceDeclaration> declarations = new ArrayList<>();
+
+        for( ModuleAssemblyImpl moduleAssembly : moduleAssemblies.values() )
+        {
+            declarations.add( moduleAssembly.importedServices( specification ) );
+        }
+        return new ImportedServiceDeclaration()
+        {
+
+            @Override
+            public ImportedServiceDeclaration importOnStartup()
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.importOnStartup();
+                }
+                return this;
+            }
+
+            @Override
+            public ImportedServiceDeclaration visibleIn( Visibility visibility )
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.visibleIn( visibility );
+                }
+                return this;
+            }
+
+            @Override
+            public ImportedServiceDeclaration importedBy( Class<? extends ServiceImporter> serviceImporterClass )
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.importedBy( serviceImporterClass );
+                }
+                return this;
+            }
+
+            @Override
+            public ImportedServiceDeclaration identifiedBy( String identity )
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.identifiedBy( identity );
+                }
+                return this;
+            }
+
+            @Override
+            public ImportedServiceDeclaration taggedWith( String... tags )
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.taggedWith( tags );
+                }
+                return this;
+            }
+
+            @Override
+            public ImportedServiceDeclaration setMetaInfo( Object serviceAttribute )
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.setMetaInfo( serviceAttribute );
+                }
+                return this;
+            }
+
+            @Override
+            @SafeVarargs
+            public final ImportedServiceDeclaration withActivators( Class<? extends Activator<?>>... activators )
+            {
+                for( ImportedServiceDeclaration declaration : declarations )
+                {
+                    declaration.withActivators( activators );
+                }
+                return this;
+            }
+
+        };
+    }
+
+    Collection<ModuleAssemblyImpl> moduleAssemblies()
+    {
+        return moduleAssemblies.values();
+    }
+
+    Set<LayerAssembly> uses()
+    {
+        return uses;
+    }
+
+    public MetaInfo metaInfo()
+    {
+        return metaInfo;
+    }
+
+    @Override
+    public String name()
+    {
+        return name;
+    }
+
+    public List<Class<? extends Activator<Layer>>> activators()
+    {
+        return activators;
+    }
+
+    @Override
+    public final String toString()
+    {
+        return "LayerAssembly [" + name + "]";
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
new file mode 100644
index 0000000..673dfe7
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ModuleAssemblyImpl.java
@@ -0,0 +1,635 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.zest.api.activation.Activator;
+import org.apache.zest.api.common.MetaInfo;
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.api.composite.TransientComposite;
+import org.apache.zest.api.entity.EntityComposite;
+import org.apache.zest.api.entity.Identity;
+import org.apache.zest.api.service.DuplicateServiceIdentityException;
+import org.apache.zest.api.service.ServiceImporter;
+import org.apache.zest.api.structure.Module;
+import org.apache.zest.api.type.HasTypes;
+import org.apache.zest.api.type.MatchTypeSpecification;
+import org.apache.zest.api.value.ValueComposite;
+import org.apache.zest.bootstrap.AssemblyException;
+import org.apache.zest.bootstrap.AssemblySpecifications;
+import org.apache.zest.bootstrap.AssemblyVisitor;
+import org.apache.zest.bootstrap.ConfigurationDeclaration;
+import org.apache.zest.bootstrap.EntityAssembly;
+import org.apache.zest.bootstrap.EntityDeclaration;
+import org.apache.zest.bootstrap.ImportedServiceAssembly;
+import org.apache.zest.bootstrap.ImportedServiceDeclaration;
+import org.apache.zest.bootstrap.LayerAssembly;
+import org.apache.zest.bootstrap.MetaInfoDeclaration;
+import org.apache.zest.bootstrap.MixinDeclaration;
+import org.apache.zest.bootstrap.ModuleAssembly;
+import org.apache.zest.bootstrap.ObjectAssembly;
+import org.apache.zest.bootstrap.ObjectDeclaration;
+import org.apache.zest.bootstrap.ServiceAssembly;
+import org.apache.zest.bootstrap.ServiceDeclaration;
+import org.apache.zest.bootstrap.TransientAssembly;
+import org.apache.zest.bootstrap.TransientDeclaration;
+import org.apache.zest.bootstrap.ValueAssembly;
+import org.apache.zest.bootstrap.ValueDeclaration;
+import org.apache.zest.functional.Iterables;
+import org.apache.zest.functional.Specification;
+import org.apache.zest.functional.Specifications;
+import org.apache.zest.runtime.activation.ActivatorsModel;
+import org.apache.zest.runtime.composite.TransientModel;
+import org.apache.zest.runtime.composite.TransientsModel;
+import org.apache.zest.runtime.entity.EntitiesModel;
+import org.apache.zest.runtime.entity.EntityModel;
+import org.apache.zest.runtime.object.ObjectModel;
+import org.apache.zest.runtime.object.ObjectsModel;
+import org.apache.zest.runtime.service.ImportedServiceModel;
+import org.apache.zest.runtime.service.ImportedServicesModel;
+import org.apache.zest.runtime.service.ServiceModel;
+import org.apache.zest.runtime.service.ServicesModel;
+import org.apache.zest.runtime.structure.ModuleModel;
+import org.apache.zest.runtime.value.ValueModel;
+import org.apache.zest.runtime.value.ValuesModel;
+
+import static org.apache.zest.functional.Iterables.first;
+import static org.apache.zest.functional.Iterables.iterable;
+
+/**
+ * Assembly of a Module. This is where you register all objects, Composites,
+ * Services. Each "add" method returns a declaration that you can use to add
+ * additional information and metadata. If you call an "add" method with many
+ * parameters then the declared metadata will apply to all types in the method
+ * call.
+ */
+public final class ModuleAssemblyImpl
+    implements ModuleAssembly
+{
+    private final LayerAssembly layerAssembly;
+    private String name;
+    private final MetaInfo metaInfo = new MetaInfo();
+    private final List<Class<? extends Activator<Module>>> activators = new ArrayList<>();
+
+    private final List<ServiceAssemblyImpl> serviceAssemblies = new ArrayList<>();
+    private final Map<Class<?>, ImportedServiceAssemblyImpl> importedServiceAssemblies = new LinkedHashMap<>();
+    private final Map<Class<? extends EntityComposite>, EntityAssemblyImpl> entityAssemblies = new LinkedHashMap<>();
+    private final Map<Class<? extends ValueComposite>, ValueAssemblyImpl> valueAssemblies = new LinkedHashMap<>();
+    private final Map<Class<? extends TransientComposite>, TransientAssemblyImpl> transientAssemblies = new LinkedHashMap<>();
+    private final Map<Class<?>, ObjectAssemblyImpl> objectAssemblies = new LinkedHashMap<>();
+
+    private final MetaInfoDeclaration metaInfoDeclaration = new MetaInfoDeclaration();
+
+    public ModuleAssemblyImpl( LayerAssembly layerAssembly, String name )
+    {
+        this.layerAssembly = layerAssembly;
+        this.name = name;
+    }
+
+    @Override
+    public LayerAssembly layer()
+    {
+        return layerAssembly;
+    }
+
+    @Override
+    public ModuleAssembly module( String layerName, String moduleName )
+    {
+        return layerAssembly.application().module( layerName, moduleName );
+    }
+
+    @Override
+    public ModuleAssembly setName( String name )
+    {
+        this.name = name;
+        return this;
+    }
+
+    @Override
+    public String name()
+    {
+        return name;
+    }
+
+    public ModuleAssembly setMetaInfo( Object info )
+    {
+        metaInfo.set( info );
+        return this;
+    }
+
+    @Override
+    @SafeVarargs
+    public final ModuleAssembly withActivators( Class<? extends Activator<Module>>... activators )
+    {
+        this.activators.addAll( Arrays.asList( activators ) );
+        return this;
+    }
+
+    @Override
+    @SuppressWarnings( {"raw", "unchecked"} )
+    public ValueDeclaration values( Class<?>... valueTypes )
+    {
+        List<ValueAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class valueType : valueTypes )
+        {
+            if( valueAssemblies.containsKey( valueType ) )
+            {
+                assemblies.add( valueAssemblies.get( valueType ) );
+            }
+            else
+            {
+                ValueAssemblyImpl valueAssembly = new ValueAssemblyImpl( valueType );
+                valueAssemblies.put( valueType, valueAssembly );
+                assemblies.add( valueAssembly );
+            }
+        }
+
+        return new ValueDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ValueDeclaration values( Specification<? super ValueAssembly> specification )
+    {
+        List<ValueAssemblyImpl> assemblies = new ArrayList<>();
+        for( ValueAssemblyImpl transientAssembly : valueAssemblies.values() )
+        {
+            if( specification.satisfiedBy( transientAssembly ) )
+            {
+                assemblies.add( transientAssembly );
+            }
+        }
+
+        return new ValueDeclarationImpl( assemblies );
+    }
+
+    @Override
+    @SuppressWarnings( {"raw", "unchecked"} )
+    public TransientDeclaration transients( Class<?>... transientTypes )
+    {
+        List<TransientAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class valueType : transientTypes )
+        {
+            if( transientAssemblies.containsKey( valueType ) )
+            {
+                assemblies.add( transientAssemblies.get( valueType ) );
+            }
+            else
+            {
+                TransientAssemblyImpl transientAssembly = new TransientAssemblyImpl( valueType );
+                transientAssemblies.put( valueType, transientAssembly );
+                assemblies.add( transientAssembly );
+            }
+        }
+
+        return new TransientDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public TransientDeclaration transients( Specification<? super TransientAssembly> specification )
+    {
+        List<TransientAssemblyImpl> assemblies = new ArrayList<>();
+        for( TransientAssemblyImpl transientAssembly : transientAssemblies.values() )
+        {
+            if( specification.satisfiedBy( transientAssembly ) )
+            {
+                assemblies.add( transientAssembly );
+            }
+        }
+
+        return new TransientDeclarationImpl( assemblies );
+    }
+
+    @Override
+    @SuppressWarnings( {"raw", "unchecked"} )
+    public EntityDeclaration entities( Class<?>... entityTypes )
+    {
+        List<EntityAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class entityType : entityTypes )
+        {
+            if( entityAssemblies.containsKey( entityType ) )
+            {
+                assemblies.add( entityAssemblies.get( entityType ) );
+            }
+            else
+            {
+                EntityAssemblyImpl entityAssembly = new EntityAssemblyImpl( entityType );
+                entityAssemblies.put( entityType, entityAssembly );
+                assemblies.add( entityAssembly );
+            }
+        }
+
+        return new EntityDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public EntityDeclaration entities( Specification<? super EntityAssembly> specification )
+    {
+        List<EntityAssemblyImpl> assemblies = new ArrayList<>();
+        for( EntityAssemblyImpl entityAssembly : entityAssemblies.values() )
+        {
+            if( specification.satisfiedBy( entityAssembly ) )
+            {
+                assemblies.add( entityAssembly );
+            }
+        }
+
+        return new EntityDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ConfigurationDeclaration configurations( Class<?>... configurationTypes )
+    {
+        List<EntityAssemblyImpl> entityAssemblyList = new ArrayList<>();
+
+        for( Class entityType : configurationTypes )
+        {
+            if( this.entityAssemblies.containsKey( entityType ) )
+            {
+                entityAssemblyList.add( this.entityAssemblies.get( entityType ) );
+            }
+            else
+            {
+                EntityAssemblyImpl entityAssembly = new EntityAssemblyImpl( entityType );
+                this.entityAssemblies.put( entityType, entityAssembly );
+                entityAssemblyList.add( entityAssembly );
+            }
+        }
+
+        List<ValueAssemblyImpl> valueAssemblyList = new ArrayList<>();
+
+        for( Class valueType : configurationTypes )
+        {
+            if( valueAssemblies.containsKey( valueType ) )
+            {
+                valueAssemblyList.add( valueAssemblies.get( valueType ) );
+            }
+            else
+            {
+                ValueAssemblyImpl valueAssembly = new ValueAssemblyImpl( valueType );
+                valueAssemblies.put( valueType, valueAssembly );
+                valueAssemblyList.add( valueAssembly );
+                valueAssembly.types.add( Identity.class );
+            }
+        }
+
+        return new ConfigurationDeclarationImpl( entityAssemblyList, valueAssemblyList  );
+    }
+
+    @Override
+    public ConfigurationDeclaration configurations( Specification<HasTypes> specification )
+    {
+        Specification<HasTypes> isConfigurationComposite = new MatchTypeSpecification( Identity.class );
+        specification = Specifications.and( specification, isConfigurationComposite );
+        List<EntityAssemblyImpl> entityAssmblyList = new ArrayList<>();
+        for( EntityAssemblyImpl entityAssembly : entityAssemblies.values() )
+        {
+            if( specification.satisfiedBy( entityAssembly ) )
+            {
+                entityAssmblyList.add( entityAssembly );
+            }
+        }
+        List<ValueAssemblyImpl> valueAssemblyList = new ArrayList<>();
+        for( ValueAssemblyImpl transientAssembly : valueAssemblies.values() )
+        {
+            if( specification.satisfiedBy( transientAssembly ) )
+            {
+                valueAssemblyList.add( transientAssembly );
+            }
+        }
+        return new ConfigurationDeclarationImpl( entityAssmblyList, valueAssemblyList );
+    }
+
+    @Override
+    public ObjectDeclaration objects( Class<?>... objectTypes )
+        throws AssemblyException
+    {
+        List<ObjectAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class<?> objectType : objectTypes )
+        {
+            if( objectType.isInterface() )
+            {
+                throw new AssemblyException( "Interfaces can not be Zest Objects." );
+            }
+            if( objectAssemblies.containsKey( objectType ) )
+            {
+                assemblies.add( objectAssemblies.get( objectType ) );
+            }
+            else
+            {
+                ObjectAssemblyImpl objectAssembly = new ObjectAssemblyImpl( objectType );
+                objectAssemblies.put( objectType, objectAssembly );
+                assemblies.add( objectAssembly );
+            }
+        }
+
+        return new ObjectDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ObjectDeclaration objects( Specification<? super ObjectAssembly> specification )
+    {
+        List<ObjectAssemblyImpl> assemblies = new ArrayList<>();
+        for( ObjectAssemblyImpl objectAssembly : objectAssemblies.values() )
+        {
+            if( specification.satisfiedBy( objectAssembly ) )
+            {
+                assemblies.add( objectAssembly );
+            }
+        }
+
+        return new ObjectDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ServiceDeclaration addServices( Class<?>... serviceTypes )
+    {
+        List<ServiceAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class<?> serviceType : serviceTypes )
+        {
+            ServiceAssemblyImpl serviceAssembly = new ServiceAssemblyImpl( serviceType );
+            serviceAssemblies.add( serviceAssembly );
+            assemblies.add( serviceAssembly );
+        }
+
+        return new ServiceDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ServiceDeclaration services( Class<?>... serviceTypes )
+    {
+        List<ServiceAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class<?> serviceType : serviceTypes )
+        {
+            if( Iterables.matchesAny( AssemblySpecifications.types( serviceType ), serviceAssemblies ) )
+            {
+                Iterables.addAll( assemblies, Iterables.filter( AssemblySpecifications.types( serviceType ), serviceAssemblies ) );
+            }
+            else
+            {
+                ServiceAssemblyImpl serviceAssembly = new ServiceAssemblyImpl( serviceType );
+                serviceAssemblies.add( serviceAssembly );
+                assemblies.add( serviceAssembly );
+            }
+        }
+
+        return new ServiceDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ServiceDeclaration services( Specification<? super ServiceAssembly> specification )
+    {
+        List<ServiceAssemblyImpl> assemblies = new ArrayList<>();
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            if( specification.satisfiedBy( serviceAssembly ) )
+            {
+                assemblies.add( serviceAssembly );
+            }
+        }
+
+        return new ServiceDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ImportedServiceDeclaration importedServices( Class<?>... serviceTypes )
+    {
+        List<ImportedServiceAssemblyImpl> assemblies = new ArrayList<>();
+
+        for( Class<?> serviceType : serviceTypes )
+        {
+            if( importedServiceAssemblies.containsKey( serviceType ) )
+            {
+                assemblies.add( importedServiceAssemblies.get( serviceType ) );
+            }
+            else
+            {
+                ImportedServiceAssemblyImpl serviceAssembly = new ImportedServiceAssemblyImpl( serviceType, this );
+                importedServiceAssemblies.put( serviceType, serviceAssembly );
+                assemblies.add( serviceAssembly );
+            }
+        }
+
+        return new ImportedServiceDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public ImportedServiceDeclaration importedServices( Specification<? super ImportedServiceAssembly> specification )
+    {
+        List<ImportedServiceAssemblyImpl> assemblies = new ArrayList<>();
+        for( ImportedServiceAssemblyImpl objectAssembly : importedServiceAssemblies.values() )
+        {
+            if( specification.satisfiedBy( objectAssembly ) )
+            {
+                assemblies.add( objectAssembly );
+            }
+        }
+
+        return new ImportedServiceDeclarationImpl( assemblies );
+    }
+
+    @Override
+    public <T> MixinDeclaration<T> forMixin( Class<T> mixinType )
+    {
+        return metaInfoDeclaration.on( mixinType );
+    }
+
+    @Override
+    public <ThrowableType extends Throwable> void visit( AssemblyVisitor<ThrowableType> visitor )
+        throws ThrowableType
+    {
+        visitor.visitModule( this );
+
+        for( TransientAssemblyImpl compositeDeclaration : transientAssemblies.values() )
+        {
+            visitor.visitComposite( new TransientDeclarationImpl( iterable( compositeDeclaration ) ) );
+        }
+
+        for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() )
+        {
+            visitor.visitEntity( new EntityDeclarationImpl( iterable( entityDeclaration ) ) );
+        }
+
+        for( ObjectAssemblyImpl objectDeclaration : objectAssemblies.values() )
+        {
+            visitor.visitObject( new ObjectDeclarationImpl( iterable( objectDeclaration ) ) );
+        }
+
+        for( ServiceAssemblyImpl serviceDeclaration : serviceAssemblies )
+        {
+            visitor.visitService( new ServiceDeclarationImpl( iterable( serviceDeclaration ) ) );
+        }
+
+        for( ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values() )
+        {
+            visitor.visitImportedService( new ImportedServiceDeclarationImpl( iterable( importedServiceDeclaration ) ) );
+        }
+
+        for( ValueAssemblyImpl valueDeclaration : valueAssemblies.values() )
+        {
+            visitor.visitValue( new ValueDeclarationImpl( iterable( valueDeclaration ) ) );
+        }
+    }
+
+    ModuleModel assembleModule( AssemblyHelper helper )
+        throws AssemblyException
+    {
+        List<TransientModel> transientModels = new ArrayList<>();
+        List<ObjectModel> objectModels = new ArrayList<>();
+        List<ValueModel> valueModels = new ArrayList<>();
+        List<ServiceModel> serviceModels = new ArrayList<>();
+        List<ImportedServiceModel> importedServiceModels = new ArrayList<>();
+
+        if( name == null )
+        {
+            throw new AssemblyException( "Module must have name set" );
+        }
+
+        for( TransientAssemblyImpl compositeDeclaration : transientAssemblies.values() )
+        {
+            transientModels.add( compositeDeclaration.newTransientModel( metaInfoDeclaration, helper ) );
+        }
+
+        for( ValueAssemblyImpl valueDeclaration : valueAssemblies.values() )
+        {
+            valueModels.add( valueDeclaration.newValueModel( metaInfoDeclaration, helper ) );
+        }
+
+        List<EntityModel> entityModels = new ArrayList<>();
+        for( EntityAssemblyImpl entityDeclaration : entityAssemblies.values() )
+        {
+            entityModels.add( entityDeclaration.newEntityModel( metaInfoDeclaration, 
+                                                                metaInfoDeclaration, 
+                                                                metaInfoDeclaration, 
+                                                                metaInfoDeclaration, 
+                                                                helper ) );
+        }
+
+        for( ObjectAssemblyImpl objectDeclaration : objectAssemblies.values() )
+        {
+            objectDeclaration.addObjectModel( objectModels );
+        }
+
+        for( ServiceAssemblyImpl serviceDeclaration : serviceAssemblies )
+        {
+            if( serviceDeclaration.identity == null )
+            {
+                serviceDeclaration.identity = generateId( serviceDeclaration.types() );
+            }
+
+            serviceModels.add( serviceDeclaration.newServiceModel( metaInfoDeclaration, helper ) );
+        }
+
+        for( ImportedServiceAssemblyImpl importedServiceDeclaration : importedServiceAssemblies.values() )
+        {
+            importedServiceDeclaration.addImportedServiceModel( importedServiceModels );
+        }
+
+        ModuleModel moduleModel = new ModuleModel( name,
+                                                   metaInfo,
+                                                   new ActivatorsModel<>( activators ),
+                                                   new TransientsModel( transientModels ),
+                                                   new EntitiesModel( entityModels ),
+                                                   new ObjectsModel( objectModels ),
+                                                   new ValuesModel( valueModels ),
+                                                   new ServicesModel( serviceModels ),
+                                                   new ImportedServicesModel( importedServiceModels ) );
+
+        // Check for duplicate service identities
+        Set<String> identities = new HashSet<>();
+        for( ServiceModel serviceModel : serviceModels )
+        {
+            String identity = serviceModel.identity();
+            if( identities.contains( identity ) )
+            {
+                throw new DuplicateServiceIdentityException(
+                    "Duplicated service identity: " + identity + " in module " + moduleModel.name()
+                );
+            }
+            identities.add( identity );
+        }
+        for( ImportedServiceModel serviceModel : importedServiceModels )
+        {
+            String identity = serviceModel.identity();
+            if( identities.contains( identity ) )
+            {
+                throw new DuplicateServiceIdentityException(
+                    "Duplicated service identity: " + identity + " in module " + moduleModel.name()
+                );
+            }
+            identities.add( identity );
+        }
+
+        for( ImportedServiceModel importedServiceModel : importedServiceModels )
+        {
+            boolean found = false;
+            for( ObjectModel objectModel : objectModels )
+            {
+                if( first( objectModel.types() ).equals( importedServiceModel.serviceImporter() ) )
+                {
+                    found = true;
+                    break;
+                }
+            }
+            if( !found )
+            {
+                @SuppressWarnings( "raw" )
+                Class<? extends ServiceImporter> serviceFactoryType = importedServiceModel.serviceImporter();
+                ObjectModel objectModel = new ObjectModel( serviceFactoryType, Visibility.module, new MetaInfo() );
+                objectModels.add( objectModel );
+            }
+        }
+
+        return moduleModel;
+    }
+
+    private String generateId( Iterable<Class<?>> serviceTypes )
+    {
+        // Find service identity that is not yet used
+        Class<?> serviceType = serviceTypes.iterator()
+            .next(); // Use the first Iterable, which *SHOULD* be the main serviceType
+        int idx = 0;
+        String id = serviceType.getSimpleName();
+        boolean invalid;
+        do
+        {
+            invalid = false;
+            for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+            {
+                if( serviceAssembly.identity() != null && serviceAssembly.identity().equals( id ) )
+                {
+                    idx++;
+                    id = serviceType.getSimpleName() + "_" + idx;
+                    invalid = true;
+                    break;
+                }
+            }
+        }
+        while( invalid );
+        return id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
new file mode 100644
index 0000000..f4fdd9c
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectAssemblyImpl.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.lang.reflect.Modifier;
+import java.util.List;
+import org.apache.zest.api.common.InvalidApplicationException;
+import org.apache.zest.api.common.MetaInfo;
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.api.composite.Composite;
+import org.apache.zest.bootstrap.ObjectAssembly;
+import org.apache.zest.functional.Iterables;
+import org.apache.zest.runtime.object.ObjectModel;
+
+/**
+ * Assembly of an Object.
+ */
+public final class ObjectAssemblyImpl
+    implements ObjectAssembly
+{
+    private Class<?> objectType;
+    MetaInfo metaInfo = new MetaInfo();
+    Visibility visibility = Visibility.module;
+
+    public ObjectAssemblyImpl( Class<?> clazz )
+    {
+        // best try to find out if the class is a concrete class
+        if( clazz.isEnum() ||
+            ( !Composite.class.isAssignableFrom( clazz ) && Modifier.isAbstract( clazz.getModifiers() ) ) )
+        {
+            throw new IllegalArgumentException( "Declared objects must be concrete classes: " + clazz );
+        }
+        this.objectType = clazz;
+    }
+
+    @Override
+    public Iterable<Class<?>> types()
+    {
+        return Iterables.<Class<?>>iterable( objectType );
+    }
+
+    void addObjectModel( List<ObjectModel> objectModels )
+    {
+        try
+        {
+            ObjectModel objectModel = new ObjectModel( objectType, visibility, metaInfo );
+            objectModels.add( objectModel );
+        }
+        catch( Throwable e )
+        {
+            throw new InvalidApplicationException( "Could not register " + objectType.getName(), e );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectDeclarationImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectDeclarationImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectDeclarationImpl.java
new file mode 100644
index 0000000..8a1af93
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ObjectDeclarationImpl.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.bootstrap.ObjectDeclaration;
+
+/**
+ * Declaration of an Object. Created by {@link org.apache.zest.runtime.bootstrap.ModuleAssemblyImpl#objects(Class[])}.
+ */
+public final class ObjectDeclarationImpl
+    implements ObjectDeclaration
+{
+    private final Iterable<ObjectAssemblyImpl> assemblies;
+
+    public ObjectDeclarationImpl( Iterable<ObjectAssemblyImpl> assemblies )
+    {
+        this.assemblies = assemblies;
+    }
+
+    @Override
+    public ObjectDeclaration setMetaInfo( Object info )
+    {
+        for( ObjectAssemblyImpl assembly : assemblies )
+        {
+            assembly.metaInfo.set( info );
+        }
+        return this;
+    }
+
+    @Override
+    public ObjectDeclaration visibleIn( Visibility visibility )
+        throws IllegalStateException
+    {
+        for( ObjectAssemblyImpl assembly : assemblies )
+        {
+            assembly.visibility = visibility;
+        }
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/OrAppliesToFilter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/OrAppliesToFilter.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/OrAppliesToFilter.java
new file mode 100644
index 0000000..90136b1
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/OrAppliesToFilter.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.lang.reflect.Method;
+import org.apache.zest.api.common.AppliesToFilter;
+
+/**
+ * JAVADOC
+ */
+final class OrAppliesToFilter
+    implements AppliesToFilter
+{
+    private final AppliesToFilter left;
+    private final AppliesToFilter right;
+
+    OrAppliesToFilter( AppliesToFilter left, AppliesToFilter right )
+    {
+        this.left = left;
+        this.right = right;
+    }
+
+    @Override
+    public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass )
+    {
+        return left.appliesTo( method, mixin, compositeType, fragmentClass ) ||
+               right.appliesTo( method, mixin, compositeType, fragmentClass );
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
new file mode 100644
index 0000000..530aeb7
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceAssemblyImpl.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * 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.
+ *
+ */
+package org.apache.zest.runtime.bootstrap;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.zest.api.activation.Activator;
+import org.apache.zest.api.activation.Activators;
+import org.apache.zest.api.common.InvalidApplicationException;
+import org.apache.zest.api.service.ServiceComposite;
+import org.apache.zest.api.util.Annotations;
+import org.apache.zest.api.util.Classes;
+import org.apache.zest.bootstrap.ServiceAssembly;
+import org.apache.zest.bootstrap.StateDeclarations;
+import org.apache.zest.functional.Function;
+import org.apache.zest.functional.Iterables;
+import org.apache.zest.runtime.activation.ActivatorsModel;
+import org.apache.zest.runtime.service.ServiceModel;
+
+/**
+ * Assembly of a Service.
+ */
+public final class ServiceAssemblyImpl extends CompositeAssemblyImpl
+    implements ServiceAssembly
+{
+    String identity;
+    boolean instantiateOnStartup = false;
+    List<Class<? extends Activator<?>>> activators = new ArrayList<>();
+
+    public ServiceAssemblyImpl( Class<?> serviceType )
+    {
+        super( serviceType );
+        // The composite must always implement ServiceComposite, as a marker interface
+        if( !ServiceComposite.class.isAssignableFrom( serviceType ) )
+        {
+            types.add( ServiceComposite.class );
+        }
+    }
+
+    @Override
+    public String identity()
+    {
+        return identity;
+    }
+
+    @SuppressWarnings( {"raw", "unchecked"} )
+    ServiceModel newServiceModel( StateDeclarations stateDeclarations, AssemblyHelper helper )
+    {
+        try
+        {
+            buildComposite( helper, stateDeclarations );
+            List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList(
+                    Iterables.<Class<? extends Activator<?>>>flatten( activators, activatorsDeclarations( types ) ) );
+            return new ServiceModel( types, visibility, metaInfo,
+                                     new ActivatorsModel( activatorClasses ),
+                                     mixinsModel, stateModel, compositeMethodsModel,
+                                     identity, instantiateOnStartup );
+        }
+        catch( Exception e )
+        {
+            throw new InvalidApplicationException( "Could not register " + types, e );
+        }
+    }
+    
+    private Iterable<Class<? extends Activator<?>>> activatorsDeclarations( Iterable<? extends Class<?>> typess )
+    {
+        // Find activator declarations
+        ArrayList<Type> allTypes = new ArrayList<>();
+        for( Class<?> type : typess )
+        {
+            Iterable<Type> types = Classes.typesOf( type );
+            Iterables.addAll( allTypes, types );
+        }
+        // Find all activators and flattern them into an iterable
+        Function<Type, Iterable<Class<? extends Activator<?>>>> function = new Function<Type, Iterable<Class<? extends Activator<?>>>>()
+        {
+            @Override
+            public Iterable<Class<? extends Activator<?>>> map( Type type )
+            {
+                Activators activators = Annotations.annotationOn( type, Activators.class );
+                if( activators == null )
+                {
+                    return Iterables.empty();
+                }
+                else
+                {
+                    return Iterables.iterable( activators.value() );
+                }
+            }
+        };
+        Iterable<Class<? extends Activator<?>>> flatten = Iterables.flattenIterables( Iterables.map( function, allTypes ) );
+        return Iterables.toList( flatten );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceDeclarationImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceDeclarationImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceDeclarationImpl.java
new file mode 100644
index 0000000..78c5ddb
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ServiceDeclarationImpl.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2012, Paul Merlin.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.zest.api.activation.Activator;
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.api.service.qualifier.ServiceTags;
+import org.apache.zest.bootstrap.ServiceDeclaration;
+
+import static java.util.Arrays.asList;
+
+/**
+ * Declaration of a Service. Created by {@link org.apache.zest.runtime.bootstrap.ModuleAssemblyImpl#services(Class[])}.
+ */
+public final class ServiceDeclarationImpl
+    implements ServiceDeclaration
+{
+    private final Iterable<ServiceAssemblyImpl> serviceAssemblies;
+
+    public ServiceDeclarationImpl( Iterable<ServiceAssemblyImpl> serviceAssemblies )
+    {
+        this.serviceAssemblies = serviceAssemblies;
+    }
+
+    @Override
+    public ServiceDeclaration visibleIn( Visibility visibility )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.visibility = visibility;
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration identifiedBy( String identity )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.identity = identity;
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration taggedWith( String... tags )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            ServiceTags previousTags = serviceAssembly.metaInfo.get( ServiceTags.class );
+            if( previousTags != null )
+            {
+                List<String> tagList = new ArrayList<>();
+                tagList.addAll( asList( previousTags.tags() ) );
+                tagList.addAll( asList( tags ) );
+                serviceAssembly.metaInfo.set( new ServiceTags( tagList.toArray( new String[ tagList.size() ] ) ) );
+            }
+            else
+            {
+                serviceAssembly.metaInfo.set( new ServiceTags( tags ) );
+            }
+        }
+
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration instantiateOnStartup()
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.instantiateOnStartup = true;
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration setMetaInfo( Object serviceAttribute )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.metaInfo.set( serviceAttribute );
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration withConcerns( Class<?>... concerns )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.concerns.addAll( asList( concerns ) );
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration withSideEffects( Class<?>... sideEffects )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.sideEffects.addAll( asList( sideEffects ) );
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration withMixins( Class<?>... mixins )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.mixins.addAll( asList( mixins ) );
+        }
+        return this;
+    }
+
+    @Override
+    public ServiceDeclaration withTypes( Class<?>... types )
+    {
+        for( ServiceAssemblyImpl serviceAssembly : serviceAssemblies )
+        {
+            serviceAssembly.types.addAll( asList( types ) );
+        }
+        return this;
+    }
+
+    @Override
+    @SafeVarargs
+    public final ServiceDeclaration withActivators( Class<? extends Activator<?>>... activators )
+    {
+        for ( ServiceAssemblyImpl serviceAssembly : serviceAssemblies ) {
+            serviceAssembly.activators.addAll( asList( activators ) );
+        }
+        return this;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
new file mode 100644
index 0000000..8f3dcdc
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientAssemblyImpl.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import org.apache.zest.api.common.InvalidApplicationException;
+import org.apache.zest.api.composite.TransientComposite;
+import org.apache.zest.bootstrap.StateDeclarations;
+import org.apache.zest.bootstrap.TransientAssembly;
+import org.apache.zest.runtime.composite.TransientModel;
+
+/**
+ * Declaration of a TransientComposite.
+ */
+public final class TransientAssemblyImpl extends CompositeAssemblyImpl
+    implements TransientAssembly
+{
+    public TransientAssemblyImpl( Class<?> transientType )
+    {
+        super( transientType );
+
+        // The composite must always implement TransientComposite, as a marker interface
+        if( !TransientComposite.class.isAssignableFrom( transientType ) )
+        {
+            types.add( TransientComposite.class );
+        }
+
+        // If type is a class, register it as a mixin
+        if( !transientType.isInterface() )
+        {
+            mixins.add( transientType );
+        }
+    }
+
+    TransientModel newTransientModel( StateDeclarations stateDeclarations, AssemblyHelper helper )
+    {
+        try
+        {
+            buildComposite( helper, stateDeclarations );
+            TransientModel transientModel = new TransientModel(
+                types, visibility, metaInfo, mixinsModel, stateModel, compositeMethodsModel );
+
+            return transientModel;
+        }
+        catch( Exception e )
+        {
+            throw new InvalidApplicationException( "Could not register " + types, e );
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientDeclarationImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientDeclarationImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientDeclarationImpl.java
new file mode 100644
index 0000000..c137202
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TransientDeclarationImpl.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.bootstrap.TransientDeclaration;
+
+import static java.util.Arrays.asList;
+
+/**
+ * Declaration of a Composite. Created by {@link org.apache.zest.bootstrap.ModuleAssembly#transients(Class[])}.
+ */
+public final class TransientDeclarationImpl
+    implements TransientDeclaration
+{
+    private final Iterable<TransientAssemblyImpl> assemblies;
+
+    public TransientDeclarationImpl( Iterable<TransientAssemblyImpl> assemblies )
+    {
+        this.assemblies = assemblies;
+    }
+
+    @Override
+    public TransientDeclaration setMetaInfo( Object info )
+    {
+        for( TransientAssemblyImpl assembly : assemblies )
+        {
+            assembly.metaInfo.set( info );
+        }
+        return this;
+    }
+
+    @Override
+    public TransientDeclaration visibleIn( Visibility visibility )
+    {
+        for( TransientAssemblyImpl assembly : assemblies )
+        {
+            assembly.visibility = visibility;
+        }
+        return this;
+    }
+
+    @Override
+    public TransientDeclaration withConcerns( Class<?>... concerns )
+    {
+        for( TransientAssemblyImpl assembly : assemblies )
+        {
+            assembly.concerns.addAll( asList( concerns ) );
+        }
+        return this;
+    }
+
+    @Override
+    public TransientDeclaration withSideEffects( Class<?>... sideEffects )
+    {
+        for( TransientAssemblyImpl assembly : assemblies )
+        {
+            assembly.sideEffects.addAll( asList( sideEffects ) );
+        }
+        return this;
+    }
+
+    @Override
+    public TransientDeclaration withMixins( Class<?>... mixins )
+    {
+        for( TransientAssemblyImpl assembly : assemblies )
+        {
+            assembly.mixins.addAll( asList( mixins ) );
+        }
+        return this;
+    }
+
+    @Override
+    public TransientDeclaration withTypes( Class<?>... types )
+    {
+        for( TransientAssemblyImpl assembly : assemblies )
+        {
+            assembly.types.addAll( asList( types ) );
+        }
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypeCheckAppliesToFilter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypeCheckAppliesToFilter.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypeCheckAppliesToFilter.java
new file mode 100644
index 0000000..519ad4f
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypeCheckAppliesToFilter.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.lang.reflect.Method;
+import org.apache.zest.api.common.AppliesToFilter;
+
+/**
+ * JAVADOC
+ */
+final class TypeCheckAppliesToFilter
+    implements AppliesToFilter
+{
+    @SuppressWarnings( "raw" )
+    private final Class type;
+
+    @SuppressWarnings( "raw" )
+    TypeCheckAppliesToFilter( Class type )
+    {
+        this.type = type;
+    }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass )
+    {
+        return type.isAssignableFrom( compositeType );
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypedFragmentAppliesToFilter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypedFragmentAppliesToFilter.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypedFragmentAppliesToFilter.java
new file mode 100644
index 0000000..f2bf128
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/TypedFragmentAppliesToFilter.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import java.lang.reflect.Method;
+import org.apache.zest.api.common.AppliesToFilter;
+
+/**
+ * JAVADOC
+ */
+final class TypedFragmentAppliesToFilter
+    implements AppliesToFilter
+{
+    @Override
+    public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass )
+    {
+        return method.getDeclaringClass().isAssignableFrom( fragmentClass );
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
new file mode 100644
index 0000000..268ba75
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueAssemblyImpl.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2007-2011, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2014, Paul Merlin. All Rights Reserved.
+ *
+ * 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. 
+ */
+package org.apache.zest.runtime.bootstrap;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Member;
+import org.apache.zest.api.association.Association;
+import org.apache.zest.api.association.GenericAssociationInfo;
+import org.apache.zest.api.association.ManyAssociation;
+import org.apache.zest.api.association.NamedAssociation;
+import org.apache.zest.api.common.InvalidApplicationException;
+import org.apache.zest.api.common.MetaInfo;
+import org.apache.zest.api.common.Optional;
+import org.apache.zest.api.common.QualifiedName;
+import org.apache.zest.api.common.UseDefaults;
+import org.apache.zest.api.constraint.Constraint;
+import org.apache.zest.api.property.GenericPropertyInfo;
+import org.apache.zest.api.property.Property;
+import org.apache.zest.api.util.Annotations;
+import org.apache.zest.api.util.Classes;
+import org.apache.zest.api.value.ValueComposite;
+import org.apache.zest.bootstrap.StateDeclarations;
+import org.apache.zest.bootstrap.ValueAssembly;
+import org.apache.zest.runtime.association.AssociationModel;
+import org.apache.zest.runtime.association.AssociationsModel;
+import org.apache.zest.runtime.association.ManyAssociationModel;
+import org.apache.zest.runtime.association.ManyAssociationsModel;
+import org.apache.zest.runtime.association.NamedAssociationModel;
+import org.apache.zest.runtime.association.NamedAssociationsModel;
+import org.apache.zest.runtime.composite.StateModel;
+import org.apache.zest.runtime.composite.ValueConstraintsInstance;
+import org.apache.zest.runtime.composite.ValueConstraintsModel;
+import org.apache.zest.runtime.property.PropertyModel;
+import org.apache.zest.runtime.value.ValueModel;
+import org.apache.zest.runtime.value.ValueStateModel;
+
+import static org.apache.zest.api.util.Annotations.isType;
+import static org.apache.zest.api.util.Classes.typeOf;
+import static org.apache.zest.functional.Iterables.filter;
+import static org.apache.zest.functional.Iterables.first;
+
+/**
+ * Declaration of a ValueComposite.
+ */
+public final class ValueAssemblyImpl
+    extends CompositeAssemblyImpl
+    implements ValueAssembly
+{
+    private AssociationsModel associationsModel;
+    private ManyAssociationsModel manyAssociationsModel;
+    private NamedAssociationsModel namedAssociationsModel;
+
+    public ValueAssemblyImpl( Class<?> compositeType )
+    {
+        super( compositeType );
+        // The composite must always implement ValueComposite, as a marker interface
+        if( !ValueComposite.class.isAssignableFrom( compositeType ) )
+        {
+            types.add( ValueComposite.class );
+        }
+    }
+
+    @Override
+    protected StateModel createStateModel()
+    {
+        return new ValueStateModel( propertiesModel, associationsModel, manyAssociationsModel, namedAssociationsModel );
+    }
+
+    ValueModel newValueModel(
+        StateDeclarations stateDeclarations,
+        AssemblyHelper helper
+    )
+    {
+        try
+        {
+            associationsModel = new AssociationsModel();
+            manyAssociationsModel = new ManyAssociationsModel();
+            namedAssociationsModel = new NamedAssociationsModel();
+            buildComposite( helper, stateDeclarations );
+
+            ValueModel valueModel = new ValueModel(
+                types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel );
+
+            return valueModel;
+        }
+        catch( Exception e )
+        {
+            throw new InvalidApplicationException( "Could not register " + types, e );
+        }
+    }
+
+    @Override
+    protected void addStateFor( AccessibleObject accessor,
+                                Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+    )
+    {
+        String stateName = QualifiedName.fromAccessor( accessor ).name();
+
+        if( registeredStateNames.contains( stateName ) )
+        {
+            return; // Skip already registered names
+        }
+
+        Class<?> accessorType = Classes.RAW_CLASS.map( typeOf( accessor ) );
+        if( Property.class.isAssignableFrom( accessorType ) )
+        {
+            propertiesModel.addProperty( newPropertyModel( accessor, constraintClasses ) );
+            registeredStateNames.add( stateName );
+        }
+        else if( Association.class.isAssignableFrom( accessorType ) )
+        {
+            associationsModel.addAssociation( newAssociationModel( accessor, constraintClasses ) );
+            registeredStateNames.add( stateName );
+        }
+        else if( ManyAssociation.class.isAssignableFrom( accessorType ) )
+        {
+            manyAssociationsModel.addManyAssociation( newManyAssociationModel( accessor, constraintClasses ) );
+            registeredStateNames.add( stateName );
+        }
+        else if( NamedAssociation.class.isAssignableFrom( accessorType ) )
+        {
+            namedAssociationsModel.addNamedAssociation( newNamedAssociationModel( accessor, constraintClasses ) );
+            registeredStateNames.add( stateName );
+        }
+    }
+
+    @Override
+    protected PropertyModel newPropertyModel( AccessibleObject accessor,
+                                              Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+    )
+    {
+        Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+        boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+        ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericPropertyInfo.propertyTypeOf( accessor ), ( (Member) accessor )
+            .getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance valueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            valueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+        MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
+        boolean useDefaults = metaInfo.get( UseDefaults.class ) != null || stateDeclarations.useDefaults( accessor );
+        Object initialValue = stateDeclarations.initialValueOf( accessor );
+        return new PropertyModel( accessor, true, useDefaults, valueConstraintsInstance, metaInfo, initialValue );
+    }
+
+    public AssociationModel newAssociationModel( AccessibleObject accessor,
+                                                 Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+    )
+    {
+        Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+        boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+
+        // Constraints for Association references
+        ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
+            .associationTypeOf( accessor ), ( (Member) accessor ).getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance valueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            valueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+
+        // Constraints for the Association itself
+        valueConstraintsModel = constraintsFor( annotations, Association.class, ( (Member) accessor ).getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance associationValueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            associationValueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+
+        MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
+        AssociationModel associationModel = new AssociationModel( accessor, valueConstraintsInstance, associationValueConstraintsInstance, metaInfo );
+        return associationModel;
+    }
+
+    public ManyAssociationModel newManyAssociationModel( AccessibleObject accessor,
+                                                         Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+    )
+    {
+        Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+        boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+
+        // Constraints for entities in ManyAssociation
+        ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
+            .associationTypeOf( accessor ), ( (Member) accessor ).getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance valueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            valueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+
+        // Constraints for the ManyAssociation itself
+        valueConstraintsModel = constraintsFor( annotations, ManyAssociation.class, ( (Member) accessor ).getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance manyValueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            manyValueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+        MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
+        ManyAssociationModel associationModel = new ManyAssociationModel( accessor, valueConstraintsInstance, manyValueConstraintsInstance, metaInfo );
+        return associationModel;
+    }
+    
+    public NamedAssociationModel newNamedAssociationModel( AccessibleObject accessor,
+                                                           Iterable<Class<? extends Constraint<?, ?>>> constraintClasses
+    )
+    {
+        Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn( accessor );
+        boolean optional = first( filter( isType( Optional.class ), annotations ) ) != null;
+
+        // Constraints for entities in NamedAssociation
+        ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations, GenericAssociationInfo
+            .associationTypeOf( accessor ), ( (Member) accessor ).getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance valueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            valueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+
+        // Constraints for the NamedAssociation itself
+        valueConstraintsModel = constraintsFor( annotations, NamedAssociation.class, ( (Member) accessor ).getName(), optional, constraintClasses, accessor );
+        ValueConstraintsInstance namedValueConstraintsInstance = null;
+        if( valueConstraintsModel.isConstrained() )
+        {
+            namedValueConstraintsInstance = valueConstraintsModel.newInstance();
+        }
+        MetaInfo metaInfo = stateDeclarations.metaInfoFor( accessor );
+        NamedAssociationModel associationModel = new NamedAssociationModel( accessor, valueConstraintsInstance, namedValueConstraintsInstance, metaInfo );
+        return associationModel;
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/8744a67f/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueDeclarationImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueDeclarationImpl.java b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueDeclarationImpl.java
new file mode 100644
index 0000000..24c9c8e
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/bootstrap/ValueDeclarationImpl.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2007, Rickard Öberg. All Rights Reserved.
+ *
+ * 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.
+ *
+ */
+
+package org.apache.zest.runtime.bootstrap;
+
+import org.apache.zest.api.common.Visibility;
+import org.apache.zest.bootstrap.ValueDeclaration;
+
+import static java.util.Arrays.asList;
+
+/**
+ * Declaration of a ValueComposite.
+ */
+public final class ValueDeclarationImpl
+    implements ValueDeclaration
+{
+    private final Iterable<ValueAssemblyImpl> assemblies;
+
+    public ValueDeclarationImpl( Iterable<ValueAssemblyImpl> assemblies )
+    {
+        this.assemblies = assemblies;
+    }
+
+    @Override
+    public ValueDeclaration setMetaInfo( Object info )
+    {
+        for( ValueAssemblyImpl assembly : assemblies )
+        {
+            assembly.metaInfo.set( info );
+        }
+        return this;
+    }
+
+    @Override
+    public ValueDeclaration visibleIn( Visibility visibility )
+    {
+        for( ValueAssemblyImpl assembly : assemblies )
+        {
+            assembly.visibility = visibility;
+        }
+        return this;
+    }
+
+    @Override
+    public ValueDeclaration withConcerns( Class<?>... concerns )
+    {
+        for( ValueAssemblyImpl assembly : assemblies )
+        {
+            assembly.concerns.addAll( asList( concerns ) );
+        }
+        return this;
+    }
+
+    @Override
+    public ValueDeclaration withSideEffects( Class<?>... sideEffects )
+    {
+        for( ValueAssemblyImpl assembly : assemblies )
+        {
+            assembly.sideEffects.addAll( asList( sideEffects ) );
+        }
+        return this;
+    }
+
+    @Override
+    public ValueDeclaration withMixins( Class<?>... mixins )
+    {
+        for( ValueAssemblyImpl assembly : assemblies )
+        {
+            assembly.mixins.addAll( asList( mixins ) );
+        }
+        return this;
+    }
+
+    @Override
+    public ValueDeclaration withTypes( Class<?>... types )
+    {
+        for( ValueAssemblyImpl assembly : assemblies )
+        {
+            assembly.types.addAll( asList( types ) );
+        }
+        return this;
+    }
+}
\ No newline at end of file


Mime
View raw message