示例#1
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;
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Tests the static newDescriptorInstance() method.
  *
  * @return void
  */
 public function testNewDescriptorInstance()
 {
     $this->assertInstanceOf('AppserverIo\\Description\\ResReferenceDescriptor', ResReferenceDescriptor::newDescriptorInstance());
 }