AppserverIo\Appserver\PersistenceContainer\DependencyInjection\DeploymentDescriptorParser::parse PHP Method

parse() public method

Parses the bean context's deployment descriptor file for beans that has to be registered in the object manager.
public parse ( ) : void
return void
    public function parse()
    {
        // load the web application base directory
        $webappPath = $this->getBeanContext()->getWebappPath();
        // prepare the deployment descriptor
        $deploymentDescriptor = AppEnvironmentHelper::getEnvironmentAwareGlobPattern($webappPath, 'META-INF' . DIRECTORY_SEPARATOR . 'epb');
        // query whether we found epb.xml deployment descriptor file
        if (file_exists($deploymentDescriptor) === false) {
            return;
        }
        // validate the passed configuration file
        /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
        $configurationService = $this->getApplication()->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService');
        $configurationService->validateFile($deploymentDescriptor, null, true);
        // prepare and initialize the configuration node
        $epbNode = new EpbNode();
        $epbNode->initFromFile($deploymentDescriptor);
        // query whether or not the deployment descriptor contains any beans
        /** @var \AppserverIo\Appserver\Core\Api\Node\EnterpriseBeansNode $enterpriseBeans */
        if ($enterpriseBeans = $epbNode->getEnterpriseBeans()) {
            // parse the session beans of the deployment descriptor
            /** @var \AppserverIo\Appserver\Core\Api\Node\SessionNode $sessionNode */
            foreach ($enterpriseBeans->getSessions() as $sessionNode) {
                $this->processConfigurationNode($sessionNode);
            }
            // parse the message driven beans from the deployment descriptor
            /** @var \AppserverIo\Appserver\Core\Api\Node\MessageDrivenNode $messageDrivenNode */
            foreach ($enterpriseBeans->getMessageDrivens() as $messageDrivenNode) {
                $this->processConfigurationNode($messageDrivenNode);
            }
        }
    }

Usage Example

Example #1
0
 /**
  * Registers the message beans at startup.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  */
 public function registerBeans(ApplicationInterface $application)
 {
     // query whether or not the web application folder exists
     if (is_dir($this->getWebappPath()) === false) {
         return;
     }
     // initialize the directory parser and parse the web application's base directory for annotated beans
     $directoryParser = new DirectoryParser();
     $directoryParser->injectBeanContext($this);
     $directoryParser->parse();
     // initialize the deployment descriptor parser and parse the web application's deployment descriptor for beans
     $deploymentDescriptorParser = new DeploymentDescriptorParser();
     $deploymentDescriptorParser->injectBeanContext($this);
     $deploymentDescriptorParser->parse();
     // load the object manager
     /** @var \AppserverIo\Appserver\DependencyInjectionContainer\Interfaces\ObjectManagerInterface $objectManager */
     $objectManager = $this->getApplication()->search('ObjectManagerInterface');
     // register the beans found by annotations and the XML configuration
     /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
     foreach ($objectManager->getObjectDescriptors() as $descriptor) {
         // check if we've found a bean descriptor and register the bean
         if ($descriptor instanceof BeanDescriptorInterface) {
             $this->registerBean($descriptor);
         }
         // if we found a singleton session bean with a startup callback
         if ($descriptor instanceof SingletonSessionBeanDescriptorInterface && $descriptor->isInitOnStartup()) {
             $this->getApplication()->search($descriptor->getName(), array(null, array($application)));
         }
     }
 }