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.domain;
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.Arg;
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      this.id = Arg.checkNotNull("id", id);
73      this.url = Arg.checkNotNull("url", url);
74    }
75  
76    // ****************************** Inner Classes *****************************
77  
78    // ********************************* Methods ********************************
79  
80    // --- init -----------------------------------------------------------------
81  
82    // --- get&set --------------------------------------------------------------
83  
84    /**
85     * Returns the unique identifier of the artifact.
86     *
87     * @return the unique identifier of the artifact. Never <code>null</code>.
88     */
89    public ArtifactId getId()
90    {
91      return id;
92    }
93  
94    /**
95     * Returns the reference to the physical artifact.
96     *
97     * @return the reference to the physical artifact. Never <code>null</code>.
98     */
99    public URL getUrl()
100   {
101     return url;
102   }
103 
104   /**
105    * Checks if the referenced artifact is an archive.
106    *
107    * @return <code>true</code> if the referenced artifact is an archive,
108    *         <code>false</code> otherwise.
109    * @impl Currently only artifacts of type POM are not archives.
110    */
111   public boolean isArchive()
112   {
113     return !"pom".equals(id.getArchiveType());
114   }
115 
116   // --- business -------------------------------------------------------------
117 
118   // --- object basics --------------------------------------------------------
119 
120   /**
121    * Returns the string representation of the object.
122    *
123    * @return the string representation of the object.
124    */
125   @Override
126   public String toString()
127   {
128     final StringBuilder buffer = new StringBuilder();
129 
130     buffer.append(id).append(':').append(url);
131 
132     return buffer.toString();
133   }
134 }