public function attach(DescriptorInterface $objectDescriptor, $instance)
    {

        // load the session ID from the environment
        $sessionId = Environment::singleton()->getAttribute(EnvironmentKeys::SESSION_ID);

        // query if we've stateful session bean
        if ($objectDescriptor instanceof StatefulSessionBeanDescriptorInterface) {
            // check if we've a session-ID available
            if ($sessionId == null) {
                throw new \Exception('Can\'t find a session-ID to attach stateful session bean');
            }

            // load the lifetime from the session bean settings
            $lifetime = $this->getManagerSettings()->getLifetime();

            // we've to check for pre-attach callbacks
            foreach ($objectDescriptor->getPreAttachCallbacks() as $preAttachCallback) {
                $instance->$preAttachCallback();
            }

            // create a unique SFSB identifier
            $identifier = SessionBeanUtil::createIdentifier($sessionId, $objectDescriptor->getName());

            // load the map with the SFSBs
            $sessionBeans = $this->getStatefulSessionBeans();

            // add the stateful session bean to the map
            $sessionBeans->add($identifier, $instance, $lifetime);

            // stop processing here
            return;
        }

        // query if we've stateless session or message bean
        if ($objectDescriptor instanceof StatelessSessionBeanDescriptorInterface ||
            $objectDescriptor instanceof MessageDrivenBeanDescriptorInterface) {
            // simply destroy the instance
            $this->destroyBeanInstance($instance);

            // stop processing here
            return;
        }

        // query if we've singleton session bean
        if ($objectDescriptor instanceof SingletonSessionBeanDescriptorInterface) {
            // we've to check for pre-attach callbacks
            foreach ($objectDescriptor->getPreAttachCallbacks() as $preAttachCallback) {
                $instance->$preAttachCallback();
            }

            // stop processing here
            return;
        }

        // we've an unknown bean type => throw an exception
        throw new InvalidBeanTypeException('Tried to attach invalid bean type');
    }
public function attach(DescriptorInterface $objectDescriptor, $instance)
    {

        // load the session ID from the environment
        $sessionId = Environment::singleton()->getAttribute(EnvironmentKeys::SESSION_ID);

        // query if we've stateful session bean
        if ($objectDescriptor instanceof StatefulSessionBeanDescriptorInterface) {
            // check if we've a session-ID available
            if ($sessionId == null) {
                throw new \Exception('Can\'t find a session-ID to attach stateful session bean');
            }

            // load the lifetime from the session bean settings
            $lifetime = $this->getManagerSettings()->getLifetime();

            // we've to check for pre-attach callbacks
            foreach ($objectDescriptor->getPreAttachCallbacks() as $preAttachCallback) {
                $instance->$preAttachCallback();
            }

            // create a unique SFSB identifier
            $identifier = SessionBeanUtil::createIdentifier($sessionId, $objectDescriptor->getName());

            // load the map with the SFSBs
            $sessionBeans = $this->getStatefulSessionBeans();

            // add the stateful session bean to the map
            $sessionBeans->add($identifier, $instance, $lifetime);

            // stop processing here
            return;
        }

        // query if we've stateless session or message bean
        if ($objectDescriptor instanceof StatelessSessionBeanDescriptorInterface ||
            $objectDescriptor instanceof MessageDrivenBeanDescriptorInterface) {
            // simply destroy the instance
            $this->destroyBeanInstance($instance);

            // stop processing here
            return;
        }

        // query if we've singleton session bean
        if ($objectDescriptor instanceof SingletonSessionBeanDescriptorInterface) {
            // we've to check for pre-attach callbacks
            foreach ($objectDescriptor->getPreAttachCallbacks() as $preAttachCallback) {
                $instance->$preAttachCallback();
            }

            // stop processing here
            return;
        }

        // we've an unknown bean type => throw an exception
        throw new InvalidBeanTypeException('Tried to attach invalid bean type');
    }
public function attach ( DescriptorInterface $ objectDescriptor , $ instance ) { // load the session ID from the environment $ sessionId = Environment :: singleton ( ) -> getAttribute ( EnvironmentKeys :: SESSION_ID ) ; // query if we've stateful session bean if ( $ objectDescriptor instanceof StatefulSessionBeanDescriptorInterface ) { // check if we've a session-ID available if ( $ sessionId == null ) { throw new \ Exception ( 'Can\'t find a session-ID to attach stateful session bean' ) ; } // load the lifetime from the session bean settings $ lifetime = $ this -> getManagerSettings ( ) -> getLifetime ( ) ; // we've to check for pre-attach callbacks foreach ( $ objectDescriptor -> getPreAttachCallbacks ( ) as $ preAttachCallback ) { $ instance -> $ preAttachCallback ( ) ; } // create a unique SFSB identifier $ identifier = SessionBeanUtil :: createIdentifier ( $ sessionId , $ objectDescriptor -> getName ( ) ) ; // load the map with the SFSBs $ sessionBeans = $ this -> getStatefulSessionBeans ( ) ; // add the stateful session bean to the map $ sessionBeans -> add ( $ identifier , $ instance , $ lifetime ) ; // stop processing here return ; } // query if we've stateless session or message bean if ( $ objectDescriptor instanceof StatelessSessionBeanDescriptorInterface || $ objectDescriptor instanceof MessageDrivenBeanDescriptorInterface ) { // simply destroy the instance $ this -> destroyBeanInstance ( $ instance ) ; // stop processing here return ; } // query if we've singleton session bean if ( $ objectDescriptor instanceof SingletonSessionBeanDescriptorInterface ) { // we've to check for pre-attach callbacks foreach ( $ objectDescriptor -> getPreAttachCallbacks ( ) as $ preAttachCallback ) { $ instance -> $ preAttachCallback ( ) ; } // stop processing here return ; } // we've an unknown bean type => throw an exception throw new InvalidBeanTypeException ( 'Tried to attach invalid bean type' ) ; }
Attaches the passed bean, depending on it's type to the container.

@param \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor The object descriptor for the passed instance
@param object                                          $instance         The bean instance to attach

@return void
@throws \AppserverIo\Psr\EnterpriseBeans\InvalidBeanTypeException Is thrown if a invalid bean type has been detected
Attaches the passed bean depending on it s type to the container .