Автор: Tim Wagner (tw@appserver.io)
Наследование: extends AppserverIo\Description\Api\Node\AbstractNode
Пример #1
0
 /**
  * Registers the entity managers at startup.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  */
 public function registerEntityManagers(ApplicationInterface $application)
 {
     // build up META-INF directory var
     $metaInfDir = $this->getWebappPath() . DIRECTORY_SEPARATOR . 'META-INF';
     // check if we've found a valid directory
     if (is_dir($metaInfDir) === false) {
         return;
     }
     // check META-INF + subdirectories for XML files with MQ definitions
     /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */
     $service = $application->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService');
     $xmlFiles = $service->globDir(AppEnvironmentHelper::getEnvironmentAwareGlobPattern($this->getWebappPath(), 'META-INF' . DIRECTORY_SEPARATOR . 'persistence'));
     // load the configuration service instance
     /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
     $configurationService = $application->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService');
     // load the container node to initialize the system properties
     /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode */
     $containerNode = $application->getContainer()->getContainerNode();
     // gather all the deployed web applications
     foreach ($xmlFiles as $file) {
         try {
             // validate the file here, but skip if the validation fails
             $configurationService->validateFile($file, null, true);
             // load the system properties
             $properties = $service->getSystemProperties($containerNode);
             // append the application specific properties
             $properties->add(SystemPropertyKeys::WEBAPP, $webappPath = $application->getWebappPath());
             $properties->add(SystemPropertyKeys::WEBAPP_NAME, basename($webappPath));
             $properties->add(SystemPropertyKeys::WEBAPP_CACHE, $application->getCacheDir());
             $properties->add(SystemPropertyKeys::WEBAPP_SESSION, $application->getSessionDir());
             // create a new persistence manager node instance and replace the properties
             $persistenceNode = new PersistenceNode();
             $persistenceNode->initFromFile($file);
             $persistenceNode->replaceProperties($properties);
             // register the entity managers found in the configuration
             foreach ($persistenceNode->getPersistenceUnits() as $persistenceUnitNode) {
                 $this->registerEntityManager($application, $persistenceUnitNode);
             }
         } catch (InvalidConfigurationException $e) {
             // try to load the system logger instance
             /** @var \Psr\Log\LoggerInterface $systemLogger */
             if ($systemLogger = $this->getApplication()->getInitialContext()->getSystemLogger()) {
                 $systemLogger->error($e->getMessage());
                 $systemLogger->critical(sprintf('Persistence configuration file %s is invalid, needed entity managers might be missing.', $file));
             }
         } catch (\Exception $e) {
             // try to load the system logger instance
             /** @var \Psr\Log\LoggerInterface $systemLogger */
             if ($systemLogger = $this->getApplication()->getInitialContext()->getSystemLogger()) {
                 $systemLogger->error($e->__toString());
             }
         }
     }
 }
Пример #2
0
 /**
  * Registers the entity managers at startup.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  */
 protected function registerEntityManagers(ApplicationInterface $application)
 {
     // build up META-INF directory var
     $metaInfDir = $this->getWebappPath() . DIRECTORY_SEPARATOR . 'META-INF';
     // check if we've found a valid directory
     if (is_dir($metaInfDir) === false) {
         return;
     }
     // check META-INF + subdirectories for XML files with MQ definitions
     /** @var \AppserverIo\Appserver\Core\Api\DeploymentService $service */
     $service = $application->newService('AppserverIo\\Appserver\\Core\\Api\\DeploymentService');
     $xmlFiles = $service->globDir($metaInfDir . DIRECTORY_SEPARATOR . 'persistence.xml');
     // gather all the deployed web applications
     foreach ($xmlFiles as $file) {
         try {
             // try to initialize a SimpleXMLElement
             $sxe = new \SimpleXMLElement($file, null, true);
             $sxe->registerXPathNamespace('a', 'http://www.appserver.io/appserver');
             // validate the file here, if it is not valid we can skip further steps
             try {
                 /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
                 $configurationService = $application->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService');
                 $configurationService->validateFile($file, null, true);
             } catch (InvalidConfigurationException $e) {
                 /** @var \Psr\Log\LoggerInterface $systemLogger */
                 $systemLogger = $this->getApplication()->getInitialContext()->getSystemLogger();
                 $systemLogger->error($e->getMessage());
                 $systemLogger->critical(sprintf('Message queue configuration file %s is invalid, needed queues might be missing.', $file));
                 return;
             }
             // initialize the entity managers found in the deployment descriptor
             $persistenceNode = new PersistenceNode();
             $persistenceNode->initFromFile($file);
             foreach ($persistenceNode->getPersistenceUnits() as $persistenceUnitNode) {
                 $this->registerEntityManager($application, $persistenceUnitNode);
             }
             // if class can not be reflected continue with next class
         } catch (\Exception $e) {
             // log an error message
             $application->getInitialContext()->getSystemLogger()->error($e->__toString());
             // proceed with the next queue
             continue;
         }
     }
 }