/** * 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); } } }
/** * 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; }