modula.parser.model.CustomAction.java Source code

Java tutorial

Introduction

Here is the source code for modula.parser.model.CustomAction.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 modula.parser.model;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * namespaceURI,customActionName and {@link Action}??
 */
public class CustomAction {

    /**
     * ??
     */
    private static final String ERR_NO_NAMESPACE = "Cannot define a custom Modula action with a null or empty namespace";

    /**
     * Modula??
     */
    private static final String NAMESPACE_MODULA = "http://localhost/2017/01/modula";

    /**
     * ????NAMESPACE_MODULA
     */
    private static final String ERR_RESERVED_NAMESPACE = "Cannot define a custom MODULA action within the MODULA namespace '"
            + NAMESPACE_MODULA + "'";

    /**
     * local name
     */
    private static final String ERR_NO_LOCAL_NAME = "Cannot define a custom MODULA action with a null or empty local name";

    /**
     * {@link Action}
     */
    private static final String ERR_NOT_AN_ACTION = "Custom MODULA action does not extend Action superclass";

    /**
     * ??
     */
    private String namespaceURI;

    /**
     * localName
     */
    private String localName;

    /**
     * custom action
     */
    private Class<? extends Action> actionClass;

    /**
     * @param namespaceURI
     * @param localName
     * @param actionClass  customAction
     */
    public CustomAction(final String namespaceURI, final String localName,
            final Class<? extends Action> actionClass) {
        Log log = LogFactory.getLog(CustomAction.class);
        if (namespaceURI == null || namespaceURI.trim().length() == 0) {
            log.error(ERR_NO_NAMESPACE);
            throw new IllegalArgumentException(ERR_NO_NAMESPACE);
        }
        if (namespaceURI.trim().equalsIgnoreCase(NAMESPACE_MODULA)) {
            log.error(ERR_RESERVED_NAMESPACE);
            throw new IllegalArgumentException(ERR_RESERVED_NAMESPACE);
        }
        if (localName == null || localName.trim().length() == 0) {
            log.error(ERR_NO_LOCAL_NAME);
            throw new IllegalArgumentException(ERR_NO_LOCAL_NAME);
        }
        if (actionClass == null || !Action.class.isAssignableFrom(actionClass)) {
            log.error(ERR_NOT_AN_ACTION);
            throw new IllegalArgumentException(ERR_NOT_AN_ACTION);
        }
        this.namespaceURI = namespaceURI;
        this.localName = localName;
        this.actionClass = actionClass;
    }

    /**
     * Get this custom action's implementation.
     *
     * @return Returns the action class.
     */
    public Class<? extends Action> getActionClass() {
        return actionClass;
    }

    /**
     * Get the local name for this custom action.
     *
     * @return Returns the local name.
     */
    public String getLocalName() {
        return localName;
    }

    /**
     * Get the namespace URI for this custom action.
     *
     * @return Returns the namespace URI.
     */
    public String getNamespaceURI() {
        return namespaceURI;
    }
}