cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r891660 [1/2] - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ dsw/cxf-osgi-remote-service-admin-interfaces/META-I...
Date Thu, 17 Dec 2009 11:49:53 GMT
Author: davidb
Date: Thu Dec 17 11:49:51 2009
New Revision: 891660

URL: http://svn.apache.org/viewvc?rev=891660&view=rev
Log:
Files SVN missed in previous commit.

Added:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/META-INF/
    cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/META-INF/MANIFEST.MF
    cxf/dosgi/trunk/dsw/cxf-topology-manager/META-INF/
    cxf/dosgi/trunk/dsw/cxf-topology-manager/META-INF/MANIFEST.MF
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java   (with props)
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/UtilsTest.java   (with props)

Added: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java (added)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,133 @@
+/** 
+ * 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.cxf.dosgi.discovery.zookeeper;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.logging.Logger;
+
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooKeeper;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ZooKeeperDiscovery implements Watcher {
+
+    private static final Logger LOG = Logger.getLogger(ZooKeeperDiscovery.class.getName());
+
+    private boolean started = false;
+    
+    private BundleContext bctx;
+    private ZooKeeper zooKeeper;
+    private Dictionary properties = null;
+
+    private EndpointListenerFactory endpointListenerFactory;
+    private ServiceTracker endpointListenerTracker;
+
+    private String zkHost;
+    private String zkPort;
+    private int zkTimeout;
+
+    public ZooKeeperDiscovery(BundleContext bctx, Dictionary initialProps) {
+        this.bctx = bctx;
+        endpointListenerFactory = new EndpointListenerFactory(this, bctx);
+        properties = initialProps;
+
+        endpointListenerTracker = new ServiceTracker(bctx, EndpointListener.class.getName(),
+                                                     new EndpointListenerTrackerCustomizer(this, bctx));
+    }
+
+    public synchronized void start() throws IOException, ConfigurationException {
+        if(started) return;
+        started = true;
+        createZooKeeper(properties);
+        endpointListenerFactory.start();
+        endpointListenerTracker.open();
+    }
+
+    public synchronized void stop() {
+        if(!started) return;
+        started = false;
+        endpointListenerFactory.stop();
+        endpointListenerTracker.close();
+    }
+
+
+    private void createZooKeeper(Dictionary props) throws IOException, ConfigurationException {
+        zkHost = getProp(props, "zookeeper.host");
+        zkPort = getProp(props, "zookeeper.port");
+        zkTimeout = Integer.parseInt(getProp(props, "zookeeper.timeout", "3000"));
+
+        zooKeeper = createZooKeeper();
+
+    }
+
+    // separated for testing
+    ZooKeeper createZooKeeper() throws IOException {
+        return new ZooKeeper(zkHost + ":" + zkPort, zkTimeout, this);
+    }
+
+    private <T> boolean hasChanged(T orig, T nw) {
+        if (orig == nw) {
+            return false;
+        }
+
+        if (orig == null) {
+            return true;
+        }
+
+        return !orig.equals(nw);
+    }
+
+    private static String getProp(Dictionary props, String key) throws ConfigurationException {
+        String val = getProp(props, key, null);
+        if (val != null) {
+            return val;
+        } else {
+            throw new ConfigurationException(key, "The property " + key + " requires a value");
+        }
+    }
+
+    private static String getProp(Dictionary props, String key, String def) {
+        Object val = props.get(key);
+        String rv;
+        if (val == null) {
+            rv = def;
+        } else {
+            rv = val.toString();
+        }
+
+        LOG.fine("Reading Config Admin property: " + key + " value returned: " + rv);
+        return rv;
+    }
+
+    /* Callback for ZooKeeper */
+    public void process(WatchedEvent arg0) {
+        // TODO Auto-generated method stub
+
+    }
+
+    protected ZooKeeper getZookeeper() {
+        return zooKeeper;
+    }
+
+}

Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,120 @@
+/** 
+  * 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.cxf.dosgi.dsw.service;
+
+import java.util.Arrays;
+import java.util.Properties;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+
+public class EventAdminHelper {
+
+    private BundleContext bctx;
+
+    public EventAdminHelper(BundleContext bc) {
+        bctx = bc;
+    }
+
+    private Event createEvent(Properties p, String t) {
+
+        String topic = "org/osgi/service/remoteserviceadmin/" + t;
+        Properties props = new Properties(p);
+
+        props.put("bundle", bctx.getBundle());
+        props.put("bundle-id", bctx.getBundle().getBundleId());
+        props.put("bundle-symbolicname", bctx.getBundle().getSymbolicName());
+        // FIXME is this correct?
+        setIfNotNull(props, "bundle-version", bctx.getBundle().getHeaders("Bundle-Version"));
+
+        return new Event(topic, props);
+    }
+
+    public void notifyEventAdmin(RemoteServiceAdminEvent rsae) {
+
+        String topic = Utils.remoteServiceAdminEventTypeToString(rsae.getType());
+
+        EndpointDescription epd = null;
+        if (rsae.getImportReference()!= null) {
+            epd = rsae.getImportReference().getImportedEndpoint();
+        } else if (rsae.getExportReference() != null) {
+            epd = rsae.getExportReference().getExportedEndpoint();
+        }
+
+        Properties props = new Properties();
+        setIfNotNull(props, "cause", rsae.getException());
+//FIXME !!!!!!!!!!!!!
+//        setIfNotNull(props, "import.registration", rsae.getImportRegistration());
+//        setIfNotNull(props, "export.registration", rsae.getExportRegistration());
+        if (epd != null) {
+            setIfNotNull(props, "service.remote.id", epd.getRemoteServiceID());
+            setIfNotNull(props, "service.remote.uuid", epd.getRemoteFrameworkUUID());
+            setIfNotNull(props, "service.remote.uri", epd.getRemoteURI());
+            // FIXME: correct ?!?
+            setIfNotNull(props, "objectClass", epd.getInterfaces().toArray());
+            setIfNotNull(props, "service.imported.configs", epd.getConfigurationTypes());
+            setIfNotNull(props, "service.imported.configs", epd.getConfigurationTypes());
+        }
+        props.put("timestamp", System.currentTimeMillis());
+        props.put("event", rsae);
+
+        Event ev = createEvent(props, topic);
+
+        EventAdmin[] eas = getEventAdmins();
+        if (eas != null) {
+            for (EventAdmin eventAdmin : eas) {
+                eventAdmin.postEvent(ev);
+            }
+        }
+
+    }
+
+    private void setIfNotNull(Properties props, String key, Object o) {
+        if (o != null)
+            props.put(key, o);
+    }
+
+    private EventAdmin[] getEventAdmins() {
+        ServiceReference[] refs = null;
+        try {
+            refs = bctx.getAllServiceReferences(EventAdmin.class.getName(), null);
+        } catch (InvalidSyntaxException e) {
+            e.printStackTrace();
+        }
+
+        if (refs == null)
+            return null;
+
+        EventAdmin[] eas = new EventAdmin[refs.length];
+        for (int x = 0; x < refs.length; ++x) {
+
+            ServiceReference serviceReference = refs[x];
+            eas[x] = (EventAdmin)bctx.getService(serviceReference);
+        }
+
+        return eas;
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,41 @@
+/** 
+  * 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.cxf.dosgi.dsw.service;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ExportReference;
+
+public class ExportReferenceImpl implements ExportReference {
+
+    private ExportRegistrationImpl exportRegistartion;
+    
+    public ExportReferenceImpl(ExportRegistrationImpl exportRegistrationImpl) {
+        exportRegistartion = exportRegistrationImpl;
+    }
+
+    public EndpointDescription getExportedEndpoint() {
+        return exportRegistartion.getEndpointDescription();
+    }
+
+    public ServiceReference getExportedService() {
+        return exportRegistartion.getExportedService();
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,448 @@
+/** 
+ * 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.cxf.dosgi.dsw.service;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.apache.cxf.dosgi.dsw.ClassUtils;
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.handlers.ClientServiceFactory;
+import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
+import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.dosgi.dsw.handlers.IntentUnsatifiedException;
+import org.apache.cxf.dosgi.dsw.hooks.ServiceHookUtils;
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.ExportRegistration;
+import org.osgi.service.remoteserviceadmin.ImportRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
+
+public class RemoteServiceAdminCore implements RemoteServiceAdmin {
+
+    private Logger LOG = Logger.getLogger(RemoteServiceAdminCore.class.getName());
+
+    private LinkedHashMap<ServiceReference, Collection<ExportRegistrationImpl>> exportedServices = new LinkedHashMap<ServiceReference, Collection<ExportRegistrationImpl>>();
+    private LinkedHashMap<EndpointDescription, ImportRegistrationImpl> importedServices = new LinkedHashMap<EndpointDescription, ImportRegistrationImpl>();
+
+    private BundleContext bctx;
+
+    private EventProducer eventProducer;
+
+    private static List<String> supportedConfigurationTypes = new ArrayList<String>();
+    static {
+        supportedConfigurationTypes.add(Constants.WSDL_CONFIG_TYPE);
+        supportedConfigurationTypes.add(Constants.RS_CONFIG_TYPE);
+        supportedConfigurationTypes.add(Constants.WS_CONFIG_TYPE);
+        supportedConfigurationTypes.add(Constants.WS_CONFIG_TYPE_OLD);
+    }
+
+    public RemoteServiceAdminCore(BundleContext bc) {
+        bctx = bc;
+        eventProducer = new EventProducer(bctx);
+    }
+
+    public List exportService(ServiceReference sref, Map additionalProperties)
+        throws IllegalArgumentException, UnsupportedOperationException {
+
+        LOG.fine("RemoteServiceAdmin: exportService: " + sref.getClass().getName());
+
+        // check if it is already exported ....
+        synchronized (exportedServices) {
+            if (exportedServices.containsKey(sref)) {
+                LOG.fine("already exported ...  " + sref.getClass().getName());
+                Collection<ExportRegistrationImpl> regs = exportedServices.get(sref);
+
+                // / create a new list with copies of the exportRegistrations
+                List<ExportRegistrationImpl> copy = new ArrayList<ExportRegistrationImpl>(regs.size());
+                for (ExportRegistrationImpl exportRegistration : regs) {
+                    copy.add(new ExportRegistrationImpl(exportRegistration));
+                }
+                eventProducer.publishNotifcation(copy);
+                return copy;
+            }
+
+            if (isCreatedByThisRSA(sref)) {
+                LOG.fine("proxy provided by this bundle ...  " + sref.getClass().getName());
+                return null;
+            }
+
+            Properties serviceProperties = new Properties();
+
+            {// gather EventProducerproperties from sRef
+                String[] keys = sref.getPropertyKeys();
+                for (String k : keys) {
+                    serviceProperties.put(k, sref.getProperty(k));
+                }
+            }
+
+            if (additionalProperties != null) {// overlay properties with the additionalProperies
+                Set<Map.Entry> adProps = additionalProperties.entrySet();
+                for (Map.Entry e : adProps) {
+                    // objectClass and service.id must not be overwritten
+                    Object keyO = e.getKey();
+                    if (keyO instanceof String && keyO != null) {
+                        String key = ((String)keyO).toLowerCase();
+                        if (org.osgi.framework.Constants.SERVICE_ID.toLowerCase().equals(key)
+                            || org.osgi.framework.Constants.OBJECTCLASS.toLowerCase().equals(key)) {
+                            LOG
+                                .info("exportService called with additional properties map that contained illegal key: "
+                                      + key + "   Te key is ignored");
+                            continue;
+                        }
+                    }
+                    serviceProperties.put(e.getKey(), e.getValue());
+                }
+            }
+
+            List<String> interfaces = new ArrayList<String>(1);
+
+            {// determine which interfaces should be exported ? based on props and sRef
+                String[] providedInterfaces = (String[])serviceProperties
+                    .get(org.osgi.framework.Constants.OBJECTCLASS);
+                String[] allowedInterfaces = Utils.normalizeStringPlus(serviceProperties
+                    .get(RemoteConstants.SERVICE_EXPORTED_INTERFACES));
+                if (providedInterfaces == null || allowedInterfaces == null) {
+                    LOG
+                        .severe("export failed: no provided service interfaces found or service_exported_interfaces is null !!");
+                    return null;
+                }
+
+                if (allowedInterfaces.length == 1 && "*".equals(allowedInterfaces[0])) {
+                    for (String i : providedInterfaces) {
+                        interfaces.add(i);
+                    }
+                } else {
+                    for (String x : allowedInterfaces) {
+                        for (String i : providedInterfaces) {
+                            if (x.equals(i)) {
+                                interfaces.add(i);
+                            }
+                        }
+                    }
+                }
+            }
+
+            LOG.info("interfaces selected for export: " + interfaces);
+
+            // if no interface is to be exported return null
+            if (interfaces.size() == 0) {
+                LOG.info("no interfaces to be exported");
+                return null;
+            }
+
+            List<String> configurationTypes = new ArrayList<String>();
+            {// determine which configuration types should be used / if the requested are supported
+                String[] requestedConfigurationTypes = Utils.normalizeStringPlus(serviceProperties
+                    .get(RemoteConstants.SERVICE_EXPORTED_CONFIGS));
+                if (requestedConfigurationTypes == null || requestedConfigurationTypes.length == 0) {
+                    // add all supported
+                    configurationTypes.addAll(supportedConfigurationTypes);
+                } else {
+                    for (String rct : requestedConfigurationTypes) {
+                        if (supportedConfigurationTypes.contains(rct)) {
+                            // this RSA supports this requested type ...
+                            configurationTypes.add(rct);
+                        }
+                    }
+                }
+
+            }
+
+            LOG.info("configuration types selected for export: " + configurationTypes);
+
+            // if no configuration type is supported ? return null
+            if (configurationTypes.size() == 0) {
+                LOG.info("the requested configuration types are not supported");
+                return null;
+            }
+
+            LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new LinkedHashMap<String, ExportRegistrationImpl>(
+                                                                                                                         1);
+            for (String iface : interfaces) {
+                LOG.info("creating initial ExportDescription for interface " + iface
+                         + "  with configuration types " + configurationTypes);
+
+                // create initial ExportRegistartion
+                ExportRegistrationImpl expReg = new ExportRegistrationImpl(sref, null, this);
+
+                exportRegs.put(iface, expReg);
+
+            }
+
+            // enlist initial export Registrations in global list of exprtRegistrations
+            exportedServices.put(sref, exportRegs.values());
+
+            // FIXME: move out of synchronized ... -> blocks until publication is finished
+            for (String iface : interfaces) {
+                LOG.info("creating server for interface " + iface);
+
+                ExportRegistrationImpl exportRegistration = exportRegs.get(iface);
+                ConfigurationTypeHandler handler = getHandler(configurationTypes, serviceProperties,
+                                                              getHandlerProperties());
+                Object serviceObject = bctx.getService(sref);
+                BundleContext callingContext = sref.getBundle().getBundleContext();
+
+                if (handler == null) {
+                    return null;
+                }
+
+                LOG.info("found handler for " + iface + "  -> " + handler);
+
+                String interfaceName = iface;
+                // this is an extra sanity check, but do we really need it now ?
+                Class<?> interfaceClass = ClassUtils.getInterfaceClass(serviceObject, interfaceName);
+
+                if (interfaceClass != null) {
+
+                    handler.createServer(exportRegistration, bctx, callingContext, serviceProperties,
+                                         interfaceClass, serviceObject);
+                    LOG.info("created server for interface " + iface);
+
+                }
+            }
+
+            List<ExportRegistrationImpl> lExpReg = new ArrayList<ExportRegistrationImpl>(exportRegs.values());
+
+            eventProducer.publishNotifcation(lExpReg);
+
+            return lExpReg;
+        }
+    }
+
+    private boolean isCreatedByThisRSA(ServiceReference sref) {
+        return sref.getBundle().equals(bctx.getBundle());
+    }
+
+    public Collection getExportedServices() {
+        synchronized (exportedServices) {
+            List<ExportRegistrationImpl> ers = new ArrayList<ExportRegistrationImpl>();
+            for (Collection<ExportRegistrationImpl> exportRegistrations : exportedServices.values()) {
+                ers.addAll(exportRegistrations);
+            }
+            return Collections.unmodifiableCollection(ers);
+        }
+    }
+
+    public Collection getImportedEndpoints() {
+        synchronized (importedServices) {
+            return Collections.unmodifiableCollection(importedServices.values());
+        }
+    }
+
+    private volatile boolean useMasterMap = true;
+    // MARC: FIXME !!!!
+    private volatile String defaultPort;
+    private volatile String defaultHost;
+
+    private ConfigurationTypeHandler getHandler(List<String> configurationTypes, Map serviceProperties,
+                                                Map<String, Object> props) {
+        return ConfigTypeHandlerFactory.getInstance().getHandler(bctx, configurationTypes, serviceProperties,
+                                                                 props);
+    }
+
+    protected Map<String, Object> getHandlerProperties() {
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put(Constants.DEFAULT_PORT_CONFIG, defaultPort == null
+            ? Constants.DEFAULT_PORT_VALUE : defaultPort);
+        props.put(Constants.DEFAULT_HOST_CONFIG, defaultHost == null
+            ? Constants.DEFAULT_HOST_VALUE : defaultHost);
+        props.put(Constants.USE_MASTER_MAP, useMasterMap);
+        return props;
+    }
+
+    /**
+     * Importing form here ....
+     */
+
+    /**
+     * For me it looks like the RSA is only able to import one interface by creating one proxy service which
+     * can than be placed in the ImportRegistration object. However the decision which service should be
+     * imported lies in the hands f the TopologyManager as the RSA has no idea about service interests ...
+     * Therefore the TM needs to modify the EndpointDescription in such a way that only one interface is
+     * listed in it anymore...
+     */
+    public ImportRegistration importService(EndpointDescription endpoint) {
+
+        LOG.info("importService() Endpoint: " + endpoint.getProperties());
+
+        synchronized (importedServices) {
+            if (importedServices.containsKey(endpoint)) {
+                ImportRegistrationImpl ir = new ImportRegistrationImpl(importedServices.get(endpoint));
+                eventProducer.publishNotifcation(ir);
+                return ir;
+            }
+
+            // FIXME:
+            List remoteConfigurationTypes = endpoint.getConfigurationTypes(); // not yet implemented
+            {
+                Object ecs_o = endpoint.getProperties().get(RemoteConstants.SERVICE_EXPORTED_CONFIGS);
+
+                if (ecs_o instanceof String) {
+                    remoteConfigurationTypes = new ArrayList(1);
+                    remoteConfigurationTypes.add((String)ecs_o);
+                }
+            }
+
+            if (remoteConfigurationTypes == null) {
+                LOG.severe("the supplied endpoint has no configuration type");
+                return null;
+            }
+
+            List<String> usableConfigurationTypes = new ArrayList<String>();
+            for (String ct : supportedConfigurationTypes) {
+                if (remoteConfigurationTypes.contains(ct)) {
+                    usableConfigurationTypes.add(ct);
+                }
+            }
+
+            if (usableConfigurationTypes.size() == 0) {
+                LOG
+                    .severe("the supplied endpoint has no compatible configuration type. Supported types are: "
+                            + supportedConfigurationTypes);
+                return null;
+            }
+
+            Map<String, Object> emptyProps = Collections.EMPTY_MAP;
+            ConfigurationTypeHandler handler = getHandler(usableConfigurationTypes, endpoint.getProperties(),
+                                                          emptyProps);
+
+            if (handler == null) {
+                LOG.severe("no handler found");
+                return null;
+            }
+
+            LOG.fine("Handler: "+handler);
+
+            // // TODO: somehow select the interfaces that should be imported ----> job of the TopologyManager
+            // ?
+            List<String> matchingInterfaces = endpoint.getInterfaces();
+
+            LOG.info("Interfaces: " + matchingInterfaces);
+
+            if (matchingInterfaces.size() == 1) {
+                LOG.info("Proxifying interface : " + matchingInterfaces.get(0));
+
+                ImportRegistrationImpl imReg = new ImportRegistrationImpl(endpoint,this);
+
+                proxifyMatchingInterface(matchingInterfaces.get(0), imReg, handler, bctx);
+                importedServices.put(endpoint, imReg);
+                return imReg;
+            } else {
+                return null;
+            }
+        }
+
+    }
+
+    private void proxifyMatchingInterface(String interfaceName, ImportRegistrationImpl imReg,
+                                          ConfigurationTypeHandler handler, BundleContext requestingContext) {
+
+        try {
+            // MARC: relies on dynamic imports ?
+            Class<?> iClass = bctx.getBundle().loadClass(interfaceName);
+            if (iClass != null) {
+                BundleContext actualContext = bctx;
+                Class<?> actualClass = requestingContext.getBundle().loadClass(interfaceName);
+                if (actualClass != iClass) {
+                    LOG.info("Class " + interfaceName + " loaded by DSW's bundle context is not "
+                             + "equal to the one loaded by the requesting bundle context, "
+                             + "DSW will use the requesting bundle context to register " + "a proxy service");
+                    iClass = actualClass;
+                    actualContext = requestingContext;
+                }
+
+                /* TODO: add additional local params ... */
+                Dictionary serviceProps = new Hashtable(imReg.getImportedEndpointDescription()
+                    .getProperties());
+                serviceProps.put(RemoteConstants.SERVICE_IMPORTED, true);
+                serviceProps.remove(RemoteConstants.SERVICE_EXPORTED_INTERFACES);
+
+                // synchronized (discoveredServices) {
+                ClientServiceFactory csf = new ClientServiceFactory(actualContext, iClass, imReg
+                    .getImportedEndpointDescription(), handler,imReg);
+
+                imReg.setClientServiceFactory(csf);
+                ServiceRegistration proxyRegistration = actualContext.registerService(interfaceName, csf,
+                                                                                      serviceProps);
+                imReg.setImportedServiceRegistration(proxyRegistration);
+                // cacheEndpointId(sd, proxyRegistration);
+                // }
+            } else {
+                LOG.info("not proxifying service, cannot load interface class: " + interfaceName);
+                imReg.setException(new ClassNotFoundException(
+                                                              "not proxifying service, cannot load interface class: "
+                                                                  + interfaceName));
+            }
+        } catch (ClassNotFoundException ex) {
+            LOG.warning("No class can be found for " + interfaceName);
+            imReg.setException(ex);
+        }
+    }
+
+    /**
+     * Removes the provided Export Registration from the internal management structures -> intended to be used
+     * when the export Registration is closed
+     */
+    protected void removeExportRegistration(ExportRegistrationImpl eri) {
+
+        synchronized (exportedServices) {
+            Collection<ExportRegistrationImpl> exRegs = exportedServices.get(eri.getServiceReference());
+            if (exRegs.contains(eri)) {
+                exRegs.remove(eri);
+            } else {
+                LOG.severe("An exportRegistartion was intended to be removed form internal management structure but couldn't be found in it !! ");
+            }
+            if (exRegs.size() == 0) {
+                exportedServices.remove(eri.getServiceReference());
+            }
+
+            eventProducer.notifyRemoval(eri);
+        }
+
+    }
+    
+    protected void removeImportRegistration(ImportRegistrationImpl iri){
+        synchronized (importedServices) {
+            LOG.finest("Removing importRegistration "+iri);
+            if(importedServices.remove(iri.getImportedEndpointDescription())==null){
+                LOG.severe("An importRegistartion couldn't be removed from the internal management structure -> structure is inconsistent !!");
+            }
+            eventProducer.notifyRemoval(iri);
+        }
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/META-INF/MANIFEST.MF?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/META-INF/MANIFEST.MF (added)
+++ cxf/dosgi/trunk/dsw/cxf-osgi-remote-service-admin-interfaces/META-INF/MANIFEST.MF Thu Dec 17 11:49:51 2009
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Export-Package: org.osgi.service.remoteserviceadmin;uses:="org.osgi.fr
+ amework";version="1.0.0"
+Embed-Directory: target/dependency
+Built-By: dbosscha
+Tool: Bnd-0.0.238
+Bundle-Name: CXF OSGi Remote Service Admin interfaces
+Created-By: Apache Maven Bundle Plugin
+Bundle-Vendor: The Apache Software Foundation
+Build-Jdk: 1.6.0_13
+Bundle-Version: 1.0.0
+Bnd-LastModified: 1261045402373
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Import-Package: org.osgi.framework,org.osgi.service.remoteserviceadmin
+ ;version="1.0.0"
+Embed-StripGroup: true
+Bundle-SymbolicName: cxf-dosgi-remote-service-admin-interfaces
+Bundle-DocURL: http://www.apache.org/
+Embed-Dependency: *;scope=compile|runtime;inline=false
+

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/META-INF/MANIFEST.MF?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/META-INF/MANIFEST.MF (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/META-INF/MANIFEST.MF Thu Dec 17 11:49:51 2009
@@ -0,0 +1,24 @@
+Manifest-Version: 1.0
+Export-Package: org.osgi.service.remoteserviceadmin;uses:="org.osgi.fr
+ amework";version="1.0.0",org.apache.cxf.dosgi.topologymanager;uses:="
+ org.osgi.service.remoteserviceadmin,org.osgi.util.tracker,org.osgi.fr
+ amework,org.osgi.framework.hooks.service";version="1.2.0.SNAPSHOT"
+Built-By: dbosscha
+Tool: Bnd-0.0.238
+Bundle-Name: CXF dOSGi Topology Manager
+Created-By: Apache Maven Bundle Plugin
+Bundle-Vendor: The Apache Software Foundation
+Build-Jdk: 1.6.0_13
+Bundle-Version: 1.2.0.SNAPSHOT
+Bnd-LastModified: 1261045415140
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.apache.cxf.dosgi.topologymanager.Activator
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: TODO
+Import-Package: org.apache.cxf.dosgi.topologymanager;version="1.2.0.SN
+ APSHOT",org.osgi.framework;version="1.4",org.osgi.framework.hooks.ser
+ vice,org.osgi.service.remoteserviceadmin;version="1.0.0",org.osgi.uti
+ l.tracker;version="1.3"
+Bundle-SymbolicName: cxf-dosgi-topology-manager
+Bundle-DocURL: http://www.apache.org/
+

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,122 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+
+// TODO: realize as ServiceFactory ! 
+public class EndpointListenerImpl implements EndpointListener {
+
+    private static final Logger LOG = Logger.getLogger(EndpointListenerImpl.class.getName());
+    
+    private final BundleContext bctx;
+    private ServiceRegistration serviceRegistration;
+    private List<String> filters = new ArrayList<String>();
+    private TopologyManagerImport topManager;
+
+    protected EndpointListenerImpl(BundleContext bc, TopologyManagerImport tm) {
+        bctx = bc;
+        topManager = tm;
+    }
+
+    protected void start() {
+        serviceRegistration = bctx.registerService(EndpointListener.class.getName(), this,
+                                                   getRegistrationProperties());
+    }
+
+
+
+    protected void stop() {
+        serviceRegistration.unregister();
+    }
+
+    protected void extendScope(String filter) {
+        if (filter == null)
+            return;
+        
+        
+        LOG.info("EndpointListener: extending scope by " + filter);
+
+        synchronized (filters) {
+            filters.add(filter);
+        }
+        updateRegistration();
+    }
+
+   
+
+    protected void reduceScope(String filter) {
+        if (filter == null)
+            return;
+        
+        
+        LOG.info("EndpointListener: reducing scope by " + filter);
+        synchronized (filters) {
+            filters.remove(filter);
+        }
+        updateRegistration();
+    }
+
+    private Dictionary getRegistrationProperties() {
+        Properties p = new Properties();
+
+        synchronized (filters) {
+            LOG.info("EndpointListener: current filter: " + filters);
+            // TODO: make a copy of the filter list
+            p.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, filters);
+        }
+
+        return p;
+    }
+
+    private void updateRegistration() {
+
+        LOG.info("EndpointListenerImpl: filters: " + filters);
+
+        serviceRegistration.setProperties(getRegistrationProperties());
+    }
+
+    public void endpointAdded(EndpointDescription epd, String filter) {
+        LOG.info("EndpointListenerImpl: EndpointAdded() filter:"+filter+"  EndpointDesc:"+epd);
+        
+        if(filter==null){
+            LOG.severe("Endpoint is not handled because no matching filter was provided! Filter: "+filter);
+            return;
+        }
+        // Decide if it is worth it ? 
+        
+        topManager.addImportableService(filter,epd);
+        
+    }
+
+    public void endpointRemoved(EndpointDescription epd, String filter) {
+        LOG.info("EndpointListenerImpl: EndpointRemoved() -> "+epd);
+        topManager.removeImportableService(filter, epd);
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/EndpointListenerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,139 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.service.ListenerHook;
+
+public class ListenerHookImpl implements ListenerHook {
+    private static final Logger LOG = Logger.getLogger(ListenerHookImpl.class.getName());
+    private BundleContext bctx;
+    private ServiceRegistration serviceRegistrations;
+    private TopologyManagerImport tm;
+
+    private final static String CLASS_NAME_EXPRESSION = ".*\\(" + Constants.OBJECTCLASS
+                                                        + "=([a-zA-Z_0-9.]+)\\).*";
+    private final static Pattern CLASS_NAME_PATTERN = Pattern.compile(CLASS_NAME_EXPRESSION);
+
+    // From the old impl.
+    private static final Set<String> SYSTEM_PACKAGES;
+    static {
+        SYSTEM_PACKAGES = new HashSet<String>();
+        SYSTEM_PACKAGES.add("org.osgi.service");
+        SYSTEM_PACKAGES.add("org.apache.felix");
+        SYSTEM_PACKAGES.add("org.ops4j.pax.logging");
+        SYSTEM_PACKAGES.add("ch.ethz.iks.slp");
+        SYSTEM_PACKAGES.add("org.ungoverned.osgi.service");
+        SYSTEM_PACKAGES.add("org.springframework.osgi.context.event.OsgiBundleApplicationContextListener");
+        SYSTEM_PACKAGES.add("java.net.ContentHandler");
+    }
+
+    public ListenerHookImpl(BundleContext bc, TopologyManagerImport tm) {
+        bctx = bc;
+        this.tm = tm;
+    }
+
+    protected void start() {
+        // TODO: properties ?
+        serviceRegistrations = bctx.registerService(ListenerHook.class.getName(), this, null);
+    }
+
+    protected void stop() {
+        serviceRegistrations.unregister();
+    }
+
+    public void added(Collection listeners) {
+        LOG.fine("ListenerHookImpl: added() " + listeners);
+        for (Object li : listeners) {
+            ListenerInfo listenerInfo = (ListenerInfo)li;
+            LOG.info("*** Filter: " + listenerInfo.getFilter());
+
+            String className = getClassNameFromFilter(listenerInfo.getFilter());
+
+            if (listenerInfo.getBundleContext().getBundle().equals(bctx.getBundle())) {
+                LOG.info("ListenerHookImpl: skipping request from myself");
+                continue;
+            }
+
+            if (listenerInfo.getFilter() == null) {
+                LOG.info("ListenerHookImpl: skipping empty filter");
+                continue;
+            }
+
+            if (isClassExcluded(className)) {
+                LOG.info("ListenerHookImpl: skipping import request for excluded classs ["
+                                   + className + "]");
+                continue;
+            }
+
+            tm.addServiceInterest(listenerInfo.getFilter());
+
+        }
+
+    }
+
+    public void removed(Collection listeners) {
+        LOG.info("ListenerHookImpl: removed: " + listeners);
+
+        for (Object li : listeners) {
+            ListenerInfo listenerInfo = (ListenerInfo)li;
+            LOG.info(listenerInfo.getFilter());
+
+            // TODO: determine if service was handled ? 
+
+            tm.removeServiceInterest(listenerInfo.getFilter());
+
+        }
+
+    }
+
+    private String getClassNameFromFilter(String filter) {
+        if (filter != null) {
+            Matcher matcher = CLASS_NAME_PATTERN.matcher(filter);
+            if (matcher.matches() && matcher.groupCount() >= 1) {
+                return matcher.group(1);
+            }
+        }
+        return null;
+    }
+
+    private static boolean isClassExcluded(String className) {
+        if (className == null) {
+            return true;
+        }
+
+        for (String p : SYSTEM_PACKAGES) {
+            if (className.startsWith(p)) {
+                LOG.fine("Lookup for " + className + " is ignored");
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/ListenerHookImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,113 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import java.util.ArrayList;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class RemoteServiceAdminList extends ArrayList<RemoteServiceAdmin>{
+
+    private BundleContext bctx;
+    private ServiceTracker stRemoteServiceAdmin;
+    private TopologyManager topManager;
+    private TopologyManagerImport topManagerImport;
+    
+    private final static Logger LOG = Logger.getLogger(RemoteServiceAdminList.class.getName()); 
+    
+    
+    public RemoteServiceAdminList(BundleContext bc) {
+
+        bctx = bc;
+        
+        final RemoteServiceAdminList rsal = this;
+        
+        stRemoteServiceAdmin = new ServiceTracker(bctx, RemoteServiceAdmin.class.getName(), null) {
+            @Override
+            public Object addingService(ServiceReference reference) {
+                LOG.info("Adding RemoteServiceAdmin to list of admins ");
+                RemoteServiceAdmin rsa = (RemoteServiceAdmin)bctx.getService(reference);
+                synchronized (rsal) {
+                    rsal.add(rsa);
+                }
+                LOG.info("enlisted RemoteEventAdmins: " + this.size());
+
+                triggerExportImportForRemoteSericeAdmin(rsa);
+
+                return super.addingService(reference);
+            }
+
+            @Override
+            public void removedService(ServiceReference reference, Object service) {
+                LOG.info("TopologyManager: Removing RemoteServiceAdmin from list of admins ");
+                synchronized (rsal) {
+                    rsal.remove(service);
+                }
+
+                // TODO: remove service exports from management structure and notify discovery stuff...
+                removeRemoteServiceAdmin((RemoteServiceAdmin)service);
+
+                LOG.info("TopologyManager: enlisted RemoteEventAdmins: " + rsal.size());
+
+                super.removedService(reference, service);
+            }
+        };
+    
+    
+        
+        
+    } 
+
+    
+    protected void removeRemoteServiceAdmin(RemoteServiceAdmin service) {
+        topManager.removeRemoteServiceAdmin(service);
+    }
+
+
+    protected void triggerExportImportForRemoteSericeAdmin(RemoteServiceAdmin rsa) {
+        topManager.triggerExportImportForRemoteSericeAdmin(rsa);
+        topManagerImport.triggerExportImportForRemoteSericeAdmin(rsa);
+    }
+
+
+    public void start(){
+        stRemoteServiceAdmin.open();
+    }
+
+    
+    public void stop(){
+        stRemoteServiceAdmin.close();
+    }
+
+
+    public void setTopologyManager(TopologyManager tm) {
+        topManager = tm;
+    }
+
+
+    public void setTopologyManagerImport(TopologyManagerImport tmi) {
+        topManagerImport = tmi;
+    }
+    
+    
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminList.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,71 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
+
+public class RemoteServiceAdminListenerImpl implements RemoteServiceAdminListener {
+
+    private Logger LOG = Logger.getLogger(RemoteServiceAdminListenerImpl.class.getName());
+
+    private BundleContext bctx;
+    private ServiceRegistration serviceRegistration;
+    private TopologyManager topManager;
+    private TopologyManagerImport topManagerImport;
+
+    public RemoteServiceAdminListenerImpl(BundleContext bctx,TopologyManager tm, TopologyManagerImport tmi) {
+        this.bctx = bctx;
+        this.topManager = tm;
+        this.topManagerImport = tmi;
+    }
+
+    public void start() {
+        // TODO: properties needed ?
+        serviceRegistration = bctx.registerService(RemoteServiceAdminListener.class.getName(), this, null);
+    }
+
+    public void stop() {
+        serviceRegistration.unregister();
+    }
+
+    public void remoteAdminEvent(RemoteServiceAdminEvent event) {
+        LOG.fine("Received RemoteAdminEvent: " + event  + "   TYPE: "  + event.getType());
+
+        switch (event.getType()) {
+        case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
+            topManager.removeExportReference(event.getExportReference());
+            break;
+
+        case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
+            topManagerImport.removeImportReference(event.getImportReference());
+            break;
+            
+        default:
+            LOG.info("Unhandled event type received: " + event.getType());
+
+        }
+
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/RemoteServiceAdminListenerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,412 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.service.remoteserviceadmin.ExportReference;
+import org.osgi.service.remoteserviceadmin.ExportRegistration;
+import org.osgi.service.remoteserviceadmin.ImportRegistration;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * <li>This class keeps a list of currently imported and exported endpoints <li>It requests the import/export
+ * from RemoteAdminServices
+ */
+public class TopologyManager {
+
+    private final static Logger LOG = Logger.getLogger(TopologyManager.class.getName());
+
+    private ExecutorService execService = new ThreadPoolExecutor(5, 10, 50, TimeUnit.SECONDS,
+                                                                 new LinkedBlockingQueue<Runnable>());
+
+    private RemoteServiceAdminList remoteServiceAdminList;
+
+    private ServiceListenerImpl serviceListerner;
+
+    /**
+     * Holds all services that are exported by this TopologyManager for each ServiceReference that should be
+     * exported a map is maintained which contains information on the endpoints for each RemoteAdminService
+     * 
+     * <pre>
+     * Bsp.:
+     * ServiceToExort_1
+     * ---&gt; RemoteAdminService_1 (CXF HTTP)
+     * --------&gt; List&lt;EndpointDescription&gt; -&gt; {http://localhost:1234/greeter, http://localhost:8080/hello}
+     * ---&gt; RemoteAdminService_2 (ActiveMQ JMS/OpenWire)
+     * --------&gt; List&lt;EndpointDescription&gt; -&gt; {OpenWire://127.0.0.1:123/testQueue}
+     * ServiceToExort_2
+     * ---&gt; RemoteAdminService_1 (CXF HTTP)
+     * --------&gt; List&lt;EndpointDescription&gt; -&gt; {empty} // not exported yet or not suitable
+     * 
+     * </pre>
+     */
+    private HashMap<ServiceReference, HashMap<RemoteServiceAdmin, Collection<ExportRegistration>>> exportedServices = new LinkedHashMap<ServiceReference, HashMap<RemoteServiceAdmin, Collection<ExportRegistration>>>();
+
+    private BundleContext bctx;
+    // private List<RemoteServiceAdmin> remoteServiceAdmins = new ArrayList<RemoteServiceAdmin>();
+
+    private ServiceTracker stEndpointListeners;
+
+    public TopologyManager(BundleContext ctx, RemoteServiceAdminList rsaList) {
+        bctx = ctx;
+
+        remoteServiceAdminList = rsaList;
+
+        stEndpointListeners = new ServiceTracker(ctx, EndpointListener.class.getName(), null) {
+            @Override
+            public Object addingService(ServiceReference reference) {
+                LOG
+                    .info("TopologyManager: new EndpointListener that wants to be informed about wants going on ... ");
+
+                notify(reference);
+
+                return super.addingService(reference);
+            }
+
+            @Override
+            public void modifiedService(ServiceReference reference, Object service) {
+                LOG.info("TopologyManager: EndpointListener changed ... ");
+                notify(reference);
+                super.modifiedService(reference, service);
+            }
+
+            private void notify(ServiceReference reference) {
+                synchronized (exportedServices) {
+                    for (HashMap<RemoteServiceAdmin, Collection<ExportRegistration>> exports : exportedServices
+                        .values()) {
+                        for (Collection<ExportRegistration> regs : exports.values()) {
+                            if (regs != null)
+                                notifyListenerOfAddingIfAppropriate(reference, regs);
+                        }
+                    }
+                }
+            }
+        };
+
+        serviceListerner = new ServiceListenerImpl(bctx, this);
+
+    }
+
+    protected void removeRemoteServiceAdmin(RemoteServiceAdmin rsa) {
+        synchronized (exportedServices) {
+            for (Map.Entry<ServiceReference, HashMap<RemoteServiceAdmin, Collection<ExportRegistration>>> exports : exportedServices
+                .entrySet()) {
+                if (exports.getValue().containsKey(rsa)) {
+                    // service was handled by this RemoteServiceAdmin
+                    Collection<ExportRegistration> endpoints = exports.getValue().get(rsa);
+                    // TODO for each notify discovery......
+
+                    try {
+                        ServiceReference[] refs = Utils.getEndpointListeners(bctx);
+                        for (ServiceReference sref : refs) {
+                            notifyListenersOfRemovalIfAppropriate(sref, endpoints);
+                        }
+                    } catch (InvalidSyntaxException e) {
+                        e.printStackTrace();
+                    }
+
+                    // remove all management information for the RemoteServiceAdmin
+                    exports.getValue().remove(rsa);
+                }
+            }
+        }
+    }
+
+    protected void triggerExportImportForRemoteSericeAdmin(RemoteServiceAdmin rsa) {
+        LOG.info("TopologyManager: triggerExportImportForRemoteSericeAdmin()");
+
+        synchronized (exportedServices) {
+            for (Map.Entry<ServiceReference, HashMap<RemoteServiceAdmin, Collection<ExportRegistration>>> exports : exportedServices
+                .entrySet()) {
+                if (exports.getValue().containsKey(rsa)) {
+                    // already handled....
+                    LOG.info("TopologyManager: service from bundle "
+                             + exports.getKey().getBundle().getSymbolicName()
+                             + "is already handled by this RSA");
+                } else {
+                    // trigger export of this service....
+                    LOG.info("TopologyManager: service from bundle "
+                             + exports.getKey().getBundle().getSymbolicName()
+                             + " is to be exported by this RSA");
+                    triggerExport(exports.getKey());
+                }
+
+            }
+        }
+
+    }
+
+    public void start() {
+        stEndpointListeners.open();
+        serviceListerner.start();
+
+        try {
+            checkExistingServices();
+        } catch (InvalidSyntaxException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void stop() {
+        execService.shutdown();
+        stEndpointListeners.close();
+        serviceListerner.stop();
+    }
+
+    void removeService(ServiceReference sref) {
+        synchronized (exportedServices) {
+            if (exportedServices.containsKey(sref)) {
+                Map<RemoteServiceAdmin, Collection<ExportRegistration>> rsas = exportedServices.get(sref);
+                for (Map.Entry<RemoteServiceAdmin, Collection<ExportRegistration>> entry : rsas.entrySet()) {
+                    if (entry.getValue() != null) {
+                        for (ExportRegistration exReg : entry.getValue()) {
+                            if (exReg != null)
+                                exReg.close();
+                        }
+                    }
+                }
+
+                exportedServices.remove(sref);
+            }
+        }
+    }
+
+    protected void exportService(ServiceReference sref) {
+
+        // add to local list of services that should/are be exported
+        synchronized (exportedServices) {
+            LOG
+                .info("TopologyManager: adding service to exportedServices list to export it --- from bundle:  "
+                      + sref.getBundle().getSymbolicName());
+            exportedServices.put(sref, new LinkedHashMap<RemoteServiceAdmin, Collection<ExportRegistration>>());
+        }
+
+        // trigger the export
+        triggerExport(sref);
+
+    }
+
+    private void triggerExport(final ServiceReference sref) {
+        execService.execute(new Runnable() {
+            @SuppressWarnings("unchecked")
+            public void run() {
+                LOG.info("TopologyManager: exporting  serice ...");
+
+                HashMap<RemoteServiceAdmin, Collection<ExportRegistration>> exports = null;
+
+                synchronized (exportedServices) {
+                    exports = exportedServices.get(sref);
+                }
+                // FIXME: Not thread safe...?
+                if (exports != null) {
+                    synchronized (exports) {
+                        synchronized (remoteServiceAdminList) {
+                            for (RemoteServiceAdmin remoteServiceAdmin : remoteServiceAdminList) {
+                                LOG
+                                    .info("TopologyManager: handling remoteServiceAdmin "
+                                          + remoteServiceAdmin);
+
+                                if (exports.containsKey(remoteServiceAdmin)) {
+                                    // already handled by this remoteServiceAdmin
+                                    LOG
+                                        .info("TopologyManager: already handled by this remoteServiceAdmin -> skipping");
+                                } else {
+                                    // TODO: additional parameter Map ?
+                                    LOG.info("TopologyManager: exporting ...");
+                                    Collection<ExportRegistration> endpoints = remoteServiceAdmin
+                                        .exportService(sref, null);
+                                    if (endpoints == null) {
+                                        // TODO export failed -> What should be done here?
+                                        LOG.info("TopologyManager: export failed");
+                                        exports.put(remoteServiceAdmin, null);
+                                    } else {
+                                        LOG.info("TopologyManager: export sucessful Endpoints:" + endpoints);
+                                        // enqueue in local list of endpoints
+                                        exports.put(remoteServiceAdmin, endpoints);
+
+                                        // publish to endpoint listeners
+                                        nofifyListeners(endpoints);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+        });
+    }
+
+    protected void nofifyListeners(Collection<ExportRegistration> exportRegistrations) {
+        try {
+            // Find all EndpointListeners; They must have the Scope property otherwise they have to be ignored
+            ServiceReference[] refs = Utils.getEndpointListeners(bctx);
+
+            if (refs != null) {
+                for (ServiceReference sref : refs) {
+                    notifyListenerOfAddingIfAppropriate(sref, exportRegistrations);
+                }
+            }
+
+        } catch (InvalidSyntaxException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /**
+     * Notifies the listener if he is interested in the provided registrations
+     * 
+     * @param sref The ServiceReference for an EndpointListener
+     * @param exportRegistrations the registrations, the listener should be informed about
+     */
+    protected void notifyListenerOfAddingIfAppropriate(ServiceReference sref,
+                                                       Collection<ExportRegistration> exportRegistrations) {
+
+        // if (sref.getBundle().equals(bctx.getBundle())) {
+        // LOG
+        // .info("TopologyManager: notifyListenerOfAddingIfAppropriate() called for own listener -> skipping ");
+        // return;
+        // }
+
+        EndpointListener epl = (EndpointListener)bctx.getService(sref);
+
+        LOG.info("TopologyManager: notifyListenerOfAddingIfAppropriate() ");
+
+        try {
+
+            List<Filter> filters = Utils.normalizeScope(sref, bctx);
+
+            for (ExportRegistration exReg : exportRegistrations) {
+
+                // FIXME!!!!!!!!!!!!! There needs to be a better way ?!?!?!
+                Map props = exReg.getExportReference().getExportedEndpoint().getProperties();
+                Dictionary d = new Hashtable(props);
+
+                for (Filter filter : filters) {
+                    LOG.info("Matching: " + filter + "  against " + d);
+                }
+
+                for (Filter filter : filters) {
+                    if (filter.match(d)) {
+                        LOG.info("Listener mached one of the Endpoints !!!!: " + epl);
+
+                        epl.endpointAdded(exReg.getExportReference().getExportedEndpoint(), filter.toString());
+                    }
+                }
+            }
+
+        } catch (InvalidSyntaxException e) {
+            e.printStackTrace();
+        }
+    }
+
+    protected void notifyListenersOfRemovalIfAppropriate(ServiceReference sref,
+                                                         Collection<ExportRegistration> exportRegistrations) {
+
+        EndpointListener epl = (EndpointListener)bctx.getService(sref);
+
+        LOG.info("TopologyManager: notifyListenerOfREMOVALIfAppropriate() ");
+
+        List<Filter> filters;
+        try {
+            filters = Utils.normalizeScope(sref, bctx);
+
+            for (ExportRegistration exReg : exportRegistrations) {
+
+                // FIXME!!!!!!!!!!!!! There needs to be a better way ?!?!?!
+                Map props = exReg.getExportReference().getExportedEndpoint().getProperties();
+                Dictionary d = new Hashtable(props);
+
+                for (Filter filter : filters) {
+                    LOG.info("Matching: " + filter + "  against " + d);
+                }
+
+                for (Filter filter : filters) {
+                    if (filter.match(d)) {
+                        LOG.info("Listener matched one of the Endpoints !!!! --> calling removed() ...");
+
+                        epl.endpointRemoved(exReg.getExportReference().getExportedEndpoint(), filter.toString());
+                    }
+                }
+            }
+        } catch (InvalidSyntaxException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+
+    private void checkExistingServices() throws InvalidSyntaxException {
+        ServiceReference[] references = bctx
+            .getServiceReferences(null, "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)");
+        // + "("+org.apache.cxf.dosgi.dsw.Constants.EXPORTED_INTERFACES_OLD + "=*))");
+
+        if (references != null) {
+            for (ServiceReference sref : references) {
+                exportService(sref);
+            }
+        }
+    }
+
+    public void removeExportRegistration(ExportRegistration exportRegistration) {
+        ServiceReference sref = exportRegistration.getExportReference().getExportedService();
+        if (sref != null) {
+            synchronized (exportedServices) {
+
+                HashMap<RemoteServiceAdmin, Collection<ExportRegistration>> ex = exportedServices.get(sref);
+                if (ex != null) {
+                    EndpointDescription ep = exportRegistration.getExportReference().getExportedEndpoint();
+                    for (Map.Entry<RemoteServiceAdmin, Collection<ExportRegistration>> export : ex.entrySet()) {
+                        export.getValue().contains(exportRegistration);
+                    }
+                }
+            }
+        } else {
+            // the manager will be notified by its own service listener about this case
+        }
+    }
+
+    public void removeExportReference(ExportReference anyObject) {
+        // TODO Auto-generated method stub
+        LOG.severe("NOT implemented !!!");
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/TopologyManager.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,88 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointListener;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+
+public class Utils {
+
+    private static final Logger LOG = Logger.getLogger(Utils.class.getName());
+    
+    protected static ServiceReference[] getEndpointListeners(BundleContext bctx) throws InvalidSyntaxException {
+        ServiceReference[] refs = bctx
+            .getServiceReferences(EndpointListener.class.getName(),
+                                  "(" + EndpointListener.ENDPOINT_LISTENER_SCOPE + "=*)");
+        return refs;
+    }
+
+    public static List<Filter> normalizeScope(ServiceReference sref,BundleContext bctx) throws InvalidSyntaxException {
+        List<Filter> filters = new ArrayList<Filter>();
+    
+        Object fo = sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE);
+        if (fo instanceof String) {
+            filters.add(bctx.createFilter((String)fo));
+        } else if (fo instanceof String[]) {
+            String[] foArray = (String[])fo;
+            for (String f : foArray) {
+                filters.add(bctx.createFilter(f));
+            }
+        } else if (fo instanceof Collection) {
+            Collection c = (Collection)fo;
+            for (Object o : c) {
+                if (o instanceof String) {
+                    filters.add(bctx.createFilter((String)o));
+                } else {
+                    LOG.info("Component of a filter is not a string -> skipped !");
+                }
+            }
+        }
+    
+        return filters;
+    }
+
+    
+    public static String getUUID(BundleContext bctx) {
+        synchronized ("org.osgi.framework.uuid") {
+            String uuid = bctx.getProperty("org.osgi.framework.uuid");
+            if(uuid==null){
+                uuid = UUID.randomUUID().toString();
+                System.setProperty("org.osgi.framework.uuid", uuid);
+            }
+            return uuid;
+        }
+    }
+    
+    
+    public static  String extendFilter(String filter,BundleContext bctx) {
+        return "(&"+filter+"(!("+RemoteConstants.ENDPOINT_FRAMEWORK_UUID+"="+Utils.getUUID(bctx)+")))";
+    }
+    
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Utils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java?rev=891660&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java (added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java Thu Dec 17 11:49:51 2009
@@ -0,0 +1,101 @@
+/** 
+  * 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.cxf.dosgi.topologymanager;
+
+import org.easymock.classextension.EasyMock;
+import org.osgi.framework.BundleContext;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class ActivatorTest {
+
+    @Test
+    public void testTopologyManagerInit() throws Exception {
+
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+
+        final TopologyManager tm = EasyMock.createNiceMock(TopologyManager.class);
+        final TopologyManagerImport tmi = EasyMock.createNiceMock(TopologyManagerImport.class);
+        final RemoteServiceAdminList rsal = EasyMock.createNiceMock(RemoteServiceAdminList.class);
+        final RemoteServiceAdminListenerImpl rsaListener = EasyMock.createNiceMock(RemoteServiceAdminListenerImpl.class);
+
+        tm.start();
+        EasyMock.expectLastCall().once();
+        
+        tm.stop();
+        EasyMock.expectLastCall().once();
+        
+        tmi.start();
+        EasyMock.expectLastCall().once();
+        
+        tmi.stop();
+        EasyMock.expectLastCall().once();
+        
+        rsaListener.start();
+        EasyMock.expectLastCall().once();
+        
+        rsaListener.stop();
+        EasyMock.expectLastCall().once();
+        
+        
+        
+        Activator a = new Activator() {
+            @Override
+            protected TopologyManager createTopologyManager(BundleContext bc, RemoteServiceAdminList rl) {
+                return tm;
+            }
+            @Override
+            protected TopologyManagerImport createTopologyManagerImport(BundleContext bc,
+                                                                        RemoteServiceAdminList rl) {
+                return tmi;
+            }
+            
+            @Override
+            protected RemoteServiceAdminList createRemoteServiceAdminList(BundleContext bc) {
+                // TODO Auto-generated method stub
+                return rsal;
+            }
+            
+            @Override
+            protected RemoteServiceAdminListenerImpl createRemoteServiceAdminListenerImpl(
+                                                                                          BundleContext bc,
+                                                                                          TopologyManager topManager,
+                                                                                          TopologyManagerImport topManagerImport) {
+                // TODO Auto-generated method stub
+                return rsaListener;
+            }
+            
+        };
+        
+        EasyMock.replay(bc);
+        EasyMock.replay(tm);
+        EasyMock.replay(tmi);
+        
+        a.start(bc);
+
+        a.stop(bc);
+        
+        EasyMock.verify(tm);
+        EasyMock.verify(tmi);
+
+    }
+
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ActivatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message