Example #1
0
 /**
  * Registers the passed EPB reference in the applications directory.
  *
  * @param \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface $epbReference The EPB reference to register
  *
  * @return void
  * @todo Replace lookupProxy callback with real proxy instance
  */
 public function registerEpbReference(EpbReferenceDescriptorInterface $epbReference)
 {
     try {
         // load the application instance and reference name
         $application = $this->getApplication();
         $name = $epbReference->getName();
         // initialize the bean's URI
         $uri = sprintf('php:global/%s/%s', $application->getName(), $name);
         // this has to be refactored, because it'll be quite faster to inject either
         // the remote/local proxy instance as injection a callback that creates the
         // proxy on-the-fly!
         // prepare the bean name
         if ($beanName = $epbReference->getBeanName()) {
             // query whether we've a local business interface
             if ($epbReference->getBeanInterface() === ($regName = sprintf('%sLocal', $beanName))) {
                 // bind the local business interface of the bean to the appliations naming directory
                 $application->getNamingDirectory()->bind($uri, array(&$this, 'lookupProxy'), array($regName = sprintf('%s/local', $beanName)));
                 // query whether we've a remote business interface
             } elseif ($epbReference->getBeanInterface() === ($regName = sprintf('%sRemote', $beanName))) {
                 // bind the remote business interface of the bean to the applications naming directory
                 $application->getNamingDirectory()->bind($uri, array(&$this, 'lookupProxy'), array($regName = sprintf('%s/remote', $beanName)));
                 // at least, we need a business interface
             } else {
                 // log a critical message that we can't bind the reference
                 $application->getInitialContext()->getSystemLogger()->critical(sprintf('Can\'t bind bean reference %s to naming directory', $uri));
             }
             // try to use the lookup, if we don't have the beanName
         } elseif ($lookup = $epbReference->getLookup()) {
             // create a reference to a bean in the global directory
             $application->getNamingDirectory()->bind($uri, array(&$this, 'lookup'), array($lookup));
             // log a critical message that we can't bind the reference
         } else {
             $application->getInitialContext()->getSystemLogger()->critical(sprintf('Can\'t bind bean reference %s to naming directory, because of missing source bean definition', $uri));
         }
         // catch the the exception that occures if a reference has already been created
     } catch (NamingException $e) {
         // log a warning that the reference has already been registered
         $application->getInitialContext()->getSystemLogger()->warning(sprintf('Bean reference %s already exists', $uri));
         // catch all other exceptions
     } catch (\Exception $e) {
         $application->getInitialContext()->getSystemLogger()->critical($e->__toString());
     }
 }
 /**
  * Merges the passed configuration into this one. Configuration values
  * of the passed configuration will overwrite the this one.
  *
  * @param \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface $epbReferenceDescriptor The configuration to merge
  *
  * @return void
  */
 public function merge(EpbReferenceDescriptorInterface $epbReferenceDescriptor)
 {
     // merge the reference name
     if ($name = $epbReferenceDescriptor->getName()) {
         $this->setName($name);
     }
     // merge the bean interface
     if ($beanInterface = $epbReferenceDescriptor->getBeanInterface()) {
         $this->setBeanInterface($beanInterface);
     }
     // merge the bean name
     if ($beanName = $epbReferenceDescriptor->getBeanName()) {
         $this->setBeanName($beanName);
     }
     // merge the lookup name
     if ($lookup = $epbReferenceDescriptor->getLookup()) {
         $this->setLookup($lookup);
     }
     // merge the description
     if ($description = $epbReferenceDescriptor->getDescription()) {
         $this->setDescription($description);
     }
     // merge the injection target
     if ($injectionTarget = $epbReferenceDescriptor->getInjectionTarget()) {
         $this->setInjectionTarget($injectionTarget);
     }
 }
 /**
  * Adds a EPB reference configuration.
  *
  * @param \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface $epbReference The EPB reference configuration
  *
  * @return void
  */
 public function addEpbReference(EpbReferenceDescriptorInterface $epbReference)
 {
     $this->epbReferences[$epbReference->getName()] = $epbReference;
 }