Spring's meta-data support

Source: Internet
Author: User
Tags filter

In line with the abstraction of other important concepts it provides, spring provides a look (façade) of the metadata implementation, expressed in the form of a org.springframework.metadata.Attributes interface.

Such a look is valuable because of the following reasons:

Currently, there is no standard metadata solution. The Java 1.5 version will provide one, but in the Spring1.0 version, Java 1.5 is still a beta version. Also, metadata support for 1.3 and 1.4 versions of applications is required for at least two years. Now spring is going to offer some work-ready solutions: It's not a good choice to wait 1.5 in an important environment.

The current metadata APIs, such as Commons Attributes (used by spring 1.0), are difficult to test. Spring provides a simple, more easily emulated metadata interface.

Even when Java 1.5 provides support for metadata at the language level, it is still valuable to provide one such abstraction:

The JSR-175 metadata is static. It is associated with a class at compile time and cannot be changed in a deployment environment. There is a need for multi-level metadata to support the overloading of certain attribute values at deployment--for example, in an XML file that defines the attribute to overwrite.

The JSR-175 metadata is returned through the Java Reflection API. This makes it impossible to simulate metadata at test time. Spring provides a simple interface to allow this emulation.

Although spring will support JSR-175 before Java 1.5 reaches its GA version, it will continue to provide an attribute abstraction API.

The attributes interface for spring looks like this:

public interface Attributes {
Collection getAttributes(Class targetClass);
Collection getAttributes(Class targetClass, Class filter);
Collection getAttributes(Method targetMethod);
Collection getAttributes(Method targetMethod, Class filter);
Collection getAttributes(Field targetField);
Collection getAttributes(Field targetField, Class filter);
}

This is one of the most common name-user interfaces. JSR-175 can provide more functionality, such as attributes defined on method parameters. In version 1.0, Spring is designed to provide a subset of the metadata, making it possible to provide efficient declarative enterprise services like EJB or. Net. After version 1.0, spring will provide more metadata methods.

Notice that the interface is like. NET provides an object type of Attibute. This makes it different from some attribute systems that provide only the attribute of the string class, such as Nanning Aspects and JBoss 4 (when DR2 version). There is a notable advantage in supporting attributes of type object. It enables attributes to contain class hierarchies, and can also enable attributes to function flexibly according to their configuration parameters.

For most attribute providers, the configuration of attribute classes is done through constructor parameters or JavaBean properties. Commons attributes supports both approaches.

Like all spring abstraction APIs, attributes is an interface. This makes it easier to simulate attribute implementations in unit tests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.