01: /*******************************************************************************
02: * Copyright (c) 2003, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.bundle;
11:
12: import java.util.Iterator;
13: import java.util.Map;
14:
15: import org.eclipse.pde.internal.core.ibundle.IBundle;
16: import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
17: import org.eclipse.pde.internal.core.text.bundle.ManifestHeader;
18: import org.eclipse.pde.internal.core.util.HeaderMap;
19: import org.osgi.framework.Constants;
20:
21: public class Bundle extends BundleObject implements IBundle {
22: private static final long serialVersionUID = 1L;
23: private Map fProperties;
24:
25: /* (non-Javadoc)
26: * @see org.eclipse.pde.internal.core.ibundle.IBundle#setHeader(java.lang.String, java.lang.String)
27: */
28: public void setHeader(String key, String value) {
29: if (fProperties == null)
30: fProperties = new HeaderMap();//TreeMap(new HeaderComparator());
31: Object oldValue = fProperties.get(key);
32: if (value == null || value.trim().length() == 0)
33: fProperties.remove(key);
34: else
35: fProperties.put(key, value);
36: getModel().fireModelObjectChanged(this , key, oldValue, value);
37: }
38:
39: /* (non-Javadoc)
40: * @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(java.lang.String)
41: */
42: public String getHeader(String key) {
43: if (fProperties == null) {
44: return null;
45: }
46: return (String) fProperties.get(key);
47: }
48:
49: public void load(Map properties) {
50: // Passed dictionary is read-only
51: fProperties = new HeaderMap();//TreeMap(new HeaderComparator());
52: Iterator it = properties.keySet().iterator();
53: while (it.hasNext()) {
54: Object o = it.next();
55: fProperties.put(o, properties.get(o));
56: }
57: }
58:
59: public String getLocalization() {
60: return getHeader(Constants.BUNDLE_LOCALIZATION);
61: }
62:
63: public void setLocalization(String localization) {
64: setHeader(Constants.BUNDLE_LOCALIZATION, localization);
65: }
66:
67: public void renameHeader(String key, String newKey) {
68: if (fProperties == null)
69: fProperties = new HeaderMap();//TreeMap(new HeaderComparator());
70: if (fProperties.get(key) != null) {
71: fProperties.put(newKey, fProperties.remove(key));
72: }
73: }
74:
75: public IManifestHeader getManifestHeader(String key) {
76: return new ManifestHeader(key, getHeader(key), this , System
77: .getProperty("line.separator")); //$NON-NLS-1$
78: }
79:
80: protected Map getHeaders() {
81: return fProperties;
82: }
83: }
|