mil.dod.th.ose.core/src/mil/dod/th/ose/core/factory/impl/FactoryServiceContextImpl.java
@Override
        public ComponentFactory addingService(final ServiceReference<ComponentFactory> reference)
        {
            final String productType = (String)reference.getProperty(ComponentConstants.COMPONENT_NAME);
            
            //Verify that a factory hasn't already been registered for the given product type.
            if (m_Factories.containsKey(productType))
            {
                m_Logging.warning("Factory already registered with product type [%s], " 
                        + "will not register factory from bundle [%s]", productType, reference.getBundle());
                return null;
            }
            
            // register as service so other components can track this factory
            m_Logging.info("Registering factory for: %s", productType);
            try
            {
                final ComponentFactory proxyComponentFactory = m_CoreContext.getService(reference);
                final Dictionary<String, Object> factoryInternalProps = new Hashtable<>();
                factoryInternalProps.put(FactoryInternal.KEY_SERVICE_CONTEXT, FactoryServiceContextImpl.this);
                factoryInternalProps.put(FactoryInternal.KEY_SERVICE_REFERENCE, reference);
                factoryInternalProps.put(FactoryInternal.KEY_COMPONENT_FACTORY, proxyComponentFactory);
                
                final ComponentInstance factoryComponentInstance = 
                        m_FactoryInternalFactory.newInstance(factoryInternalProps);
                m_FactoryComponents.put(productType, factoryComponentInstance);
                
                final FactoryInternal factory = (FactoryInternal)factoryComponentInstance.getInstance();
                
                m_Proxy.beforeAddFactory(FactoryServiceContextImpl.this, factory);
                
                // must put factory in map after call to beforeAddFactory as proxy assumes factory is not in map yet
                m_Factories.put(productType, factory);
                
                m_ExecutorService.execute(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        try
                        {
                            factory.registerServices();
                            getRegistry().restoreAllObjects(factory);
                            factory.makeAvailable();
                        }
                        catch (final RuntimeException e)
                        {
                            handleRegistrationException(reference, productType, factory, e);
                        }
                    }
                });
                return proxyComponentFactory;
                    
            }
            catch (final Exception e)
            {
                handleRegistrationException(reference, productType, null, e);
            }

            return null;
        }
/**
         * Create {@link FactoryInternal} instances and initialize the factory by restoring objects for the factory and 
         * registering services.
         * 
         * Call to {@link FactoryInternal#makeAvailable()} must come after the call to {@link 
         * FactoryInternal#registerServices()} as the {@link FactoryInternal#makeAvailable()} method is what 
         * signals to other services that the factory is wholly registered and ready. Therefore, it must also be in the 
         * {@link FactoryServiceContext} set of factories first. If the factory cannot be successfully registered then 
         * the factory will be removed from the list of active factories kept by the given 
         * {@link FactoryServiceContext}.
         * 
         * @param reference 
         *      The reference to the service being added to the ServiceTracker.
         * @return
         *      The service object to be tracked for the specified referenced service or null if the specified 
         *      referenced service should not be tracked.
         */
Create  FactoryInternal instances and initialize the factory by restoring objects for the factory and
registering services.

Call to  FactoryInternal#makeAvailable() must come after the call to {@link
FactoryInternal#registerServices()} as the  FactoryInternal#makeAvailable() method is what
signals to other services that the factory is wholly registered and ready. Therefore, it must also be in the
FactoryServiceContext set of factories first. If the factory cannot be successfully registered then
the factory will be removed from the list of active factories kept by the given
FactoryServiceContext.

