Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WithLicense |
|
| 1.2727272727272727;1.273 |
1 | /** | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.apache.creadur.whisker.model; | |
20 | ||
21 | import java.util.Collection; | |
22 | import java.util.Collections; | |
23 | import java.util.Map; | |
24 | ||
25 | /** | |
26 | * Groups resources sharing a license and claimed copyright. | |
27 | */ | |
28 | 0 | public class WithLicense implements Comparable<WithLicense> { |
29 | ||
30 | /** License shared by contained resources, not null. */ | |
31 | private final License license; | |
32 | /** Resources grouped by responsible organisation. */ | |
33 | private final Collection<ByOrganisation> organisations; | |
34 | /** Copyright claim shared by contained resources. */ | |
35 | private final String copyrightNotice; | |
36 | /** Parameters to specialise the license family template. */ | |
37 | private final Map<String, String> parameters; | |
38 | ||
39 | /** | |
40 | * Groups resources sharing a license and copyright claim. | |
41 | * @param license License shared by contained resources, | |
42 | * not null | |
43 | * @param copyrightNotice copyright claim | |
44 | * shared by contained resources, not null | |
45 | * @param parameters parameters to specialise | |
46 | * the license family template, not null | |
47 | * @param organisations resources grouped by | |
48 | * responsible organisation, not null | |
49 | */ | |
50 | public WithLicense(final License license, final String copyrightNotice, | |
51 | final Map<String, String> parameters, | |
52 | final Collection<ByOrganisation> organisations) { | |
53 | 8 | super(); |
54 | 8 | this.license = license; |
55 | 8 | this.copyrightNotice = copyrightNotice; |
56 | 8 | this.parameters = Collections.unmodifiableMap(parameters); |
57 | 8 | this.organisations = Collections.unmodifiableCollection(organisations); |
58 | 8 | } |
59 | ||
60 | /** | |
61 | * Gets the copyright claim shared | |
62 | * by the resources contained. | |
63 | * @return not null | |
64 | */ | |
65 | public String getCopyrightNotice() { | |
66 | 0 | return this.copyrightNotice; |
67 | } | |
68 | ||
69 | /** | |
70 | * Gets the presentation name for the license | |
71 | * shared by the resources contained. | |
72 | * @return not null | |
73 | */ | |
74 | public String getName() { | |
75 | 0 | return this.license.getName(); |
76 | } | |
77 | ||
78 | /** | |
79 | * Gets a locator for the license | |
80 | * shared by the resources contained. | |
81 | * @return not null | |
82 | */ | |
83 | public String getURL() { | |
84 | 0 | return this.license.getURL(); |
85 | } | |
86 | ||
87 | /** | |
88 | * Gets license meta-data shared by the resources | |
89 | * contained. | |
90 | * @return not null | |
91 | */ | |
92 | public License getLicense() { | |
93 | 3 | return this.license; |
94 | } | |
95 | ||
96 | /** | |
97 | * Gets the license legalise shared by the resources | |
98 | * contained. Computed by applying the parameters | |
99 | * to the license template. | |
100 | * @return not null | |
101 | * @throws LicenseTemplateException when the license | |
102 | * text cannot be generated from the template | |
103 | */ | |
104 | public String getText() throws LicenseTemplateException { | |
105 | 0 | return this.license.getText(this.parameters); |
106 | } | |
107 | ||
108 | /** | |
109 | * Gets resources grouped by responsible organisation. | |
110 | * @return not null | |
111 | */ | |
112 | public Collection<ByOrganisation> getOrganisations() { | |
113 | 6 | return this.organisations; |
114 | } | |
115 | ||
116 | /** | |
117 | * Gets the parameters substituted into the license | |
118 | * template when generating the license legalise. | |
119 | * @return not null | |
120 | */ | |
121 | public Map<String, String> getParameters() { | |
122 | 0 | return this.parameters; |
123 | } | |
124 | ||
125 | /** | |
126 | * Based on license. | |
127 | * @see java.lang.Comparable#compareTo(java.lang.Object) | |
128 | * @param other possibly null | |
129 | * @return license comparison | |
130 | */ | |
131 | public int compareTo(final WithLicense other) { | |
132 | 0 | return this.license.compareTo(other.getLicense()); |
133 | } | |
134 | ||
135 | /** | |
136 | * Accepts a visit. | |
137 | * @param visitor possibly null | |
138 | */ | |
139 | public void accept(final Visitor visitor) { | |
140 | 6 | if (visitor != null && visitor.traverseWithLicense()) { |
141 | 6 | visitor.visit(this); |
142 | 6 | for (final ByOrganisation organisation : getOrganisations()) { |
143 | 6 | organisation.accept(visitor); |
144 | } | |
145 | } | |
146 | 6 | } |
147 | ||
148 | /** | |
149 | * Should information about the source distribution of | |
150 | * contained resources be included? | |
151 | * @return true when license asks that information | |
152 | * about the source distribution is included, | |
153 | * false otherwise | |
154 | */ | |
155 | public boolean isSourceRequired() { | |
156 | 0 | return this.license.isSourceRequired(); |
157 | } | |
158 | } |