KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > bundle > Bundle


1 /*******************************************************************************
2  * Copyright (c) 2003, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.bundle;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.pde.internal.core.ibundle.IBundle;
17 import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
18 import org.eclipse.pde.internal.core.text.bundle.ManifestHeader;
19 import org.eclipse.pde.internal.core.util.HeaderMap;
20 import org.osgi.framework.Constants;
21
22 public class Bundle extends BundleObject implements IBundle {
23     private static final long serialVersionUID = 1L;
24     private Map JavaDoc fProperties;
25
26     /* (non-Javadoc)
27      * @see org.eclipse.pde.internal.core.ibundle.IBundle#setHeader(java.lang.String, java.lang.String)
28      */

29     public void setHeader(String JavaDoc key, String JavaDoc value) {
30         if (fProperties == null)
31             fProperties = new HeaderMap();//TreeMap(new HeaderComparator());
32
Object JavaDoc oldValue = fProperties.get(key);
33         if (value == null || value.trim().length() == 0)
34             fProperties.remove(key);
35         else
36             fProperties.put(key, value);
37         getModel().fireModelObjectChanged(this, key, oldValue, value);
38     }
39     /* (non-Javadoc)
40      * @see org.eclipse.pde.internal.core.ibundle.IBundle#getHeader(java.lang.String)
41      */

42     public String JavaDoc getHeader(String JavaDoc key) {
43         if (fProperties == null) {
44             return null;
45         }
46         return (String JavaDoc)fProperties.get(key);
47     }
48     
49     public void load(Map JavaDoc properties) {
50         // Passed dictionary is read-only
51
fProperties = new HeaderMap();//TreeMap(new HeaderComparator());
52
Iterator JavaDoc it = properties.keySet().iterator();
53         while (it.hasNext()) {
54             Object JavaDoc o = it.next();
55             fProperties.put(o, properties.get(o));
56         }
57     }
58     
59     public String JavaDoc getLocalization() {
60         return getHeader(Constants.BUNDLE_LOCALIZATION);
61     }
62     
63     public void setLocalization(String JavaDoc localization) {
64         setHeader(Constants.BUNDLE_LOCALIZATION, localization);
65     }
66     
67     public void renameHeader(String JavaDoc key, String JavaDoc 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 JavaDoc key) {
76         return new ManifestHeader(key, getHeader(key), this, System.getProperty("line.separator")); //$NON-NLS-1$
77
}
78     
79     protected Map JavaDoc getHeaders() {
80         return fProperties;
81     }
82 }
83
Popular Tags