Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attach meta info? #28

Open
stephanos opened this issue Mar 26, 2015 · 4 comments
Open

attach meta info? #28

stephanos opened this issue Mar 26, 2015 · 4 comments

Comments

@stephanos
Copy link

Would it be feasible to attach meta information to each class in the index?

Here is our use case:
We have several hundred pages, they all inherit from BasePage.java. There is also a mapping file, PageIndex.java they is basically a big hash map that looks like this:

   .put("/some/path", "com.myproject.pages.XYZ")

The reason we need to use the full qualified name is that we want to prevent the classloading of the page (slow on our platform). So in order to apply classindex to this we'd need to attach the page's path to the index (since we can't load the entire class and evaluate any runtime annotations).

So, basically I'd imagine a annotation like @IndexMeta("/some/path") and the ability to read it from the classindex API.

I know this is quite a big concept, but I just wanted to throw it out there :)

Stephan

@marembo2008
Copy link

I think the classindex does not need to add this.
You can define your own annotation like:

@Retention(RUNTIME)
@Target(TYPE)
@IndexAnnotated
public @interface PageIndex{
   String path();
}

And then at boot, in your post construct, or however you do it, you just process the pages

@PostConstruct
void initializePageIndeces(){
    final Iterable<Class<?>> pages = ClassIndex.getAnnotated(PageIndex.class);
    for(final Class<?> pageIndexClass:pages) {
        final PageIndex = pageIndexClass:pages.getAnnotation(PageIndex.class);
    }
}

@stephanos
Copy link
Author

The ClassIndex.getAnnotated loads all the classes. This is too slow on our platform :(

@marembo2008
Copy link

So i guess you would like to do something like:

final PageIndex pageIndex = getHoldOfPageIndexForPath("/some/path");
Class<? extends BasePage> pageClass = ClassIndex.getAnnotated(pageIndex);

So that you load the class at the point it is needed.
That would be a big toll, and the use case may actually be there, as i do this quite often in CDI.
I would try to tickle with it, and then see if i can actually add such a functionality. if you do before me, let me get an update

@stephanos
Copy link
Author

Actually I want to do this:

void initializePageIndeces(){
    HashMap<String, String> pathToPageClassName = new HashMap<>();
    Iterable<String> pageClasses = ClassIndex.getSubclassesNames(BasePage.class);
    for (String pageClass : pageClasses) {
        String path = (String) ClassIndex.getSubclassMetaData(BasePage.class, pageClass);
        pathToPageClassName.put(path, pageClass);
    }
}

I should have written this in the first place :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants