This project has retired. For details please refer to its Attic page.
ArchivaModelCloner xref
View Javadoc
1   package org.apache.archiva.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Enumeration;
24  import java.util.List;
25  import java.util.Properties;
26  
27  /**
28   * Utility methods for cloning various Archiva Model objects.
29   *
30   *
31   */
32  public class ArchivaModelCloner
33  {
34  
35      public static ArtifactReference/../org/apache/archiva/model/ArtifactReference.html#ArtifactReference">ArtifactReference clone( ArtifactReference artifactReference )
36      {
37          if ( artifactReference == null )
38          {
39              return null;
40          }
41  
42          ArtifactReferencence.html#ArtifactReference">ArtifactReference cloned = new ArtifactReference();
43  
44          cloned.setGroupId( artifactReference.getGroupId() );
45          cloned.setArtifactId( artifactReference.getArtifactId() );
46          cloned.setVersion( artifactReference.getVersion() );
47          cloned.setClassifier( artifactReference.getClassifier() );
48          cloned.setType( artifactReference.getType() );
49  
50          return cloned;
51      }
52  
53      @SuppressWarnings( "unchecked" )
54      public static Properties clone( Properties properties )
55      {
56          if ( properties == null )
57          {
58              return null;
59          }
60  
61          Properties cloned = new Properties();
62  
63          Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
64          while ( keys.hasMoreElements() )
65          {
66              String key = (String) keys.nextElement();
67              String value = properties.getProperty( key );
68              cloned.setProperty( key, value );
69          }
70  
71          return cloned;
72      }
73  
74      public static SnapshotVersion../../org/apache/archiva/model/SnapshotVersion.html#SnapshotVersion">SnapshotVersion clone( SnapshotVersion snapshotVersion )
75      {
76          if ( snapshotVersion == null )
77          {
78              return null;
79          }
80  
81          SnapshotVersionion.html#SnapshotVersion">SnapshotVersion cloned = new SnapshotVersion();
82  
83          cloned.setTimestamp( snapshotVersion.getTimestamp() );
84          cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
85  
86          return cloned;
87      }
88  
89      public static VersionedReference../org/apache/archiva/model/VersionedReference.html#VersionedReference">VersionedReference clone( VersionedReference versionedReference )
90      {
91          if ( versionedReference == null )
92          {
93              return null;
94          }
95  
96          VersionedReferencence.html#VersionedReference">VersionedReference cloned = new VersionedReference();
97  
98          cloned.setGroupId( versionedReference.getGroupId() );
99          cloned.setArtifactId( versionedReference.getArtifactId() );
100         cloned.setVersion( versionedReference.getVersion() );
101 
102         return cloned;
103     }
104 
105     public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList )
106     {
107         if ( artifactReferenceList == null )
108         {
109             return null;
110         }
111 
112         List<ArtifactReference> ret = new ArrayList<>( artifactReferenceList.size() );
113 
114         for ( ArtifactReference ref : artifactReferenceList )
115         {
116             ret.add( clone( ref ) );
117         }
118 
119         return ret;
120     }
121 
122     private static List<String> cloneSimpleStringList( List<String> simple )
123     {
124         if ( simple == null )
125         {
126             return null;
127         }
128 
129         List<String> ret = new ArrayList<>( simple.size() );
130 
131         for ( String txt : simple )
132         {
133             ret.add( txt );
134         }
135 
136         return ret;
137     }
138 
139     public static List<String> cloneAvailableVersions( List<String> availableVersions )
140     {
141         return cloneSimpleStringList( availableVersions );
142     }
143 }