Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/ReferenceSync.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,223 @@
+/**
+ * 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.aries.cdi.container.internal.container;
+
+import java.util.AbstractMap.SimpleImmutableEntry;
+
+import org.apache.aries.cdi.container.internal.container.ComponentContext.With;
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedComponentInstanceDTO;
+import org.apache.aries.cdi.container.internal.model.ExtendedReferenceDTO;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedReferenceTemplateDTO;
+import org.apache.aries.cdi.container.internal.model.InstanceActivator;
+import org.apache.aries.cdi.container.internal.model.ReferenceEventImpl;
+import org.apache.aries.cdi.container.internal.util.Conversions;
+import org.apache.aries.cdi.container.internal.util.Maps;
+import org.apache.aries.cdi.container.internal.util.SRs;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cdi.ReferencePolicy;
+import org.osgi.service.cdi.ReferencePolicyOption;
+import org.osgi.service.cdi.runtime.dto.template.ReferenceTemplateDTO;
+import org.osgi.service.log.Logger;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class ReferenceSync implements ServiceTrackerCustomizer<Object, Object> 
{
+
+       public ReferenceSync(
+               ContainerState containerState,
+               ExtendedReferenceDTO referenceDTO,
+               ExtendedComponentInstanceDTO componentInstanceDTO,
+               InstanceActivator.Builder<?> builder) {
+
+               _containerState = containerState;
+               _referenceDTO = referenceDTO;
+               _componentInstanceDTO = componentInstanceDTO;
+               _builder = builder;
+               _templateDTO = 
(ExtendedReferenceTemplateDTO)_referenceDTO.template;
+               _log = _containerState.containerLogs().getLogger(getClass());
+       }
+
+       @Override
+       public Object addingService(final ServiceReference<Object> reference) {
+               boolean active = _componentInstanceDTO.active;
+               boolean resolved = (_referenceDTO.matches.size() >= 
_templateDTO.minimumCardinality);
+               boolean dynamic = (_templateDTO.policy == 
ReferencePolicy.DYNAMIC);
+               boolean reluctant = (_templateDTO.policyOption == 
ReferencePolicyOption.RELUCTANT);
+               CollectionType collectionType = _templateDTO.collectionType;
+               boolean requiresUpdate = true;
+
+               if (resolved && reluctant && active && !dynamic) {
+                       requiresUpdate = false;
+               }
+
+               _referenceDTO.matches = 
SRs.from(_referenceDTO.serviceTracker.getServiceReferences(), reference);
+
+               try {
+                       if (collectionType == CollectionType.OBSERVER) {
+                               @SuppressWarnings("unchecked")
+                               ReferenceEventImpl<Object> event = new 
ReferenceEventImpl<>(_containerState, (Class<Object>)_templateDTO.serviceClass);
+                               event.addingService(reference);
+                               if (active) {
+                                       
_componentInstanceDTO.activations.forEach(
+                                               a -> {
+                                                       try (With with = new 
With(a)) {
+                                                               
_templateDTO.bean.fireEvent(event);
+                                                       }
+                                               }
+                                       );
+                                       requiresUpdate = false;
+                               }
+                               return event;
+                       }
+                       else if (collectionType == CollectionType.PROPERTIES) {
+                               return Maps.of(reference.getProperties());
+                       }
+                       else if (collectionType == CollectionType.REFERENCE) {
+                               return reference;
+                       }
+                       else if (collectionType == 
CollectionType.SERVICEOBJECTS) {
+                               return new ReferenceServiceObjectsImpl<>(
+                                       
_containerState.bundleContext().getServiceObjects(reference));
+                       }
+                       else if (collectionType == CollectionType.TUPLE) {
+                               return new SimpleImmutableEntry<>(
+                                       Maps.of(reference.getProperties()),
+                                       
_containerState.bundleContext().getService(reference));
+                       }
+
+                       return 
_containerState.bundleContext().getService(reference);
+               }
+               finally {
+                       if (requiresUpdate) {
+                               InstanceActivator activator = 
_builder.setInstance(
+                                       _componentInstanceDTO
+                               ).setReferenceDTO(
+                                       _referenceDTO
+                               ).setReference(
+                                       reference
+                               ).build();
+
+                               updateStatically(activator);
+                       }
+               }
+       }
+
+       @Override
+       @SuppressWarnings("unchecked")
+       public void modifiedService(ServiceReference<Object> reference, Object 
service) {
+               CollectionType collectionType = _templateDTO.collectionType;
+
+               if (collectionType == CollectionType.OBSERVER) {
+                       
((ReferenceEventImpl<Object>)service).modifiedService(reference);
+               }
+               else if (collectionType == CollectionType.PROPERTIES ||
+                               collectionType == CollectionType.REFERENCE ||
+                               collectionType == CollectionType.SERVICEOBJECTS 
||
+                               collectionType == CollectionType.TUPLE) {
+
+                       removedService(reference, service);
+                       addingService(reference);
+               }
+       }
+
+       @Override
+       @SuppressWarnings("unchecked")
+       public void removedService(ServiceReference<Object> reference, Object 
service) {
+               boolean active = _componentInstanceDTO.active;
+               boolean resolved = (_referenceDTO.matches.size() >= 
_templateDTO.minimumCardinality);
+               boolean dynamic = (_templateDTO.policy == 
ReferencePolicy.DYNAMIC);
+               boolean reluctant = (_templateDTO.policyOption == 
ReferencePolicyOption.RELUCTANT);
+               CollectionType collectionType = _templateDTO.collectionType;
+               boolean requiresUpdate = false;
+
+               if (resolved && reluctant && active && !dynamic) {
+                       requiresUpdate = true;
+               }
+
+               _referenceDTO.matches.removeIf(d -> d.id == SRs.id(reference));
+
+               try {
+                       if (collectionType == CollectionType.OBSERVER) {
+                               
((ReferenceEventImpl<Object>)service).removedService(reference);
+
+                               return;
+                       }
+                       else if (collectionType == CollectionType.PROPERTIES) {
+                               return;
+                       }
+                       else if (collectionType == CollectionType.REFERENCE) {
+                               return;
+                       }
+                       else if (collectionType == 
CollectionType.SERVICEOBJECTS) {
+                               
((ReferenceServiceObjectsImpl<Object>)service).close();
+
+                               return;
+                       }
+
+                       _containerState.bundleContext().ungetService(reference);
+               }
+               finally {
+                       if (requiresUpdate) {
+                               InstanceActivator activator = 
_builder.setInstance(
+                                       _componentInstanceDTO
+                               ).setReferenceDTO(
+                                       _referenceDTO
+                               ).setReference(
+                                       reference
+                               ).build();
+
+                               updateStatically(activator);
+                       }
+               }
+       }
+
+       @Override
+       public String toString() {
+               if (_string == null) {
+                       _string = 
Conversions.convert(_referenceDTO.template).to(ReferenceTemplateDTO.class).toString();
+               }
+               return _string;
+       }
+
+       private void updateStatically(InstanceActivator activator) {
+               _containerState.submit(
+                       activator.closeOp(), activator::close
+               ).then(
+                       s -> _containerState.submit(
+                               activator.openOp(), activator::open
+                       ).onFailure(
+                               f -> {
+                                       _log.error(l -> l.error("CCR Error in 
OPEN for {} on {}", _componentInstanceDTO.ident(), _containerState.bundle(), 
f));
+
+                                       _containerState.error(f);
+                               }
+                       ),
+                       f -> {
+                               _log.error(l -> l.error("CCR Error in CLODE for 
{} on {}", _componentInstanceDTO.ident(), _containerState.bundle(), 
f.getFailure()));
+
+                               _containerState.error(f.getFailure());
+                       }
+               );
+       }
+
+       private final InstanceActivator.Builder<?> _builder;
+       private final ExtendedComponentInstanceDTO _componentInstanceDTO;
+       private final ContainerState _containerState;
+       private final Logger _log;
+       private final ExtendedReferenceDTO _referenceDTO;
+       private volatile String _string;
+       private final ExtendedReferenceTemplateDTO _templateDTO;
+
+}

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/RuntimeExtension.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/RuntimeExtension.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/RuntimeExtension.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/RuntimeExtension.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,497 @@
+/**
+ * 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.aries.cdi.container.internal.container;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.BeforeShutdown;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.ProcessInjectionPoint;
+import javax.enterprise.inject.spi.Producer;
+import javax.enterprise.inject.spi.ProducerFactory;
+
+import org.apache.aries.cdi.container.internal.bean.ConfigurationBean;
+import org.apache.aries.cdi.container.internal.bean.ReferenceBean;
+import org.apache.aries.cdi.container.internal.container.Op.Mode;
+import org.apache.aries.cdi.container.internal.container.Op.Type;
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.model.ConfigurationModel;
+import org.apache.aries.cdi.container.internal.model.ExtendedActivationDTO;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedActivationTemplateDTO;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedComponentInstanceDTO;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedComponentTemplateDTO;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedConfigurationTemplateDTO;
+import org.apache.aries.cdi.container.internal.model.ExtendedReferenceDTO;
+import 
org.apache.aries.cdi.container.internal.model.ExtendedReferenceTemplateDTO;
+import org.apache.aries.cdi.container.internal.model.FactoryComponent;
+import org.apache.aries.cdi.container.internal.model.OSGiBean;
+import org.apache.aries.cdi.container.internal.model.ReferenceModel;
+import org.apache.aries.cdi.container.internal.model.SingleComponent;
+import org.apache.aries.cdi.container.internal.util.Conversions;
+import org.apache.aries.cdi.container.internal.util.SRs;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.PrototypeServiceFactory;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cdi.CDIConstants;
+import org.osgi.service.cdi.ComponentType;
+import org.osgi.service.cdi.ServiceScope;
+import org.osgi.service.cdi.annotations.ComponentScoped;
+import org.osgi.service.cdi.annotations.Configuration;
+import org.osgi.service.cdi.annotations.Reference;
+import org.osgi.service.cdi.runtime.dto.ComponentDTO;
+import org.osgi.service.cdi.runtime.dto.ConfigurationDTO;
+import org.osgi.service.cdi.runtime.dto.template.ComponentTemplateDTO;
+import org.osgi.service.cdi.runtime.dto.template.ConfigurationTemplateDTO;
+import org.osgi.service.log.Logger;
+import org.osgi.util.promise.Promise;
+
+public class RuntimeExtension implements Extension {
+
+       public RuntimeExtension(
+               ContainerState containerState,
+               ConfigurationListener.Builder configurationBuilder,
+               SingleComponent.Builder singleBuilder,
+               FactoryComponent.Builder factoryBuilder) {
+
+               _containerState = containerState;
+
+               _log = _containerState.containerLogs().getLogger(getClass());
+               _log.debug(l -> l.debug("CCR RuntimeExtension {}", 
containerState.bundle()));
+
+               _configurationBuilder = configurationBuilder;
+               _singleBuilder = singleBuilder;
+               _factoryBuilder = factoryBuilder;
+
+               _containerComponentDTO = 
_containerState.containerDTO().components.stream().filter(
+                       c -> c.template.type == ComponentType.CONTAINER
+               ).findFirst().get();
+
+               _containerInstanceDTO = 
(ExtendedComponentInstanceDTO)_containerComponentDTO.instances.get(0);
+       }
+
+       void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) {
+               bbd.addQualifier(org.osgi.service.cdi.annotations.Bundle.class);
+               
bbd.addQualifier(org.osgi.service.cdi.annotations.Configuration.class);
+               bbd.addQualifier(org.osgi.service.cdi.annotations.Greedy.class);
+               bbd.addQualifier(org.osgi.service.cdi.annotations.PID.class);
+               
bbd.addQualifier(org.osgi.service.cdi.annotations.Prototype.class);
+               
bbd.addQualifier(org.osgi.service.cdi.annotations.Reference.class);
+               
bbd.addQualifier(org.osgi.service.cdi.annotations.Service.class);
+               bbd.addScope(ComponentScoped.class, false, false);
+               
bbd.addStereotype(org.osgi.service.cdi.annotations.FactoryComponent.class);
+               
bbd.addStereotype(org.osgi.service.cdi.annotations.SingleComponent.class);
+       }
+
+       void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager 
bm) {
+               abd.addContext(_containerState.componentContext());
+
+               _containerState.containerDTO().template.components.forEach(
+                       ct -> addBeans(ct, abd, bm)
+               );
+       }
+
+       void afterDeploymentValidation(@Observes AfterDeploymentValidation adv, 
BeanManager bm) {
+               _log.debug(l -> l.debug("CCR AfterDeploymentValidation on {}", 
_containerState.bundle()));
+
+               _containerState.beanManager(bm);
+
+               Dictionary<String, Object> properties = new Hashtable<>();
+               properties.put(CDIConstants.CDI_CONTAINER_ID, 
_containerState.id());
+
+               registerService(
+                       new String[] {BeanManager.class.getName()}, bm,
+                       properties);
+
+               _containerState.submit(
+                       Op.of(Mode.OPEN, Type.CONTAINER_FIRE_EVENTS, 
_containerState.id()),
+                       _containerInstanceDTO::fireEvents
+               ).then(
+                       s-> {
+                               return _containerState.submit(
+                                       Op.of(Mode.OPEN, 
Type.CONTAINER_PUBLISH_SERVICES, _containerState.id()),
+                                       () -> 
registerServices(_containerComponentDTO, _containerInstanceDTO, bm)
+                               );
+                       }
+               ).then(
+                       s -> initComponents()
+               );
+       }
+
+       void beforeShutdown(@Observes BeforeShutdown bs) {
+               _log.debug(l -> l.debug("CCR BeforeShutdown on {}", 
_containerState.bundle()));
+
+               _configurationListeners.removeIf(
+                       cl -> {
+                               _containerState.submit(cl.closeOp(), 
cl::close).onFailure(
+                                       f -> {
+                                               _log.error(l -> l.error("CCR 
Error while closing configuration listener {} on {}", cl, 
_containerState.bundle(), f));
+                                       }
+                               );
+
+                               return true;
+                       }
+               );
+
+               _containerInstanceDTO.activations.clear();
+
+               _registrations.removeIf(
+                       r -> {
+                               try {
+                                       r.unregister();
+                               }
+                               catch (Exception e) {
+                                       _log.error(l -> l.error("CCR Error 
while unregistring {} on {}", r, _containerState.bundle(), e));
+                               }
+                               return true;
+                       }
+               );
+       }
+
+       void processInjectionPoint(@Observes ProcessInjectionPoint<?, ?> pip, 
BeanManager beanManager) {
+               InjectionPoint injectionPoint = pip.getInjectionPoint();
+
+               Class<?> declaringClass = 
DiscoveryExtension.getDeclaringClass(injectionPoint);
+
+               String className = declaringClass.getName();
+
+               OSGiBean osgiBean = 
_containerState.beansModel().getOSGiBean(className);
+
+               if (osgiBean == null) {
+                       return;
+               }
+
+               Annotated annotated = injectionPoint.getAnnotated();
+               Configuration configuration = 
annotated.getAnnotation(Configuration.class);
+               Reference reference = annotated.getAnnotation(Reference.class);
+
+               if ((reference != null) && matchReference(osgiBean, reference, 
pip)) {
+                       return;
+               }
+
+               if (configuration != null) {
+                       matchConfiguration(osgiBean, configuration, pip);
+               }
+       }
+
+       private void addBeans(ComponentTemplateDTO componentTemplate, 
AfterBeanDiscovery abd, BeanManager bm) {
+               
componentTemplate.references.stream().map(ExtendedReferenceTemplateDTO.class::cast).forEach(
+                       t -> {
+                               ReferenceBean bean = t.bean;
+                               bean.setBeanManager(bm);
+                               if (componentTemplate.type == 
ComponentType.CONTAINER) {
+                                       
_containerInstanceDTO.references.stream().filter(
+                                               r -> r.template == t
+                                       ).findFirst().map(
+                                               ExtendedReferenceDTO.class::cast
+                                       ).ifPresent(
+                                               r -> bean.setReferenceDTO(r)
+                                       );
+                               }
+                               if (t.collectionType != 
CollectionType.OBSERVER) {
+                                       _log.debug(l -> l.debug("CCR Adding 
synthetic bean {} on {}", bean, _containerState.bundle()));
+
+                                       abd.addBean(bean);
+                               }
+                       }
+               );
+
+               
componentTemplate.configurations.stream().map(ExtendedConfigurationTemplateDTO.class::cast).filter(
+                       t -> Objects.nonNull(t.injectionPointType)
+               ).forEach(
+                       t -> {
+                               ConfigurationBean bean = t.bean;
+                               if (componentTemplate.type == 
ComponentType.CONTAINER) {
+                                       if (t.pid == null) {
+                                               
bean.setProperties(componentTemplate.properties);
+                                       }
+                                       else {
+                                               
bean.setProperties(_containerInstanceDTO.properties);
+                                       }
+                               }
+
+                               _log.debug(l -> l.debug("CCR Adding synthetic 
bean {} on {}", bean, _containerState.bundle()));
+
+                               abd.addBean(bean);
+                       }
+               );
+       }
+
+       @SuppressWarnings("unchecked")
+       private Producer<Object> createProducer(Object producerObject, 
Bean<Object> bean, BeanManager bm) {
+               ProducerFactory<Object> producerFactory = null;
+               if (producerObject instanceof AnnotatedField)
+                       producerFactory = 
bm.getProducerFactory((AnnotatedField<Object>)producerObject, bean);
+               else if (producerObject instanceof AnnotatedMethod)
+                       producerFactory = 
bm.getProducerFactory((AnnotatedMethod<Object>)producerObject, bean);
+
+               if (producerFactory == null)
+                       return null;
+
+               return producerFactory.createProducer(bean);
+       }
+
+       private Promise<List<Boolean>> initComponents() {
+               
_containerState.containerDTO().template.components.stream().filter(
+                       t -> t.type != ComponentType.CONTAINER
+               ).map(ExtendedComponentTemplateDTO.class::cast).map(
+                       this::initComponent
+               ).collect(Collectors.toList());
+
+               return null;
+       }
+
+       private Promise<Boolean> initComponent(ExtendedComponentTemplateDTO 
componentTemplateDTO) {
+               List<ConfigurationDTO> configurations = 
_containerInstanceDTO.configurations;
+
+               if (!configurations.isEmpty()) {
+                       ConfigurationDTO defaultContainerConfiguration = 
configurations.get(0);
+
+                       Boolean enabled = Conversions.convert(
+                               defaultContainerConfiguration.properties.get(
+                                       
componentTemplateDTO.name.concat(".enabled"))
+                       ).defaultValue(Boolean.TRUE).to(Boolean.class);
+
+                       if (!enabled) {
+                               
_containerState.containerDTO().components.stream().filter(
+                                       c -> c.template == componentTemplateDTO
+                               ).findFirst().ifPresent(
+                                       c -> c.enabled = false
+                               );
+
+                               return 
_containerState.promiseFactory().resolved(Boolean.TRUE);
+                       }
+               }
+
+               if (componentTemplateDTO.type == ComponentType.FACTORY) {
+                       return initFactoryComponent(componentTemplateDTO);
+               }
+
+               return initSingleComponent(componentTemplateDTO);
+       }
+
+       private Promise<Boolean> 
initFactoryComponent(ExtendedComponentTemplateDTO componentTemplateDTO) {
+               ConfigurationListener cl = _configurationBuilder.component(
+                       _factoryBuilder.template(componentTemplateDTO).build()
+               ).build();
+
+               _configurationListeners.add(cl);
+
+               return _containerState.submit(cl.openOp(), cl::open);
+       }
+
+       private Promise<Boolean> 
initSingleComponent(ExtendedComponentTemplateDTO componentTemplateDTO) {
+               ConfigurationListener cl = _configurationBuilder.component(
+                       _singleBuilder.template(componentTemplateDTO).build()
+               ).build();
+
+               _configurationListeners.add(cl);
+
+               return _containerState.submit(cl.openOp(), cl::open);
+       }
+
+       private boolean matchConfiguration(OSGiBean osgiBean, Configuration 
configuration, ProcessInjectionPoint<?, ?> pip) {
+               InjectionPoint injectionPoint = pip.getInjectionPoint();
+
+               Class<?> declaringClass = 
DiscoveryExtension.getDeclaringClass(injectionPoint);
+
+               ConfigurationTemplateDTO current = new 
ConfigurationModel.Builder(injectionPoint.getType()).declaringClass(
+                       declaringClass
+               ).injectionPoint(
+                       injectionPoint
+               ).build().toDTO();
+
+               return osgiBean.getComponent().configurations.stream().map(
+                       t -> (ExtendedConfigurationTemplateDTO)t
+               ).filter(
+                       t -> current.equals(t)
+               ).findFirst().map(
+                       t -> {
+                               MarkedInjectionPoint markedInjectionPoint = new 
MarkedInjectionPoint(injectionPoint);
+
+                               pip.setInjectionPoint(markedInjectionPoint);
+
+                               t.bean.setMark(markedInjectionPoint.getMark());
+
+                               return true;
+                       }
+               ).orElse(false);
+       }
+
+       private boolean matchReference(OSGiBean osgiBean, Reference reference, 
ProcessInjectionPoint<?, ?> pip) {
+               InjectionPoint injectionPoint = pip.getInjectionPoint();
+
+               Annotated annotated = injectionPoint.getAnnotated();
+
+               ReferenceModel.Builder builder = null;
+
+               if (annotated instanceof AnnotatedField) {
+                       builder = new 
ReferenceModel.Builder((AnnotatedField<?>)annotated);
+               }
+               else if (annotated instanceof AnnotatedMethod) {
+                       builder = new 
ReferenceModel.Builder((AnnotatedMethod<?>)annotated);
+               }
+               else {
+                       builder = new 
ReferenceModel.Builder((AnnotatedParameter<?>)annotated);
+               }
+
+               ReferenceModel referenceModel = 
builder.injectionPoint(injectionPoint).build();
+
+               ExtendedReferenceTemplateDTO current = referenceModel.toDTO();
+
+               return osgiBean.getComponent().references.stream().map(
+                       t -> (ExtendedReferenceTemplateDTO)t
+               ).filter(
+                       t -> current.equals(t)
+               ).findFirst().map(
+                       t -> {
+                               MarkedInjectionPoint markedInjectionPoint = new 
MarkedInjectionPoint(injectionPoint);
+
+                               pip.setInjectionPoint(markedInjectionPoint);
+
+                               t.bean.setMark(markedInjectionPoint.getMark());
+
+                               return true;
+                       }
+               ).orElse(false);
+       }
+
+       @SuppressWarnings({ "rawtypes", "unchecked" })
+       private void registerService(
+               ExtendedComponentInstanceDTO componentInstance,
+               ExtendedActivationTemplateDTO activationTemplate,
+               BeanManager bm) {
+
+               ServiceScope scope = activationTemplate.scope;
+
+               if (activationTemplate.cdiScope == ApplicationScoped.class) {
+                       scope = ServiceScope.SINGLETON;
+               }
+
+               final Context context = 
bm.getContext(activationTemplate.cdiScope);
+               final Bean<Object> bean = (Bean<Object>)bm.resolve(
+                       bm.getBeans(activationTemplate.declaringClass, 
Any.Literal.INSTANCE));
+               final Producer producer = 
createProducer(activationTemplate.producer, bean, bm);
+
+               Object serviceObject;
+
+               if (scope == ServiceScope.PROTOTYPE) {
+                       serviceObject = new PrototypeServiceFactory<Object>() {
+                               @Override
+                               public Object getService(Bundle bundle, 
ServiceRegistration<Object> registration) {
+                                       CreationalContext<Object> cc = 
bm.createCreationalContext(bean);
+                                       if (producer != null) {
+                                               return producer.produce(cc);
+                                       }
+                                       return context.get(bean, cc);
+                               }
+
+                               @Override
+                               public void ungetService(Bundle bundle, 
ServiceRegistration<Object> registration, Object service) {
+                               }
+                       };
+               }
+               else if (scope == ServiceScope.BUNDLE) {
+                       serviceObject = new ServiceFactory<Object>() {
+                               @Override
+                               public Object getService(Bundle bundle, 
ServiceRegistration<Object> registration) {
+                                       CreationalContext<Object> cc = 
bm.createCreationalContext(bean);
+                                       if (producer != null) {
+                                               return producer.produce(cc);
+                                       }
+                                       return context.get(bean, cc);
+                               }
+
+                               @Override
+                               public void ungetService(Bundle bundle, 
ServiceRegistration<Object> registration, Object service) {
+                               }
+                       };
+               }
+               else {
+                       CreationalContext<Object> cc = 
bm.createCreationalContext(bean);
+                       if (producer != null) {
+                               serviceObject = producer.produce(cc);
+                       }
+                       else {
+                               serviceObject = context.get(bean, cc);
+                       }
+               }
+
+               Objects.requireNonNull(serviceObject, "The service object is 
somehow null on " + this);
+
+               Dictionary<String, Object> properties = new Hashtable<>(
+                       
componentInstance.componentProperties(activationTemplate.properties));
+
+               ServiceRegistration<?> serviceRegistration = registerService(
+                       activationTemplate.serviceClasses.toArray(new 
String[0]),
+                       serviceObject, properties);
+
+               ExtendedActivationDTO activationDTO = new 
ExtendedActivationDTO();
+               activationDTO.errors = new CopyOnWriteArrayList<>();
+               activationDTO.service = 
SRs.from(serviceRegistration.getReference());
+               activationDTO.template = activationTemplate;
+               componentInstance.activations.add(activationDTO);
+       }
+
+       private ServiceRegistration<?> registerService(String[] serviceTypes, 
Object serviceObject, Dictionary<String, Object> properties) {
+               ServiceRegistration<?> serviceRegistration = 
_containerState.bundleContext().registerService(
+                       serviceTypes, serviceObject, properties);
+
+               _registrations.add(serviceRegistration);
+
+               return serviceRegistration;
+       }
+
+       private boolean registerServices(ComponentDTO componentDTO, 
ExtendedComponentInstanceDTO instance, BeanManager bm) {
+               componentDTO.template.activations.stream().map(
+                       ExtendedActivationTemplateDTO.class::cast
+               ).forEach(
+                       a -> registerService(instance, a, bm)
+               );
+
+               return true;
+       }
+
+       private final ComponentDTO _containerComponentDTO;
+       private final ConfigurationListener.Builder _configurationBuilder;
+       private final List<ConfigurationListener> _configurationListeners = new 
CopyOnWriteArrayList<>();
+       private final ContainerState _containerState;
+       private final FactoryComponent.Builder _factoryBuilder;
+       private final ExtendedComponentInstanceDTO _containerInstanceDTO;
+       private final Logger _log;
+       private final List<ServiceRegistration<?>> _registrations = new 
CopyOnWriteArrayList<>();
+       private final SingleComponent.Builder _singleBuilder;
+
+}

Modified: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/loader/BundleResourcesLoader.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/loader/BundleResourcesLoader.java?rev=1829115&r1=1829114&r2=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/loader/BundleResourcesLoader.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/loader/BundleResourcesLoader.java
 Sat Apr 14 01:10:27 2018
@@ -110,30 +110,4 @@ public class BundleResourcesLoader imple
 
        private final ClassLoader _classLoader;
 
-       public static Bundle[] getBundles(Bundle bundle, Bundle extenderBundle) 
{
-               List<Bundle> bundles = new ArrayList<>();
-
-               bundles.add(bundle);
-               bundles.add(extenderBundle);
-
-               BundleWiring extenderWiring = 
extenderBundle.adapt(BundleWiring.class);
-
-               List<BundleWire> requiredWires = 
extenderWiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
-
-               for (BundleWire bundleWire : requiredWires) {
-                       BundleCapability capability = 
bundleWire.getCapability();
-                       Map<String, Object> attributes = 
capability.getAttributes();
-                       String packageName = 
(String)attributes.get(PackageNamespace.PACKAGE_NAMESPACE);
-                       if (!packageName.startsWith("org.jboss.weld.")) {
-                               continue;
-                       }
-
-                       Bundle wireBundle = 
bundleWire.getProvider().getBundle();
-                       if (!bundles.contains(wireBundle)) {
-                               bundles.add(wireBundle);
-                       }
-               }
-
-               return bundles.toArray(new Bundle[0]);
-       }
 }

Modified: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModel.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModel.java?rev=1829115&r1=1829114&r2=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModel.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModel.java
 Sat Apr 14 01:10:27 2018
@@ -16,10 +16,8 @@ package org.apache.aries.cdi.container.i
 
 import java.net.URL;
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
 
-import org.apache.aries.cdi.container.internal.component.OSGiBean;
 import org.jboss.weld.bootstrap.spi.BeansXml;
 import org.jboss.weld.xml.BeansXmlParser;
 
@@ -27,13 +25,9 @@ public class BeansModel {
 
        public BeansModel(
                Map<String, OSGiBean> beans,
-               List<Class<?>> qualifierBlackList,
-               List<Throwable> errors,
                Collection<URL> beanDescriptorURLs) {
 
                _beans = beans;
-               _qualifierBlackList = qualifierBlackList;
-               _errors = errors;
 
                BeansXml beansXml = BeansXml.EMPTY_BEANS_XML;
 
@@ -53,14 +47,6 @@ public class BeansModel {
                return _beansXml;
        }
 
-       public List<Class<?>> getQualifierBlackList() {
-               return _qualifierBlackList;
-       }
-
-       public List<Throwable> getErrors() {
-               return _errors;
-       }
-
        public OSGiBean getOSGiBean(String beanClass) {
                return _beans.get(beanClass);
        }
@@ -75,7 +61,5 @@ public class BeansModel {
 
        private final Map<String, OSGiBean> _beans;
        private final BeansXml _beansXml;
-       private final List<Throwable> _errors;
-       private final List<Class<?>> _qualifierBlackList;
 
 }
\ No newline at end of file

Modified: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModelBuilder.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModelBuilder.java?rev=1829115&r1=1829114&r2=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModelBuilder.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/BeansModelBuilder.java
 Sat Apr 14 01:10:27 2018
@@ -14,70 +14,93 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
-import static org.osgi.namespace.extender.ExtenderNamespace.EXTENDER_NAMESPACE;
-import static org.osgi.service.cdi.CdiConstants.CDI_CAPABILITY_NAME;
+import static org.apache.aries.cdi.container.internal.util.Reflection.*;
+import static org.osgi.service.cdi.CDIConstants.*;
 
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
+import org.apache.aries.cdi.container.internal.container.ContainerState;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.wiring.BundleCapability;
-import org.osgi.framework.wiring.BundleRequirement;
-import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.service.log.Logger;
 
-public class BeansModelBuilder extends AbstractModelBuilder {
+public class BeansModelBuilder {
 
-       public BeansModelBuilder(ClassLoader classLoader, BundleWiring 
bundleWiring) {
-               _classLoader = classLoader;
+       public BeansModelBuilder(
+               ContainerState containerState,
+               ClassLoader aggregateClassLoader,
+               BundleWiring bundleWiring,
+               Map<String, Object> cdiAttributes) {
+
+               _containerState = containerState;
+               _aggregateClassLoader = aggregateClassLoader;
                _bundleWiring = bundleWiring;
+               _attributes = cdiAttributes;
                _bundle = _bundleWiring.getBundle();
+               _log = containerState.containerLogs().getLogger(getClass());
+       }
+
+       public BeansModel build() {
+               List<URL> beanDescriptorURLs = new ArrayList<URL>();
+               Map<String, Object> attributes = getAttributes();
+
+               List<String> beanDescriptorPaths = 
cast(attributes.get(REQUIREMENT_BEANS_ATTRIBUTE));
+
+               if (beanDescriptorPaths != null) {
+                       for (String descriptorPath : beanDescriptorPaths) {
+                               URL url = getResource(descriptorPath);
+
+                               if (url != null) {
+                                       beanDescriptorURLs.add(url);
+                               }
+                       }
+               }
+
+               @SuppressWarnings("unchecked")
+               List<String> beanClassNames = Optional.ofNullable(
+                       _attributes.get(REQUIREMENT_OSGI_BEANS_ATTRIBUTE)
+               ).map(v -> (List<String>)v).orElse(Collections.emptyList());
 
-               List<BundleWire> wires = 
bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
+               Map<String, OSGiBean> beans = new HashMap<>();
 
-               Map<String, Object> cdiAttributes = Collections.emptyMap();
+               for (String beanClassName : beanClassNames) {
+                       try {
+                               Class<?> clazz = 
_aggregateClassLoader.loadClass(beanClassName);
 
-               for (BundleWire wire : wires) {
-                       BundleCapability capability = wire.getCapability();
-                       Map<String, Object> attributes = 
capability.getAttributes();
-                       String extender = 
(String)attributes.get(EXTENDER_NAMESPACE);
-
-                       if (extender.equals(CDI_CAPABILITY_NAME)) {
-                               BundleRequirement requirement = 
wire.getRequirement();
-                               cdiAttributes = requirement.getAttributes();
-                               break;
+                               beans.put(beanClassName, new 
OSGiBean.Builder(_containerState.containerLogs(), clazz).build());
+
+                               _log.debug(l -> l.debug("CCR found bean {} on 
{}", beanClassName, _containerState.bundle()));
+                       }
+                       catch (Exception e) {
+                               _log.error(l -> l.error("CCR Error loading 
class {} on {}", beanClassName, _containerState.bundle(), e));
+
+                               _containerState.error(e);
                        }
                }
 
-               _attributes = cdiAttributes;
+               return new BeansModel(beans, beanDescriptorURLs);
        }
 
-       @Override
        public Map<String, Object> getAttributes() {
                return _attributes;
        }
 
-       @Override
-       public ClassLoader getClassLoader() {
-               return _classLoader;
-       }
-
-       @Override
        public URL getResource(String resource) {
                return _bundle.getResource(resource);
        }
 
-       @Override
-       public List<String> getDefaultResources() {
-               return new 
ArrayList<>(_bundleWiring.listResources("OSGI-INF/cdi", "*.xml", 
BundleWiring.LISTRESOURCES_LOCAL));
-       }
 
+       private final ClassLoader _aggregateClassLoader;
        private final Map<String, Object> _attributes;
        private final Bundle _bundle;
-       private final ClassLoader _classLoader;
        private final BundleWiring _bundleWiring;
+       private final ContainerState _containerState;
+       private final Logger _log;
 
 }

Modified: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/CollectionType.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/CollectionType.java?rev=1829115&r1=1829114&r2=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/CollectionType.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/CollectionType.java
 Sat Apr 14 01:10:27 2018
@@ -58,7 +58,12 @@ public enum CollectionType {
         * ordering as {@code ServiceReference.compareTo} based upon service 
ranking
         * and service id.
         */
