001/*
002 * (C) Copyright 2018 Nuxeo SA (http://nuxeo.com/) and others.
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 *     http://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 *
016 * Contributors:
017 *     Luís Duarte <lduarte@nuxeo.com>
018 *     Florent Guillaume <fguillaume@nuxeo.com>
019 *
020 */
021package org.nuxeo.ecm.automation.server.jaxrs.batch.handler;
022
023import java.util.HashMap;
024import java.util.Map;
025
026import org.nuxeo.common.xmap.annotation.XNode;
027import org.nuxeo.common.xmap.annotation.XNodeMap;
028import org.nuxeo.common.xmap.annotation.XObject;
029import org.nuxeo.ecm.automation.server.jaxrs.batch.BatchHandler;
030import org.nuxeo.ecm.core.api.NuxeoException;
031
032/**
033 * BatchHandler Descriptor
034 *
035 * @since 10.1
036 */
037@XObject("batchHandler")
038public class BatchHandlerDescriptor {
039
040    @XNode("name")
041    protected String name;
042
043    @XNode("class")
044    protected Class<? extends BatchHandler> klass;
045
046    @XNodeMap(value = "property", key = "@name", type = HashMap.class, componentType = String.class)
047    protected Map<String, String> properties;
048
049    public void setName(String name) {
050        this.name = name;
051    }
052
053    public void setKlass(Class<? extends BatchHandler> klass) {
054        this.klass = klass;
055    }
056
057    public void setProperties(Map<String, String> properties) {
058        this.properties = properties;
059    }
060
061    public String getName() {
062        return name;
063    }
064
065    public Class<? extends BatchHandler> getKlass() {
066        return klass;
067    }
068
069    public BatchHandler newInstance() {
070        try {
071            return klass.getConstructor().newInstance();
072        } catch (ReflectiveOperationException e) {
073            throw new NuxeoException(e);
074        }
075    }
076
077    public Map<String, String> getProperties() {
078        return properties;
079    }
080
081}