net.navasoft.madcoin.backend.services.vo.response.impl.AuthenticationFailedResponseVO.java Source code

Java tutorial

Introduction

Here is the source code for net.navasoft.madcoin.backend.services.vo.response.impl.AuthenticationFailedResponseVO.java

Source

/*******************************************************************************
 * Copyright 2014 Juan Diego Navarre Gonzalez
 * 
 * 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 net.navasoft.madcoin.backend.services.vo.response.impl;

import java.lang.reflect.Array;

import net.navasoft.madcoin.backend.JsonAllowedUserTypes;
import net.navasoft.madcoin.backend.UserTypes;
import net.navasoft.madcoin.backend.services.vo.response.FailedResponseVO;

import org.apache.commons.lang.ArrayUtils;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;

/**
 * net.navasoft.madcoin.backend.services.vo.response.impl Class class
 * AuthenticationFailedResponseVO. Description:
 * 
 * @author Juan Diego Navarre Gonzalez - (<a
 *         href="mailto:jdnavarreg@outlook.com">{@literal jdnavarreg@outlook.com}
 *         </a>)
 * @version 1.0
 * @since 28/07/2014 10:51:01 PM
 */
public class AuthenticationFailedResponseVO implements FailedResponseVO {

    /**
     * message.
     * 
     * @since 28/07/2014, 10:51:01 PM
     */
    @JsonProperty
    private String message;

    /**
     * failed user.
     * 
     * @since 28/07/2014, 10:51:01 PM
     */
    @JsonProperty
    private String failedUser;

    /**
     * failed user type.
     * 
     * @since 28/07/2014, 10:51:01 PM
     */
    @JsonProperty
    private JsonAllowedUserTypes failedUserType;

    /**
     * additional message.
     * 
     * @since 28/07/2014, 10:51:01 PM
     */
    @JsonProperty
    private String[] additionalMessage;

    /**
     * tip.
     * 
     * @since 28/07/2014, 10:51:01 PM
     */
    @JsonProperty
    private String tip[];

    /**
     * Sets the error message.
     * 
     * @param errorMessage
     *            the new error message
     * @since 28/07/2014, 10:51:01 PM
     */
    @Override
    public void setErrorMessage(String errorMessage) {
        message = errorMessage;
    }

    /**
     * Sets the causes.
     * 
     * @param reasons
     *            the new causes
     * @since 28/07/2014, 10:51:01 PM
     */
    @Override
    public void setCauses(Object... reasons) {
        for (Object reason : reasons) {
            if (reason instanceof String) {
                failedUser = ((String) reason);
            } else if (reason instanceof UserTypes) {
                failedUserType = ((UserTypes) reason).getExternalValue();
            } else if (reason instanceof Integer) {
            } else {
                additionalMessage = ((String[]) reason);
            }
        }
    }

    /**
     * Sets the tip.
     * 
     * @param tips
     *            the new tip
     * @since 28/07/2014, 10:51:01 PM
     */
    @Override
    public void setTip(String... tips) {
        tip = tips;
    }

    /**
     * Gets the error message.
     * 
     * @return the error message
     * @since 28/07/2014, 10:51:01 PM
     */
    @Override
    @JsonIgnore
    public String getErrorMessage() {
        return message;
    }

    /**
     * Gets the causes.
     * 
     * @return the causes
     * @since 28/07/2014, 10:51:01 PM
     */
    @Override
    @JsonIgnore
    public Object[] getCauses() {
        Object[] causes = (Object[]) Array.newInstance(Object.class, 0);
        causes = ArrayUtils.add(causes, failedUser);
        causes = ArrayUtils.add(causes, failedUserType);
        causes = ArrayUtils.add(causes, additionalMessage);
        return causes;
    }

    /**
     * Gets the tip.
     * 
     * @return the tip
     * @since 28/07/2014, 10:51:01 PM
     */
    @Override
    public String[] getTip() {
        return tip;
    }

}