Java tutorial
/******************************************************************************* * 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.controller.exception.impl; import java.lang.reflect.Array; import java.text.MessageFormat; import java.util.Locale; import net.navasoft.madcoin.backend.HardCodedConstants; import net.navasoft.madcoin.backend.services.controller.exception.AllowedExceptionMessage; import net.navasoft.madcoin.backend.services.controller.exception.ControllerException; import org.apache.commons.lang.ArrayUtils; import org.springframework.context.MessageSource; /** * net.navasoft.madcoin.backend.services.controller.exception.impl Class class * BusinessControllerException. Description: * * @author Juan Diego Navarre Gonzalez - (${authorMail}) * @version 1.0 * @since 24/08/2014 07:46:29 PM */ public class BusinessControllerException extends ControllerException implements HardCodedConstants { /** * Constant serialVersionUID. * * @since 28/07/2014, 11:34:20 PM */ private static final long serialVersionUID = 1L; private Object[] reasonsToFail; private String locatedMessage; private Locale language; /** * Instantiates a new session * net.navasoft.madcoin.backend.model.controller.impl exception. * * @param exceptionMessages * the exception messages * @param injected * the injected * @param key * the key * @param parameters * the parameters * @since 28/07/2014, 11:34:20 PM */ public BusinessControllerException(final MessageSource exceptionMessages, final Locale injected, final AllowedExceptionMessage key, Object... parameters) { super(exceptionMessages.getMessage(key.getPropertyKey(), literal(parameters), injected)); locatedMessage = key.getPropertyKey(); language = injected; if (parameters != null) { reasonsToFail = (Object[]) Array.newInstance(Object.class, 0); for (Object param : parameters) { reasonsToFail = ArrayUtils.add(reasonsToFail, param); } } } /** * Gets the causes. * * @return the causes * @since 24/08/2014, 07:46:29 PM */ @Override public Object[] getCauses() { return reasonsToFail; } /** * Formulate tips. * * @return the string[] * @since 24/08/2014, 07:46:29 PM */ @Override public String[] formulateTips() { String[] finalTips = (String[]) Array.newInstance(String.class, 0); if (allowedTipsQuantity != -1) { for (int availableTip = 1; availableTip < allowedTipsQuantity + 1; availableTip++) { finalTips = (String[]) ArrayUtils.add(finalTips, tips.getMessage(MessageFormat.format(locatedMessage + tipSuffix, availableTip), new Object[] { availableTip }, "", language)); } } // Add the filter chain or REGEXP case handling, if applies. return finalTips; } }