All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deephacks.tools4j.cli.Command Maven / Gradle / Ivy

/**
 * 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.deephacks.tools4j.cli;

import static org.deephacks.tools4j.cli.Utils.validateArgs;
import static org.deephacks.tools4j.cli.Utils.validateOpts;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.PropertyException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.deephacks.tools4j.cli.Conversion.ConversionException;

/**
 * Internal representation of commands.
 */
@XmlAccessorType(XmlAccessType.FIELD)
final class Command {
    /** handle conversion of command input strings to objects */
    private static final Conversion c = Conversion.get();
    /** command alias */
    @XmlAttribute(name = "cmd")
    private String cmd;
    /** maintain the mapping between command alias and class */
    @XmlAttribute(name = "class")
    private String className;
    /** documentation of this command */
    @XmlElement(name = "doc")
    private String doc;
    /** options of this command */
    @XmlElement(name = "opt")
    private List