Added response data to operational datastore, refactored data validation
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / ValidationException.java
1 /*
2  * Copyright (c) 2015 CableLabs and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.packetcable.provider.validation;
10
11 import static com.google.common.base.Preconditions.checkNotNull;
12
13 import com.google.common.collect.ImmutableList;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.Iterator;
17
18 /**
19  * @author rvail
20  */
21 public class ValidationException extends Exception {
22
23     private final ImmutableList<String> errorMessages;
24
25     public ValidationException(final String... errorMessages) {
26         super(concat(Arrays.asList(errorMessages)));
27         this.errorMessages = ImmutableList.copyOf(errorMessages);
28     }
29
30     private static String concat(Collection<String> strings) {
31         checkNotNull(strings);
32
33         final Iterator<String> iter = strings.iterator();
34         if (!iter.hasNext()) {
35             return "";
36         }
37
38         StringBuilder sb = new StringBuilder(iter.next());
39         while (iter.hasNext()) {
40             sb.append(" : ").append(iter.next());
41         }
42
43         return sb.toString();
44     }
45
46     public ValidationException(final Collection<String> errorMessages) {
47         super(concat(errorMessages));
48         this.errorMessages = ImmutableList.copyOf(errorMessages);
49     }
50
51     public ImmutableList<String> getErrorMessages() {
52         return errorMessages;
53     }
54 }