Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2006-2007 the original author or authors.
   *
   * 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 org.springframework.batch.classify;
 
Wrapper for an object to adapt it to the Classifier interface.

Author(s):
Dave Syer
 
 public class ClassifierAdapter<C, T> implements Classifier<C, T> {
 
 	private MethodInvoker invoker;
 
 	private Classifier<C, T> classifier;

Default constructor for use with setter injection.
 
 	public ClassifierAdapter() {
 		super();
 	}

Create a new Classifier from the delegate provided. Use the constructor as an alternative to the setDelegate(java.lang.Object) method.

Parameters:
delegate
 
 	public ClassifierAdapter(Object delegate) {
 		setDelegate(delegate);
 	}

Create a new Classifier from the delegate provided. Use the constructor as an alternative to the setDelegate(org.springframework.batch.classify.Classifier) method.

Parameters:
delegate
 
 	public ClassifierAdapter(Classifier<C, T> delegate) {
 		 = delegate;
 	}
 
 	public void setDelegate(Classifier<C, T> delegate) {
 		 = delegate;
 		 = null;
 	}

Search for the Classifier annotation on a method in the supplied delegate and use that to create a Classifier from the parameter type to the return type. If the annotation is not found a unique non-void method with a single parameter will be used, if it exists. The signature of the method cannot be checked here, so might be a runtime exception when the method is invoked if the signature doesn't match the classifier types.

Parameters:
delegate an object with an annotated method
 
 	public final void setDelegate(Object delegate) {
 		 = null;
 		 = MethodInvokerUtils.getMethodInvokerByAnnotation(
 		if ( == null) {
 			 = MethodInvokerUtils.<C, T> getMethodInvokerForSingleArgument(delegate);
 		}
 		Assert.state( != null"No single argument public method with or without "
 				+ "@Classifier was found in delegate of type " + delegate.getClass());
 	}

 
 	@SuppressWarnings("unchecked")
 	public T classify(C classifiable) {
 		if ( != null) {
 			return .classify(classifiable);
 		}
 		return (T) .invokeMethod(classifiable);
 	}
New to GrepCode? Check out our FAQ X