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.Date;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.ivy.core.module.id.ArtifactRevisionId;
027: import org.apache.ivy.core.module.id.ModuleRevisionId;
028:
029: /**
030: *
031: */
032: public class MDArtifact extends AbstractArtifact {
033:
034: public static Artifact newIvyArtifact(ModuleDescriptor md) {
035: return new MDArtifact(md, "ivy", "ivy", "xml", true);
036: }
037:
038: private ModuleDescriptor md;
039:
040: private String name;
041:
042: private String type;
043:
044: private String ext;
045:
046: private List confs = new ArrayList();
047:
048: private Map extraAttributes = null;
049:
050: private URL url;
051:
052: private boolean isMetadata = false;
053:
054: public MDArtifact(ModuleDescriptor md, String name, String type,
055: String ext) {
056: this (md, name, type, ext, null, null);
057: }
058:
059: public MDArtifact(ModuleDescriptor md, String name, String type,
060: String ext, boolean isMetadata) {
061: this (md, name, type, ext, null, null);
062: this .isMetadata = isMetadata;
063: }
064:
065: public MDArtifact(ModuleDescriptor md, String name, String type,
066: String ext, URL url, Map extraAttributes) {
067: if (md == null) {
068: throw new NullPointerException(
069: "null module descriptor not allowed");
070: }
071: if (name == null) {
072: throw new NullPointerException("null name not allowed");
073: }
074: if (type == null) {
075: throw new NullPointerException("null type not allowed");
076: }
077: if (ext == null) {
078: throw new NullPointerException("null ext not allowed");
079: }
080: this .md = md;
081: this .name = name;
082: this .type = type;
083: this .ext = ext;
084: this .url = url;
085: this .extraAttributes = extraAttributes;
086: }
087:
088: public ModuleRevisionId getModuleRevisionId() {
089: return md.getResolvedModuleRevisionId();
090: }
091:
092: public Date getPublicationDate() {
093: return md.getResolvedPublicationDate();
094: }
095:
096: public ArtifactRevisionId getId() {
097: // do not cache the result because the resolvedModuleRevisionId can change!
098: return ArtifactRevisionId.newInstance(md
099: .getResolvedModuleRevisionId(), name, type, ext,
100: extraAttributes);
101: }
102:
103: public String getName() {
104: return name;
105: }
106:
107: public String getType() {
108: return type;
109: }
110:
111: public String getExt() {
112: return ext;
113: }
114:
115: public String[] getConfigurations() {
116: return (String[]) confs.toArray(new String[confs.size()]);
117: }
118:
119: public void addConfiguration(String conf) {
120: confs.add(conf);
121: }
122:
123: public URL getUrl() {
124: return url;
125: }
126:
127: public boolean isMetadata() {
128: return isMetadata;
129: }
130: }
|