-       TUPLE("tuple");
+       TUPLE("tuple"),
+
+       /**
+        * The observer type is used to indicate the reference is targeted to a 
observer method.
+        */
+       OBSERVER("observer");
 
        private final String value;
 

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Component.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Component.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Component.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Component.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,75 @@
+/**
+ * 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.aries.cdi.container.internal.model;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.aries.cdi.container.internal.container.ContainerState;
+import org.apache.aries.cdi.container.internal.container.Phase;
+import org.osgi.service.cdi.runtime.dto.ComponentDTO;
+import org.osgi.service.cdi.runtime.dto.ComponentInstanceDTO;
+import org.osgi.service.cdi.runtime.dto.template.ComponentTemplateDTO;
+import org.osgi.service.cdi.runtime.dto.template.ConfigurationTemplateDTO;
+
+public abstract class Component extends Phase {
+
+       public abstract static class Builder<T extends Builder<T>> {
+
+               public Builder(ContainerState containerState, 
InstanceActivator.Builder<?> activatorBuilder) {
+                       _containerState = containerState;
+                       _activatorBuilder = activatorBuilder;
+               }
+
+               @SuppressWarnings("unchecked")
+               public T template(ComponentTemplateDTO templateDTO) {
+                       _templateDTO = templateDTO;
+                       return (T)this;
+               }
+
+               public abstract Component build();
+
+               protected InstanceActivator.Builder<?> _activatorBuilder;
+               protected ContainerState _containerState;
+               protected Phase _next;
+               protected ComponentTemplateDTO _templateDTO;
+
+       }
+
+       Component(Builder<?> builder) {
+               super(builder._containerState, null);
+               _activatorBuilder = builder._activatorBuilder;
+       }
+
+       public InstanceActivator.Builder<?> activatorBuilder() {
+               return _activatorBuilder;
+       }
+
+       public abstract List<ConfigurationTemplateDTO> configurationTemplates();
+
+       public abstract List<ComponentInstanceDTO> instances();
+
+       public abstract ComponentDTO snapshot();
+
+       public abstract ComponentTemplateDTO template();
+
+       @Override
+       public String toString() {
+               return Arrays.asList(getClass().getSimpleName(), 
template().name).toString();
+       }
+
+       private final InstanceActivator.Builder<?> _activatorBuilder;
+
+}

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ConfigurationModel.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationModel.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ConfigurationModel.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ConfigurationModel.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationModel.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationModel.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ConfigurationModel.java
 Sat Apr 14 01:10:27 2018
@@ -12,9 +12,12 @@
  * limitations under the License.
  */
 
