001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.plugin;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.util.CollectionFactory;
025: import com.liferay.util.Version;
026:
027: import java.util.Map;
028: import java.util.StringTokenizer;
029:
030: /**
031: * <a href="ModuleId.java.html"><b><i>View Source</i></b></a>
032: *
033: * @author Jorge Ferrer
034: *
035: */
036: public class ModuleId {
037:
038: public static ModuleId getInstance(String moduleId) {
039: ModuleId moduleIdObj = (ModuleId) _moduleIds.get(moduleId);
040:
041: if (moduleIdObj == null) {
042: moduleIdObj = new ModuleId(moduleId);
043:
044: _moduleIds.put(moduleId, moduleIdObj);
045: }
046:
047: return moduleIdObj;
048: }
049:
050: public static String toString(String groupId, String artifactId,
051: String version, String type) {
052:
053: return groupId + StringPool.SLASH + artifactId
054: + StringPool.SLASH + version + StringPool.SLASH + type;
055: }
056:
057: public String getGroupId() {
058: return _groupId;
059: }
060:
061: public String getArtifactId() {
062: return _artifactId;
063: }
064:
065: public String getPackageId() {
066: return _groupId + StringPool.SLASH + _artifactId;
067: }
068:
069: public String getVersion() {
070: return _pluginVersion.toString();
071: }
072:
073: public String getType() {
074: return _type;
075: }
076:
077: public String getArtifactPath() {
078: return StringPool.SLASH + _groupId + StringPool.SLASH
079: + _artifactId + StringPool.SLASH + _pluginVersion
080: + StringPool.SLASH + getArtifactWARName();
081: }
082:
083: public String getArtifactWARName() {
084: return _artifactId + StringPool.DASH + _pluginVersion
085: + StringPool.PERIOD + _type;
086: }
087:
088: public boolean isLaterVersionThan(String version) {
089: return _pluginVersion.isLaterVersionThan(version);
090: }
091:
092: public boolean isPreviousVersionThan(String version) {
093: return _pluginVersion.isPreviousVersionThan(version);
094: }
095:
096: public boolean isSameVersionAs(String version) {
097: return _pluginVersion.isSameVersionAs(version);
098: }
099:
100: public boolean equals(Object obj) {
101: if (!(obj instanceof ModuleId)) {
102: return false;
103: }
104:
105: ModuleId moduleId = (ModuleId) obj;
106:
107: return toString().equals(moduleId.toString());
108: }
109:
110: public int hashCode() {
111: return toString().hashCode();
112: }
113:
114: public String toString() {
115: return toString(_groupId, _artifactId, _pluginVersion
116: .toString(), _type);
117: }
118:
119: protected ModuleId(String groupId, String artifactId,
120: Version pluginVersion, String type) {
121:
122: _groupId = groupId;
123: _artifactId = artifactId;
124: _pluginVersion = pluginVersion;
125: _type = type;
126: }
127:
128: protected ModuleId(String moduleId) {
129: StringTokenizer st = new StringTokenizer(moduleId,
130: StringPool.SLASH);
131:
132: if (st.countTokens() < 4) {
133: throw new RuntimeException("The moduleId " + moduleId
134: + " is not correct");
135: }
136:
137: _groupId = st.nextToken();
138: _artifactId = st.nextToken();
139: _pluginVersion = Version.getInstance(st.nextToken());
140: _type = st.nextToken();
141: }
142:
143: private static Map _moduleIds = CollectionFactory.getSyncHashMap();
144:
145: private String _artifactId;
146: private String _groupId;
147: private Version _pluginVersion;
148: private String _type;
149:
150: }
|