[forge-dev] How to get value as class from annotation?

George Gastaldi ggastald at redhat.com
Sat Aug 8 21:55:08 EDT 2015


Hy Doychin,

We provide a "getClassValue()" in this case, so your code should be like:

                        AnnotationSource<JavaClassSource> idClassAnotation
= entityClass
                                        .getAnnotation(IdClass.class);
                        Class<?> valueClass =
idClassAnotation.getClassValue();

Note that this method may fail if the ClassLoader fails to load the class
(if the ID Class is part of the project, for example). In this case, you
can load the class by using the ClassLoaderFacet from the project:

try (URLClassLoader cl =
project.getFacet(ClassLoaderFacet.class).getClassLoader()) {
     // call cl.loadClass(yourClassName);
}

Hope that helps,

Best Regards!

George Gastaldi

On Sat, Aug 8, 2015 at 1:23 PM, Doychin Bondzhev <doychin at dsoft-bg.com>
wrote:

> Hi,
>
> We are part of the group that is trying to develop spring boot forge
> addon. We try to cover the case when we have entity with IdClass annotation
> and we have problem to get IdClass value parameter as some object that can
> give use more inform about that class.
>
> This is the code we are using :
>
> JavaClassSource entityClass = ((JavaResource) repositoryEntity
>                                 .getValue()).getJavaType();
>
>                 if (entityClass.hasAnnotation(IdClass.class)) {
>                         AnnotationSource<JavaClassSource> idClassAnotation
> = entityClass
>                                         .getAnnotation(IdClass.class);
>                         String valueClassName =
> idClassAnotation.getLiteralValue();
>
> We get as result in valueClassName the name of the class
> ("ClassName.class") but we need some sort of object that can provide us
> with some additional information like qualified class name and simple class
> name.
>
> This class can be part of the project or can be imported from another
> project/jar archive.
>
> Any idea how to achieve this?
>
> --
> Doychin Bondzhev
> dSoft-Bulgaria Ltd.
> PowerPro - billing & provisioning solution for Service providers
> PowerStor - Warehouse & POS
> http://www.dsoft-bg.com/
> Mobile: +359888243116
>
> _______________________________________________
> forge-dev mailing list
> forge-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/forge-dev
>



-- 
*George Gastaldi | Senior Software Engineer*

JBoss Forge Team
T: +55 11 3524-6169
M: +55 47 9711-1000
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/forge-dev/attachments/20150808/b2d5313f/attachment.html 


More information about the forge-dev mailing list