-package org.apache.aries.cdi.container.internal.configuration;
+package org.apache.aries.cdi.container.internal.model;
+
+import static org.apache.aries.cdi.container.internal.util.Reflection.*;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.LinkedHashSet;
 import java.util.Objects;
@@ -22,22 +25,28 @@ import java.util.Set;
 
 import javax.enterprise.inject.spi.InjectionPoint;
 
+import org.osgi.service.cdi.ConfigurationPolicy;
+import org.osgi.service.cdi.MaximumCardinality;
 import org.osgi.service.cdi.annotations.PID;
-import org.osgi.service.cdi.runtime.dto.template.ConfigurationPolicy;
 import org.osgi.service.cdi.runtime.dto.template.ConfigurationTemplateDTO;
-import org.osgi.service.cdi.runtime.dto.template.MaximumCardinality;
 
 public class ConfigurationModel {
 
        public static class Builder {
 
-               public Builder(Type type) {
-                       Objects.requireNonNull(type);
-                       _type = type;
+               public Builder(Type injectionPointType) {
+                       _injectionPointType = injectionPointType;
                }
 
                public ConfigurationModel build() {
-                       return new ConfigurationModel(_type, _pid, _qualifiers);
+                       Objects.requireNonNull(_delcaringClass);
+                       Objects.requireNonNull(_injectionPointType);
+                       return new ConfigurationModel(_injectionPointType, 
_delcaringClass, _pid, _qualifiers);
+               }
+
+               public Builder declaringClass(Class<?> delcaringClass) {
+                       _delcaringClass = delcaringClass;
+                       return this;
                }
 
                public Builder injectionPoint(InjectionPoint injectionPoint) {
@@ -46,50 +55,37 @@ public class ConfigurationModel {
                        return this;
                }
 
+               private Class<?> _delcaringClass;
                private PID _pid;
                private Set<Annotation> _qualifiers;
-               private Type _type;
+               private Type _injectionPointType;
 
        }
 
-       private ConfigurationModel(Type type, PID pid, Set<Annotation> 
qualifiers) {
-               _type = type;
+       private ConfigurationModel(
+               Type injectionPointType,
+               Class<?> delcaringClass,
+               PID pid,
+               Set<Annotation> qualifiers) {
+
+               _injectionPointType = injectionPointType;
                _pid = pid;
                _qualifiers = new LinkedHashSet<>();
+               _declaringClass = delcaringClass;
+
                if (qualifiers != null) {
                        _qualifiers.addAll(qualifiers);
                }
-       }
 
-       @Override
-       public int hashCode() {
-               final int prime = 31;
-               int result = 1;
-               result = prime * result + ((_qualifiers == null) ? 0 : 
_qualifiers.hashCode());
-               result = prime * result + ((_type == null) ? 0 : 
_type.hashCode());
-               return result;
-       }
+               Type rawType = injectionPointType;
 
-       @Override
-       public boolean equals(Object obj) {
-               if (this == obj)
-                       return true;
-               if (obj == null)
-                       return false;
-               if (getClass() != obj.getClass())
-                       return false;
-               ConfigurationModel other = (ConfigurationModel) obj;
-               if (_qualifiers == null) {
-                       if (other._qualifiers != null)
-                               return false;
-               } else if (!_qualifiers.equals(other._qualifiers))
-                       return false;
-               if (_type == null) {
-                       if (other._type != null)
-                               return false;
-               } else if (!_type.equals(other._type))
-                       return false;
-               return true;
+               if (_injectionPointType instanceof ParameterizedType) {
+                       ParameterizedType pt = 
(ParameterizedType)_injectionPointType;
+
+                       rawType = pt.getRawType();
+               }
+
+               _beanClass = cast(rawType);
        }
 
        public PID getPid() {
@@ -101,38 +97,42 @@ public class ConfigurationModel {
        }
 
        public Type getType() {
-               return _type;
-       }
-
-       public void setQualifiers(Set<Annotation> qualifiers) {
-               _qualifiers.clear();
-               _qualifiers.addAll(qualifiers);
+               return _injectionPointType;
        }
 
        public ConfigurationTemplateDTO toDTO() {
-               if (_pid != null) {
-                       ConfigurationTemplateDTO dto = new 
ConfigurationTemplateDTO();
+               ExtendedConfigurationTemplateDTO dto = new 
ExtendedConfigurationTemplateDTO();
+
+               dto.beanClass = _beanClass;
+               dto.declaringClass = _declaringClass;
+               dto.injectionPointType = _injectionPointType;
+               dto.maximumCardinality = MaximumCardinality.ONE;
 
+               if (_pid != null) {
                        dto.componentConfiguration = false;
-                       dto.maximumCardinality = MaximumCardinality.ONE;
                        dto.pid = _pid.value();
-                       dto.policy = 
(_pid.policy().toString().equals(ConfigurationPolicy.REQUIRED.toString()))
-                               ? ConfigurationPolicy.REQUIRED : 
ConfigurationPolicy.OPTIONAL;
                }
+               else {
+                       dto.componentConfiguration = true;
+               }
+
+               dto.policy = (_pid != null) ? _pid.policy() : 
ConfigurationPolicy.OPTIONAL;
 
-               return null;
+               return dto;
        }
 
        @Override
        public String toString() {
                if (_string == null) {
-                       _string = String.format("configuration[type='%s', 
pid='%s', policy='%s']", _type, _pid.value(), _pid.policy());
+                       _string = String.format("configuration[type='%s', 
pid='%s', policy='%s']", _injectionPointType, _pid.value(), _pid.policy());
                }
                return _string;
        }
 
+       private final Class<?> _beanClass;
+       private final Class<?> _declaringClass;
        private final PID _pid;
        private final Set<Annotation> _qualifiers;
        private volatile String _string;
-       private final Type _type;
+       private final Type _injectionPointType;
 }

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerActivator.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerActivator.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerActivator.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerActivator.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,100 @@
+/**
+ * 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.aries.cdi.container.internal.model;
+
+import org.apache.aries.cdi.container.internal.container.ContainerBootstrap;
+import org.apache.aries.cdi.container.internal.container.ContainerState;
+import org.apache.aries.cdi.container.internal.container.Op;
+import org.apache.aries.cdi.container.internal.container.Op.Mode;
+import org.apache.aries.cdi.container.internal.container.Op.Type;
+import org.osgi.service.log.Logger;
+
+public class ContainerActivator extends InstanceActivator {
+
+       public static class Builder extends InstanceActivator.Builder<Builder> {
+
+               public Builder(ContainerState containerState, 
ContainerBootstrap next) {
+                       super(containerState, next);
+               }
+
+               @Override
+               public ContainerActivator build() {
+                       return new ContainerActivator(this);
+               }
+
+       }
+
+       private ContainerActivator(Builder builder) {
+               super(builder);
+               _log = containerState.containerLogs().getLogger(getClass());
+       }
+
+       @Override
+       public boolean close() {
+               boolean result = next.map(
+                       next -> {
+                               submit(next.closeOp(), next::close).onFailure(
+                                       f -> {
+                                               _log.error(l -> l.error("CCR 
Failure in container activator close on {}", next, f));
+                                       }
+                               );
+
+                               return true;
+                       }
+               ).orElse(true);
+
+               instance.active = false;
+
+               return result;
+       }
+
+       @Override
+       public Op closeOp() {
+               return Op.of(Mode.CLOSE, Type.CONTAINER_ACTIVATOR, 
instance.template.name);
+       }
+
+       @Override
+       public boolean open() {
+               if (!instance.referencesResolved()) {
+                       return false;
+               }
+
+               boolean result = next.map(
+                       next -> {
+                               submit(next.openOp(), next::open).onFailure(
+                                       f -> {
+                                               _log.error(l -> l.error("CCR 
Failure in container activator open on {}", next, f));
+                                       }
+                               );
+
+                               return true;
+                       }
+               ).orElse(true);
+
+               if (result) {
+                       instance.active = true;
+               }
+
+               return result;
+       }
+
+       @Override
+       public Op openOp() {
+               return Op.of(Mode.OPEN, Type.CONTAINER_ACTIVATOR, 
instance.template.name);
+       }
+
+       private final Logger _log;
+
+}

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerComponent.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerComponent.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerComponent.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ContainerComponent.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,146 @@
+/**
+ * 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.aries.cdi.container.internal.model;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.aries.cdi.container.internal.container.ContainerState;
+import org.apache.aries.cdi.container.internal.container.Op;
+import org.apache.aries.cdi.container.internal.container.Op.Mode;
+import org.apache.aries.cdi.container.internal.container.Op.Type;
+import org.apache.aries.cdi.container.internal.util.Conversions;
+import org.osgi.service.cdi.runtime.dto.ComponentDTO;
+import org.osgi.service.cdi.runtime.dto.ComponentInstanceDTO;
+import org.osgi.service.cdi.runtime.dto.ConfigurationDTO;
+import org.osgi.service.cdi.runtime.dto.template.ComponentTemplateDTO;
+import org.osgi.service.cdi.runtime.dto.template.ConfigurationTemplateDTO;
+import org.osgi.service.log.Logger;
+
+public class ContainerComponent extends Component {
+
+       public static class Builder extends Component.Builder<Builder> {
+
+               public Builder(ContainerState containerState, 
ContainerActivator.Builder activatorBuilder) {
+                       super(containerState, activatorBuilder);
+               }
+
+               @Override
+               public ContainerComponent build() {
+                       
template(_containerState.containerComponentTemplateDTO());
+                       return new ContainerComponent(this);
+               }
+
+       }
+
+       protected ContainerComponent(Builder builder) {
+               super(builder);
+
+               _log = containerState.containerLogs().getLogger(getClass());
+
+               _template = builder._templateDTO;
+
+               _snapshot = new ComponentDTO();
+               _snapshot.instances = new CopyOnWriteArrayList<>();
+               _snapshot.template = _template;
+
+               _instanceDTO = new ExtendedComponentInstanceDTO(containerState, 
builder._activatorBuilder);
+               _instanceDTO.activations = new CopyOnWriteArrayList<>();
+               _instanceDTO.configurations = new CopyOnWriteArrayList<>();
+               _instanceDTO.pid = _template.configurations.get(0).pid;
+               _instanceDTO.properties = null;
+               _instanceDTO.references = new CopyOnWriteArrayList<>();
+               _instanceDTO.template = _template;
+
+               _snapshot.instances.add(_instanceDTO);
+
+               containerState.containerDTO().components.add(_snapshot);
+       }
+
+       @Override
+       public boolean close() {
+               submit(_instanceDTO.closeOp(), _instanceDTO::close).onFailure(
+                       f -> {
+                               _log.error(l -> l.error("CCR Error in container 
component close for {} on {}", _template.name, containerState.bundle()));
+                       }
+               );
+
+               return true;
+       }
+
+       @Override
+       public Op closeOp() {
+               return Op.of(Mode.CLOSE, Type.CONTAINER_COMPONENT, 
_template.name);
+       }
+
+       @Override
+       public List<ConfigurationTemplateDTO> configurationTemplates() {
+               return _template.configurations;
+       }
+
+       @Override
+       public List<ComponentInstanceDTO> instances() {
+               return Collections.singletonList(_instanceDTO);
+       }
+
+       @Override
+       public boolean open() {
+               List<ConfigurationDTO> configurations = 
_instanceDTO.configurations;
+
+               if (!configurations.isEmpty()) {
+                       ConfigurationDTO defaultContainerConfiguration = 
configurations.get(0);
+
+                       Boolean enabled = Conversions.convert(
+                                       
defaultContainerConfiguration.properties.get(
+                                                       
_template.name.concat(".enabled"))
+                                       
).defaultValue(Boolean.TRUE).to(Boolean.class);
+
+                       if (!enabled) {
+                               return _snapshot.enabled = false;
+                       }
+               }
+
+               submit(_instanceDTO.openOp(), _instanceDTO::open).onFailure(
+                       f -> {
+                               _log.error(l -> l.error("CCR Error in container 
component open for {} on {}", _template.name, containerState.bundle()));
+                       }
+               );
+
+               return true;
+       }
+
+       @Override
+       public Op openOp() {
+               return Op.of(Mode.OPEN, Type.CONTAINER_COMPONENT, 
_template.name);
+       }
+
+       @Override
+       public ComponentDTO snapshot() {
+               return _snapshot;
+       }
+
+       @Override
+       public ComponentTemplateDTO template() {
+               return _template;
+       }
+
+
+       private final ExtendedComponentInstanceDTO _instanceDTO;
+       private final Logger _log;
+       private final ComponentDTO _snapshot;
+       private final ComponentTemplateDTO _template;
+
+}

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationDTO.java
 Sat Apr 14 01:10:27 2018
@@ -14,18 +14,12 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
-public enum XmlSchema {
+import java.util.function.Consumer;
 
-       CDI10("META-INF/cdi.xsd");
+import org.osgi.service.cdi.runtime.dto.ActivationDTO;
 
-       private final String _fileName;
+public class ExtendedActivationDTO extends ActivationDTO {
 
-       private XmlSchema(String fileName) {
-               _fileName = fileName;
-       }
-
-       public String getFileName() {
-               return _fileName;
-       }
+       public Consumer<ExtendedActivationDTO> onClose;
 
 }

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationTemplateDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Context.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationTemplateDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationTemplateDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Context.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Context.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedActivationTemplateDTO.java
 Sat Apr 14 01:10:27 2018
@@ -14,15 +14,19 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
-import org.osgi.framework.ServiceObjects;
-import org.osgi.framework.ServiceReference;
+import java.lang.annotation.Annotation;
 
-public abstract class Context {
+import org.osgi.service.cdi.runtime.dto.template.ActivationTemplateDTO;
 
-       public abstract <T> T getService(ServiceReference<T> reference);
+public class ExtendedActivationTemplateDTO extends ActivationTemplateDTO {
 
-       public abstract <T> ServiceObjects<T> 
getServiceObjects(ServiceReference<T> reference);
+       /**
+        * The class which declared the activation (i.e. @Service).
+        */
+       public Class<?> declaringClass;
 
-       public abstract <T> boolean ungetService(ServiceReference<T> reference);
+       public Class<? extends Annotation> cdiScope;
+
+       public Object producer;
 
 }

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentInstanceDTO.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,297 @@
+/**
+ * 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.aries.cdi.container.internal.model;
+
+import static org.apache.aries.cdi.container.internal.util.Filters.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.aries.cdi.container.internal.container.ContainerState;
+import org.apache.aries.cdi.container.internal.container.Op;
+import org.apache.aries.cdi.container.internal.container.Op.Mode;
+import org.apache.aries.cdi.container.internal.container.Op.Type;
+import org.apache.aries.cdi.container.internal.container.ReferenceSync;
+import org.osgi.framework.Constants;
+import org.osgi.service.cdi.ConfigurationPolicy;
+import org.osgi.service.cdi.runtime.dto.ComponentInstanceDTO;
+import org.osgi.service.cdi.runtime.dto.ConfigurationDTO;
+import org.osgi.service.cdi.runtime.dto.ReferenceDTO;
+import org.osgi.service.cdi.runtime.dto.template.ComponentTemplateDTO;
+import org.osgi.service.cdi.runtime.dto.template.ConfigurationTemplateDTO;
+import org.osgi.service.cdi.runtime.dto.template.ReferenceTemplateDTO;
+import org.osgi.service.log.Logger;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ExtendedComponentInstanceDTO extends ComponentInstanceDTO {
+
+       public boolean active;
+       public String pid;
+       public ComponentTemplateDTO template;
+
+       private final InstanceActivator.Builder<?> _builder;
+       private final Long _componentId = _componentIds.incrementAndGet();
+       private final ContainerState _containerState;
+       private final Logger _log;
+       private final AtomicReference<InstanceActivator> 
_noRequiredDependenciesActivator = new AtomicReference<>();
+
+       public ExtendedComponentInstanceDTO(
+               ContainerState containerState,
+               InstanceActivator.Builder<?> builder) {
+
+               _containerState = containerState;
+               _builder = builder;
+
+               _log = _containerState.containerLogs().getLogger(getClass());
+       }
+
+       public boolean close() {
+               _containerState.submit(Op.of(Mode.CLOSE, Type.REFERENCES, 
template.name),
+                       () -> {
+                               references.removeIf(
+                                       r -> {
+                                               ExtendedReferenceDTO 
referenceDTO = (ExtendedReferenceDTO)r;
+                                               
referenceDTO.serviceTracker.close();
+                                               return true;
+                                       }
+                               );
+
+                               if (_noRequiredDependenciesActivator.get() != 
null) {
+                                       _containerState.submit(
+                                               
_noRequiredDependenciesActivator.get().closeOp(),
+                                               () -> 
_noRequiredDependenciesActivator.get().close()
+                                       ).onFailure(
+                                               f -> {
+                                                       _log.error(l -> 
l.error("CCR Error in CLOSE on {}", ident(), f));
+
+                                                       
_containerState.error(f);
+                                               }
+                                       );
+                               }
+
+                               return true;
+                       }
+               ).onFailure(
+                       f -> {
+                               _log.error(l -> l.error("CCR Error in component 
instance stop on {}", this, f));
+                       }
+               );
+
+               properties = null;
+
+               return true;
+       }
+
+       public Op closeOp() {
+               return Op.of(Mode.CLOSE, getType(), ident());
+       }
+
+       /**
+        * @return true when all the configuration templates are resolved, 
otherwise false
+        */
+       public final boolean configurationsResolved() {
+               for (ConfigurationTemplateDTO template : 
template.configurations) {
+                       if (template.policy == ConfigurationPolicy.REQUIRED) {
+                               // find a configuration snapshot or not resolved
+                               boolean found = false;
+                               for (ConfigurationDTO snapshot : 
configurations) {
+                                       if (snapshot.template == template) {
+                                               found = true;
+                                       }
+                               }
+                               if (!found) {
+                                       return false;
+                               }
+                       }
+               }
+
+               return true;
+       }
+
+       public final boolean fireEvents() {
+               
references.stream().map(ExtendedReferenceDTO.class::cast).filter(
+                       r -> 
((ExtendedReferenceTemplateDTO)r.template).collectionType == 
CollectionType.OBSERVER
+               ).map(
+                       r -> (ExtendedReferenceTemplateDTO)r.template
+               ).forEach(
+                       t -> {
+                               t.bean.fireEvents();
+                       }
+               );
+
+               return true;
+       }
+
+       public final boolean referencesResolved() {
+               for (ReferenceTemplateDTO template : template.references) {
+                       if (template.minimumCardinality > 0) {
+                               // find a reference snapshot or not resolved
+                               boolean found = false;
+                               for (ReferenceDTO snapshot : references) {
+                                       if 
(!snapshot.template.equals(template)) continue;
+                                       ExtendedReferenceDTO extended = 
(ExtendedReferenceDTO)snapshot;
+                                       if (extended.matches.size() >= 
extended.minimumCardinality) {
+                                               found = true;
+                                       }
+                               }
+                               if (!found) {
+                                       return false;
+                               }
+                       }
+               }
+
+               return true;
+       }
+
+       public boolean open() {
+               if (!configurationsResolved() || (properties != null)) {
+                       return false;
+               }
+
+               properties = componentProperties(null);
+
+               
template.references.stream().map(ExtendedReferenceTemplateDTO.class::cast).forEach(
+                       t -> {
+                               ExtendedReferenceDTO referenceDTO = new 
ExtendedReferenceDTO();
+
+                               referenceDTO.matches = new 
CopyOnWriteArrayList<>();
+                               referenceDTO.minimumCardinality = 
minimumCardinality(t.name, t.minimumCardinality);
+                               referenceDTO.targetFilter = 
targetFilter(t.serviceType, t.name, t.targetFilter);
+                               referenceDTO.template = t;
+                               referenceDTO.serviceTracker = new 
ServiceTracker<>(
+                                       _containerState.bundleContext(),
+                                       asFilter(referenceDTO.targetFilter),
+                                       new ReferenceSync(_containerState, 
referenceDTO, this, _builder));
+
+                               references.add(referenceDTO);
+                       }
+               );
+
+               _containerState.submit(
+                       Op.of(Mode.OPEN, Type.REFERENCES, template.name),
+                       () -> {
+                               
references.stream().map(ExtendedReferenceDTO.class::cast).forEach(
+                                       r -> r.serviceTracker.open()
+                               );
+
+                               return referencesResolved();
+                       }
+               ).then(
+                       s -> {
+                               if (s.getValue()) {
+                                       // none of the reference dependencies 
are required
+                                       
_noRequiredDependenciesActivator.set(_builder.setInstance(this).build());
+
+                                       return _containerState.submit(
+                                               
_noRequiredDependenciesActivator.get().openOp(),
+                                               () -> 
_noRequiredDependenciesActivator.get().open()
+                                       ).onFailure(
+                                               f -> {
+                                                       _log.error(l -> 
l.error("CCR Error in OPEN on {}", ident(), f));
+
+                                                       
_containerState.error(f);
+                                               }
+                                       );
+                               }
+
+                               return s;
+                       }
+               );
+
+               return true;
+       }
+
+       public Op openOp() {
+               return Op.of(Mode.OPEN, getType(), ident());
+       }
+
+       public Map<String, Object> componentProperties(Map<String, Object> 
others) {
+               Map<String, Object> props = new HashMap<>();
+               if (others != null) {
+                       props.putAll(others);
+               }
+               props.putAll(template.properties);
+               List<String> servicePids = new ArrayList<>();
+
+               for (ConfigurationTemplateDTO t : template.configurations) {
+                       configurations.stream().filter(
+                               c -> c.template.equals(t) && 
t.componentConfiguration
+                       ).findFirst().ifPresent(
+                               c -> {
+                                       Map<String, Object> copy = new 
HashMap<>(c.properties);
+
+                                       Optional.ofNullable(
+                                               
copy.remove(Constants.SERVICE_PID)
+                                       ).map(String.class::cast).ifPresent(
+                                               v -> servicePids.add(v)
+                                       );
+
+                                       props.putAll(copy);
+                               }
+                       );
+               }
+
+               props.put(Constants.SERVICE_PID, servicePids);
+               props.put("component.id", _componentId);
+               props.put("component.name", template.name);
+
+               return props;
+       }
+
+       private Type getType() {
+               switch (template.type) {
+                       case SINGLE: return Type.SINGLE_INSTANCE;
+                       case FACTORY: return Type.FACTORY_INSTANCE;
+                       default: return Type.CONTAINER_INSTANCE;
+               }
+       }
+
+       private int minimumCardinality(String componentName, int 
minimumCardinality) {
+               return Optional.ofNullable(
+                       
properties.get(componentName.concat(".cardinality.minimum"))
+               ).map(
+                       v -> Integer.valueOf(String.valueOf(v))
+               ).filter(
+                       v -> v >= minimumCardinality
+               ).orElse(minimumCardinality);
+       }
+
+       private String targetFilter(String serviceType, String componentName, 
String targetFilter) {
+               String base = "(objectClass=".concat(serviceType).concat(")");
+               String extraFilter = Optional.ofNullable(
+                       properties.get(componentName.concat(".target"))
+               ).map(
+                       v -> v + targetFilter
+               ).orElse(targetFilter);
+
+               if (extraFilter.length() == 0) {
+                       return base;
+               }
+               return "(&".concat(base).concat(extraFilter).concat(")");
+       }
+
+       public String ident() {
+               return template.name + "[" + _componentId + "]";
+       }
+
+       private static final AtomicLong _componentIds = new AtomicLong();
+
+}

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentTemplateDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentTemplateDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentTemplateDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedComponentTemplateDTO.java
 Sat Apr 14 01:10:27 2018
@@ -14,18 +14,11 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
-public enum XmlSchema {
+import javax.enterprise.inject.spi.Bean;
 
-       CDI10("META-INF/cdi.xsd");
+import org.osgi.service.cdi.runtime.dto.template.ComponentTemplateDTO;
 
-       private final String _fileName;
-
-       private XmlSchema(String fileName) {
-               _fileName = fileName;
-       }
-
-       public String getFileName() {
-               return _fileName;
-       }
+public class ExtendedComponentTemplateDTO extends ComponentTemplateDTO {
 
+       public Bean<?> bean;
 }

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationDTO.java
 Sat Apr 14 01:10:27 2018
@@ -14,18 +14,17 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
-public enum XmlSchema {
+import org.osgi.service.cdi.runtime.dto.ConfigurationDTO;
+import org.osgi.service.cm.Configuration;
 
-       CDI10("META-INF/cdi.xsd");
+public class ExtendedConfigurationDTO extends ConfigurationDTO {
 
-       private final String _fileName;
+       /**
+        * The actual PID whether the template is a factory or single
+        * configuration.
+        */
+       public String pid;
 
-       private XmlSchema(String fileName) {
-               _fileName = fileName;
-       }
-
-       public String getFileName() {
-               return _fileName;
-       }
+       public Configuration configuration;
 
 }

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationTemplateDTO.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationTemplateDTO.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationTemplateDTO.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedConfigurationTemplateDTO.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,108 @@
+/**
+ * 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.aries.cdi.container.internal.model;
+
+import java.lang.reflect.Type;
+
+import org.apache.aries.cdi.container.internal.bean.ConfigurationBean;
+import org.osgi.service.cdi.runtime.dto.template.ConfigurationTemplateDTO;
+
+public class ExtendedConfigurationTemplateDTO extends ConfigurationTemplateDTO 
{
+
+       /**
+        * The bean class which the synthetic bean required to resolve the
+        * injection point must provide.
+        */
+       public Class<?> beanClass;
+
+       /**
+        * The class which declared the reference.
+        */
+       public Class<?> declaringClass;
+
+       /**
+        * The type of the injection point declaring the configuration.
+        */
+       public Type injectionPointType;
+
+       public ConfigurationBean bean;
+
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((beanClass == null) ? 0 : 
beanClass.hashCode());
+               result = prime * result + (componentConfiguration ? 1231 : 
1237);
+               result = prime * result + ((declaringClass == null) ? 0 : 
declaringClass.hashCode());
+               result = prime * result + ((injectionPointType == null) ? 0 : 
injectionPointType.hashCode());
+               result = prime * result + ((maximumCardinality == null) ? 0 : 
maximumCardinality.hashCode());
+               result = prime * result + ((pid == null) ? 0 : pid.hashCode());
+               result = prime * result + ((policy == null) ? 0 : 
policy.hashCode());
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj) {
+                       return true;
+               }
+               if (obj == null) {
+                       return false;
+               }
+               if (getClass() != obj.getClass()) {
+                       return false;
+               }
+               ExtendedConfigurationTemplateDTO other = 
(ExtendedConfigurationTemplateDTO) obj;
+               if (beanClass == null) {
+                       if (other.beanClass != null) {
+                               return false;
+                       }
+               } else if (!beanClass.equals(other.beanClass)) {
+                       return false;
+               }
+               if (componentConfiguration != other.componentConfiguration) {
+                       return false;
+               }
+               if (declaringClass == null) {
+                       if (other.declaringClass != null) {
+                               return false;
+                       }
+               } else if (!declaringClass.equals(other.declaringClass)) {
+                       return false;
+               }
+               if (injectionPointType == null) {
+                       if (other.injectionPointType != null) {
+                               return false;
+                       }
+               } else if 
(!injectionPointType.equals(other.injectionPointType)) {
+                       return false;
+               }
+               if (maximumCardinality != other.maximumCardinality) {
+                       return false;
+               }
+               if (pid == null) {
+                       if (other.pid != null) {
+                               return false;
+                       }
+               } else if (!pid.equals(other.pid)) {
+                       return false;
+               }
+               if (policy != other.policy) {
+                       return false;
+               }
+               return true;
+       }
+
+}

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Context.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Context.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/Context.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionDTO.java
 Sat Apr 14 01:10:27 2018
@@ -14,15 +14,14 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
+import javax.enterprise.inject.spi.Extension;
+
 import org.osgi.framework.ServiceObjects;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.cdi.runtime.dto.ExtensionDTO;
 
-public abstract class Context {
-
-       public abstract <T> T getService(ServiceReference<T> reference);
-
-       public abstract <T> ServiceObjects<T> 
getServiceObjects(ServiceReference<T> reference);
-
-       public abstract <T> boolean ungetService(ServiceReference<T> reference);
+public class ExtendedExtensionDTO extends ExtensionDTO {
+       public ServiceObjects<Extension> extension;
 
+       public ServiceReference<Extension> serviceReference;
 }

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionTemplateDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/phase/Phase.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionTemplateDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionTemplateDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/phase/Phase.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/phase/Phase.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedExtensionTemplateDTO.java
 Sat Apr 14 01:10:27 2018
@@ -12,12 +12,12 @@
  * limitations under the License.
  */
 
-package org.apache.aries.cdi.container.internal.phase;
+package org.apache.aries.cdi.container.internal.model;
 
-public interface Phase {
+import org.osgi.framework.Filter;
+import org.osgi.service.cdi.runtime.dto.template.ExtensionTemplateDTO;
 
-       public void close();
-
-       public void open();
+public class ExtendedExtensionTemplateDTO extends ExtensionTemplateDTO {
 
+       public Filter filter;
 }

Copied: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceDTO.java
 (from r1829114, 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java)
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceDTO.java?p2=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceDTO.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java&r1=1829114&r2=1829115&rev=1829115&view=diff
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/XmlSchema.java
 (original)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceDTO.java
 Sat Apr 14 01:10:27 2018
@@ -14,18 +14,11 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
-public enum XmlSchema {
+import org.osgi.service.cdi.runtime.dto.ReferenceDTO;
+import org.osgi.util.tracker.ServiceTracker;
 
-       CDI10("META-INF/cdi.xsd");
+public class ExtendedReferenceDTO extends ReferenceDTO {
 
-       private final String _fileName;
-
-       private XmlSchema(String fileName) {
-               _fileName = fileName;
-       }
-
-       public String getFileName() {
-               return _fileName;
-       }
+       public ServiceTracker<Object, Object> serviceTracker;
 
 }

Added: 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceTemplateDTO.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceTemplateDTO.java?rev=1829115&view=auto
==============================================================================
--- 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceTemplateDTO.java
 (added)
+++ 
aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/ExtendedReferenceTemplateDTO.java
 Sat Apr 14 01:10:27 2018
@@ -0,0 +1,126 @@
+/**
+ * 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.aries.cdi.container.internal.model;
+
+import java.lang.reflect.Type;
+
+import org.apache.aries.cdi.container.internal.bean.ReferenceBean;
+import org.osgi.service.cdi.runtime.dto.template.ReferenceTemplateDTO;
+
+public class ExtendedReferenceTemplateDTO extends ReferenceTemplateDTO {
+
+       public ReferenceBean bean;
+
+       public Class<?> beanClass;
+
+       public CollectionType collectionType;
+
+       public Class<?> declaringClass;
+
+       public Type injectionPointType;
+
+       public Class<?> serviceClass;
+
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((beanClass == null) ? 0 : 
beanClass.hashCode());
+               result = prime * result + ((collectionType == null) ? 0 : 
collectionType.hashCode());
+               result = prime * result + ((declaringClass == null) ? 0 : 
declaringClass.hashCode());
+               result = prime * result + ((injectionPointType == null) ? 0 : 
injectionPointType.hashCode());
+               result = prime * result + ((maximumCardinality == null) ? 0 : 
maximumCardinality.hashCode());
+               result = prime * result + minimumCardinality;
+               result = prime * result + ((name == null) ? 0 : 
name.hashCode());
+               result = prime * result + ((policy == null) ? 0 : 
policy.hashCode());
+               result = prime * result + ((policyOption == null) ? 0 : 
policyOption.hashCode());
+               result = prime * result + ((serviceType == null) ? 0 : 
serviceType.hashCode());
+               result = prime * result + ((targetFilter == null) ? 0 : 
targetFilter.hashCode());
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj) {
+                       return true;
+               }
+               if (obj == null) {
+                       return false;
+               }
+               if (getClass() != obj.getClass()) {
+                       return false;
+               }
+               ExtendedReferenceTemplateDTO other = 
(ExtendedReferenceTemplateDTO) obj;
+               if (beanClass == null) {
+                       if (other.beanClass != null) {
+                               return false;
+                       }
+               } else if (!beanClass.equals(other.beanClass)) {
+                       return false;
+               }
+               if (collectionType != other.collectionType) {
+                       return false;
+               }
+               if (declaringClass == null) {
+                       if (other.declaringClass != null) {
+                               return false;
+                       }
+               } else if (!declaringClass.equals(other.declaringClass)) {
+                       return false;
+               }
+               if (injectionPointType == null) {
+                       if (other.injectionPointType != null) {
+                               return false;
+                       }
+               } else if 
(!injectionPointType.equals(other.injectionPointType)) {
+                       return false;
+               }
+               if (maximumCardinality != other.maximumCardinality) {
+                       return false;
+               }
+               if (minimumCardinality != other.minimumCardinality) {
+                       return false;
+               }
+               if (name == null) {
+                       if (other.name != null) {
+                               return false;
+                       }
+               } else if (!name.equals(other.name)) {
+                       return false;
+               }
+               if (policy != other.policy) {
+                       return false;
+               }
+               if (policyOption != other.policyOption) {
+                       return false;
+               }
+               if (serviceType == null) {
+                       if (other.serviceType != null) {
+                               return false;
+                       }
+               } else if (!serviceType.equals(other.serviceType)) {
+                       return false;
+               }
+               if (targetFilter == null) {
+                       if (other.targetFilter != null) {
+                               return false;
+                       }
+               } else if (!targetFilter.equals(other.targetFilter)) {
+                       return false;
+               }
+               return true;
+       }
+
+}


Reply via email to