/**
  * Creates and initializes a beans injection target configuration instance from the passed
  * reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans injection target configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\InjectionTargetDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // initialize the injection target from the passed method
     $this->setTargetClass($reflectionMethod->getClassName());
     $this->setTargetMethod($reflectionMethod->getMethodName());
     // return the instance
     return $this;
 }
 /**
  * Creates and initializes a beans reference configuration instance from the passed
  * reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans reference configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // if we found a @EnterpriseBean annotation, load the annotation instance
     if ($reflectionMethod->hasAnnotation(EnterpriseBean::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // initialize the annotation instance
     $annotation = $reflectionMethod->getAnnotation(EnterpriseBean::ANNOTATION);
     // load the annotation instance
     $annotationInstance = $annotation->newInstance($annotation->getAnnotationName(), $annotation->getValues());
     // load the reference name defined as @EnterpriseBean(name=****)
     if ($name = $annotationInstance->getName()) {
         $this->setName(sprintf('%s/%s', EpbReferenceDescriptor::REF_DIRECTORY, $name));
     } else {
         // use the name of the first parameter as local business interface
         foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
             $this->setName(sprintf('%s/%s', EpbReferenceDescriptor::REF_DIRECTORY, ucfirst($reflectionParameter->getParameterName())));
             break;
         }
     }
     // register the bean with the name defined as @EnterpriseBean(beanName=****)
     if ($beanNameAttribute = $annotationInstance->getBeanName()) {
         $this->setBeanName($beanNameAttribute);
     } else {
         $this->setBeanName(ucfirst(str_replace(EpbReferenceDescriptor::REF_DIRECTORY . '/', '', $this->getName())));
     }
     // register the bean with the interface defined as @EnterpriseBean(beanInterface=****)
     if ($beanInterfaceAttribute = $annotationInstance->getBeanInterface()) {
         $this->setBeanInterface($beanInterfaceAttribute);
     } else {
         $this->setBeanInterface(sprintf('%sLocal', ucfirst($this->getBeanName())));
     }
     // register the bean with the lookup name defined as @EnterpriseBean(lookup=****)
     if ($lookupAttribute = $annotationInstance->getLookup()) {
         $this->setLookup($lookupAttribute);
     }
     // register the bean with the interface defined as @EnterpriseBean(description=****)
     if ($descriptionAttribute = $annotationInstance->getDescription()) {
         $this->setDescription($descriptionAttribute);
     }
     // load the injection target data
     $this->setInjectionTarget(InjectionTargetDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod));
     // return the instance
     return $this;
 }
 /**
  * Responsible for invoking the timeout method on the target object.
  *
  * The timerservice implementation invokes this method as a callback when a timeout occurs for the
  * passed timer. The timerservice implementation will be responsible for passing the correct
  * timeout method corresponding to the <code>timer</code> on which the timeout has occurred.
  *
  * @param \AppserverIo\Psr\EnterpriseBeans\TimerInterface $timer         The timer that is passed to timeout
  * @param \AppserverIo\Lang\Reflection\MethodInterface    $timeoutMethod The timeout method
  *
  * @return void
  */
 public function callTimeout(TimerInterface $timer, MethodInterface $timeoutMethod = null)
 {
     // synchronize the application instance and register the class loaders
     $application = $this->getApplication();
     $application->registerClassLoaders();
     // initialize the initial context instance
     $initialContext = new InitialContext();
     $initialContext->injectApplication($application);
     // lookup the enterprise bean using the initial context
     $instance = $initialContext->lookup($this->getTimedObjectId());
     // check if the timeout method has been passed
     if ($timeoutMethod != null) {
         // if yes, invoke it on the proxy
         $callback = array($instance, $timeoutMethod->getMethodName());
         call_user_func_array($callback, array($timer));
         return;
     }
     // check if we've a default timeout method
     if ($this->defaultTimeoutMethod != null) {
         // if yes, invoke it on the proxy
         $callback = array($instance, $this->defaultTimeoutMethod->getMethodName());
         call_user_func_array($callback, array($timer));
         return;
     }
 }
 /**
  * Creates and initializes a beans reference configuration instance from the passed
  * reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans reference configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\PersistenceUnitReferenceDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // if we found a @PersistenceUnit annotation, load the annotation instance
     if ($reflectionMethod->hasAnnotation(PersistenceUnit::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // initialize the annotation instance
     $annotation = $reflectionMethod->getAnnotation(PersistenceUnit::ANNOTATION);
     // load the annotation instance
     $annotationInstance = $annotation->newInstance($annotation->getAnnotationName(), $annotation->getValues());
     // load the reference name defined as @PersistenceUnit(name=****)
     if ($name = $annotationInstance->getName()) {
         $this->setName(sprintf('%s/%s', PersistenceUnitReferenceDescriptor::REF_DIRECTORY, $name));
     } else {
         // use the name of the first parameter
         foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
             $this->setName(sprintf('%s/%s', PersistenceUnitReferenceDescriptor::REF_DIRECTORY, ucfirst($reflectionParameter->getParameterName())));
             break;
         }
     }
     // load the resource type defined as @PersistenceUnit(unitName=****)
     if ($unitName = $annotationInstance->getUnitName()) {
         $this->setUnitName($unitName);
     } else {
         // use the name of the first parameter unit name
         foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
             $this->setUnitName(ucfirst($reflectionParameter->getParameterName()));
             break;
         }
     }
     // load the injection target data
     $this->setInjectionTarget(InjectionTargetDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod));
     // return the instance
     return $this;
 }
 /**
  * Creates and initializes a beans reference configuration instance from the passed
  * reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the beans reference configuration
  *
  * @return \AppserverIo\Psr\EnterpriseBeans\Description\EpbReferenceDescriptorInterface|null The initialized descriptor instance
  */
 public function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // if we found a @Resource annotation, load the annotation instance
     if ($reflectionMethod->hasAnnotation(Resource::ANNOTATION) === false) {
         // if not, do nothing
         return;
     }
     // initialize the annotation instance
     $annotation = $reflectionMethod->getAnnotation(Resource::ANNOTATION);
     // load the annotation instance
     $annotationInstance = $annotation->newInstance($annotation->getAnnotationName(), $annotation->getValues());
     // load the reference name defined as @Resource(name=****)
     if ($name = $annotationInstance->getName()) {
         $this->setName(sprintf('%s/%s', ResReferenceDescriptor::REF_DIRECTORY, $name));
     } else {
         // use the name of the first parameter
         foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
             $this->setName(sprintf('%s/%s', ResReferenceDescriptor::REF_DIRECTORY, ucfirst($reflectionParameter->getParameterName())));
             break;
         }
     }
     // load the resource type defined as @Resource(type=****)
     if ($type = $annotationInstance->getType()) {
         $this->setType($type);
     } else {
         // use the name of the first parameter as local business interface
         foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
             $this->setType(ucfirst($reflectionParameter->getParameterName()));
             break;
         }
     }
     // load the lookup defined as @Resource(lookup=****)
     if ($lookup = $annotationInstance->getLookup()) {
         $this->setLookup($lookup);
     }
     // load the resource description defined as @Resource(description=****)
     if ($description = $annotationInstance->getDescription()) {
         $this->setDescription($description);
     }
     // load the injection target data
     $this->setInjectionTarget(InjectionTargetDescriptor::newDescriptorInstance()->fromReflectionMethod($reflectionMethod));
     // return the instance
     return $this;
 }
