001/*
002 *  Copyright 2011 Anyware Services
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 */
016package org.ametys.cms.workflow;
017
018import java.util.LinkedHashMap;
019import java.util.Map;
020
021import org.ametys.runtime.parameter.Errors;
022
023/**
024 * Object for storing binding and validation errors.
025 */
026public class AllErrors
027{
028    private Map<String, Errors> _allErrors = new LinkedHashMap<>();
029    
030    /**
031     * Test if there is at least one error.
032     * @return <code>true</code> if there is at least one error,
033     *         <code>false</code> otherwise.
034     */
035    public boolean hasErrors()
036    {
037        return !_allErrors.isEmpty();
038    }
039    
040    /**
041     * Retrieves the errors.
042     * @return the errors.
043     */
044    public Map<String, Errors> getAllErrors()
045    {
046        return _allErrors;
047    }
048    
049    /**
050     * Add an error.
051     * @param metadataPath the metadata path or <code>null</code>
052     *        if global to the content.
053     * @param errors the errors.
054     */
055    public void addError(String metadataPath, Errors errors)
056    {
057        _allErrors.put(metadataPath, errors);
058    }
059    
060    @Override
061    public String toString()
062    {
063        return _allErrors.toString();
064    }
065}