Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2012-2013 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.callbackparams.internal.template;

Author(s):
Henrik Kaipe
public abstract class AnnotationSpecifiedCallbacks {
    private final static Constructor methodParamConstructor =
            locateMethodParamConstructor();
    private final static Constructor fieldConstructor =
            locateFieldConstructor();
    private static Constructor locateMethodParamConstructor() {
        String actualAnnotationSpecifiedCallbacksClassName =
                AnnotationSpecifiedCallbacks.class.getName()
                .replaceFirst("A""annotation.A");
        try {
            return Class.forName(actualAnnotationSpecifiedCallbacksClassName)
                    .getConstructor(new Class[] {Method.classint.class});
        } catch (UnsupportedClassVersionError detectionOf_JDK1_4) {
            return null;
        } catch (Exception shouldNeverHappen) {
            throw ExceptionUtil.unchecked(shouldNeverHappen);
        }
    }
    private static Constructor locateFieldConstructor() {
        if (null == ) {
            return null;
        } else {
            try {
                return .getDeclaringClass()
                        .getConstructor(new Class[]{Field.class});
            } catch (NoSuchMethodException shouldNeverHappen) {
                throw ExceptionUtil.unchecked(shouldNeverHappen);
            }
        }
    }
    static AnnotationSpecifiedCallbacks forCallbackRef(Method mint paramIndex) {
        return newInstance(,
                new Object[] {mnew Integer(paramIndex)});
    }
        return newInstance(new Object[] {f});
    }
    private static AnnotationSpecifiedCallbacks newInstance(
            Constructor constructorObject[] constructorArgs) {
        if (null == constructor) {
            return jdk14Impl();
        } else {
            try {
                return (AnnotationSpecifiedCallbacks)
                        constructor.newInstance(constructorArgs);
            } catch (Exception shouldNeverHappen) {
                throw ExceptionUtil.unchecked(shouldNeverHappen);
            }
        }
    }
    private static AnnotationSpecifiedCallbacks jdk14Impl() {
        /*
         * This functionality is unsupported for JDK-1.4, so the
         * returned instance is simply a dummy instance.
         */
        return new AnnotationSpecifiedCallbacks() {
            protected Object asCallback(Object callbackValue) {
                return null;
            }
        };
    }
    abstract protected Object asCallback(Object callbackValue);
New to GrepCode? Check out our FAQ X