KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > internal > baseadaptor > BasePermissionStorage


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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
12 package org.eclipse.osgi.internal.baseadaptor;
13
14 import java.io.IOException JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import org.eclipse.osgi.framework.adaptor.PermissionStorage;
18
19 public class BasePermissionStorage implements PermissionStorage {
20
21     private HashMap JavaDoc locations = new HashMap JavaDoc();
22     private String JavaDoc[] defaultInfos;
23     private String JavaDoc[] condPermInfos;
24     private BaseStorage storage;
25     private boolean dirty;
26
27     BasePermissionStorage(BaseStorage storage) {
28         this.storage = storage;
29     }
30
31     public String JavaDoc[] getLocations() throws IOException JavaDoc {
32         synchronized (locations) {
33             String JavaDoc[] result = new String JavaDoc[locations.size()];
34             int i = 0;
35             for (Iterator JavaDoc iLocs = locations.keySet().iterator(); iLocs.hasNext(); i++)
36                 result[i] = (String JavaDoc) iLocs.next();
37             return result;
38         }
39     }
40
41     public String JavaDoc[] getPermissionData(String JavaDoc location) throws IOException JavaDoc {
42         if (location == null)
43             return defaultInfos;
44         synchronized (locations) {
45             if (locations.size() == 0)
46                 return null;
47             return (String JavaDoc[]) locations.get(location);
48         }
49     }
50
51     public void setPermissionData(String JavaDoc location, String JavaDoc[] data) throws IOException JavaDoc {
52         if (location == null) {
53             defaultInfos = data;
54             return;
55         }
56         synchronized (locations) {
57             if (data == null)
58                 locations.remove(location);
59             else
60                 locations.put(location, data);
61         }
62         setDirty(true);
63         storage.requestSave();
64     }
65
66     public void saveConditionalPermissionInfos(String JavaDoc[] infos) throws IOException JavaDoc {
67         condPermInfos = infos;
68         setDirty(true);
69         storage.requestSave();
70     }
71
72     public String JavaDoc[] getConditionalPermissionInfos() throws IOException JavaDoc {
73         return condPermInfos;
74     }
75
76     public boolean isDirty() {
77         return dirty;
78     }
79
80     public void setDirty(boolean dirty) {
81         this.dirty = dirty;
82     }
83 }
84
Popular Tags