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 2016/12/17 10:27:53 UTC
[17/81] [abbrv] [partial] zest-java git commit: ZEST-195 ;
Replace all "zest" with "polygene"
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/TestValue.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/TestValue.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/TestValue.java
deleted file mode 100644
index 0892909..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/TestValue.java
+++ /dev/null
@@ -1,29 +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.
- *
- *
- */
-package org.apache.zest.bootstrap;
-
-import org.apache.zest.api.value.ValueComposite;
-
-/**
- */
-public interface TestValue
- extends ValueComposite
-{
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/LayeredApplicationAssemblerTest.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/LayeredApplicationAssemblerTest.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/LayeredApplicationAssemblerTest.java
deleted file mode 100644
index 71c6d03..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/LayeredApplicationAssemblerTest.java
+++ /dev/null
@@ -1,43 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly;
-
-import org.junit.Test;
-import org.apache.zest.api.activation.ActivationException;
-import org.apache.zest.api.structure.Application;
-import org.apache.zest.bootstrap.AssemblyException;
-
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-public class LayeredApplicationAssemblerTest
-{
- @Test
- public void validateThatAssemblerCreatesApplication()
- throws AssemblyException, ActivationException
- {
- TestApplication assembler = new TestApplication( "Test Application", "1.0.1", Application.Mode.test );
- assembler.initialize();
- assembler.start();
-
- assertThat( assembler.application().name(), equalTo("Test Application") );
- assertThat( assembler.application().version(), equalTo("1.0.1") );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/TestApplication.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/TestApplication.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/TestApplication.java
deleted file mode 100644
index 7e9c565..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/TestApplication.java
+++ /dev/null
@@ -1,62 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly;
-
-import org.apache.zest.api.structure.Application;
-import org.apache.zest.bootstrap.ApplicationAssembly;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.layered.LayeredApplicationAssembler;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.assembly.config.ConfigurationLayer;
-import org.apache.zest.bootstrap.assembly.connectivity.ConnectivityLayer;
-import org.apache.zest.bootstrap.assembly.domain.DomainLayer;
-import org.apache.zest.bootstrap.assembly.infrastructure.InfrastructureLayer;
-import org.apache.zest.bootstrap.assembly.service.ServiceLayer;
-
-// START SNIPPET: application
-public class TestApplication extends LayeredApplicationAssembler
-{
-
- public TestApplication( String name, String version, Application.Mode mode )
- throws AssemblyException
- {
- super( name, version, mode );
- }
-
- @Override
- protected void assembleLayers( ApplicationAssembly assembly )
- throws AssemblyException
- {
- LayerAssembly configLayer = createLayer( ConfigurationLayer.class );
- ModuleAssembly configModule = configLayer.module( "Configuration Module" );
- LayerAssembly infraLayer = new InfrastructureLayer( configModule ).assemble( assembly.layer( InfrastructureLayer.NAME ));
- LayerAssembly domainLayer = createLayer( DomainLayer.class );
- LayerAssembly serviceLayer = createLayer( ServiceLayer.class );
- LayerAssembly connectivityLayer = createLayer( ConnectivityLayer.class );
-
- connectivityLayer.uses( serviceLayer );
- connectivityLayer.uses( domainLayer );
- serviceLayer.uses( domainLayer );
- domainLayer.uses( infraLayer );
- infraLayer.uses( configLayer );
- }
-}
-// END SNIPPET: application
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/config/ConfigurationLayer.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/config/ConfigurationLayer.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/config/ConfigurationLayer.java
deleted file mode 100644
index b285088..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/config/ConfigurationLayer.java
+++ /dev/null
@@ -1,34 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.config;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.layered.LayerAssembler;
-import org.apache.zest.bootstrap.LayerAssembly;
-
-public class ConfigurationLayer implements LayerAssembler
-{
- @Override
- public LayerAssembly assemble( LayerAssembly layer )
- throws AssemblyException
- {
- return layer;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/connectivity/ConnectivityLayer.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/connectivity/ConnectivityLayer.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/connectivity/ConnectivityLayer.java
deleted file mode 100644
index 9e304bb..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/connectivity/ConnectivityLayer.java
+++ /dev/null
@@ -1,36 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.connectivity;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.layered.LayerAssembler;
-import org.apache.zest.bootstrap.LayerAssembly;
-
-public class ConnectivityLayer implements LayerAssembler
-{
- public static final String NAME = "Connectivity";
-
- @Override
- public LayerAssembly assemble( LayerAssembly layer )
- throws AssemblyException
- {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/DomainLayer.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/DomainLayer.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/DomainLayer.java
deleted file mode 100644
index a2b7907..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/DomainLayer.java
+++ /dev/null
@@ -1,36 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.domain;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.layered.LayeredLayerAssembler;
-
-public class DomainLayer extends LayeredLayerAssembler
-{
- @Override
- public LayerAssembly assemble( LayerAssembly layer )
- throws AssemblyException
- {
- createModule( layer, InvoicingModule.class );
- createModule( layer, OrderModule.class );
- return layer;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/InvoicingModule.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/InvoicingModule.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/InvoicingModule.java
deleted file mode 100644
index 9ee5aab..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/InvoicingModule.java
+++ /dev/null
@@ -1,36 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.domain;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.layered.ModuleAssembler;
-
-public class InvoicingModule
- implements ModuleAssembler
-{
- @Override
- public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )
- throws AssemblyException
- {
- return module;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/OrderModule.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/OrderModule.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/OrderModule.java
deleted file mode 100644
index adf02c3..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/domain/OrderModule.java
+++ /dev/null
@@ -1,57 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.domain;
-
-import org.apache.zest.api.association.Association;
-import org.apache.zest.api.property.Property;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.layered.ModuleAssembler;
-
-public class OrderModule
- implements ModuleAssembler
-{
- @Override
- public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )
- throws AssemblyException
- {
- module.entities( Order.class, Customer.class );
- module.values( Address.class );
- return module;
- }
-
- public interface Order
- {
- Association<Customer> customer();
-
- Property<Address> invoicingAddress();
-
- Property<Address> deliveryAddress();
- }
-
- public interface Customer
- {
- }
-
- public interface Address
- {
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/IndexingModule.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/IndexingModule.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/IndexingModule.java
deleted file mode 100644
index b1f23f6..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/IndexingModule.java
+++ /dev/null
@@ -1,44 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.infrastructure;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.layered.ModuleAssembler;
-
-public class IndexingModule
- implements ModuleAssembler
-{
- public static final String NAME = "Indexing Module";
- private final ModuleAssembly configModule;
-
- public IndexingModule( ModuleAssembly configModule )
- {
- this.configModule = configModule;
- }
-
- @Override
- public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )
- throws AssemblyException
- {
- return module;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/InfrastructureLayer.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/InfrastructureLayer.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/InfrastructureLayer.java
deleted file mode 100644
index 9b4cfe0..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/InfrastructureLayer.java
+++ /dev/null
@@ -1,48 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.infrastructure;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.layered.LayerAssembler;
-import org.apache.zest.bootstrap.layered.LayeredLayerAssembler;
-
-public class InfrastructureLayer extends LayeredLayerAssembler
- implements LayerAssembler
-{
- public static final String NAME = "Infrastructure Layer";
- private final ModuleAssembly configModule;
-
- public InfrastructureLayer( ModuleAssembly configModule )
- {
- this.configModule = configModule;
- }
-
- @Override
- public LayerAssembly assemble( LayerAssembly layer )
- throws AssemblyException
- {
- new StorageModule( configModule ).assemble( layer, layer.module( StorageModule.NAME ) );
- new IndexingModule( configModule ).assemble( layer, layer.module( IndexingModule.NAME ) );
- createModule( layer, SerializationModule.class );
- return layer;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/SerializationModule.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/SerializationModule.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/SerializationModule.java
deleted file mode 100644
index ad7d8ae..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/SerializationModule.java
+++ /dev/null
@@ -1,37 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.infrastructure;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.layered.ModuleAssembler;
-
-public class SerializationModule
- implements ModuleAssembler
-{
- @Override
- public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module
- )
- throws AssemblyException
- {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/StorageModule.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/StorageModule.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/StorageModule.java
deleted file mode 100644
index 29e6697..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/infrastructure/StorageModule.java
+++ /dev/null
@@ -1,44 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.infrastructure;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.LayerAssembly;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.apache.zest.bootstrap.layered.ModuleAssembler;
-
-public class StorageModule
- implements ModuleAssembler
-{
- public static final String NAME = "Storage Module";
- private final ModuleAssembly configModule;
-
- public StorageModule( ModuleAssembly configModule )
- {
- this.configModule = configModule;
- }
-
- @Override
- public ModuleAssembly assemble( LayerAssembly layer, ModuleAssembly module )
- throws AssemblyException
- {
- return module;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/service/ServiceLayer.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/service/ServiceLayer.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/service/ServiceLayer.java
deleted file mode 100644
index 45f126d..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/assembly/service/ServiceLayer.java
+++ /dev/null
@@ -1,36 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.assembly.service;
-
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.layered.LayerAssembler;
-import org.apache.zest.bootstrap.LayerAssembly;
-
-public class ServiceLayer implements LayerAssembler
-{
- public static final String NAME = "Service";
-
- @Override
- public LayerAssembly assemble( LayerAssembly layer )
- throws AssemblyException
- {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/builder/ApplicationBuilderTest.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/builder/ApplicationBuilderTest.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/builder/ApplicationBuilderTest.java
deleted file mode 100644
index d6e9b39..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/builder/ApplicationBuilderTest.java
+++ /dev/null
@@ -1,136 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.builder;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import org.apache.zest.api.activation.ActivationException;
-import org.apache.zest.api.mixin.Mixins;
-import org.apache.zest.api.structure.Application;
-import org.apache.zest.api.structure.Module;
-import org.apache.zest.bootstrap.Assembler;
-import org.apache.zest.bootstrap.AssemblyException;
-import org.apache.zest.bootstrap.ModuleAssembly;
-import org.json.JSONException;
-import org.junit.Test;
-
-import static java.util.stream.Collectors.toList;
-import static org.apache.zest.bootstrap.ClassScanner.findClasses;
-import static org.apache.zest.bootstrap.ClassScanner.matches;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-public class ApplicationBuilderTest
-{
- @Test
- public void givenBuilderUseWhenBuildingApplicationExpectSuccess()
- throws AssemblyException, ActivationException
- {
- ApplicationBuilder builder = new ApplicationBuilder( "Build from API test." );
- builder.withLayer( "layer1" ).using( "layer2" ).using( "layer3" );
- builder.withLayer( "layer2" );
- builder.withLayer( "layer3" )
- .withModule( "test module" )
- .withAssemblers( findClasses( getClass() ).filter( matches( ".*ServiceAssembler" ) )
- .collect( toList() ) );
- Application application = builder.newApplication();
- Module module = application.findModule( "layer3", "test module" );
- TestService service = module.findService( TestService.class ).get();
- assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) );
- }
-
- @Test
- public void givenJsonWhenBuildingApplicationExpectSuccess()
- throws JSONException, ActivationException, AssemblyException
- {
- ApplicationBuilder builder = ApplicationBuilder.fromJson( APPLICATION );
- Application application = builder.newApplication();
- Module module = application.findModule( "layer3", "test module" );
- TestService service = module.findService( TestService.class ).get();
- assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) );
- }
-
- @Test
- public void givenJsonInputStreamWhenBuildingApplicationExpectSuccess()
- throws IOException, JSONException, ActivationException, AssemblyException
- {
- InputStream input = new ByteArrayInputStream( APPLICATION.getBytes( "UTF-8" ) );
- ApplicationBuilder builder = ApplicationBuilder.fromJson( input );
- Application application = builder.newApplication();
- Module module = application.findModule( "layer3", "test module" );
- TestService service = module.findService( TestService.class ).get();
- assertThat( service.sayHello(), equalTo( "Hello Polygene!" ) );
- }
-
-
- private static final String APPLICATION =
- "{\n" +
- " \"name\": \"Build from JSON test.\",\n" +
- " \"layers\": [\n" +
- " {\n" +
- " \"name\": \"layer1\",\n" +
- " \"uses\": [ \"layer2\", \"layer3\"]\n" +
- " },\n" +
- " {\n" +
- " \"name\": \"layer2\"\n" +
- " },\n" +
- " {\n" +
- " \"name\": \"layer3\",\n" +
- " \"modules\" : [\n" +
- " {\n" +
- " \"name\" : \"test module\",\n" +
- " \"assemblers\" : [\n" +
- " \"org.apache.zest.bootstrap.builder.ApplicationBuilderTest$TestServiceAssembler\"\n" +
- " ]\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- " ]\n" +
- "}";
-
- public static class TestServiceAssembler
- implements Assembler
- {
- @Override
- public void assemble( ModuleAssembly module )
- throws AssemblyException
- {
- module.addServices( TestService.class );
- }
- }
-
- @Mixins( TestService.TestMixin.class )
- public interface TestService
- {
- String sayHello();
-
- class TestMixin
- implements TestService
- {
-
- @Override
- public String sayHello()
- {
- return "Hello Polygene!";
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/bootstrap/src/test/java/org/apache/zest/bootstrap/somepackage/Test2Value.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/somepackage/Test2Value.java b/core/bootstrap/src/test/java/org/apache/zest/bootstrap/somepackage/Test2Value.java
deleted file mode 100644
index 5503fc0..0000000
--- a/core/bootstrap/src/test/java/org/apache/zest/bootstrap/somepackage/Test2Value.java
+++ /dev/null
@@ -1,29 +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.
- *
- *
- */
-package org.apache.zest.bootstrap.somepackage;
-
-import org.apache.zest.api.value.ValueComposite;
-
-/**
- */
-public interface Test2Value
- extends ValueComposite
-{
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/docs/runtime.txt
----------------------------------------------------------------------
diff --git a/core/runtime/src/docs/runtime.txt b/core/runtime/src/docs/runtime.txt
index 6509299..6caaa4a 100644
--- a/core/runtime/src/docs/runtime.txt
+++ b/core/runtime/src/docs/runtime.txt
@@ -31,7 +31,7 @@ perhaps that a new Core SPI Extension is needed.
include::../../build/docs/buildinfo/artifact.txt[]
Let's repeat that; *Never, never, ever depend on Core Runtime*. Make sure that the compile dependency does NOT include
-the `org.apache.zest.core.runtime` jar.
+the `org.apache.polygene.core.runtime` jar.
== Custom AssemblyHelper ==
BUT, there are super-rare cases, where a custom AssemblyHelper might be needed. One known use-case is tp introduce
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/ZestRuntimeImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/ZestRuntimeImpl.java b/core/runtime/src/main/java/org/apache/polygene/runtime/ZestRuntimeImpl.java
new file mode 100644
index 0000000..2a0be69
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/ZestRuntimeImpl.java
@@ -0,0 +1,360 @@
+/*
+ * 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;
+
+import java.lang.reflect.InvocationHandler;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.stream.Stream;
+import org.apache.polygene.api.PolygeneAPI;
+import org.apache.polygene.api.association.AbstractAssociation;
+import org.apache.polygene.api.association.Association;
+import org.apache.polygene.api.association.AssociationDescriptor;
+import org.apache.polygene.api.association.AssociationStateHolder;
+import org.apache.polygene.api.association.AssociationWrapper;
+import org.apache.polygene.api.association.ManyAssociation;
+import org.apache.polygene.api.association.ManyAssociationWrapper;
+import org.apache.polygene.api.association.NamedAssociation;
+import org.apache.polygene.api.association.NamedAssociationWrapper;
+import org.apache.polygene.api.composite.Composite;
+import org.apache.polygene.api.composite.CompositeDescriptor;
+import org.apache.polygene.api.composite.CompositeInstance;
+import org.apache.polygene.api.composite.ModelDescriptor;
+import org.apache.polygene.api.composite.TransientComposite;
+import org.apache.polygene.api.composite.TransientDescriptor;
+import org.apache.polygene.api.entity.EntityComposite;
+import org.apache.polygene.api.entity.EntityDescriptor;
+import org.apache.polygene.api.entity.EntityReference;
+import org.apache.polygene.api.property.Property;
+import org.apache.polygene.api.property.PropertyDescriptor;
+import org.apache.polygene.api.property.PropertyWrapper;
+import org.apache.polygene.api.property.StateHolder;
+import org.apache.polygene.api.service.ServiceComposite;
+import org.apache.polygene.api.service.ServiceDescriptor;
+import org.apache.polygene.api.service.ServiceReference;
+import org.apache.polygene.api.structure.ModuleDescriptor;
+import org.apache.polygene.api.unitofwork.UnitOfWork;
+import org.apache.polygene.api.value.ValueComposite;
+import org.apache.polygene.api.value.ValueDescriptor;
+import org.apache.polygene.bootstrap.ApplicationAssemblyFactory;
+import org.apache.polygene.bootstrap.ApplicationModelFactory;
+import org.apache.polygene.bootstrap.PolygeneRuntime;
+import org.apache.polygene.runtime.association.AbstractAssociationInstance;
+import org.apache.polygene.runtime.bootstrap.ApplicationAssemblyFactoryImpl;
+import org.apache.polygene.runtime.bootstrap.ApplicationModelFactoryImpl;
+import org.apache.polygene.runtime.composite.ProxyReferenceInvocationHandler;
+import org.apache.polygene.runtime.composite.TransientInstance;
+import org.apache.polygene.runtime.entity.EntityInstance;
+import org.apache.polygene.runtime.property.PropertyInstance;
+import org.apache.polygene.runtime.service.ImportedServiceReferenceInstance;
+import org.apache.polygene.runtime.service.ServiceInstance;
+import org.apache.polygene.runtime.service.ServiceReferenceInstance;
+import org.apache.polygene.runtime.unitofwork.ModuleUnitOfWork;
+import org.apache.polygene.runtime.value.ValueInstance;
+import org.apache.polygene.spi.PolygeneSPI;
+import org.apache.polygene.spi.entity.EntityState;
+
+import static java.lang.reflect.Proxy.getInvocationHandler;
+import static org.apache.polygene.runtime.composite.TransientInstance.compositeInstanceOf;
+
+/**
+ * Incarnation of Polygene.
+ */
+public final class PolygeneRuntimeImpl
+ implements PolygeneSPI, PolygeneRuntime
+{
+ private final ApplicationAssemblyFactory applicationAssemblyFactory;
+ private final ApplicationModelFactory applicationModelFactory;
+
+ public PolygeneRuntimeImpl()
+ {
+ applicationAssemblyFactory = new ApplicationAssemblyFactoryImpl();
+ applicationModelFactory = new ApplicationModelFactoryImpl();
+ }
+
+ @Override
+ public ApplicationAssemblyFactory applicationAssemblyFactory()
+ {
+ return applicationAssemblyFactory;
+ }
+
+ @Override
+ public ApplicationModelFactory applicationModelFactory()
+ {
+ return applicationModelFactory;
+ }
+
+ @Override
+ public PolygeneAPI api()
+ {
+ return this;
+ }
+
+ @Override
+ public PolygeneSPI spi()
+ {
+ return this;
+ }
+
+ // API
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <T> T dereference( T composite )
+ {
+ InvocationHandler handler = getInvocationHandler( composite );
+ if( handler instanceof ProxyReferenceInvocationHandler )
+ {
+ return (T) ( (ProxyReferenceInvocationHandler) handler ).proxy();
+ }
+ if( handler instanceof CompositeInstance )
+ {
+ return composite;
+ }
+ return null;
+ }
+
+ @Override
+ public ModuleDescriptor moduleOf( Object compositeOrServiceReferenceOrUow )
+ {
+ if( compositeOrServiceReferenceOrUow instanceof TransientComposite )
+ {
+ TransientComposite composite = (TransientComposite) compositeOrServiceReferenceOrUow;
+ return TransientInstance.compositeInstanceOf( composite ).module();
+ }
+ else if( compositeOrServiceReferenceOrUow instanceof EntityComposite )
+ {
+ EntityComposite composite = (EntityComposite) compositeOrServiceReferenceOrUow;
+ return EntityInstance.entityInstanceOf( composite ).module();
+ }
+ else if( compositeOrServiceReferenceOrUow instanceof ValueComposite )
+ {
+ ValueComposite composite = (ValueComposite) compositeOrServiceReferenceOrUow;
+ return ValueInstance.valueInstanceOf( composite ).module();
+ }
+ else if( compositeOrServiceReferenceOrUow instanceof ServiceComposite )
+ {
+ ServiceComposite composite = (ServiceComposite) compositeOrServiceReferenceOrUow;
+ InvocationHandler handler = getInvocationHandler( composite );
+ if( handler instanceof ServiceInstance )
+ {
+ return ( (ServiceInstance) handler ).module();
+ }
+ return ( (ServiceReferenceInstance.ServiceInvocationHandler) handler ).module();
+ }
+ else if( compositeOrServiceReferenceOrUow instanceof UnitOfWork )
+ {
+ ModuleUnitOfWork unitOfWork = (ModuleUnitOfWork) compositeOrServiceReferenceOrUow;
+ return unitOfWork.module();
+ }
+ else if( compositeOrServiceReferenceOrUow instanceof ServiceReferenceInstance )
+ {
+ ServiceReferenceInstance<?> reference = (ServiceReferenceInstance<?>) compositeOrServiceReferenceOrUow;
+ return reference.module();
+ }
+ else if( compositeOrServiceReferenceOrUow instanceof ImportedServiceReferenceInstance )
+ {
+ ImportedServiceReferenceInstance<?> importedServiceReference
+ = (ImportedServiceReferenceInstance<?>) compositeOrServiceReferenceOrUow;
+ return importedServiceReference.module();
+ }
+ throw new IllegalArgumentException( "Wrong type. Must be one of "
+ + Arrays.asList( TransientComposite.class, ValueComposite.class,
+ ServiceComposite.class, ServiceReference.class,
+ UnitOfWork.class ) );
+ }
+
+ @Override
+ public ModelDescriptor modelDescriptorFor( Object compositeOrServiceReference )
+ {
+ if( compositeOrServiceReference instanceof TransientComposite )
+ {
+ TransientComposite composite = (TransientComposite) compositeOrServiceReference;
+ return TransientInstance.compositeInstanceOf( composite ).descriptor();
+ }
+ else if( compositeOrServiceReference instanceof EntityComposite )
+ {
+ EntityComposite composite = (EntityComposite) compositeOrServiceReference;
+ return EntityInstance.entityInstanceOf( composite ).descriptor();
+ }
+ else if( compositeOrServiceReference instanceof ValueComposite )
+ {
+ ValueComposite composite = (ValueComposite) compositeOrServiceReference;
+ return ValueInstance.valueInstanceOf( composite ).descriptor();
+ }
+ else if( compositeOrServiceReference instanceof ServiceComposite )
+ {
+ ServiceComposite composite = (ServiceComposite) compositeOrServiceReference;
+ InvocationHandler handler = getInvocationHandler( composite );
+ if( handler instanceof ServiceInstance )
+ {
+ return ( (ServiceInstance) handler ).descriptor();
+ }
+ return ( (ServiceReferenceInstance.ServiceInvocationHandler) handler ).descriptor();
+ }
+ else if( compositeOrServiceReference instanceof ServiceReferenceInstance )
+ {
+ ServiceReferenceInstance<?> reference = (ServiceReferenceInstance<?>) compositeOrServiceReference;
+ return reference.serviceDescriptor();
+ }
+ else if( compositeOrServiceReference instanceof ImportedServiceReferenceInstance )
+ {
+ ImportedServiceReferenceInstance<?> importedServiceReference
+ = (ImportedServiceReferenceInstance<?>) compositeOrServiceReference;
+ return importedServiceReference.serviceDescriptor();
+ }
+ throw new IllegalArgumentException( "Wrong type. Must be one of "
+ + Arrays.asList( TransientComposite.class, ValueComposite.class,
+ ServiceComposite.class, ServiceReference.class ) );
+ }
+
+ @Override
+ public CompositeDescriptor compositeDescriptorFor( Object compositeOrServiceReference )
+ {
+ return (CompositeDescriptor) modelDescriptorFor( compositeOrServiceReference );
+ }
+
+ // Descriptors
+
+ @Override
+ public TransientDescriptor transientDescriptorFor( Object transsient )
+ {
+ if( transsient instanceof TransientComposite )
+ {
+ TransientInstance transientInstance = compositeInstanceOf( (Composite) transsient );
+ return (TransientDescriptor) transientInstance.descriptor();
+ }
+ throw new IllegalArgumentException( "Wrong type. Must be subtype of " + TransientComposite.class );
+ }
+
+ @Override
+ public StateHolder stateOf( TransientComposite composite )
+ {
+ return TransientInstance.compositeInstanceOf( composite ).state();
+ }
+
+ @Override
+ public EntityDescriptor entityDescriptorFor( Object entity )
+ {
+ if( entity instanceof EntityComposite )
+ {
+ EntityInstance entityInstance = (EntityInstance) getInvocationHandler( entity );
+ return entityInstance.entityModel();
+ }
+ throw new IllegalArgumentException( "Wrong type. Must be subtype of " + EntityComposite.class );
+ }
+
+ @Override
+ public AssociationStateHolder stateOf( EntityComposite composite )
+ {
+ return EntityInstance.entityInstanceOf( composite ).state();
+ }
+
+ @Override
+ public ValueDescriptor valueDescriptorFor( Object value )
+ {
+ if( value instanceof ValueComposite )
+ {
+ ValueInstance valueInstance = ValueInstance.valueInstanceOf( (ValueComposite) value );
+ return valueInstance.descriptor();
+ }
+ throw new IllegalArgumentException( "Wrong type. Must be subtype of " + ValueComposite.class );
+ }
+
+ @Override
+ public AssociationStateHolder stateOf( ValueComposite composite )
+ {
+ return ValueInstance.valueInstanceOf( composite ).state();
+ }
+
+ @Override
+ public ServiceDescriptor serviceDescriptorFor( Object service )
+ {
+ if( service instanceof ServiceReferenceInstance )
+ {
+ ServiceReferenceInstance<?> ref = (ServiceReferenceInstance<?>) service;
+ return ref.serviceDescriptor();
+ }
+ if( service instanceof ServiceComposite )
+ {
+ ServiceComposite composite = (ServiceComposite) service;
+ return (ServiceDescriptor) ServiceInstance.serviceInstanceOf( composite ).descriptor();
+ }
+ throw new IllegalArgumentException( "Wrong type. Must be subtype of "
+ + ServiceComposite.class + " or " + ServiceReference.class );
+ }
+
+ @Override
+ public PropertyDescriptor propertyDescriptorFor( Property<?> property )
+ {
+ while( property instanceof PropertyWrapper )
+ {
+ property = ( (PropertyWrapper) property ).next();
+ }
+
+ return (PropertyDescriptor) ( (PropertyInstance<?>) property ).propertyInfo();
+ }
+
+ @Override
+ public AssociationDescriptor associationDescriptorFor( AbstractAssociation association )
+ {
+ while( association instanceof AssociationWrapper )
+ {
+ association = ( (AssociationWrapper) association ).next();
+ }
+
+ while( association instanceof ManyAssociationWrapper )
+ {
+ association = ( (ManyAssociationWrapper) association ).next();
+ }
+
+ while( association instanceof NamedAssociationWrapper )
+ {
+ association = ( (NamedAssociationWrapper) association ).next();
+ }
+
+ return (AssociationDescriptor) ( (AbstractAssociationInstance) association ).associationInfo();
+ }
+
+ // SPI
+ @Override
+ public EntityState entityStateOf( EntityComposite composite )
+ {
+ return EntityInstance.entityInstanceOf( composite ).entityState();
+ }
+
+ @Override
+ public EntityReference entityReferenceOf( Association<?> assoc )
+ {
+ return assoc.reference();
+ }
+
+ @Override
+ public Stream<EntityReference> entityReferencesOf( ManyAssociation<?> assoc )
+ {
+ return assoc.references();
+ }
+
+ @Override
+ public Stream<Map.Entry<String, EntityReference>> entityReferencesOf( NamedAssociation<?> assoc )
+ {
+ return assoc.references();
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationDelegate.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationDelegate.java b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationDelegate.java
new file mode 100644
index 0000000..22b6c7b
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationDelegate.java
@@ -0,0 +1,401 @@
+/*
+ * 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.activation;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.Stream;
+import org.apache.polygene.api.activation.Activation;
+import org.apache.polygene.api.activation.ActivationEvent;
+import org.apache.polygene.api.activation.ActivationEventListener;
+import org.apache.polygene.api.activation.ActivationException;
+import org.apache.polygene.api.activation.PassivationException;
+import org.apache.polygene.api.composite.ModelDescriptor;
+import org.apache.polygene.api.identity.Identity;
+import org.apache.polygene.api.service.ServiceReference;
+
+import static org.apache.polygene.api.activation.ActivationEvent.EventType.ACTIVATED;
+import static org.apache.polygene.api.activation.ActivationEvent.EventType.ACTIVATING;
+import static org.apache.polygene.api.activation.ActivationEvent.EventType.PASSIVATED;
+import static org.apache.polygene.api.activation.ActivationEvent.EventType.PASSIVATING;
+
+/**
+ * This class manage Activation of a target and propagates to children.
+ */
+@SuppressWarnings( "raw" )
+public final class ActivationDelegate
+ extends ActivationEventListenerSupport
+{
+ private final Object target;
+ private final boolean fireEvents;
+ private ActivatorsInstance targetActivators = null;
+ private final LinkedList<Activation> activeChildren = new LinkedList<>();
+
+ /**
+ * Create a new ActivationDelegate that will fire events.
+ * @param target target of Activation
+ */
+ public ActivationDelegate( Object target )
+ {
+ this( target, true );
+ }
+
+ /**
+ * Create a new ActivationDelegate.
+ * @param target target of Activation
+ * @param fireEvents if {@link ActivationEvent}s should be fired
+ */
+ public ActivationDelegate( Object target, boolean fireEvents )
+ {
+ super();
+ this.target = target;
+ this.fireEvents = fireEvents;
+ }
+
+ public void activate( ActivatorsInstance targetActivators, Activation child )
+ throws Exception
+ {
+ activate( targetActivators, Collections.singleton( child ), null );
+ }
+
+ public void activate( ActivatorsInstance targetActivators, Activation child, Runnable callback )
+ throws Exception
+ {
+ activate( targetActivators, Collections.singleton( child ), callback );
+ }
+
+ public void activate( ActivatorsInstance targetActivators, Iterable<? extends Activation> children )
+ throws ActivationException
+ {
+ activate( targetActivators, children, null );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public void activate( ActivatorsInstance targetActivators, Iterable<? extends Activation> children, Runnable callback )
+ throws ActivationException
+ {
+ if( this.targetActivators != null )
+ {
+ throw new IllegalStateException( "Activation.activate() called multiple times "
+ + "or without calling passivate() first!" );
+ }
+
+ try
+ {
+ // Before Activation Events
+ if( fireEvents )
+ {
+ fireEvent( new ActivationEvent( target, ACTIVATING ) );
+ }
+
+ // Before Activation for Activators
+ targetActivators.beforeActivation( target instanceof ServiceReference
+ ? new PassiveServiceReference( (ServiceReference) target )
+ : target );
+
+ // Activation
+ for( Activation child : children )
+ {
+ if( !activeChildren.contains( child ) )
+ {
+ child.activate();
+ }
+ activeChildren.addFirst( child );
+ }
+
+ // Internal Activation Callback
+ if( callback != null )
+ {
+ callback.run();
+ }
+
+ // After Activation
+ targetActivators.afterActivation( target );
+
+ // After Activation Events
+ if( fireEvents )
+ {
+ fireEvent( new ActivationEvent( target, ACTIVATED ) );
+ }
+
+ // Activated
+ this.targetActivators = targetActivators;
+ }
+ catch( Exception e )
+ {
+ // Passivate actives
+ try
+ {
+ passivate();
+ }
+ catch( PassivationException e1 )
+ {
+ ActivationException activationEx = new ActivationException( "Unable to Activate application.", e );
+ activationEx.addSuppressed( e1 );
+ throw activationEx;
+ }
+ if( e instanceof ActivationException )
+ {
+ throw ( (ActivationException) e );
+ }
+ throw new ActivationException( "Unable to Activate application.", e );
+ }
+ }
+
+ public void passivate()
+ throws PassivationException
+ {
+ passivate( null );
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public void passivate( Runnable callback )
+ throws PassivationException
+ {
+ Set<Exception> exceptions = new LinkedHashSet<>();
+
+ // Before Passivation Events
+ if( fireEvents )
+ {
+ ActivationEvent event = new ActivationEvent( target, PASSIVATING );
+ for( ActivationEventListener listener : listeners )
+ {
+ try
+ {
+ listener.onEvent( event );
+ }
+ catch( Exception ex )
+ {
+ if( ex instanceof PassivationException )
+ {
+ exceptions.addAll( ( (PassivationException) ex ).causes() );
+ }
+ else
+ {
+ exceptions.add( ex );
+ }
+ }
+ }
+ }
+
+ // Before Passivation for Activators
+ if( targetActivators != null )
+ {
+ try
+ {
+ targetActivators.beforePassivation( target );
+ }
+ catch( PassivationException ex )
+ {
+ exceptions.addAll( ex.causes() );
+ }
+ catch( Exception ex )
+ {
+ exceptions.add( ex );
+ }
+ }
+
+ // Passivation
+ while( !activeChildren.isEmpty() )
+ {
+ passivateOneChild( exceptions );
+ }
+
+ // Internal Passivation Callback
+ if( callback != null )
+ {
+ try
+ {
+ callback.run();
+ }
+ catch( Exception ex )
+ {
+ exceptions.add( ex );
+ }
+ }
+
+ // After Passivation for Activators
+ if( targetActivators != null )
+ {
+ try
+ {
+ targetActivators.afterPassivation( target instanceof ServiceReference
+ ? new PassiveServiceReference( (ServiceReference) target )
+ : target );
+ }
+ catch( PassivationException ex )
+ {
+ exceptions.addAll( ex.causes() );
+ }
+ catch( Exception ex )
+ {
+ exceptions.add( ex );
+ }
+ }
+ targetActivators = null;
+
+ // After Passivation Events
+ if( fireEvents )
+ {
+ ActivationEvent event = new ActivationEvent( target, PASSIVATED );
+ for( ActivationEventListener listener : listeners )
+ {
+ try
+ {
+ listener.onEvent( event );
+ }
+ catch( Exception ex )
+ {
+ if( ex instanceof PassivationException )
+ {
+ exceptions.addAll( ( (PassivationException) ex ).causes() );
+ }
+ else
+ {
+ exceptions.add( ex );
+ }
+ }
+ }
+ }
+
+ // Error handling
+ if( exceptions.isEmpty() )
+ {
+ return;
+ }
+ throw new PassivationException( exceptions );
+ }
+
+ @SuppressWarnings( "TooBroadCatch" )
+ private void passivateOneChild( Set<Exception> exceptions )
+ {
+ Activation activeChild = activeChildren.removeFirst();
+ try
+ {
+ activeChild.passivate();
+ }
+ catch( PassivationException ex )
+ {
+ exceptions.addAll( ex.causes() );
+ }
+ catch( Exception ex )
+ {
+ exceptions.add( ex );
+ }
+ }
+
+ @SuppressWarnings( "raw" )
+ private static class PassiveServiceReference
+ implements ServiceReference
+ {
+
+ private final ServiceReference reference;
+
+ private PassiveServiceReference( ServiceReference reference )
+ {
+ this.reference = reference;
+ }
+
+ @Override
+ public Identity identity()
+ {
+ return reference.identity();
+ }
+
+ @Override
+ public Object get()
+ {
+ throw new IllegalStateException( "Service is passive, either activating and"
+ + " cannot be used yet or passivating and cannot be used anymore." );
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isAvailable()
+ {
+ return false;
+ }
+
+ @Override
+ public ModelDescriptor model()
+ {
+ return reference.model();
+ }
+
+ @Override
+ public Stream<Class<?>> types()
+ {
+ return reference.types();
+ }
+
+ @Override
+ public <T> T metaInfo( Class<T> infoType )
+ {
+ return reference.metaInfo( infoType );
+ }
+
+ @Override
+ public void registerActivationEventListener( ActivationEventListener listener )
+ {
+ reference.registerActivationEventListener( listener );
+ }
+
+ @Override
+ public void deregisterActivationEventListener( ActivationEventListener listener )
+ {
+ reference.deregisterActivationEventListener( listener );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return identity().hashCode();
+ }
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if( obj == null )
+ {
+ return false;
+ }
+ if( getClass() != obj.getClass() )
+ {
+ return false;
+ }
+ final ServiceReference other = (ServiceReference) obj;
+ return identity().equals( other.identity() );
+ }
+
+ @Override
+ public String toString()
+ {
+ return reference.toString();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationEventListenerSupport.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationEventListenerSupport.java b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationEventListenerSupport.java
new file mode 100644
index 0000000..b844756
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivationEventListenerSupport.java
@@ -0,0 +1,69 @@
+/*
+ * 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.activation;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.polygene.api.activation.ActivationEvent;
+import org.apache.polygene.api.activation.ActivationEventListener;
+import org.apache.polygene.api.activation.ActivationEventListenerRegistration;
+
+/**
+ * Internal helper for managing registrations and firing events
+ */
+/* package */ class ActivationEventListenerSupport
+ implements ActivationEventListenerRegistration, ActivationEventListener
+{
+ protected List<ActivationEventListener> listeners = new ArrayList<>();
+
+ @Override
+ public void registerActivationEventListener( ActivationEventListener listener )
+ {
+ List<ActivationEventListener> newListeners = new ArrayList<>();
+ newListeners.addAll( listeners );
+ newListeners.add( listener );
+ listeners = newListeners;
+ }
+
+ @Override
+ public void deregisterActivationEventListener( ActivationEventListener listener )
+ {
+ List<ActivationEventListener> newListeners = new ArrayList<>();
+ newListeners.addAll( listeners );
+ newListeners.remove( listener );
+ listeners = newListeners;
+ }
+
+ /* package */ void fireEvent( ActivationEvent event )
+ throws Exception
+ {
+ for( ActivationEventListener listener : listeners )
+ {
+ listener.onEvent( event );
+ }
+ }
+
+ @Override
+ public void onEvent( ActivationEvent event )
+ throws Exception
+ {
+ fireEvent( event );
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorModel.java
new file mode 100644
index 0000000..72d957b
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorModel.java
@@ -0,0 +1,110 @@
+/*
+ * 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.activation;
+
+import org.apache.polygene.api.activation.Activator;
+import org.apache.polygene.api.activation.ActivatorDescriptor;
+import org.apache.polygene.api.common.ConstructionException;
+import org.apache.polygene.api.util.HierarchicalVisitor;
+import org.apache.polygene.api.util.VisitableHierarchy;
+import org.apache.polygene.runtime.composite.ConstructorsModel;
+import org.apache.polygene.runtime.injection.InjectedFieldsModel;
+import org.apache.polygene.runtime.injection.InjectedMethodsModel;
+import org.apache.polygene.runtime.injection.InjectionContext;
+
+/**
+ * Model for a single Activator.
+ *
+ * @param <ActivateeType> Type of the activation target
+ */
+public class ActivatorModel<ActivateeType>
+ implements ActivatorDescriptor, VisitableHierarchy<Object, Object>
+{
+ private final Class<? extends Activator<ActivateeType>> activatorType;
+ private final ConstructorsModel constructorsModel;
+ private final InjectedFieldsModel injectedFieldsModel;
+ private final InjectedMethodsModel injectedMethodsModel;
+
+ public ActivatorModel( Class<? extends Activator<ActivateeType>> activatorType )
+ {
+ this.activatorType = activatorType;
+ this.constructorsModel = new ConstructorsModel( activatorType );
+ this.injectedFieldsModel = new InjectedFieldsModel( activatorType );
+ this.injectedMethodsModel = new InjectedMethodsModel( activatorType );
+ }
+
+ @Override
+ public <ThrowableType extends Throwable> boolean accept( HierarchicalVisitor<? super Object, ? super Object, ThrowableType> visitor )
+ throws ThrowableType
+ {
+ if( visitor.visitEnter( this ) )
+ {
+ if( constructorsModel.accept( visitor ) )
+ {
+ if( injectedFieldsModel.accept( visitor ) )
+ {
+ injectedMethodsModel.accept( visitor );
+ }
+ }
+ }
+ return visitor.visitLeave( this );
+ }
+
+ public Activator<ActivateeType> newInstance()
+ {
+ try
+ {
+ return activatorType.newInstance();
+ }
+ catch( InstantiationException | IllegalAccessException ex )
+ {
+ throw new ConstructionException( "Could not instantiate " + activatorType.getName(), ex );
+ }
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public Activator<ActivateeType> newInstance( InjectionContext injectionContext )
+ {
+ try
+ {
+ Activator<ActivateeType> instance = (Activator<ActivateeType>) constructorsModel.newInstance( injectionContext );
+ injectionContext = new InjectionContext( injectionContext.module(), injectionContext.uses(), instance );
+ inject( injectionContext, instance );
+ return instance;
+ }
+ catch( Exception ex )
+ {
+ throw new ConstructionException( "Could not instantiate " + activatorType.getName(), ex );
+ }
+ }
+
+ public void inject( InjectionContext injectionContext, Activator<ActivateeType> instance )
+ {
+ injectedFieldsModel.inject( injectionContext, instance );
+ injectedMethodsModel.inject( injectionContext, instance );
+ }
+
+ @Override
+ public String toString()
+ {
+ return activatorType.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsInstance.java
new file mode 100644
index 0000000..26ef238
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsInstance.java
@@ -0,0 +1,126 @@
+/*
+ * 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.activation;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.stream.StreamSupport;
+import org.apache.polygene.api.activation.Activator;
+import org.apache.polygene.api.activation.PassivationException;
+
+import static java.util.stream.Collectors.toCollection;
+
+/**
+ * Instance of a Polygene Activators of one Activation target. Contains ordered
+ * Activators and roll the Activation on the target.
+ *
+ * @param <ActivateeType> Type of the activation target
+ */
+public class ActivatorsInstance<ActivateeType>
+ implements Activator<ActivateeType>
+{
+ @SuppressWarnings( { "raw", "unchecked" } )
+ public static final ActivatorsInstance EMPTY = new ActivatorsInstance( Collections.emptyList() );
+
+ private final Iterable<Activator<ActivateeType>> activators;
+
+ public ActivatorsInstance( Iterable<Activator<ActivateeType>> activators )
+ {
+ this.activators = activators;
+ }
+
+ @Override
+ public void beforeActivation( ActivateeType activating )
+ throws Exception
+ {
+ for( Activator<ActivateeType> activator : activators )
+ {
+ activator.beforeActivation( activating );
+ }
+ }
+
+ @Override
+ public void afterActivation( ActivateeType activated )
+ throws Exception
+ {
+ for( Activator<ActivateeType> activator : activators )
+ {
+ activator.afterActivation( activated );
+ }
+ }
+
+ @Override
+ public void beforePassivation( ActivateeType passivating )
+ throws Exception
+ {
+ Set<Exception> exceptions = new LinkedHashSet<>();
+ Iterator<Activator<ActivateeType>> iterator = reverseActivatorsIterator();
+ while( iterator.hasNext() )
+ {
+ Activator<ActivateeType> activator = iterator.next();
+ try
+ {
+ activator.beforePassivation( passivating );
+ }
+ catch( Exception ex )
+ {
+ exceptions.add( ex );
+ }
+ }
+ if( !exceptions.isEmpty() )
+ {
+ throw new PassivationException( exceptions );
+ }
+ }
+
+ @Override
+ public void afterPassivation( ActivateeType passivated )
+ throws Exception
+ {
+ Set<Exception> exceptions = new LinkedHashSet<>();
+ Iterator<Activator<ActivateeType>> iterator = reverseActivatorsIterator();
+ while( iterator.hasNext() )
+ {
+ Activator<ActivateeType> activator = iterator.next();
+ try
+ {
+ activator.afterPassivation( passivated );
+ }
+ catch( Exception ex )
+ {
+ exceptions.add( ex );
+ }
+ }
+ if( !exceptions.isEmpty() )
+ {
+ throw new PassivationException( exceptions );
+ }
+ }
+
+ private Iterator<Activator<ActivateeType>> reverseActivatorsIterator()
+ {
+ return StreamSupport.stream( activators.spliterator(), false )
+ .collect( toCollection( LinkedList::new ) )
+ .descendingIterator();
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsModel.java
new file mode 100644
index 0000000..69b3800
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/activation/ActivatorsModel.java
@@ -0,0 +1,98 @@
+/*
+ * 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.activation;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.polygene.api.activation.ActivationException;
+import org.apache.polygene.api.activation.Activator;
+import org.apache.polygene.api.structure.ModuleDescriptor;
+import org.apache.polygene.api.util.HierarchicalVisitor;
+import org.apache.polygene.api.util.VisitableHierarchy;
+import org.apache.polygene.runtime.composite.UsesInstance;
+import org.apache.polygene.runtime.injection.InjectionContext;
+
+/**
+ * Activators Model.
+ *
+ * @param <ActivateeType> Type of the activation target
+ */
+public class ActivatorsModel<ActivateeType>
+ implements VisitableHierarchy<Object, Object>
+{
+
+ private final List<ActivatorModel<ActivateeType>> activatorModels = new ArrayList<>();
+ private final Iterable<Class<? extends Activator<ActivateeType>>> activatorsClasses;
+
+ public ActivatorsModel( Iterable<Class<? extends Activator<ActivateeType>>> activatorsClasses )
+ {
+ this.activatorsClasses = activatorsClasses;
+ for( Class<? extends Activator<ActivateeType>> activatorClass : activatorsClasses )
+ {
+ activatorModels.add( new ActivatorModel<>( activatorClass ) );
+ }
+ }
+
+ @Override
+ public <ThrowableType extends Throwable> boolean accept( HierarchicalVisitor<? super Object, ? super Object, ThrowableType> visitor )
+ throws ThrowableType
+ {
+ if( visitor.visitEnter( this ) )
+ {
+ for( ActivatorModel<ActivateeType> activatorModel : activatorModels )
+ {
+ if( !activatorModel.accept( visitor ) )
+ {
+ break;
+ }
+ }
+ }
+ return visitor.visitLeave( this );
+ }
+
+ public Iterable<ActivatorModel<ActivateeType>> models()
+ {
+ return activatorModels;
+ }
+
+ public Iterable<Activator<ActivateeType>> newInstances()
+ throws ActivationException
+ {
+ List<Activator<ActivateeType>> activators = new ArrayList<>();
+ for( ActivatorModel<ActivateeType> activatorModel : activatorModels )
+ {
+ activators.add( activatorModel.newInstance() );
+ }
+ return activators;
+ }
+
+ public Iterable<Activator<ActivateeType>> newInstances( ModuleDescriptor module )
+ throws ActivationException
+ {
+ List<Activator<ActivateeType>> activators = new ArrayList<>();
+ for( ActivatorModel<ActivateeType> activatorModel : activatorModels )
+ {
+ InjectionContext injectionContext = new InjectionContext( module, UsesInstance.EMPTY_USES );
+ activators.add( activatorModel.newInstance( injectionContext ) );
+ }
+ return activators;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/association/AbstractAssociationInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/association/AbstractAssociationInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AbstractAssociationInstance.java
new file mode 100644
index 0000000..51106d3
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AbstractAssociationInstance.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.association;
+
+import java.lang.reflect.Type;
+import java.util.function.BiFunction;
+import org.apache.polygene.api.association.AbstractAssociation;
+import org.apache.polygene.api.entity.EntityReference;
+import org.apache.polygene.api.identity.HasIdentity;
+
+/**
+ * Implementation of AbstractAssociation. Includes helper methods for subclasses
+ */
+public abstract class AbstractAssociationInstance<T>
+ implements AbstractAssociation
+{
+ protected AssociationInfo associationInfo;
+ private final BiFunction<EntityReference, Type, Object> entityFunction;
+
+ public AbstractAssociationInstance( AssociationInfo associationInfo,
+ BiFunction<EntityReference, Type, Object> entityFunction
+ )
+ {
+ this.associationInfo = associationInfo;
+ this.entityFunction = entityFunction;
+ }
+
+ public AssociationInfo associationInfo()
+ {
+ return associationInfo;
+ }
+
+ public void setAssociationInfo( AssociationInfo newInfo )
+ {
+ this.associationInfo = newInfo;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ protected T getEntity( EntityReference entityId )
+ {
+ if( entityId == null )
+ {
+ return null;
+ }
+
+ return (T) entityFunction.apply( entityId, associationInfo.type() );
+ }
+
+ protected EntityReference getEntityReference( Object composite )
+ {
+ if( composite == null )
+ {
+ return null;
+ }
+
+ return EntityReference.create(((HasIdentity) composite).identity().get());
+ }
+
+ protected void checkType( Object instance )
+ {
+
+ if( instance instanceof HasIdentity || instance == null )
+ {
+ return;
+ }
+ throw new IllegalArgumentException( "Object must be a subtype of org.apache.polygene.api.reference.Identity: " + instance.getClass() );
+ }
+
+ protected void checkImmutable()
+ throws IllegalStateException
+ {
+ if( associationInfo.isImmutable() )
+ {
+ throw new IllegalStateException( "Association [" + associationInfo.qualifiedName() + "] is immutable." );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/1c722f44/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInfo.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInfo.java b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInfo.java
new file mode 100644
index 0000000..e5f7ac0
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/association/AssociationInfo.java
@@ -0,0 +1,37 @@
+/*
+ * 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.association;
+
+import java.lang.reflect.Type;
+import org.apache.polygene.api.common.QualifiedName;
+import org.apache.polygene.runtime.composite.ConstraintsCheck;
+
+/**
+ * TODO
+ */
+public interface AssociationInfo
+ extends ConstraintsCheck
+{
+ boolean isImmutable();
+
+ QualifiedName qualifiedName();
+
+ Type type();
+}