Stuart McCulloch | de5fbec | 2008-12-03 12:03:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * $Id: ManifestEntry.java 92 2008-11-06 07:46:37Z peter.kriens@aqute.biz $ |
| 3 | * |
| 4 | * Copyright (c) OSGi Alliance (2002, 2006, 2007). All Rights Reserved. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | package org.osgi.impl.bundle.obr.resource; |
| 19 | |
| 20 | import java.util.*; |
| 21 | |
| 22 | |
| 23 | public class ManifestEntry implements Comparable { |
| 24 | String name; |
| 25 | VersionRange version; |
| 26 | Map attributes; |
| 27 | public Map directives; |
| 28 | public Set uses; |
| 29 | |
| 30 | public ManifestEntry(String name) { |
| 31 | this.name = name; |
| 32 | } |
| 33 | |
| 34 | public ManifestEntry(String name, VersionRange version) { |
| 35 | this.name = name; |
| 36 | this.version = version; |
| 37 | } |
| 38 | |
| 39 | public String toString() { |
| 40 | if (version == null) |
| 41 | return name; |
| 42 | return name + " ;version=" + version; |
| 43 | } |
| 44 | |
| 45 | public String getName() { |
| 46 | return name; |
| 47 | } |
| 48 | |
| 49 | public VersionRange getVersion() { |
| 50 | if (version != null) |
| 51 | return version; |
| 52 | return new VersionRange("0"); |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * (non-Javadoc) |
| 57 | * |
| 58 | * @see java.lang.Comparable#compareTo(java.lang.Object) |
| 59 | */ |
| 60 | public int compareTo(Object o) { |
| 61 | ManifestEntry p = (ManifestEntry) o; |
| 62 | return name.compareTo(p.name); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return |
| 67 | */ |
| 68 | public Object getPath() { |
| 69 | return getName().replace('.', '/'); |
| 70 | } |
| 71 | |
| 72 | public Map getDirectives() { |
| 73 | return directives; |
| 74 | } |
| 75 | |
| 76 | public Map getAttributes() { |
| 77 | return attributes; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @param parameter |
| 82 | */ |
| 83 | public void addParameter(Parameter parameter) { |
| 84 | switch (parameter.type) { |
| 85 | case Parameter.ATTRIBUTE : |
| 86 | if (attributes == null) |
| 87 | attributes = new HashMap(); |
| 88 | attributes.put(parameter.key, parameter.value); |
| 89 | if (parameter.key.equalsIgnoreCase("version") |
| 90 | || parameter.key |
| 91 | .equalsIgnoreCase("specification-version")) |
| 92 | this.version = new VersionRange(parameter.value); |
| 93 | break; |
| 94 | |
| 95 | case Parameter.DIRECTIVE : |
| 96 | if (directives == null) |
| 97 | directives = new HashMap(); |
| 98 | directives.put(parameter.key, parameter.value); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | public ManifestEntry getAlias(String key) { |
| 104 | ManifestEntry me = new ManifestEntry(key); |
| 105 | me.attributes = attributes; |
| 106 | me.directives = directives; |
| 107 | me.version = version; |
| 108 | return me; |
| 109 | } |
| 110 | |
| 111 | public String getDirective(String directive) { |
| 112 | if ( directives == null ) |
| 113 | return null; |
| 114 | |
| 115 | return (String) directives.get(directive); |
| 116 | } |
| 117 | |
| 118 | public String getAttribute(String attribute) { |
| 119 | if ( attributes == null ) |
| 120 | return null; |
| 121 | |
| 122 | return (String) attributes.get(attribute); |
| 123 | } |
| 124 | |
| 125 | } |