Javadoc polish & pruning dead code

This commit is contained in:
Chris Beams 2009-03-07 05:49:12 +00:00
parent 3231f458c8
commit faffd98621
4 changed files with 88 additions and 173 deletions

View File

@ -17,137 +17,83 @@ package org.springframework.config.java;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.context.annotation.Scope;
/** /**
* Annotation to be applied to methods that create beans in a Spring context. The name of * Indicates that a method produces a bean to be managed by the Spring container. The
* the bean is the method name. (It is also possible to specify aliases using the aliases * names and semantics of the attributes to this annotation are intentionally similar
* array on this annotation.) * to those of the {@literal <bean/>} element in the Spring XML schema. Deviations are
* as follows:
* *
* <p> * <p>The Bean annotation does not provide attributes for scope, primary or lazy. Rather,
* Contains information similar to that held in Spring's internal BeanDefinition metadata. * it should be used in conjunction with {@link Scope}, {@link Primary} and {@link Lazy}
* </p> * annotations to acheive the same semantics.
* *
* <p> * <p>While a {@link #name()} attribute is available, the default strategy for determining
* Bean creation methods must be non-private (default, public or protected). Bean creation * the name of a bean is to use the name of the Bean method. This is convenient and
* methods may throw any exception, which will be caught and handled by the Spring container * intuitive, but if explicit naming is desired, the {@link #name()} attribute may be used.
* on processing of the configuration class.<br> * Also note that {@link #name()} accepts an array of strings. This is in order to allow
* Bean creation methods must return an object type. The decision to return a class or an * for specifying multiple names (aka aliases) for a single bean.
* interface will be significant in the event of proxying. Bean methods that return
* interfaces will be proxied using dynamic proxies; those that return a class will require
* CGLIB or other subclass-based proxying. It is recommended to return an interface where
* possible, as this is also consistent with best practice around loose coupling.
* </p>
* *
* <p> * <h3>Constraints</h3>
* Bean creation methods may reference other bean creation methods by calling them directly, * <ul>
* as follows. This ensures that references between beans are strongly typed: * <li>Bean methods are valid only when declared within a {@link Configuration}-annotated class
* </p> * <li>Bean methods must be non-void, non-final, non-private
* <li>Bean methods may not accept any arguments
* <li>Bean methods may throw any exception, which will be caught and handled
* by the Spring container on processing of the declaring {@link Configuration} class.
* </ul>
*
* <h3>Usage</h3>
* <p>Bean methods may reference other Bean methods by calling them directly. This ensures
* that references between beans are strongly typed and navigable. So called 'inter-bean
* references' are guaranteed to respect scoping and AOP semantics.
* *
* @see Configuration
* *
* @author Rod Johnson * @author Rod Johnson
* @author Costin Leau * @author Costin Leau
* @author Chris Beams * @author Chris Beams
* @since 3.0 * @since 3.0
* @see Configuration
*/ */
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented @Documented
public @interface Bean { public @interface Bean {
// TODO: /**
// /** * The name of this bean, or if plural, aliases for this bean. If left unspecified
// * Role this bean plays in the overall application configuration. * the name of the bean is the name of the annotated method. If specified, the method
// * * name is ignored.
// * @see BeanDefinition#ROLE_APPLICATION */
// * @see BeanDefinition#ROLE_INFRASTRUCTURE
// * @see BeanDefinition#ROLE_SUPPORT
// *
// * @see AbstractBeanDefinition the 'role' field is assigned by default to
// * ROLE_APPLICATION
// */
// int role() default BeanDefinition.ROLE_APPLICATION;
String[] name() default {}; String[] name() default {};
// TODO: Prune aliases, favor name[]
// /**
// * Bean aliases.
// */
// String[] aliases() default {};
// TODO: favor @Scope
// /**
// * Scope: whether the bean is a singleton, prototype or custom scope. Default is
// * singleton.
// */
// String scope() default StandardScopes.SINGLETON;
// TODO: prune autowiring?
// /**
// * Bean autowire strategy.
// */
// Autowire autowire() default Autowire.INHERITED;
// /**
// * Bean lazy strategy.
// */
// Lazy lazy() default Lazy.UNSPECIFIED;
//
// /**
// * A bean may be marked as primary, useful for disambiguation when looking
// * up beans by type.
// *
// * @see
// org.springframework.config.java.context.JavaConfigApplicationContext#getBean(Class);
// */
// Primary primary() default Primary.UNSPECIFIED;
/** /**
* Bean init method name. Normally this is not needed, as the initialization (with * The optional name of a method to call on the bean instance during initialization.
* parameterization) can be done directly through java code. * Not commonly used, given that the method may be called programmatically directly
* within the Bean method.
*/ */
String initMethod() default ""; String initMethod() default "";
/** /**
* Bean destroy method name. * The optional name of a method to call on the bean instance during upon closing
* the application context, for example a {@literal close()}
* method on a {@literal DataSource}.
*/ */
String destroyMethod() default ""; String destroyMethod() default "";
// TODO: Prune DependencyCheck
// /**
// * Bean dependency check strategy.
// */
// DependencyCheck dependencyCheck() default DependencyCheck.UNSPECIFIED;
/** /**
* Beans on which the current bean depends on. * Beans on which the current bean depends. Any beans specified are guaranteed to be
* created by the container before this bean. Used infrequently in cases where a bean
* does not explicitly depend on another through properties or constructor arguments,
* but rather depends on the side effects of another bean's initialization.
*/ */
String[] dependsOn() default {}; String[] dependsOn() default {};
// TODO: Prune @Meta
// /**
// * Metadata for the current bean.
// */
// Meta[] meta() default { };
// TODO: Prune allowOverriding
// /**
// * Allow the bean to be overridden in another JavaConfig, XML or other non-Java
// * configuration. This is consistent with DefaultListableBeanFactory's
// * allowBeanDefinitionOverriding property, which defaults to true.
// *
// * @return whether overriding of this bean is allowed
// */
// boolean allowOverriding() default true;
//
//String name() default "";
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,33 +22,42 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.config.java.support.ConfigurationClassPostProcessor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* Annotation indicating that a class is a "Java Configuration" class, meaning that it * Indicates that a class declares one or more {@link Bean} methods and may be processed
* exposes one or more {@link Bean} methods. Holds similar information to that held in the * by the Spring container to generate bean definitions and service requests for those beans
* default values of a bean factory; can generally be thought of as the JavaConfig * at runtime.
* equivalent of XML's 'beans' root element.
* *
* <p> * <p>Configuration is itself annotated as a {@link Component}, therefore Configuration
* Note however that the information here is not used to populate the defaults of the owning * classes are candidates for component-scanning and may also take advantage of
* bean factory, which would affect other configurations. In the style of the Java * {@link Autowire} at the field and method and constructor level.
* configuration mechanism generally, each Java configuration class is kept isolated.
* </p>
* *
* <p> * <p>May be used in conjunction with the {@link Lazy} annotation to indicate that all Bean
* Configuration-annotated classes are also candidates for component scanning thanks to the * methods declared within this class are by default lazily initialized.
* fact that this annotation is meta-annotated with {@link Component @Component}.
* </p>
* *
* May be used in conjunction with {@link Lazy} * <h3>Constraints</h3>
* <ul>
* <li>Configuration classes must be non-final
* <li>Configuration classes must be non-local (may not be declared within a method)
* <li>Configuration classes must have a default/no-arg constructor or an
* {@link Autowired} constructor
* </ul>
*
* TODO: test constructor autowiring<br>
* TODO: test private Configuration classes<br>
* TODO: test @Lazy @Configuration<br>
* *
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
* @since 3.0 * @since 3.0
* @see Lazy * @see ConfigurationClassPostProcessor
* @see Bean * @see Bean
* @see Lazy
*/ */
@Component @Component
@Target( { ElementType.TYPE }) @Target( { ElementType.TYPE })
@ -57,55 +66,4 @@ import org.springframework.stereotype.Component;
@Documented @Documented
public @interface Configuration { public @interface Configuration {
// TODO: consider pruning @Configuration(name[])
// /**
// * Configuration name. Allow different variants, such as test, production etc. Default
// * will always match.
// *
// * @return
// */
// String[] name() default "";
// TODO: Prune defaultAutowire
// /**
// * Specifies the default autowiring strategy.
// *
// * @see Autowire
// * @return
// */
// Autowire defaultAutowire() default Autowire.INHERITED;
// TODO: Prune DependencyCheck
// /**
// * Dependency check strategy. By default, the dependency check is
// * unspecified, that is the default Spring option will apply. In most cases,
// * it means no dependency check will be done.
// *
// * @see DependencyCheck
// * @return
// */
// DependencyCheck defaultDependencyCheck() default DependencyCheck.UNSPECIFIED;
//
// TODO: Favor @Lazy at the @Configuration class level. Should have @Target(TYPE, METHOD)
// /**
// * Bean instantiation strategy. By default, it is unspecified.
// *
// * @see Lazy
// * @return
// */
// Lazy defaultLazy() default Lazy.UNSPECIFIED;
// TODO: prune useFactoryAspects
// /**
// * Do we autowire with aspects from the enclosing factory scope?
// */
// boolean useFactoryAspects() default false;
// TODO: this is the default, and needs to be switched off at annotation-config
// /**
// * Do we check {@link Required @Required} methods to make sure they've been called?
// */
// boolean checkRequired() default false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,8 +29,8 @@ import org.objectweb.asm.MethodVisitor;
* the desired annotation is not already present before adding. Used by * the desired annotation is not already present before adding. Used by
* {@link ConfigurationEnhancer} to dynamically add an {@link org.aspectj.lang.Aspect} * {@link ConfigurationEnhancer} to dynamically add an {@link org.aspectj.lang.Aspect}
* annotation to an enhanced Configuration subclass. * annotation to an enhanced Configuration subclass.
* <p/> *
* This class was originally adapted from examples the ASM 3.0 documentation. * <p>This class was originally adapted from examples the ASM 3.0 documentation.
* *
* @author Chris Beams * @author Chris Beams
*/ */

View File

@ -23,16 +23,26 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.stereotype.Component;
/** /**
* Indicates the name of a scope to use for instances of the annotated class. * When used as a type-level annotation in conjunction with the {@link Component}
* annotation, indicates the name of a scope to use for instances of the annotated
* type.
*
* <p>When used as a method-level annotation in conjunction with the
* {@link Bean} annotation, indicates the name of a scope to use for
* the instance returned from the method.
* *
* <p>In this context, scope means the lifecycle of an instance, such as * <p>In this context, scope means the lifecycle of an instance, such as
* '<code>singleton</code>', '<code>prototype</code>', and so forth. * {@literal singleton}, {@literal prototype}, and so forth.
* *
* @author Mark Fisher * @author Mark Fisher
* @author Chris Beams * @author Chris Beams
* @since 2.5 * @since 2.5
* @see Component
* @see Bean
* @see StandardScopes
*/ */
@Target({ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ -40,8 +50,9 @@ import org.springframework.beans.factory.config.BeanDefinition;
public @interface Scope { public @interface Scope {
/** /**
* Specifies the scope to use for instances of the annotated class. * Specifies the scope to use for the annotated component/bean.
* @return the desired scope * @return the specified scope
* @see StandardScopes
*/ */
String value() default BeanDefinition.SCOPE_SINGLETON; String value() default BeanDefinition.SCOPE_SINGLETON;
@ -52,7 +63,7 @@ public @interface Scope {
* <p>Defaults to {@link ScopedProxyMode#NO}, indicating no scoped proxy * <p>Defaults to {@link ScopedProxyMode#NO}, indicating no scoped proxy
* should be created. * should be created.
* *
* <p>Analogous to {@literal <aop:scoped-proxy/>} support in XML. Valid * <p>Analogous to {@literal <aop:scoped-proxy/>} support in Spring XML. Valid
* only in conjunction with a non-singleton, non-prototype {@link #value()}. * only in conjunction with a non-singleton, non-prototype {@link #value()}.
*/ */
ScopedProxyMode proxyMode() default ScopedProxyMode.NO; ScopedProxyMode proxyMode() default ScopedProxyMode.NO;