001package org.apache.archiva.admin.model.beans; 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021import javax.xml.bind.annotation.XmlRootElement; 022import java.io.Serializable; 023 024/** 025 * @author Olivier Lamy 026 * @since 1.4-M1 027 */ 028@XmlRootElement( name = "legacyArtifactPath" ) 029public class LegacyArtifactPath 030 implements Serializable 031{ 032 /** 033 * The legacy path. 034 */ 035 private String path; 036 037 /** 038 * The artifact reference, as " [groupId] : 039 * [artifactId] : [version] : [classifier] : [type] ". 040 */ 041 private String artifact; 042 043 private String groupId; 044 045 private String artifactId; 046 047 private String version; 048 049 private String classifier; 050 051 private String type; 052 053 public LegacyArtifactPath() 054 { 055 // no op 056 } 057 058 public LegacyArtifactPath( String path, String artifact ) 059 { 060 this.path = path; 061 062 this.artifact = artifact; 063 initValues( this.artifact ); 064 } 065 066 private void initValues( String artifact ) 067 { 068 String[] splitted = artifact.split( ":" ); 069 if ( splitted.length < 4 ) 070 { 071 throw new IllegalArgumentException( "artifact value '" + artifact + "' is not correct" ); 072 } 073 this.groupId = splitted[0];// artifact.split( ":" )[0]; 074 this.artifactId = splitted[1];// artifact.split( ":" )[1]; 075 this.version = splitted[2];// artifact.split( ":" )[2]; 076 String classifier = splitted.length >= 4 ? splitted[3] : null;// artifact.split( ":" )[3]; 077 this.classifier = classifier.length() > 0 ? classifier : null; 078 String type = splitted.length >= 5 ? splitted[4] : null; 079 this.type = type.length() > 0 ? artifact.split( ":" )[4] : null; 080 } 081 082 public String getPath() 083 { 084 return path; 085 } 086 087 public void setPath( String path ) 088 { 089 this.path = path; 090 } 091 092 public String getArtifact() 093 { 094 return artifact; 095 } 096 097 public void setArtifact( String artifact ) 098 { 099 this.artifact = artifact; 100 initValues( this.artifact ); 101 } 102 103 public boolean match( String path ) 104 { 105 return path.equals( this.path ); 106 } 107 108 public void setGroupId( String groupId ) 109 { 110 this.groupId = groupId; 111 } 112 113 public String getGroupId() 114 { 115 return this.groupId;// artifact.split( ":" )[0]; 116 } 117 118 119 public String getArtifactId() 120 { 121 return this.artifactId;// artifact.split( ":" )[1]; 122 } 123 124 public void setArtifactId( String artifactId ) 125 { 126 this.artifactId = artifactId; 127 } 128 129 public String getVersion() 130 { 131 return this.version;// artifact.split( ":" )[2]; 132 } 133 134 public String getClassifier() 135 { 136 //String classifier = artifact.split( ":" )[3]; 137 //return classifier.length() > 0 ? classifier : null; 138 return this.classifier; 139 } 140 141 public String getType() 142 { 143 return this.type;// artifact.split( ":" )[4]; 144 } 145 146 @Override 147 public boolean equals( Object o ) 148 { 149 if ( this == o ) 150 { 151 return true; 152 } 153 if ( o == null || getClass() != o.getClass() ) 154 { 155 return false; 156 } 157 158 LegacyArtifactPath that = (LegacyArtifactPath) o; 159 160 if ( path != null ? !path.equals( that.path ) : that.path != null ) 161 { 162 return false; 163 } 164 165 return true; 166 } 167 168 @Override 169 public int hashCode() 170 { 171 return path != null ? 37 + path.hashCode() : 0; 172 } 173 174 @Override 175 public String toString() 176 { 177 final StringBuilder sb = new StringBuilder(); 178 sb.append( "LegacyArtifactPath" ); 179 sb.append( "{path='" ).append( path ).append( '\'' ); 180 sb.append( ", artifact='" ).append( artifact ).append( '\'' ); 181 sb.append( ", groupId='" ).append( groupId ).append( '\'' ); 182 sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); 183 sb.append( ", version='" ).append( version ).append( '\'' ); 184 sb.append( ", classifier='" ).append( classifier ).append( '\'' ); 185 sb.append( ", type='" ).append( type ).append( '\'' ); 186 sb.append( '}' ); 187 return sb.toString(); 188 } 189}