View Javadoc
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  public class WithLicense implements Comparable<WithLicense>, ContentElement {
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, possibly 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          super();
54          this.license = license;
55          this.copyrightNotice = copyrightNotice;
56          this.parameters = Collections.unmodifiableMap(parameters);
57          this.organisations = Collections.unmodifiableCollection(organisations);
58      }
59  
60      /**
61       * Gets the copyright claim shared
62       * by the resources contained.
63       * @return possibly null
64       */
65      public String getCopyrightNotice() {
66          return this.copyrightNotice;
67      }
68  
69  
70      /**
71       * Indicates whether a copyright notice
72       * accumpianies this license.
73       * @return true when {@link #getCopyrightNotice()} is not null,
74       * false when {@link #getCopyrightNotice()} is null
75       */
76      public boolean hasCopyrightNotice() {
77          return getCopyrightNotice() != null;
78      }
79  
80      /**
81       * Gets the presentation name for the license
82       * shared by the resources contained.
83       * @return not null
84       */
85      public String getName() {
86          return this.license.getName();
87      }
88  
89      /**
90       * Gets a locator for the license
91       * shared by the resources contained.
92       * @return not null
93       */
94      public String getURL() {
95          return this.license.getURL();
96      }
97  
98      /**
99       * Gets license meta-data shared by the resources
100      * contained.
101      * @return not null
102      */
103     public License getLicense() {
104         return this.license;
105     }
106 
107     /**
108      * Gets the license legalise shared by the resources
109      * contained. Computed by applying the parameters
110      * to the license template.
111      * @return not null
112      * @throws LicenseTemplateException when the license
113      * text cannot be generated from the template
114      */
115     public String getText() throws LicenseTemplateException {
116         return this.license.getText(this.parameters);
117     }
118 
119     /**
120      * Gets resources grouped by responsible organisation.
121      * @return not null
122      */
123     public Collection<ByOrganisation> getOrganisations() {
124         return this.organisations;
125     }
126 
127     /**
128      * Gets the parameters substituted into the license
129      * template when generating the license legalise.
130      * @return not null
131      */
132     public Map<String, String> getParameters() {
133         return this.parameters;
134     }
135 
136     /**
137      * Based on license.
138      * @see java.lang.Comparable#compareTo(java.lang.Object)
139      * @param other possibly null
140      * @return license comparison
141      */
142     public int compareTo(final WithLicense other) {
143         return this.license.compareTo(other.getLicense());
144     }
145 
146     /**
147      * Accepts a visit.
148      * @param visitor possibly null
149      */
150     public void accept(final Visitor visitor) {
151         if (visitor != null && visitor.traverseWithLicense()) {
152             visitor.visit(this);
153             for (final ByOrganisation organisation : getOrganisations()) {
154                 organisation.accept(visitor);
155             }
156         }
157     }
158 
159     /**
160      * Should information about the source distribution of
161      * contained resources be included?
162      * @return true when license asks that information
163      * about the source distribution is included,
164      * false otherwise
165      */
166     public boolean isSourceRequired() {
167         return this.license.isSourceRequired();
168     }
169 }