1 /***
2 * Copyright 2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * For more information visit
11 * http://72miles.com and
12 * http://architecturerules.googlecode.com/svn/docs/index.html
13 */
14
15 package com.seventytwomiles.architecturerules.exceptions;
16
17 import java.util.HashMap;
18 import java.util.Map;
19 import java.util.Set;
20
21
22 /***
23 * <p>Thrown to indicate that a cyclic redundancy was found.</p>
24 *
25 * @author mikenereson
26 * @see ArchitectureException
27 */
28 public class CyclicRedundancyException extends ArchitectureException {
29
30 /***
31 * <p>Holds the cycles by package name. The Map key is the full package and
32 * the key is a Set of packages that are involved in the cycle.</p>
33 */
34 protected Map<String, Set<String>> cycles = new HashMap<String, Set<String>>();
35
36
37 /***
38 * @see RuntimeException#RuntimeException()
39 */
40 public CyclicRedundancyException() {
41 super("cyclic redundancy");
42 }
43
44
45 /***
46 * @see RuntimeException#RuntimeException(String)
47 */
48 public CyclicRedundancyException(final String message) {
49 super(message);
50 }
51
52
53 /***
54 * @see RuntimeException#RuntimeException(Throwable)
55 */
56 public CyclicRedundancyException(final Throwable cause) {
57 super("cyclic redundancy", cause);
58 }
59
60
61 /***
62 * @see RuntimeException#RuntimeException(String,Throwable)
63 */
64 public CyclicRedundancyException(final String message,
65 final Throwable cause) {
66 super(message, cause);
67 }
68
69
70 /***
71 * <p>Constructs a new CyclicRedundancyException with a generated message
72 * containing the given <tt>packageName</tt> and <tt>efferentPackage</tt>.</p>
73 *
74 * @param packageName String the name of the package containing the
75 * cyclic dependency
76 * @param efferentPackage String the name of the package the package is
77 * cyclically involved with.
78 */
79 public CyclicRedundancyException(final String packageName,
80 final String efferentPackage) {
81
82 super("'{0}' is involved in an cyclically redundant dependency with '{1}'"
83 .replaceAll("//{0}", packageName)
84 .replaceAll("//{1}", efferentPackage));
85 }
86
87 public Map<String, Set<String>> getCycles() {
88 return this.cycles;
89 }
90 }