001/*
002 * Copyright 2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.springframework.batch.core.jsr;
017
018import java.lang.annotation.Annotation;
019import java.util.HashMap;
020import java.util.Map;
021
022import javax.batch.api.listener.JobListener;
023
024import org.springframework.batch.core.listener.ListenerMetaData;
025
026/**
027 * Enumeration for {@link JobListener} meta data, which ties together the names
028 * of methods, their interfaces, annotation, and expected arguments.
029 *
030 * @author Michael Minella
031 * @since 3.0
032 */
033public enum JsrJobListenerMetaData implements ListenerMetaData {
034        BEFORE_JOB("beforeJob", "jsr-before-job"),
035        AFTER_JOB("afterJob", "jsr-after-job");
036
037        private final String methodName;
038        private final String propertyName;
039        private static final Map<String, JsrJobListenerMetaData> propertyMap;
040
041        JsrJobListenerMetaData(String methodName, String propertyName) {
042                this.methodName = methodName;
043                this.propertyName = propertyName;
044        }
045
046        static{
047                propertyMap = new HashMap<String, JsrJobListenerMetaData>();
048                for(JsrJobListenerMetaData metaData : values()){
049                        propertyMap.put(metaData.getPropertyName(), metaData);
050                }
051        }
052
053        @Override
054        public String getMethodName() {
055                return methodName;
056        }
057
058        @Override
059        public Class<? extends Annotation> getAnnotation() {
060                return null;
061        }
062
063        @Override
064        public Class<?> getListenerInterface() {
065                return JobListener.class;
066        }
067
068        @Override
069        public String getPropertyName() {
070                return propertyName;
071        }
072
073        @Override
074        public Class<?>[] getParamTypes() {
075                return new Class<?>[0];
076        }
077
078        /**
079         * Return the relevant meta data for the provided property name.
080         *
081         * @param propertyName the name of the property to return.
082         * @return meta data with supplied property name, null if none exists.
083         */
084        public static JsrJobListenerMetaData fromPropertyName(String propertyName){
085                return propertyMap.get(propertyName);
086        }
087}