示例#1
0
 /**
  * Register the servlet described by the passed descriptor.
  *
  * @param \AppserverIo\Psr\Servlet\Description\ServletDescriptorInterface $descriptor The servlet descriptor
  *
  * @return void
  */
 protected function registerServlet(ServletDescriptorInterface $descriptor)
 {
     try {
         // create a new reflection class instance
         $reflectionClass = new ReflectionClass($descriptor->getClassName());
         // instantiate the servlet
         $instance = $reflectionClass->newInstance();
         // load servlet name
         $servletName = $descriptor->getName();
         // initialize the servlet configuration
         $servletConfig = new ServletConfiguration();
         $servletConfig->injectServletContext($this);
         $servletConfig->injectServletName($servletName);
         // append the init params to the servlet configuration
         foreach ($descriptor->getInitParams() as $paramName => $paramValue) {
             $servletConfig->addInitParameter($paramName, $paramValue);
         }
         // initialize the servlet
         $instance->init($servletConfig);
         // the servlet is added to the dictionary using the complete request path as the key
         $this->addServlet($servletName, $instance);
         // prepend the url-pattern - servlet mapping to the servlet mappings
         foreach ($descriptor->getUrlPatterns() as $pattern) {
             $this->addServletMapping($pattern, $servletName);
         }
         // register the EPB references
         foreach ($descriptor->getEpbReferences() as $epbReference) {
             $this->registerEpbReference($epbReference);
         }
         // register the resource references
         foreach ($descriptor->getResReferences() as $resReference) {
             $this->registerResReference($resReference);
         }
         // register the persistence unit references
         foreach ($descriptor->getPersistenceUnitReferences() as $persistenceUnitReference) {
             $this->registerPersistenceUnitReference($persistenceUnitReference);
         }
     } catch (\Exception $e) {
         // log the exception
         $this->getApplication()->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\ServletDescriptorInterface $servletDescriptor The descriptor to merge
  *
  * @return void
  * @throws \AppserverIo\Psr\Servlet\ServletException Is thrown if you try to merge a servlet descriptor with a different class name
  */
 public function merge(ServletDescriptorInterface $servletDescriptor)
 {
     // check if the classes are equal
     if ($this->getClassName() !== $servletDescriptor->getClassName()) {
         throw new ServletException(sprintf('You try to merge a servlet descriptor for % with %s', $servletDescriptor->getClassName(), $servletDescriptor->getClassName()));
     }
     // merge the servlet name
     if ($name = $servletDescriptor->getName()) {
         $this->setName($name);
     }
     // merge the servlet description
     if ($description = $servletDescriptor->getDescription()) {
         $this->setDescription($description);
     }
     // merge the servlet display name
     if ($displayName = $servletDescriptor->getDisplayName()) {
         $this->setDisplayName($displayName);
     }
     // merge the URL patterns
     foreach ($servletDescriptor->getUrlPatterns() as $urlPattern) {
         $this->addUrlPattern($urlPattern);
     }
     // merge the initialization parameters
     foreach ($servletDescriptor->getInitParams() as $paramKey => $paramValue) {
         $this->addInitParam($paramKey, $paramValue);
     }
     // merge the EPB references
     foreach ($servletDescriptor->getEpbReferences() as $epbReference) {
         $this->addEpbReference($epbReference);
     }
     // merge the resource references
     foreach ($servletDescriptor->getResReferences() as $resReference) {
         $this->addResReference($resReference);
     }
     // merge the persistence unit references
     foreach ($servletDescriptor->getPersistenceUnitReferences() as $persistenceUnitReference) {
         $this->addPersistenceUnitReference($persistenceUnitReference);
     }
 }