public AbstractName(URI uri) {
if (uri == null) throw new NullPointerException("uri is null");
//
// Artifact
//
String artifactString = uri.getPath();
if (artifactString == null) throw new IllegalArgumentException("uri does not contain a path part used for the artifact");
List artifactParts = split(artifactString, '/');
if (artifactParts.size() != 4) {
throw new IllegalArgumentException("uri path must be in the form [vendorId]/artifactId/[version]/[type] : " + artifactString);
}
String groupId = (String) artifactParts.get(0);
if (groupId.length() == 0) groupId = null;
String artifactId = (String) artifactParts.get(1);
if (artifactId.length() == 0) artifactId = null;
String version = (String) artifactParts.get(2);
if (version.length() == 0) version = null;
String type = (String) artifactParts.get(3);
if (type.length() == 0) type = null;
artifact = new Artifact(groupId, artifactId, version, type);
//
// name map
//
name = new TreeMap();
String nameString = uri.getQuery();
if (nameString == null) {
throw new IllegalArgumentException("uri does not contain a query part used for the name map; uri: " + uri);
}
List nameParts = split(nameString, ',');
for (Iterator iterator = nameParts.iterator(); iterator.hasNext();) {
String namePart = (String) iterator.next();
List keyValue = split(namePart, '=');
if (keyValue.size() != 2) {
throw new IllegalArgumentException("uri query string must be in the form ?key=value[,key=value]*] : " + nameString);
}
String key = (String) keyValue.get(0);
String value = (String) keyValue.get(1);
if (name.containsKey(key)) {
throw new IllegalArgumentException("uri query string contains the key '"+ key + "' twice : " + nameString);
}
name.put(key, value);
}
if (name.isEmpty()) {
throw new IllegalArgumentException("name is empty: " + nameString);
}
//
// uri
//
this.uri = createURI(artifact, name);
//
// object name
//
this.objectName = Jsr77Naming.createObjectName(name);
}
Contructs an AbstractName object from the given URI.
The artifactId for the AbstractName is constructed from the URI path
(everything up to the ? character) and is composed of four parts delimited by
slashes. The artifactId is the only mandatory part, all slashes are mandatory.
The name map for the AbstractName is constructed from key=value pairs.
Each key=value pair is delimited by a ',' character and the key is separated
from the value by the '=' character. Each key must be unique.
At least one key=value pair must be specified in the query string.
The URI has the following format:
[vendorId]/artifactId/[version]/[type]?key=value[,key=value][,...] Parameters:
uri - The URI to be used to generate an AbstractName.
|
public AbstractName(Artifact artifact,
Map name,
ObjectName objectName) {
if (artifact == null) throw new NullPointerException("artifact is null");
if (name == null) throw new NullPointerException("name is null");
if (name.isEmpty()) throw new IllegalArgumentException("name is empty");
if (objectName == null) throw new NullPointerException("objectName is null");
this.artifact = artifact;
this.name = name;
this.objectName = objectName;
this.uri = createURI(artifact, name);
}
|