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.configuration.xml;
017
018import java.util.ArrayList;
019import java.util.Collections;
020import java.util.List;
021
022import javax.batch.api.listener.JobListener;
023
024import org.springframework.batch.core.JobExecutionListener;
025import org.springframework.batch.core.jsr.JsrJobListenerMetaData;
026import org.springframework.batch.core.listener.JobListenerMetaData;
027import org.springframework.batch.core.listener.ListenerMetaData;
028import org.springframework.beans.factory.FactoryBean;
029
030/**
031 * This {@link FactoryBean} is used by the JSR-352 namespace parser to create
032 * {@link JobExecutionListener} objects.
033 * 
034 * @author Michael Minella
035 * @since 3.0
036 */
037public class JsrJobListenerFactoryBean extends org.springframework.batch.core.listener.JobListenerFactoryBean {
038
039        @Override
040        public Class<?> getObjectType() {
041                return JobListener.class;
042        }
043
044        @Override
045        protected ListenerMetaData[] getMetaDataValues() {
046                List<ListenerMetaData> values = new ArrayList<ListenerMetaData>();
047                Collections.addAll(values, JobListenerMetaData.values());
048                Collections.addAll(values, JsrJobListenerMetaData.values());
049
050                return values.toArray(new ListenerMetaData[0]);
051        }
052
053        @Override
054        protected ListenerMetaData getMetaDataFromPropertyName(String propertyName) {
055                ListenerMetaData result = JobListenerMetaData.fromPropertyName(propertyName);
056
057                if(result == null) {
058                        result = JsrJobListenerMetaData.fromPropertyName(propertyName);
059                }
060
061                return result;
062        }
063}