com.google.web.bindery.autobean.shared.AutoBeanFactory Maven / Gradle / Ivy
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.web.bindery.autobean.shared;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* A tag interface for the AutoBean generator. Instances of AutoBeans are
* created by declaring factory methods on a subtype of this interface.
*
* Simple interfaces, consisting of only getters and setters, can be constructed
* with a no-arg method. Non-simple interfaces must provide a delegate object to
* implement a non-simple interface or use a {@link Category}.
*
*
* interface MyFactory extends AutoBeanFactory {
* // A factory method for a simple bean
* AutoBean<BeanInterface> beanInterface();
* // A factory method for a wrapper bean
* AutoBean<ArbitraryInterface> wrapper(ArbitraryInterface delegate);
* }
*
*
* @see AutoBean
* wiki page
*/
public interface AutoBeanFactory {
/**
* Allows non-property methods on simple bean implementations when applied.
* For any given method, the specified classes will be searched for a public,
* static method whose method signature is exactly equal to the declared
* method's signature, save for the addition of a new initial parameter that
* must accept AutoBean<T>
.
*
*
* interface HasMethod {
* void doSomething(int a, double b);
* }
*
*
* would be paired with a category implemenation such as
*
*
* class HasMethodCategory {
* public static void doSomething(AutoBean<HasMethod> bean, int a, double b) {
* }
* }
*
*
* and registered with
*
*
* {@literal @}Category(HasMethodCategory.class)
* interface MyBeanFactory extends AutoBeanFactory {
* AutoBean<HasMethod> hasMethod();
* }
*
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Category {
Class>[] value();
}
/**
* The types specified by this annotation will not be wrapped by an AutoBean
* when returned from an AutoBean-controlled method.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface NoWrap {
/**
* The interface types that should not be wrapped.
*/
Class>[] value();
}
/**
* Allows dynamic creation of AutoBean instances based on declared
* parameterizations.
*
* @param the parameterization of the created {@link AutoBean}
* @param clazz the Class of type T of the new instance
* @return an {@link AutoBean} of type T or {@code null} if the interface type
* is unknown to the factory
*/
AutoBean create(Class clazz);
/**
* Allows dynamic creation of wrapped AutoBean instances based on declared
* parameterizations.
*
* @param the parameterization of the created {@link AutoBean}
* @param the delegate's type, a subtype of T
* @param clazz the Class of type T of the new instance
* @param delegate a delegate that extends type T
* @return an {@link AutoBean} of type T or {@code null} if the interface type
* is unknown to the factory
*/
AutoBean create(Class clazz, U delegate);
}