]> git.argeo.org Git - gpl/argeo-jcr.git/blob - DefaultMetadata.java
aa9c830558c186c3cb1197281f1ab378ec3b3ff3
[gpl/argeo-jcr.git] / DefaultMetadata.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2012 Sonatype, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.aether.metadata;
12
13 import java.io.File;
14 import java.util.Map;
15
16 /**
17 * A basic metadata instance. <em>Note:</em> Instances of this class are immutable and the exposed mutators return new
18 * objects rather than changing the current instance.
19 */
20 public final class DefaultMetadata
21 extends AbstractMetadata
22 {
23
24 private final String groupId;
25
26 private final String artifactId;
27
28 private final String version;
29
30 private final String type;
31
32 private final Nature nature;
33
34 private final File file;
35
36 private final Map<String, String> properties;
37
38 /**
39 * Creates a new metadata for the repository root with the specific type and nature.
40 *
41 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}.
42 * @param nature The nature of the metadata, must not be {@code null}.
43 */
44 public DefaultMetadata( String type, Nature nature )
45 {
46 this( "", "", "", type, nature, null, (File) null );
47 }
48
49 /**
50 * Creates a new metadata for the groupId level with the specific type and nature.
51 *
52 * @param groupId The group identifier to which this metadata applies, may be {@code null}.
53 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}.
54 * @param nature The nature of the metadata, must not be {@code null}.
55 */
56 public DefaultMetadata( String groupId, String type, Nature nature )
57 {
58 this( groupId, "", "", type, nature, null, (File) null );
59 }
60
61 /**
62 * Creates a new metadata for the groupId:artifactId level with the specific type and nature.
63 *
64 * @param groupId The group identifier to which this metadata applies, may be {@code null}.
65 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}.
66 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}.
67 * @param nature The nature of the metadata, must not be {@code null}.
68 */
69 public DefaultMetadata( String groupId, String artifactId, String type, Nature nature )
70 {
71 this( groupId, artifactId, "", type, nature, null, (File) null );
72 }
73
74 /**
75 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature.
76 *
77 * @param groupId The group identifier to which this metadata applies, may be {@code null}.
78 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}.
79 * @param version The version to which this metadata applies, may be {@code null}.
80 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}.
81 * @param nature The nature of the metadata, must not be {@code null}.
82 */
83 public DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature )
84 {
85 this( groupId, artifactId, version, type, nature, null, (File) null );
86 }
87
88 /**
89 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature.
90 *
91 * @param groupId The group identifier to which this metadata applies, may be {@code null}.
92 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}.
93 * @param version The version to which this metadata applies, may be {@code null}.
94 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}.
95 * @param nature The nature of the metadata, must not be {@code null}.
96 * @param file The resolved file of the metadata, may be {@code null}.
97 */
98 public DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature, File file )
99 {
100 this( groupId, artifactId, version, type, nature, null, file );
101 }
102
103 /**
104 * Creates a new metadata for the groupId:artifactId:version level with the specific type and nature.
105 *
106 * @param groupId The group identifier to which this metadata applies, may be {@code null}.
107 * @param artifactId The artifact identifier to which this metadata applies, may be {@code null}.
108 * @param version The version to which this metadata applies, may be {@code null}.
109 * @param type The type of the metadata, e.g. "maven-metadata.xml", may be {@code null}.
110 * @param nature The nature of the metadata, must not be {@code null}.
111 * @param properties The properties of the metadata, may be {@code null} if none.
112 * @param file The resolved file of the metadata, may be {@code null}.
113 */
114 public DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature,
115 Map<String, String> properties, File file )
116 {
117 this.groupId = emptify( groupId );
118 this.artifactId = emptify( artifactId );
119 this.version = emptify( version );
120 this.type = emptify( type );
121 if ( nature == null )
122 {
123 throw new IllegalArgumentException( "metadata nature was not specified" );
124 }
125 this.nature = nature;
126 this.file = file;
127 this.properties = copyProperties( properties );
128 }
129
130 DefaultMetadata( String groupId, String artifactId, String version, String type, Nature nature, File file,
131 Map<String, String> properties )
132 {
133 // NOTE: This constructor assumes immutability of the provided properties, for internal use only
134 this.groupId = emptify( groupId );
135 this.artifactId = emptify( artifactId );
136 this.version = emptify( version );
137 this.type = emptify( type );
138 this.nature = nature;
139 this.file = file;
140 this.properties = properties;
141 }
142
143 private static String emptify( String str )
144 {
145 return ( str == null ) ? "" : str;
146 }
147
148 public String getGroupId()
149 {
150 return groupId;
151 }
152
153 public String getArtifactId()
154 {
155 return artifactId;
156 }
157
158 public String getVersion()
159 {
160 return version;
161 }
162
163 public String getType()
164 {
165 return type;
166 }
167
168 public Nature getNature()
169 {
170 return nature;
171 }
172
173 public File getFile()
174 {
175 return file;
176 }
177
178 public Map<String, String> getProperties()
179 {
180 return properties;
181 }
182
183 }