001/**
002 * Copyright 2010-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.project.model;
017
018import org.kuali.common.util.Assert;
019import org.kuali.common.util.ObjectUtils;
020import org.kuali.common.util.identify.Identifiable;
021
022/**
023 * The project identifier concept is based on two facts:
024 * 
025 * <p>
026 * 1 - All Kuali projects produce only one artifact containing executable java code and associated resources.<br>
027 * 2 - There is only one version of any given Kuali project in the java classpath.<br>
028 * </p>
029 * 
030 * <p>
031 * Thus, groupId + artifactId is a simple way to uniquely namespace project resources at runtime.
032 * 
033 * For example, files residing in the kuali-util project at the following locations:
034 * 
035 * <pre>
036 *   src/main/resources/org/kuali/common/kuali-util/foo.txt
037 *   src/main/resources/org/kuali/common/kuali-util/bar.txt
038 * </pre>
039 * 
040 * Can be uniquely referenced at runtime as:
041 * 
042 * <pre>
043 *   classpath:org/kuali/common/kuali-util/foo.txt
044 *   classpath:org/kuali/common/kuali-util/bar.txt
045 * </pre>
046 * 
047 * </p>
048 */
049public final class ProjectIdentifier implements Identifiable {
050
051        private final String groupId;
052        private final String artifactId;
053
054        private final String identifier;
055        private final int hashCode;
056
057        public ProjectIdentifier(String groupId, String artifactId) {
058                // Make sure we are being configured correctly
059                Assert.noBlanks(groupId, artifactId);
060
061                // Finish setting things up
062                this.groupId = groupId;
063                this.artifactId = artifactId;
064                this.identifier = groupId + ":" + artifactId;
065                this.hashCode = identifier.hashCode();
066        }
067
068        public String getGroupId() {
069                return this.groupId;
070        }
071
072        public String getArtifactId() {
073                return this.artifactId;
074        }
075
076        @Override
077        public String getIdentifier() {
078                return identifier;
079        }
080
081        @Override
082        public String toString() {
083                return identifier;
084        }
085
086        @Override
087        public int hashCode() {
088                return hashCode;
089        }
090
091        @Override
092        public boolean equals(Object object) {
093                return ObjectUtils.equalsByToString(this, object);
094        }
095
096}