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
18 /***
19 * <p>Exception to be thrown when a Rule is illegal constructed. That is, an
20 * illegal violation is created. One example of an illegal violation is when a
21 * violation is added to a rule that matches one of the packages that the rule
22 * constrins.</p>
23 *
24 * <pre>
25 * <rule id="dao">
26 * <packages>
27 * <package>com.seventytwomiles.pagerank.core.dao</package>
28 * </packages>
29 * <violations>
30 * <violation>com.seventytwomiles.pagerank.core.dao</violation>
31 * </violations>>
32 * </rule>
33 * </pre>
34 *
35 * @author mikenereson
36 * @see ArchitectureException
37 */
38 public class IllegalArchitectureRuleException extends ArchitectureException {
39
40
41 /***
42 * @see RuntimeException#RuntimeException()
43 */
44 public IllegalArchitectureRuleException() {
45 super("illegal architecture rule");
46 }
47
48
49 /***
50 * @see RuntimeException#RuntimeException(String)
51 */
52 public IllegalArchitectureRuleException(final String message) {
53 super(message);
54 }
55
56
57 /***
58 * @see RuntimeException#RuntimeException(Throwable)
59 */
60 public IllegalArchitectureRuleException(final Throwable cause) {
61 super("illegal architecture rule", cause);
62 }
63
64
65 /***
66 * @see RuntimeException#RuntimeException(String,Throwable)
67 */
68 public IllegalArchitectureRuleException(final String message,
69 final Throwable cause) {
70 super(message, cause);
71 }
72
73
74 /***
75 * <p>Instantiates a new IllegalArchitectureRuleException with the given
76 * ruleId and rulePackages.</p>
77 *
78 * @param ruleId String id of the Rule
79 * @param rulePackages String some description of the package rules, such as
80 * a delimited list
81 */
82 public IllegalArchitectureRuleException(final String ruleId,
83 final String rulePackages) {
84 this(ruleId, rulePackages, null);
85 }
86
87
88 /***
89 * <p>Instantiates a new IllegalArchitectureRuleException with the given
90 * ruleId and rulePackages, and passes on the cause.</p>
91 *
92 * @param ruleId String id of the Rule
93 * @param rulePackages String some description of the package rules, such as
94 * a delimited list
95 * @param cause Throwable root cause
96 */
97 public IllegalArchitectureRuleException(final String ruleId,
98 final String rulePackages,
99 final Throwable cause) {
100
101 super("rule '{id}' contains an invalid violation that refers to itself; remove violation '{violation}' or change package"
102 .replaceAll("//{id}", ruleId)
103 .replaceAll("//{violation}", rulePackages.trim())
104 .replaceAll("//[", "")
105 .replaceAll("//]", ""),
106 cause);
107 }
108 }