001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.ivy.core.module.descriptor;
019:
020: import java.net.URL;
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.Map;
024:
025: import org.apache.ivy.core.IvyPatternHelper;
026: import org.apache.ivy.util.extendable.UnmodifiableExtendableItem;
027:
028: public class DefaultDependencyArtifactDescriptor extends
029: UnmodifiableExtendableItem implements
030: DependencyArtifactDescriptor, ConfigurationAware {
031:
032: private Collection confs = new ArrayList();
033:
034: private URL url;
035:
036: private String name;
037:
038: private String type;
039:
040: private String ext;
041:
042: /**
043: * @param dd
044: * @param name
045: * @param type
046: * @param url
047: */
048: public DefaultDependencyArtifactDescriptor(String name,
049: String type, String ext, URL url, Map extraAttributes) {
050: super (null, extraAttributes);
051: if (name == null) {
052: throw new NullPointerException("name must not be null");
053: }
054: if (type == null) {
055: throw new NullPointerException("type must not be null");
056: }
057: if (ext == null) {
058: throw new NullPointerException("ext must not be null");
059: }
060: this .name = name;
061: this .type = type;
062: this .ext = ext;
063: this .url = url;
064: initStandardAttributes();
065: }
066:
067: private void initStandardAttributes() {
068: setStandardAttribute(IvyPatternHelper.ARTIFACT_KEY, getName());
069: setStandardAttribute(IvyPatternHelper.TYPE_KEY, getType());
070: setStandardAttribute(IvyPatternHelper.EXT_KEY, getExt());
071: setStandardAttribute("url", url != null ? String.valueOf(url)
072: : "");
073: }
074:
075: public boolean equals(Object obj) {
076: if (!(obj instanceof DependencyArtifactDescriptor)) {
077: return false;
078: }
079: DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor) obj;
080: return getAttributes().equals(dad.getAttributes());
081: }
082:
083: public int hashCode() {
084: return getAttributes().hashCode();
085: }
086:
087: /**
088: * Add a configuration for this artifact.
089: *
090: * @param conf
091: */
092: public void addConfiguration(String conf) {
093: confs.add(conf);
094: }
095:
096: public String getName() {
097: return name;
098: }
099:
100: public String getType() {
101: return type;
102: }
103:
104: public String getExt() {
105: return ext;
106: }
107:
108: public String[] getConfigurations() {
109: return (String[]) confs.toArray(new String[confs.size()]);
110: }
111:
112: public URL getUrl() {
113: return url;
114: }
115:
116: public String toString() {
117: return "DA:" + name + "." + ext + "(" + type + ") " + "("
118: + confs + ")" + (url == null ? "" : url.toString());
119: }
120: }
|