Example #6
0
 /**
  * Initializes the action configuration instance from the passed reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the action configuration
  *
  * @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor
  */
 public function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // add the annotation alias to the reflection method
     $reflectionMethod->addAnnotationAlias(Action::ANNOTATION, Action::__getClass());
     // query if we've a method with a @Action annotation
     if ($reflectionMethod->hasAnnotation(Action::ANNOTATION) === false && $reflectionMethod->getMethodName() !== 'perform') {
         // if not, do nothing
         return;
         // query whether we've the default perform() method WITHOUT an @Action annotation
     } elseif ($reflectionMethod->hasAnnotation(Action::ANNOTATION) === false && $reflectionMethod->getMethodName() === 'perform') {
         // create an annotation instance manually
         $reflectionAnnotation = new ReflectionAnnotation(Action::__getClass());
     } else {
         // create a new annotation instance by default
         $reflectionAnnotation = $this->newAnnotationInstance($reflectionMethod);
     }
     // load method name
     $this->setMethodName($reflectionMethod->getMethodName());
     // initialize the annotation instance
     $annotationInstance = $reflectionAnnotation->newInstance($reflectionAnnotation->getAnnotationName(), $reflectionAnnotation->getValues());
     // load the default name to register in naming directory
     if (($nameAttribute = $annotationInstance->getName()) || $nameAttribute === '') {
         $this->setName($nameAttribute);
     } else {
         // if @Annotation(name=****) is NOT SET, we use the method name by default
         $this->setName('/' . lcfirst(str_replace('Action', '', $reflectionMethod->getMethodName())));
     }
     // initialize the array for the annotated request methods
     $annotatedRequestMethods = array();
     // parse the method for annotated request methods
     foreach ($this->getRequestMethods() as $requestMethod) {
         // prepare the annotation name, e. g. POST -> Post
         $annotationName = ucfirst(strtolower($requestMethod));
         // query whether the reflection method has been annotated
         if ($reflectionMethod->hasAnnotation($annotationName)) {
             array_push($annotatedRequestMethods, $requestMethod);
         }
     }
     // query whether at least one annotated request method has been found
     if (sizeof($annotatedRequestMethods) > 0) {
         // if yes, override the default request methods
         $this->setRequestMethods($annotatedRequestMethods);
     }
     // initialize the restrictions for the route placeholders
     if (is_array($restrictions = $annotationInstance->getRestrictions())) {
         foreach ($restrictions as $restriction) {
             list($name, $value) = $restriction;
             $this->restrictions[$name] = $value;
         }
     }
     // initialize the defaults for the route placeholders
     if (is_array($defaults = $annotationInstance->getDefaults())) {
         foreach ($defaults as $default) {
             list($name, $value) = $default;
             $this->defaults[$name] = $value;
         }
     }
     // return the instance
     return $this;
 }
 /**
  * Initializes and returns an array with annotation instances from the doc comment
  * found in the passed reflection method instance.
  *
  * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method to load the doc comment from
  *
  * @return array The array with the ReflectionAnnotation instances loaded from the passed reflection method
  * @see \AppserverIo\Lang\Reflection\ReflectionAnnotation::fromDocComment()
  */
 public static function fromReflectionMethod(MethodInterface $reflectionMethod)
 {
     // load the reflection method data we need to initialize the annotations
     $aliases = $reflectionMethod->getAnnotationAliases();
     $ignore = $reflectionMethod->getAnnotationsToIgnore();
     $docComment = $reflectionMethod->toPhpReflectionMethod()->getDocComment();
     // load and return the annotations found in the doc comment
     return ReflectionAnnotation::fromDocComment($docComment, $ignore, $aliases);
 }