667514 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

News News News Messages: 8 Messages: 8 Messages: 8 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

Reflections - Java runtime metadata analysis

Posted by: r m on December 03, 2008 DIGG
from the google code project page http://code.google.com/p/reflections/

Reflections scans your classpath, indexes the metadata, allows you to query it on runtime and may save and collect that information for many modules within your project.

Using Reflections you can query your metadata for:

* get all subtypes of some type
* get all types annotated with some annotation
* get all types annotated with some annotation, including annotation parameters matching
* get all methods annotated with some

How to use?

Use the one-stop-shop Reflections object for all that Reflections:

* Get an instance of a Reflections object, providing it with your preferred configuration
* Query your project's metadata

A simple example might be:

Configuration configuration = new AbstractConfiguration() {
{
setUrls(ClasspathHelper.getUrlsForCurrentClasspath());
setScanners(new SubTypesScanner(), new ClassAnnotationsScanner());
setFilter(new IncludeExcludeChain(
new IncludePrefix("your project's common package prefix here...")
));
}
};

Reflections reflections = new Reflections(configuration);

// get all subtypes of some type
Set<Class><?>> subTypes = reflections.getSubTypesOf(SomeClassOrInterface.class);

// get all types annotated with some annotation
Set<Class><?>> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class);

// get all types annotated with some annotation, including annotation parameters matching
Set<Class><?>> annotated1 = reflections.getTypesAnnotatedWith(new SomeAnnotation() {
public String value() {return "1";}
public Class<? extends Annotation> annotationType() {return SomeAnnotation.class;}
});
}

check out the project home page http://code.google.com/p/reflections/

Threaded replies

·  Reflections - Java runtime metadata analysis by r m on Wed Dec 03 02:39:21 EST 2008
  ·  Looks great! by Ophir Radnitz on Wed Dec 03 09:08:01 EST 2008
    ·  Re: Looks great! by Avishay Halperen on Wed Dec 03 14:15:23 EST 2008
    ·  Good One... by Jey Bees on Thu Dec 04 06:08:11 EST 2008
  ·  Re: Reflections - Java runtime metadata analysis by Ethan Allen on Wed Dec 03 18:01:06 EST 2008
  ·  Re: Reflections - Java runtime metadata analysis by Sumit Gupta on Thu Dec 04 01:31:54 EST 2008
  ·  Very useful! by Baruch Sadogursky on Thu Dec 04 03:52:04 EST 2008
  ·  More info please !!!! by Jeronimo Azevedo on Fri Dec 05 08:46:56 EST 2008
    ·  Re: More info please !!!! by r m on Fri Dec 05 10:16:13 EST 2008
  Message #280647 Post reply Post reply Post reply Go to top Go to top Go to top

Looks great!

Posted by: Ophir Radnitz on December 03, 2008 in response to Message #280622
Congratulations!
Looks like a very powerful frameworks library. I like the pluggable scanners and filters. I also like the Maven integration for post-compile scanning.
http://code.google.com/p/reflections/wiki/ReflectionsMojo

Nice stuff :)

  Message #280661 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Looks great!

Posted by: Avishay Halperen on December 03, 2008 in response to Message #280647
I second that feeling,

This framework can provide a very good bootstrap for any application regardless the container it runs on(if exist).

The maven plugin is reducing the bootstrap time.

I suggest you should publish it to the main maven repositories:
repo1 etc ...

good work !

  Message #280667 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Reflections - Java runtime metadata analysis

Posted by: Ethan Allen on December 03, 2008 in response to Message #280622
Looks very useful - thanks!!

  Message #280677 Post reply Post reply Post reply Go to top Go to top Go to top

Re: Reflections - Java runtime metadata analysis

Posted by: Sumit Gupta on December 04, 2008 in response to Message #280622
Pretty Good!

The best part is the Scanning of Compiled sources and saving Metadata into a XML file and use it further for bootstrapping.

  Message #280681 Post reply Post reply Post reply Go to top Go to top Go to top

Very useful!

Posted by: Baruch Sadogursky on December 04, 2008 in response to Message #280622
Every time while waiting for Spring, JBoss-common and dozen of other frameworks finishing their own sclasspath scan I am thinking wouldn't it be nice to have one unified framework for classpath scan.
Thanks!

  Message #280685 Post reply Post reply Post reply Go to top Go to top Go to top

Good One...

Posted by: Jey Bees on December 04, 2008 in response to Message #280647
Pretty good explanation. Thanks for sharing.

http://qnatech.wordpress.com

  Message #280971 Post reply Post reply Post reply Go to top Go to top Go to top

More info please !!!!

Posted by: Jeronimo Azevedo on December 05, 2008 in response to Message #280622
Hi,

Just for what I was looking for. Where could I find more exmaples and documentation, I am trying to use it but I alawys have the same output 'non class file' or 'null'. I don't get it.

Thanks,

azevedo

  Message #280985 Post reply Post reply Post reply Go to top Go to top Go to top

Re: More info please !!!!

Posted by: r m on December 05, 2008 in response to Message #280971
kindly supply more information and contact me at ronmamo atgmaildotcom

New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com

Dependency Injection in Java EE 6 - Part 1

Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (November 2, Article)

SAML: It's Not just for Web services

SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options. (September 28, Article)

Programming is Also Teaching Your Team

Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team. (September 22, Article)

Can Java EE Deliver The Asynchronous Web?

Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies. (July 14, Article)

JSF Flex

JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags. (June 29, Article)

The Rules of SOA - A Road to a Successful SOA Implementation

In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project. (June 23, Tech Talk)

Ari Zilka Talks About Terracotta 3.1

Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now. (June 15, Tech Talk)

Enterprise Application Integration, and Spring

In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements. (June 15, Tech Talk)

Google Web Toolkit: An Introduction

In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls. (June 4, Tech Talk)

Just Enough Early Architecture to Guide Development

Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable. (May 28, Tech Talk)

Productive Programmer: On the Lam from the Furniture Police

This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work. (May 26, Tech Talk)

Auto-Scaling Your Existing Web Application

Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers. (May 21, Tech Talk)

Automating Hibernate Mapping and Queries For Java Web Development

Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application. (May 19, Article)

Auto-Scaling Your Existing Web Application

In this session Nati Shalom demonstrates how to take a standard Java EE web application and scale it out or down dynamically without changes to the application code. Seeing as most web applications are over-provisioned to meet infrequent peak loads, this is a dramatic change because it enables growing your application as needed, when needed, without paying for unutilized resources. (May 19, Tech Talk)

Free Book PDF Download: Mastering EJB Third Edition

Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)

Application Server Matrix

The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map