/**
  * Initializes the bean descriptor instance from the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\MessageDrivenBeanDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionClass(ClassInterface $reflectionClass)
 {
     // query if we've an enterprise bean with a @MessageDriven annotation
     if ($reflectionClass->hasAnnotation(MessageDriven::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // initialize the descriptor instance
     parent::fromReflectionClass($reflectionClass);
     // return the instance
     return $this;
 }
 /**
  * Initializes the bean descriptor instance from the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\StatelessSessionBeanDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionClass(ClassInterface $reflectionClass)
 {
     // query if we've an enterprise bean with a @Stateless annotation
     if ($reflectionClass->hasAnnotation(Stateless::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // set the session type
     $this->setSessionType(StatelessSessionBeanDescriptor::SESSION_TYPE);
     // initialize the descriptor instance
     parent::fromReflectionClass($reflectionClass);
     // return the instance
     return $this;
 }
 /**
  * Initializes the servlet descriptor instance from the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the servlet description
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\ServletDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionClass(ClassInterface $reflectionClass)
 {
     // query if we've a servlet
     if ($reflectionClass->implementsInterface('AppserverIo\\Psr\\Servlet\\ServletInterface') === false) {
         // if not, do nothing
         return;
     }
     // query if we've an interface or an abstract class
     if ($reflectionClass->toPhpReflectionClass()->isInterface() || $reflectionClass->toPhpReflectionClass()->isAbstract()) {
         // if so, do nothing
         return;
     }
     // set the servlet name
     $this->setName(lcfirst($reflectionClass->getShortName()));
     // set the class name
     $this->setClassName($reflectionClass->getName());
     // query if we've a servlet with a @Route annotation
     if ($reflectionClass->hasAnnotation(Route::ANNOTATION)) {
         // create a new annotation instance
         $reflectionAnnotation = $this->newAnnotationInstance($reflectionClass);
         // initialize the annotation instance
         $annotationInstance = $reflectionAnnotation->newInstance($reflectionAnnotation->getAnnotationName(), $reflectionAnnotation->getValues());
         // load the default name to register in naming directory
         if ($nameAttribute = $annotationInstance->getName()) {
             $this->setName($nameAttribute);
         }
         // register the servlet description defined as @Route(description=****)
         if ($description = $annotationInstance->getDescription()) {
             $this->setDescription($description);
         }
         // register the servlet display name defined as @Route(displayName=****)
         if ($displayName = $annotationInstance->getDisplayName()) {
             $this->setDisplayName($displayName);
         }
         // register the init params defined as @Route(initParams=****)
         foreach ($annotationInstance->getInitParams() as $initParam) {
             list($paramName, $paramValue) = $initParam;
             $this->addInitParam($paramName, $paramValue);
         }
         // register the URL pattern defined as @Route(urlPattern=****)
         foreach ($annotationInstance->getUrlPattern() as $urlPattern) {
             $this->addUrlPattern($urlPattern);
         }
     }
     // initialize references from the passed reflection class
     $this->referencesFromReflectionClass($reflectionClass);
     // return the instance
     return $this;
 }
 /**
  * Initializes the bean configuration instance with the references of the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration
  *
  * @return void
  */
 public function referencesFromReflectionClass(ClassInterface $reflectionClass)
 {
     // we've to check for property annotations that references EPB or resources
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         // load the EPB references
         if ($epbReference = EpbReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) {
             $this->addEpbReference($epbReference);
         }
         // load the resource references
         if ($resReference = ResReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) {
             $this->addResReference($resReference);
         }
         // load the persistence unit references
         if ($persistenceUnitReference = PersistenceUnitReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) {
             $this->addPersistenceUnitReference($persistenceUnitReference);
         }
     }
     // we've to check for method annotations that references EPB or resources
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         // load the EPB references
         if ($epbReference = EpbReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) {
             $this->addEpbReference($epbReference);
         }
         // load the resource references
         if ($resReference = ResReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) {
             $this->addResReference($resReference);
         }
         // load the persistence unit references
         if ($persistenceUnitReference = PersistenceUnitReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) {
             $this->addPersistenceUnitReference($persistenceUnitReference);
         }
     }
 }
Beispiel #5
0
 /**
  * Initializes the bean configuration instance from the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration
  *
  * @return \AppserverIo\Routlt\Description\PathDescriptorInterface The initialized descriptor
  */
 public function fromReflectionClass(ClassInterface $reflectionClass)
 {
     // add the annotation alias to the reflection class
     $reflectionClass->addAnnotationAlias(Path::ANNOTATION, Path::__getClass());
     $reflectionClass->addAnnotationAlias(Result::ANNOTATION, Result::__getClass());
     $reflectionClass->addAnnotationAlias(Results::ANNOTATION, Results::__getClass());
     // query if we've an action
     if ($reflectionClass->implementsInterface('AppserverIo\\Routlt\\ActionInterface') === false && $reflectionClass->toPhpReflectionClass()->isAbstract() === false) {
         // if not, do nothing
         return;
     }
     // query if we've a servlet with a @Path annotation
     if ($reflectionClass->hasAnnotation(Path::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // create a new annotation instance
     $reflectionAnnotation = $this->newAnnotationInstance($reflectionClass);
     // load class name
     $this->setClassName($reflectionClass->getName());
     // initialize the annotation instance
     $annotationInstance = $reflectionAnnotation->newInstance($reflectionAnnotation->getAnnotationName(), $reflectionAnnotation->getValues());
     // load the default name to register in naming directory
     if ($nameAttribute = $annotationInstance->getName()) {
         $name = $nameAttribute;
     } else {
         // if @Annotation(name=****) is NOT set, we use the class name by default
         $name = strtolower(str_replace('\\', '/', $reflectionClass->getName()));
     }
     // prepare and set the name
     $this->setName(sprintf('/%s', ltrim($name, '/')));
     // we've to check for method annotations that declare the action methods
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         if ($action = ActionDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) {
             $this->addAction($action);
         }
     }
     // we've to check for result annotations
     if ($reflectionClass->hasAnnotation(Results::ANNOTATION)) {
         // create the reflection annotation instance
         $resultsAnnotation = $reflectionClass->getAnnotation(Results::ANNOTATION);
         // initialize the @Results annotation instance
         $resultsAnnotationInstance = $resultsAnnotation->newInstance($resultsAnnotation->getAnnotationName(), $resultsAnnotation->getValues());
         // load the results
         foreach ($resultsAnnotationInstance->getResults() as $resultAnnotation) {
             $this->addResult(ResultDescriptor::newDescriptorInstance()->fromReflectionAnnotation($resultAnnotation));
         }
     }
     // we've to check for property annotations that references EPB or resources
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         // load the EPB references
         if ($epbReference = EpbReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) {
             $this->addEpbReference($epbReference);
         }
         // load the resource references
         if ($resReference = ResReferenceDescriptor::newDescriptorInstance()->fromReflectionProperty($reflectionProperty)) {
             $this->addResReference($resReference);
         }
     }
     // we've to check for method annotations that references EPB or resources
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         // load the EPB references
         if ($epbReference = EpbReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) {
             $this->addEpbReference($epbReference);
         }
         // load the resource references
         if ($resReference = ResReferenceDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod)) {
             $this->addResReference($resReference);
         }
     }
     // return the instance
     return $this;
 }
Beispiel #6
0
 /**
  * Adds the passe reflection class instance to the DI provider.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class instance to add
  *
  * @return void
  */
 public function setReflectionClass(ClassInterface $reflectionClass)
 {
     $this->reflectionClasses[$reflectionClass->getName()] = $reflectionClass;
 }
 /**
  * Initializes the bean descriptor instance from the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\SingletonSessionBeanDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionClass(ClassInterface $reflectionClass)
 {
     // query if we've an enterprise bean with a @Singleton annotation
     if ($reflectionClass->hasAnnotation(Singleton::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // set the session type
     $this->setSessionType(SingletonSessionBeanDescriptor::SESSION_TYPE);
     // we've to check for a @PostDetach or @PreAttach annotation
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         // if we found a @PostDetach annotation, invoke the method
         if ($reflectionMethod->hasAnnotation(PostDetach::ANNOTATION)) {
             $this->addPostDetachCallback(DescriptorUtil::trim($reflectionMethod->getMethodName()));
         }
         // if we found a @PreAttach annotation, invoke the method
         if ($reflectionMethod->hasAnnotation(PreAttach::ANNOTATION)) {
             $this->addPreAttachCallback(DescriptorUtil::trim($reflectionMethod->getMethodName()));
         }
     }
     // initialize the descriptor instance
     parent::fromReflectionClass($reflectionClass);
     // if we found a bean with @Singleton + @Startup annotation
     if ($reflectionClass->hasAnnotation(Startup::ANNOTATION)) {
         // instanciate the bean
         $this->setInitOnStartup();
     }
     // return the instance
     return $this;
 }
 /**
  * Initializes and returns an array with annotation instances from the doc comment
  * found in the passed reflection class instance.
  *
  * @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class to load the doc comment from
  *
  * @return array The array with the ReflectionAnnotation instances loaded from the passed reflection class
  * @see \AppserverIo\Lang\Reflection\ReflectionAnnotation::fromDocComment()
  */
 public static function fromReflectionClass(ClassInterface $reflectionClass)
 {
     // load the reflection method data we need to initialize the annotations
     $aliases = $reflectionClass->getAnnotationAliases();
     $ignore = $reflectionClass->getAnnotationsToIgnore();
     $docComment = $reflectionClass->toPhpReflectionClass()->getDocComment();
     // load and return the annotations found in the doc comment
     return ReflectionAnnotation::fromDocComment($docComment, $ignore, $aliases);
 }