View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.resource.repository;
17  
18  import java.io.Serializable;
19  import java.net.URL;
20  
21  import javax.annotation.concurrent.ThreadSafe;
22  
23  import de.smartics.util.lang.Arguments;
24  
25  /**
26   * An artifact identifier including a physical reference to an exemplar of the
27   * artifact.
28   */
29  @ThreadSafe
30  public final class ArtifactRef implements Serializable
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The class version identifier.
38     */
39    private static final long serialVersionUID = 1L;
40  
41    // --- members --------------------------------------------------------------
42  
43    /**
44     * The unique identifier of the artifact.
45     *
46     * @serial
47     */
48    private final ArtifactId id;
49  
50    /**
51     * The reference to the physical artifact.
52     *
53     * @serial
54     */
55    private final URL url;
56  
57    // ****************************** Initializer *******************************
58  
59    // ****************************** Constructors ******************************
60  
61    /**
62     * Default constructor.
63     *
64     * @param id the unique identifier of the artifact.
65     * @param url the reference to the physical artifact.
66     * @throws NullPointerException if {@code id} or {@code url} is
67     *           <code>null</code>.
68     */
69    public ArtifactRef(final ArtifactId id, final URL url)
70      throws NullPointerException
71    {
72      Arguments.checkNotNull("id", id);
73      Arguments.checkNotNull("url", url);
74  
75      this.id = id;
76      this.url = url;
77    }
78  
79    // ****************************** Inner Classes *****************************
80  
81    // ********************************* Methods ********************************
82  
83    // --- init -----------------------------------------------------------------
84  
85    // --- get&set --------------------------------------------------------------
86  
87    /**
88     * Returns the unique identifier of the artifact.
89     *
90     * @return the unique identifier of the artifact. Never <code>null</code>.
91     */
92    public ArtifactId getId()
93    {
94      return id;
95    }
96  
97    /**
98     * Returns the reference to the physical artifact.
99     *
100    * @return the reference to the physical artifact. Never <code>null</code>.
101    */
102   public URL getUrl()
103   {
104     return url;
105   }
106 
107   /**
108    * Checks if the referenced artifact is an archive.
109    *
110    * @return <code>true</code> if the referenced artifact is an archive,
111    *         <code>false</code> otherwise.
112    * @impl Currently only artifacts of type POM are not archives.
113    */
114   public boolean isArchive()
115   {
116     return !"pom".equals(id.getArchiveType());
117   }
118 
119   // --- business -------------------------------------------------------------
120 
121   // --- object basics --------------------------------------------------------
122 
123   /**
124    * Returns the string representation of the object.
125    *
126    * @return the string representation of the object.
127    */
128   @Override
129   public String toString()
130   {
131     final StringBuilder buffer = new StringBuilder();
132 
133     buffer.append(id).append(':').append(url);
134 
135     return buffer.toString();
136   }
137 }