View Javadoc
1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.project.model;
17  
18  import org.kuali.common.util.Assert;
19  import org.kuali.common.util.ObjectUtils;
20  import org.kuali.common.util.identify.Identifiable;
21  
22  /**
23   * The project identifier concept is based on two facts:
24   * 
25   * <p>
26   * 1 - All Kuali projects produce only one artifact containing executable java code and associated resources.<br>
27   * 2 - There is only one version of any given Kuali project in the java classpath.<br>
28   * </p>
29   * 
30   * <p>
31   * Thus, groupId + artifactId is a simple way to uniquely namespace project resources at runtime.
32   * 
33   * For example, files residing in the kuali-util project at the following locations:
34   * 
35   * <pre>
36   *   src/main/resources/org/kuali/common/kuali-util/foo.txt
37   *   src/main/resources/org/kuali/common/kuali-util/bar.txt
38   * </pre>
39   * 
40   * Can be uniquely referenced at runtime as:
41   * 
42   * <pre>
43   *   classpath:org/kuali/common/kuali-util/foo.txt
44   *   classpath:org/kuali/common/kuali-util/bar.txt
45   * </pre>
46   * 
47   * </p>
48   */
49  public final class ProjectIdentifier implements Identifiable {
50  
51  	private final String groupId;
52  	private final String artifactId;
53  
54  	private final String identifier;
55  	private final int hashCode;
56  
57  	public ProjectIdentifier(String groupId, String artifactId) {
58  		// Make sure we are being configured correctly
59  		Assert.noBlanks(groupId, artifactId);
60  
61  		// Finish setting things up
62  		this.groupId = groupId;
63  		this.artifactId = artifactId;
64  		this.identifier = groupId + ":" + artifactId;
65  		this.hashCode = identifier.hashCode();
66  	}
67  
68  	public String getGroupId() {
69  		return this.groupId;
70  	}
71  
72  	public String getArtifactId() {
73  		return this.artifactId;
74  	}
75  
76  	@Override
77  	public String getIdentifier() {
78  		return identifier;
79  	}
80  
81  	@Override
82  	public String toString() {
83  		return identifier;
84  	}
85  
86  	@Override
87  	public int hashCode() {
88  		return hashCode;
89  	}
90  
91  	@Override
92  	public boolean equals(Object object) {
93  		return ObjectUtils.equalsByToString(this, object);
94  	}
95  
96  }