You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/10/10 14:58:31 UTC
svn commit: r1764113 - in /felix/trunk/prefs: ./
src/main/java/org/apache/felix/prefs/
src/main/java/org/apache/felix/prefs/impl/ src/test/ src/test/java/
src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/felix/ src/test/java/org/ap...
Author: cziegeler
Date: Mon Oct 10 14:58:30 2016
New Revision: 1764113
URL: http://svn.apache.org/viewvc?rev=1764113&view=rev
Log:
Update pom, use newer dependencies, use generics, add a simple test case
Added:
felix/trunk/prefs/src/test/
felix/trunk/prefs/src/test/java/
felix/trunk/prefs/src/test/java/org/
felix/trunk/prefs/src/test/java/org/apache/
felix/trunk/prefs/src/test/java/org/apache/felix/
felix/trunk/prefs/src/test/java/org/apache/felix/prefs/
felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java (with props)
Modified:
felix/trunk/prefs/pom.xml
felix/trunk/prefs/src/main/java/org/apache/felix/prefs/ChangeSet.java
felix/trunk/prefs/src/main/java/org/apache/felix/prefs/PreferencesImpl.java
felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/DataFileBackingStoreImpl.java
felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesManager.java
felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesServiceImpl.java
felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/StreamBackingStoreImpl.java
Modified: felix/trunk/prefs/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/pom.xml?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/pom.xml (original)
+++ felix/trunk/prefs/pom.xml Mon Oct 10 14:58:30 2016
@@ -36,36 +36,9 @@
Implementation of the OSGi Preferences Service Specification 1.1.1
</description>
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.annotation</artifactId>
- <version>6.0.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>5.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.log</artifactId>
- <version>1.3.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.prefs</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.10</version>
- </dependency>
- </dependencies>
+ <properties>
+ <felix.java.version>6</felix.java.version>
+ </properties>
<build>
<plugins>
@@ -106,4 +79,44 @@
</plugin>
</plugins>
</build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ <version>6.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>5.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.log</artifactId>
+ <version>1.3.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.prefs</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.10</version>
+ </dependency>
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
+ </dependencies>
</project>
Modified: felix/trunk/prefs/src/main/java/org/apache/felix/prefs/ChangeSet.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/main/java/org/apache/felix/prefs/ChangeSet.java?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/src/main/java/org/apache/felix/prefs/ChangeSet.java (original)
+++ felix/trunk/prefs/src/main/java/org/apache/felix/prefs/ChangeSet.java Mon Oct 10 14:58:30 2016
@@ -18,7 +18,10 @@
*/
package org.apache.felix.prefs;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
/**
* This class keeps track of the changes to a preferences node.
@@ -29,16 +32,16 @@ public class ChangeSet {
protected boolean hasChanges = false;
/** A set of changed/added properties. */
- protected final Set changedProperties = new HashSet();
+ protected final Set<String> changedProperties = new HashSet<String>();
/** A set of removed properties. */
- protected final Set removedProperties = new HashSet();
+ protected final Set<String> removedProperties = new HashSet<String>();
/** A set of added children. */
- protected final Set addedChildren = new HashSet();
+ protected final Set<String> addedChildren = new HashSet<String>();
/** A set of removed children. */
- protected final Set removedChildren = new HashSet();
+ protected final Set<String> removedChildren = new HashSet<String>();
/**
* Do we have changes?
@@ -117,7 +120,7 @@ public class ChangeSet {
* Return a collection with the changed property names.
* @return A collection.
*/
- public Collection getChangedProperties() {
+ public Collection<String> getChangedProperties() {
return Collections.unmodifiableCollection(this.changedProperties);
}
@@ -125,7 +128,7 @@ public class ChangeSet {
* Return a collection with the removed property names.
* @return A collection.
*/
- public Collection getRemovedProperties() {
+ public Collection<String> getRemovedProperties() {
return Collections.unmodifiableCollection(this.removedProperties);
}
@@ -133,7 +136,7 @@ public class ChangeSet {
* Return a collection with the added children names.
* @return A collection.
*/
- public Collection getAddedChildren() {
+ public Collection<String> getAddedChildren() {
return Collections.unmodifiableCollection(this.addedChildren);
}
@@ -141,7 +144,7 @@ public class ChangeSet {
* Return a collection with the removed children names.
* @return A collection.
*/
- public Collection getRemovedChildren() {
+ public Collection<String> getRemovedChildren() {
return Collections.unmodifiableCollection(this.removedChildren);
}
}
Modified: felix/trunk/prefs/src/main/java/org/apache/felix/prefs/PreferencesImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/main/java/org/apache/felix/prefs/PreferencesImpl.java?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/src/main/java/org/apache/felix/prefs/PreferencesImpl.java (original)
+++ felix/trunk/prefs/src/main/java/org/apache/felix/prefs/PreferencesImpl.java Mon Oct 10 14:58:30 2016
@@ -19,7 +19,12 @@
package org.apache.felix.prefs;
import java.io.UnsupportedEncodingException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.osgi.service.prefs.BackingStoreException;
@@ -38,7 +43,7 @@ import org.osgi.service.prefs.Preference
public class PreferencesImpl implements Preferences {
/** The properties. */
- protected final Map properties = new HashMap();
+ protected final Map<String, String> properties = new HashMap<String, String>();
/** Has this node been removed? */
protected boolean valid = true;
@@ -47,7 +52,7 @@ public class PreferencesImpl implements
protected final PreferencesImpl parent;
/** The child nodes. */
- protected final Map children = new HashMap();
+ protected final Map<String, PreferencesImpl> children = new HashMap<String, PreferencesImpl>();
/** The name of the properties. */
protected final String name;
@@ -115,14 +120,14 @@ public class PreferencesImpl implements
* Return all children or an empty collection.
* @return A collection containing the children.
*/
- public Collection getChildren() {
+ public Collection<PreferencesImpl> getChildren() {
return this.children.values();
}
/**
* Return the properties set.
*/
- public Map getProperties() {
+ public Map<String, String> getProperties() {
return this.properties;
}
@@ -183,7 +188,7 @@ public class PreferencesImpl implements
*/
public synchronized String get(String key, String def) {
this.checkValidity();
- String value = (String) this.properties.get(key);
+ String value = this.properties.get(key);
if ( value == null ) {
value = def;
}
@@ -207,9 +212,9 @@ public class PreferencesImpl implements
public synchronized void clear() throws BackingStoreException {
this.checkValidity();
- final Iterator i = this.properties.keySet().iterator();
+ final Iterator<String> i = this.properties.keySet().iterator();
while ( i.hasNext() ) {
- final String key = (String)i.next();
+ final String key = i.next();
this.changeSet.propertyRemoved(key);
}
this.properties.clear();
@@ -364,8 +369,8 @@ public class PreferencesImpl implements
*/
public synchronized String[] keys() throws BackingStoreException {
this.sync();
- final Set keys = this.properties.keySet();
- return (String[])keys.toArray(new String[keys.size()]);
+ final Set<String> keys = this.properties.keySet();
+ return keys.toArray(new String[keys.size()]);
}
/**
@@ -373,8 +378,8 @@ public class PreferencesImpl implements
*/
public synchronized String[] childrenNames() throws BackingStoreException {
this.sync();
- final Set names = this.children.keySet();
- return (String[])names.toArray(new String[names.size()]);
+ final Set<String> names = this.children.keySet();
+ return names.toArray(new String[names.size()]);
}
/**
@@ -456,7 +461,7 @@ public class PreferencesImpl implements
path = path.substring(0, pos);
}
boolean save = false;
- PreferencesImpl child = (PreferencesImpl) this.children.get(path);
+ PreferencesImpl child = this.children.get(path);
if ( child == null ) {
if ( !create ) {
return null;
@@ -530,16 +535,16 @@ public class PreferencesImpl implements
*/
protected void safelyRemoveNode() {
if ( this.valid ) {
- Collection c = null;
+ Collection<PreferencesImpl> c = null;
synchronized ( this ) {
this.valid = false;
this.properties.clear();
- c = new ArrayList(this.children.values());
+ c = new ArrayList<PreferencesImpl>(this.children.values());
this.children.clear();
}
- final Iterator i = c.iterator();
+ final Iterator<PreferencesImpl> i = c.iterator();
while ( i.hasNext() ) {
- final PreferencesImpl child = (PreferencesImpl) i.next();
+ final PreferencesImpl child = i.next();
child.safelyRemoveNode();
}
}
@@ -594,23 +599,23 @@ public class PreferencesImpl implements
* @param impl
*/
public void update(PreferencesImpl impl) {
- final Iterator i = impl.properties.entrySet().iterator();
+ final Iterator<Map.Entry<String, String>> i = impl.properties.entrySet().iterator();
while ( i.hasNext() ) {
- final Map.Entry entry = (Map.Entry)i.next();
+ final Map.Entry<String, String> entry = i.next();
if ( !this.properties.containsKey(entry.getKey()) ) {
this.properties.put(entry.getKey(), entry.getValue());
}
}
- final Iterator cI = impl.children.entrySet().iterator();
+ final Iterator<Map.Entry<String, PreferencesImpl>> cI = impl.children.entrySet().iterator();
while ( cI.hasNext() ) {
- final Map.Entry entry = (Map.Entry)cI.next();
+ final Map.Entry<String, PreferencesImpl> entry = cI.next();
final String name = entry.getKey().toString();
- final PreferencesImpl child = (PreferencesImpl)entry.getValue();
+ final PreferencesImpl child = entry.getValue();
if ( !this.children.containsKey(name) ) {
// create node
this.node(name);
}
- ((PreferencesImpl)this.children.get(name)).update(child);
+ this.children.get(name).update(child);
}
}
@@ -622,7 +627,7 @@ public class PreferencesImpl implements
final ChangeSet changeSet = prefs.getChangeSet();
if ( changeSet.hasChanges ) {
this.changeSet.importChanges(prefs.changeSet);
- Iterator i;
+ Iterator<String> i;
// remove properties
i = changeSet.removedProperties.iterator();
while ( i.hasNext() ) {
@@ -631,20 +636,20 @@ public class PreferencesImpl implements
// set/update properties
i = changeSet.changedProperties.iterator();
while ( i.hasNext() ) {
- final String key = (String)i.next();
+ final String key = i.next();
this.properties.put(key, prefs.properties.get(key));
}
// remove children
i = changeSet.removedChildren.iterator();
while ( i.hasNext() ) {
- final String name = (String)i.next();
+ final String name = i.next();
this.children.remove(name);
}
// added childs are processed in the next loop
}
- final Iterator cI = prefs.getChildren().iterator();
+ final Iterator<PreferencesImpl> cI = prefs.getChildren().iterator();
while ( cI.hasNext() ) {
- final PreferencesImpl current = (PreferencesImpl)cI.next();
+ final PreferencesImpl current = cI.next();
final PreferencesImpl child = this.getOrCreateNode(current.name());
child.applyChanges(current);
}
Modified: felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/DataFileBackingStoreImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/DataFileBackingStoreImpl.java?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/DataFileBackingStoreImpl.java (original)
+++ felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/DataFileBackingStoreImpl.java Mon Oct 10 14:58:30 2016
@@ -18,14 +18,24 @@
*/
package org.apache.felix.prefs.impl;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.*;
-
-import org.apache.felix.prefs.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.felix.prefs.BackingStoreManager;
+import org.apache.felix.prefs.PreferencesDescription;
+import org.apache.felix.prefs.PreferencesImpl;
import org.osgi.framework.BundleContext;
import org.osgi.service.prefs.BackingStoreException;
@@ -51,6 +61,7 @@ public class DataFileBackingStoreImpl ex
/**
* @see org.apache.felix.sandbox.preferences.impl.StreamBackingStoreImpl#checkAccess()
*/
+ @Override
protected void checkAccess() throws BackingStoreException {
if ( this.rootDirectory == null ) {
throw new BackingStoreException("Saving of data files to the bundle context is currently not supported.");
@@ -60,6 +71,7 @@ public class DataFileBackingStoreImpl ex
/**
* @see org.apache.felix.sandbox.preferences.impl.StreamBackingStoreImpl#getOutputStream(org.apache.felix.sandbox.preferences.PreferencesDescription)
*/
+ @Override
protected OutputStream getOutputStream(PreferencesDescription desc) throws IOException {
final File file = this.getFile(desc);
return getFileOutputStream(file);
@@ -75,7 +87,7 @@ public class DataFileBackingStoreImpl ex
} catch (BackingStoreException ignore) {
return new Long[0];
}
- final Set bundleIds = new HashSet();
+ final Set<Long> bundleIds = new HashSet<Long>();
final File[] children = getFilesList(this.rootDirectory);
for( int i=0; i<children.length; i++ ) {
final File current = children[i];
@@ -85,7 +97,7 @@ public class DataFileBackingStoreImpl ex
bundleIds.add(desc.getBundleId());
}
}
- return (Long[])bundleIds.toArray(new Long[bundleIds.size()]);
+ return bundleIds.toArray(new Long[bundleIds.size()]);
}
protected PreferencesDescription getDescription(File file) {
@@ -132,7 +144,7 @@ public class DataFileBackingStoreImpl ex
*/
public PreferencesImpl[] loadAll(BackingStoreManager manager, Long bundleId) throws BackingStoreException {
this.checkAccess();
- final List list = new ArrayList();
+ final List<PreferencesImpl> list = new ArrayList<PreferencesImpl>();
final File[] children = getFilesList(this.rootDirectory);
for( int i=0; i<children.length; i++ ) {
final File current = children[i];
@@ -152,7 +164,7 @@ public class DataFileBackingStoreImpl ex
}
}
}
- return (PreferencesImpl[])list.toArray(new PreferencesImpl[list.size()]);
+ return list.toArray(new PreferencesImpl[list.size()]);
}
/**
@@ -194,28 +206,28 @@ public class DataFileBackingStoreImpl ex
}
// few utility methods to access File APIs from a privileged block
-
+
private static File[] getFilesList(final File file) {
- return (File[]) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
+ return AccessController.doPrivileged(new PrivilegedAction<File[]>() {
+ public File[] run() {
return file.listFiles();
}
});
}
-
+
private static Boolean fileExists(final File file) {
- return (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
+ return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
return (file.exists() ? Boolean.TRUE : Boolean.FALSE);
}
});
}
-
+
private static FileInputStream getFileInputStream(final File file) throws IOException {
try {
- return (FileInputStream) AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public Object run() throws FileNotFoundException {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<FileInputStream>() {
+ public FileInputStream run() throws FileNotFoundException {
return new FileInputStream(file);
}
});
@@ -225,12 +237,12 @@ public class DataFileBackingStoreImpl ex
throw (FileNotFoundException) e.getException();
}
}
-
+
private static FileOutputStream getFileOutputStream(final File file) throws IOException {
try {
- return (FileOutputStream) AccessController.doPrivileged(
- new PrivilegedExceptionAction() {
- public Object run() throws FileNotFoundException {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<FileOutputStream>() {
+ public FileOutputStream run() throws FileNotFoundException {
return new FileOutputStream(file);
}
});
Modified: felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesManager.java?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesManager.java (original)
+++ felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesManager.java Mon Oct 10 14:58:30 2016
@@ -18,10 +18,20 @@
*/
package org.apache.felix.prefs.impl;
-import java.util.*;
-
-import org.apache.felix.prefs.*;
-import org.osgi.framework.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.felix.prefs.BackingStore;
+import org.apache.felix.prefs.BackingStoreManager;
+import org.apache.felix.prefs.PreferencesImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.PreferencesService;
@@ -34,20 +44,20 @@ import org.osgi.util.tracker.ServiceTrac
public class PreferencesManager
implements BundleActivator,
BundleListener,
- ServiceFactory,
+ ServiceFactory<PreferencesService>,
BackingStoreManager {
/**
* The map of already created services. For each client bundle
* a new service is created.
*/
- protected final Map services = new HashMap();
+ protected final Map<Long, PreferencesServiceImpl> services = new HashMap<Long, PreferencesServiceImpl>();
/** The bundle context. */
protected BundleContext context;
/** The backing store service tracker. */
- protected ServiceTracker storeTracker;
+ protected ServiceTracker<BackingStore, BackingStore> storeTracker;
/** The service tracker for the log service. */
protected ServiceTracker logTracker;
@@ -91,7 +101,7 @@ public class PreferencesManager
this.logTracker.open();
// create the tracker for our backing store
- this.storeTracker = new ServiceTracker(context, BackingStore.class.getName(), null);
+ this.storeTracker = new ServiceTracker<BackingStore, BackingStore>(context, BackingStore.class, null);
this.storeTracker.open();
// register this activator as a bundle lister
@@ -107,9 +117,9 @@ public class PreferencesManager
public void stop(final BundleContext context) throws Exception {
// if we get stopped, we should save all in memory representations
synchronized (this.services) {
- final Iterator i = this.services.values().iterator();
+ final Iterator<PreferencesServiceImpl> i = this.services.values().iterator();
while (i.hasNext()) {
- final PreferencesServiceImpl service = (PreferencesServiceImpl) i.next();
+ final PreferencesServiceImpl service = i.next();
this.save(service);
}
this.services.clear();
@@ -133,13 +143,14 @@ public class PreferencesManager
/**
* @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
*/
- public Object getService(final Bundle bundle, final ServiceRegistration reg) {
+ public PreferencesService getService(final Bundle bundle,
+ final ServiceRegistration<PreferencesService> reg) {
final Long bundleId = new Long(bundle.getBundleId());
synchronized (this.services) {
PreferencesServiceImpl service;
// do we already have created a service for this bundle?
- service = (PreferencesServiceImpl) this.services.get(bundleId);
+ service = this.services.get(bundleId);
if (service == null) {
// create a new service instance
@@ -153,11 +164,13 @@ public class PreferencesManager
/**
* @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
*/
- public void ungetService(final Bundle bundle, final ServiceRegistration reg, final Object s) {
+ public void ungetService(final Bundle bundle,
+ final ServiceRegistration<PreferencesService> reg,
+ final PreferencesService s) {
final Long bundleId = new Long(bundle.getBundleId());
// we save all the preferences
synchronized (this.services) {
- final PreferencesServiceImpl service = (PreferencesServiceImpl) this.services.get(bundleId);
+ final PreferencesServiceImpl service = this.services.get(bundleId);
if (service != null) {
this.save(service);
}
@@ -170,9 +183,9 @@ public class PreferencesManager
* @param service
*/
protected void save(final PreferencesServiceImpl service) {
- final Iterator i = service.getAllPreferences().iterator();
+ final Iterator<PreferencesImpl> i = service.getAllPreferences().iterator();
while (i.hasNext()) {
- final PreferencesImpl prefs = (PreferencesImpl) i.next();
+ final PreferencesImpl prefs = i.next();
try {
this.getStore().store(prefs);
}
@@ -195,13 +208,13 @@ public class PreferencesManager
*/
public BackingStore getStore() throws BackingStoreException {
BackingStore service = null;
- ServiceTracker storeTracker = this.storeTracker;
+ ServiceTracker<BackingStore, BackingStore> storeTracker = this.storeTracker;
// Only possible if we're not stopped already...
if (storeTracker != null) {
// has the service changed?
int currentCount = storeTracker.getTrackingCount();
- service = (BackingStore) storeTracker.getService();
+ service = storeTracker.getService();
if (service != null && this.storeTrackingCount < currentCount) {
this.storeTrackingCount = currentCount;
this.cleanupStore(service);
Modified: felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesServiceImpl.java?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesServiceImpl.java (original)
+++ felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/PreferencesServiceImpl.java Mon Oct 10 14:58:30 2016
@@ -40,7 +40,7 @@ public class PreferencesServiceImpl impl
protected PreferencesImpl systemTree;
/** This is the map containing the user preferences trees. */
- protected final Map trees = new HashMap();
+ protected final Map<String, PreferencesImpl> trees = new HashMap<String, PreferencesImpl>();
/** The service id for the bundle this service belongs to. */
protected final Long bundleId;
@@ -88,7 +88,7 @@ public class PreferencesServiceImpl impl
* @see org.osgi.service.prefs.PreferencesService#getUserPreferences(java.lang.String)
*/
public synchronized Preferences getUserPreferences(String name) {
- PreferencesImpl result = (PreferencesImpl) this.trees.get(name);
+ PreferencesImpl result = this.trees.get(name);
// if the tree does not exist yet, create it
if (result == null || !result.isValid()) {
result = new PreferencesImpl(new PreferencesDescription(this.bundleId, name), this.storeManager);
@@ -108,12 +108,12 @@ public class PreferencesServiceImpl impl
*/
public synchronized String[] getUsers() {
// TODO - we have to sync with the store
- final Set userKeys = this.trees.keySet();
- return (String[])userKeys.toArray(new String[userKeys.size()]);
+ final Set <String> userKeys = this.trees.keySet();
+ return userKeys.toArray(new String[userKeys.size()]);
}
- protected List getAllPreferences() {
- final List list = new ArrayList();
+ protected List<PreferencesImpl> getAllPreferences() {
+ final List<PreferencesImpl> list = new ArrayList<PreferencesImpl>();
if ( this.systemTree != null ) {
list.add(this.systemTree);
}
Modified: felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/StreamBackingStoreImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/StreamBackingStoreImpl.java?rev=1764113&r1=1764112&r2=1764113&view=diff
==============================================================================
--- felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/StreamBackingStoreImpl.java (original)
+++ felix/trunk/prefs/src/main/java/org/apache/felix/prefs/impl/StreamBackingStoreImpl.java Mon Oct 10 14:58:30 2016
@@ -18,10 +18,18 @@
*/
package org.apache.felix.prefs.impl;
-import java.io.*;
-import java.util.*;
-
-import org.apache.felix.prefs.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.felix.prefs.BackingStore;
+import org.apache.felix.prefs.PreferencesDescription;
+import org.apache.felix.prefs.PreferencesImpl;
import org.osgi.framework.BundleContext;
import org.osgi.service.prefs.BackingStoreException;
@@ -119,7 +127,7 @@ public abstract class StreamBackingStore
throws IOException {
this.writePreferences(prefs, os);
final ObjectOutputStream oos = new ObjectOutputStream(os);
- final Collection children = prefs.getChildren();
+ final Collection<PreferencesImpl> children = prefs.getChildren();
oos.writeInt(children.size());
oos.flush();
final Iterator i = children.iterator();
Added: felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java?rev=1764113&view=auto
==============================================================================
--- felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java (added)
+++ felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java Mon Oct 10 14:58:30 2016
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.prefs;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.file.Files;
+
+import org.apache.felix.prefs.impl.DataFileBackingStoreImpl;
+import org.junit.Test;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+public class PreferencesImplTest {
+
+ @Test public void testAddRemoveAdd()
+ throws Exception {
+ final BackingStore store = new DataFileBackingStoreImpl(null, Files.createTempDirectory("prefs").toFile());
+ final PreferencesImpl prefs = new PreferencesImpl(new PreferencesDescription(5L, null),
+ new BackingStoreManager() {
+
+ public BackingStore getStore() throws BackingStoreException {
+ return store;
+ }
+ });
+ Preferences firstA = prefs.node("A");
+ firstA.node("1");
+ firstA.node("2");
+ assertEquals(1, prefs.childrenNames().length);
+ assertEquals(2, firstA.childrenNames().length);
+
+ firstA.removeNode();
+ prefs.flush();
+
+ assertEquals(0, prefs.childrenNames().length);
+
+ firstA = prefs.node("A");
+ assertEquals(1, prefs.childrenNames().length);
+ assertEquals(0, firstA.childrenNames().length);
+ firstA.node("1");
+ firstA.node("2");
+ assertEquals(2, firstA.childrenNames().length);
+ }
+}
Propchange: felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/prefs/src/test/java/org/apache/felix/prefs/PreferencesImplTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url