You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/01/16 15:26:38 UTC
svn commit: r612468 - in /servicemix/smx4/nmr/trunk:
jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/
preferences/ preferences/src/main/java/org/apache/servicemix/preferences/
preferences/src/test/java/org/ preferences/src/test/java/or...
Author: gnodet
Date: Wed Jan 16 06:26:35 2008
New Revision: 612468
URL: http://svn.apache.org/viewvc?rev=612468&view=rev
Log:
Continue PreferencesService implementation
Added:
servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/Activator.java
servicemix/smx4/nmr/trunk/preferences/src/test/java/org/
servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/
servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/
servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/preferences/
servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/preferences/PreferencesServiceTest.java
Removed:
servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/Store.java
Modified:
servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
servicemix/smx4/nmr/trunk/preferences/pom.xml
servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/AbstractPreferencesImpl.java
servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/FilePreferencesImpl.java
servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceFactoryImpl.java
servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceImpl.java
Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java?rev=612468&r1=612467&r2=612468&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ComponentContextImpl.java Wed Jan 16 06:26:35 2008
@@ -126,11 +126,11 @@
}
public void registerExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
- //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
}
public void deregisterExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
- //To change body of implemented methods use File | Settings | File Templates.
+ // TODO
}
public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
@@ -187,7 +187,7 @@
}
}
}
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
public ServiceEndpoint[] getEndpoints(QName interfaceName) {
Modified: servicemix/smx4/nmr/trunk/preferences/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/pom.xml?rev=612468&r1=612467&r2=612468&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/preferences/pom.xml Wed Jan 16 06:26:35 2008
@@ -63,9 +63,8 @@
<instructions>
<Bundle-Name>${pom.name}</Bundle-Name>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
- <Export-Package>
- ${pom.artifactId},${pom.artifactId}.service,${pom.artifactId}.event,${pom.artifactId}.internal
- </Export-Package>
+ <Private-Package>org.apache.servicemix.preferences</Private-Package>
+ <Bundle-Activator>org.apache.servicemix.preferences.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
Modified: servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/AbstractPreferencesImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/AbstractPreferencesImpl.java?rev=612468&r1=612467&r2=612468&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/AbstractPreferencesImpl.java (original)
+++ servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/AbstractPreferencesImpl.java Wed Jan 16 06:26:35 2008
@@ -1,3 +1,19 @@
+/*
+ * 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.servicemix.preferences;
import java.util.ArrayList;
@@ -244,7 +260,9 @@
public void flush() throws BackingStoreException {
checkStatus();
- parent.flush();
+ if (parent != null) {
+ parent.flush();
+ }
if (dirty) {
doFlush();
dirty = false;
Added: servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/Activator.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/Activator.java?rev=612468&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/Activator.java (added)
+++ servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/Activator.java Wed Jan 16 06:26:35 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.servicemix.preferences;
+
+import java.io.File;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.prefs.PreferencesService;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Jan 16, 2008
+ * Time: 11:32:02 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Activator implements BundleActivator {
+
+ private PreferencesServiceFactoryImpl factory;
+ private ServiceRegistration registration;
+
+ public void start(BundleContext bundleContext) throws Exception {
+ File root = new File(System.getProperty("servicemix.base"), "data/prefs");
+ factory = new PreferencesServiceFactoryImpl(bundleContext, root);
+ registration = bundleContext.registerService(PreferencesService.class.getName(), factory, null);
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception {
+ registration.unregister();
+ factory.destroy();
+ }
+}
Modified: servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/FilePreferencesImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/FilePreferencesImpl.java?rev=612468&r1=612467&r2=612468&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/FilePreferencesImpl.java (original)
+++ servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/FilePreferencesImpl.java Wed Jan 16 06:26:35 2008
@@ -1,3 +1,19 @@
+/*
+ * 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.servicemix.preferences;
import java.io.File;
@@ -123,19 +139,22 @@
props = new Properties();
children = new HashMap<String, FilePreferencesImpl>();
deleted = new ArrayList<FilePreferencesImpl>();
- if (root.exists()) {
- InputStream is = null;
- try {
- is = new FileInputStream(new File(root, PROPS_FILE));
- props.load(is);
- } catch (IOException e) {
- error("Unable to load node " + name(), e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- // Ignore
+ if (root.isDirectory()) {
+ File fp = new File(root, PROPS_FILE);
+ if (fp.isFile()) {
+ InputStream is = null;
+ try {
+ is = new FileInputStream(fp);
+ props.load(is);
+ } catch (IOException e) {
+ error("Unable to load node " + name(), e);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
}
}
Modified: servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceFactoryImpl.java?rev=612468&r1=612467&r2=612468&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceFactoryImpl.java (original)
+++ servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceFactoryImpl.java Wed Jan 16 06:26:35 2008
@@ -1,5 +1,23 @@
+/*
+ * 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.servicemix.preferences;
+import java.io.File;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -19,12 +37,14 @@
private BundleContext bundleContext;
private AbstractPreferencesImpl preferences;
+ private File root;
public PreferencesServiceFactoryImpl() {
}
- public PreferencesServiceFactoryImpl(BundleContext bundleContext) {
+ public PreferencesServiceFactoryImpl(BundleContext bundleContext, File root) {
this.bundleContext = bundleContext;
+ this.root = root;
init();
}
@@ -36,18 +56,31 @@
this.bundleContext = bundleContext;
}
+ public File getRoot() {
+ return root;
+ }
+
+ public void setRoot(File root) {
+ this.root = root;
+ }
+
public synchronized Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
checkInit();
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return preferences.node("/" + bundle.getBundleId());
}
public synchronized void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object o) {
- //To change body of implemented methods use File | Settings | File Templates.
}
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.UNINSTALLED) {
- // TODO: remove backing bundle
+ try {
+ if (preferences.nodeExists("/" + event.getBundle().getBundleId())) {
+ preferences.node("/" + event.getBundle().getBundleId()).removeNode();
+ }
+ } catch (BackingStoreException e) {
+ e.printStackTrace();
+ }
}
}
@@ -56,7 +89,7 @@
throw new NullPointerException("bundleContext is null");
}
bundleContext.addBundleListener(this);
- preferences = null;
+ preferences = new FilePreferencesImpl(null, null, root);
}
public void destroy() throws BackingStoreException {
Modified: servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceImpl.java?rev=612468&r1=612467&r2=612468&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceImpl.java (original)
+++ servicemix/smx4/nmr/trunk/preferences/src/main/java/org/apache/servicemix/preferences/PreferencesServiceImpl.java Wed Jan 16 06:26:35 2008
@@ -1,5 +1,22 @@
+/*
+ * 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.servicemix.preferences;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -34,7 +51,7 @@
public String[] getUsers() {
try {
- List<String> children = Arrays.asList(preferences.childrenNames());
+ List<String> children = new ArrayList(Arrays.asList(preferences.childrenNames()));
children.remove(SYSTEM_NODE);
return children.toArray(new String[children.size()]);
} catch (BackingStoreException e) {
Added: servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/preferences/PreferencesServiceTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/preferences/PreferencesServiceTest.java?rev=612468&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/preferences/PreferencesServiceTest.java (added)
+++ servicemix/smx4/nmr/trunk/preferences/src/test/java/org/apache/servicemix/preferences/PreferencesServiceTest.java Wed Jan 16 06:26:35 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.servicemix.preferences;
+
+import java.io.File;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.osgi.service.prefs.PreferencesService;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Jan 16, 2008
+ * Time: 10:46:47 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class PreferencesServiceTest {
+
+ @Test
+ public void test1() throws Exception {
+ PreferencesService prefs = new PreferencesServiceImpl(new FilePreferencesImpl(null, "3", new File("target/prefs/3")));
+
+ prefs.getSystemPreferences().put("key", "value");
+ prefs.getUserPreferences("user1").put("key", "value2");
+
+ assertNotNull(prefs.getUsers());
+ assertEquals(1, prefs.getUsers().length);
+ assertEquals("user1", prefs.getUsers()[0]);
+ assertEquals("value2", prefs.getUserPreferences("user1").get("key", null));
+ assertEquals("value", prefs.getSystemPreferences().get("key", null));
+
+ prefs.getSystemPreferences().flush();
+ prefs.getUserPreferences("user1").flush();
+
+ prefs = new PreferencesServiceImpl(new FilePreferencesImpl(null, "3", new File("target/prefs/3")));
+ assertNotNull(prefs.getUsers());
+ assertEquals(1, prefs.getUsers().length);
+ assertEquals("user1", prefs.getUsers()[0]);
+ assertEquals("value2", prefs.getUserPreferences("user1").get("key", null));
+ assertEquals("value", prefs.getSystemPreferences().get("key", null));
+ }
+
+}