@param reference
The reference to the service being added to the ServiceTracker.
@return
The service object to be tracked for the specified referenced service or null if the specified
referenced service should not be tracked.
Create FactoryInternal instances and initialize the factory by restoring objects for the factory and registering services . Call to FactoryInternal#makeAvailable () must come after the call to { @link FactoryInternal#registerServices () } as the FactoryInternal#makeAvailable () method is what signals to other services that the factory is wholly registered and ready . Therefore it must also be in the FactoryServiceContext set of factories first . If the factory cannot be successfully registered then the factory will be removed from the list of active factories kept by the given FactoryServiceContext . @param reference The reference to the service being added to the ServiceTracker . @return The service object to be tracked for the specified referenced service or null if the specified referenced service should not be tracked .
@Override
        public ComponentFactory addingService(final ServiceReference<ComponentFactory> reference)
        {
            final String productType = (String)reference.getProperty(ComponentConstants.COMPONENT_NAME);
            if (m_Factories.containsKey(productType))
            {
                m_Logging.warning("Factory already registered with product type [%s], " 
                        + "will not register factory from bundle [%s]", productType, reference.getBundle());
                return null;
            }
            m_Logging.info("Registering factory for: %s", productType);
            try
            {
                final ComponentFactory proxyComponentFactory = m_CoreContext.getService(reference);
                final Dictionary<String, Object> factoryInternalProps = new Hashtable<>();
                factoryInternalProps.put(FactoryInternal.KEY_SERVICE_CONTEXT, FactoryServiceContextImpl.this);
                factoryInternalProps.put(FactoryInternal.KEY_SERVICE_REFERENCE, reference);
                factoryInternalProps.put(FactoryInternal.KEY_COMPONENT_FACTORY, proxyComponentFactory);
                final ComponentInstance factoryComponentInstance = 
                        m_FactoryInternalFactory.newInstance(factoryInternalProps);
                m_FactoryComponents.put(productType, factoryComponentInstance);
                final FactoryInternal factory = (FactoryInternal)factoryComponentInstance.getInstance();
                m_Proxy.beforeAddFactory(FactoryServiceContextImpl.this, factory);
                m_Factories.put(productType, factory);
                m_ExecutorService.execute(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        try
                        {
                            factory.registerServices();
                            getRegistry().restoreAllObjects(factory);
                            factory.makeAvailable();
                        }
                        catch (final RuntimeException e)
                        {
                            handleRegistrationException(reference, productType, factory, e);
                        }
                    }
                });
                return proxyComponentFactory;
            }
            catch (final Exception e)
            {
                handleRegistrationException(reference, productType, null, e);
            }
            return null;
        }
@ Override public ComponentFactory addingService ( final ServiceReference < ComponentFactory > reference ) { final String productType = ( String ) reference . getProperty ( ComponentConstants . COMPONENT_NAME ) ; if ( m_Factories . containsKey ( productType ) ) { m_Logging . warning ( "Factory already registered with product type [%s], " + "will not register factory from bundle [%s]" , productType , reference . getBundle ( ) ) ; return null ; } m_Logging . info ( "Registering factory for: %s" , productType ) ; try { final ComponentFactory proxyComponentFactory = m_CoreContext . getService ( reference ) ; final Dictionary < String , Object > factoryInternalProps = new Hashtable < > ( ) ; factoryInternalProps . put ( FactoryInternal . KEY_SERVICE_CONTEXT , FactoryServiceContextImpl . this ) ; factoryInternalProps . put ( FactoryInternal . KEY_SERVICE_REFERENCE , reference ) ; factoryInternalProps . put ( FactoryInternal . KEY_COMPONENT_FACTORY , proxyComponentFactory ) ; final ComponentInstance factoryComponentInstance = m_FactoryInternalFactory . newInstance ( factoryInternalProps ) ; m_FactoryComponents . put ( productType , factoryComponentInstance ) ; final FactoryInternal factory = ( FactoryInternal ) factoryComponentInstance . getInstance ( ) ; m_Proxy . beforeAddFactory ( FactoryServiceContextImpl . this , factory ) ; m_Factories . put ( productType , factory ) ; m_ExecutorService . execute ( new Runnable ( ) { @ Override public void run ( ) { try { factory . registerServices ( ) ; getRegistry ( ) . restoreAllObjects ( factory ) ; factory . makeAvailable ( ) ; } catch ( final RuntimeException e ) { handleRegistrationException ( reference , productType , factory , e ) ; } } } ) ; return proxyComponentFactory ; } catch ( final Exception e ) { handleRegistrationException ( reference , productType , null , e ) ; } return null ; }
Create {@link FactoryInternal} instances and initialize the factory by restoring objects for the factory and
 registering services.
Create { @link FactoryInternal } instances and initialize the factory by restoring objects for the factory and registering services .
//Verify that a factory hasn't already been registered for the given product type. // register as service so other components can track this factory // must put factory in map after call to beforeAddFactory as proxy assumes factory is not in map yet