/** * 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; }
/** * 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; }
/** * 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; }
/** * Returns a new annotation instance for the passed reflection method. * * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the action configuration * * @return \AppserverIo\Lang\Reflection\AnnotationInterface The reflection annotation */ protected function newAnnotationInstance(MethodInterface $reflectionMethod) { return $reflectionMethod->getAnnotation(Action::ANNOTATION); }