This project has retired. For details please refer to its Attic page.
LegacyArtifactPath xref
View Javadoc
1   package org.apache.archiva.admin.model.beans;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import javax.xml.bind.annotation.XmlRootElement;
22  import java.io.Serializable;
23  
24  /**
25   * @author Olivier Lamy
26   * @since 1.4-M1
27   */
28  @XmlRootElement( name = "legacyArtifactPath" )
29  public class LegacyArtifactPath
30      implements Serializable
31  {
32      /**
33       * The legacy path.
34       */
35      private String path;
36  
37      /**
38       * The artifact reference, as " [groupId] :
39       * [artifactId] : [version] : [classifier] : [type] ".
40       */
41      private String artifact;
42  
43      private String groupId;
44  
45      private String artifactId;
46  
47      private String version;
48  
49      private String classifier;
50  
51      private String type;
52  
53      public LegacyArtifactPath()
54      {
55          // no op
56      }
57  
58      public LegacyArtifactPath( String path, String artifact )
59      {
60          this.path = path;
61  
62          this.artifact = artifact;
63          initValues( this.artifact );
64      }
65  
66      private void initValues( String artifact )
67      {
68          String[] splitted = artifact.split( ":" );
69          if ( splitted.length < 4 )
70          {
71              throw new IllegalArgumentException( "artifact value '" + artifact + "' is not correct" );
72          }
73          this.groupId = splitted[0];// artifact.split( ":" )[0];
74          this.artifactId = splitted[1];// artifact.split( ":" )[1];
75          this.version = splitted[2];// artifact.split( ":" )[2];
76          String classifier = splitted.length >= 4 ? splitted[3] : null;// artifact.split( ":" )[3];
77          this.classifier = classifier.length() > 0 ? classifier : null;
78          String type = splitted.length >= 5 ? splitted[4] : null;
79          this.type = type.length() > 0 ? artifact.split( ":" )[4] : null;
80      }
81  
82      public String getPath()
83      {
84          return path;
85      }
86  
87      public void setPath( String path )
88      {
89          this.path = path;
90      }
91  
92      public String getArtifact()
93      {
94          return artifact;
95      }
96  
97      public void setArtifact( String artifact )
98      {
99          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 }