cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r690991 [2/20] - in /cxf/sandbox/dosgi: ./ discovery/ discovery/local/ discovery/local/src/ discovery/local/src/main/ discovery/local/src/main/java/ discovery/local/src/main/java/org/ discovery/local/src/main/java/org/apache/ discovery/loca...
Date Mon, 01 Sep 2008 15:08:10 GMT
Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,332 @@
+/** 
+  * 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;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.dosgi.dsw.qos.IntentMap;
+import org.apache.cxf.dosgi.dsw.service.ServiceDescriptionImpl;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServiceDescription;
+import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
+
+
+public final class OsgiUtils {
+
+    private static final Logger LOG = 
+        Logger.getLogger(OsgiUtils.class.getName());    
+    private static final String REMOTE_SERVICES_ENTRY = 
+        "/META-INF/osgi/remote-services.xml";
+    private static final String REMOTE_SERVICES_NS =
+        "http://www.osgi.org/xmlns/rs/v1.0.0";
+    
+    private static final String[] INTENT_MAP = {"/META-INF/osgi/intent-map.xml"};
+    
+    private static final String PROPERTY_NAME_ATTRIBUTE = "name";
+    private static final String PROVIDE_INTERFACE_ATTRIBUTE = "interface";
+    
+    private OsgiUtils() {
+    }
+
+    
+    // Used by PublishHook 
+    public static ServiceDescription getRemoteReference(ServiceReference sref, boolean matchAllNames) {
+        
+        String[] names = (String[])sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS);
+        if (names == null || names.length == 0) {
+            return null;
+        }
+        Map<String, Object> userProperties = new HashMap<String, Object>();
+        for (String key : sref.getPropertyKeys()) {
+            // we're after remote properties only
+            Object property = sref.getProperty(key);
+            if (property.toString().startsWith(Constants.REMOTE_PROPERTY_PREFIX)) {
+                userProperties.put(key, property);
+            }
+        }
+        List<ServiceDescription> srefs = getRemoteReferences(sref.getBundle(), 
+                                                             names, 
+                                                             userProperties,
+                                                             matchAllNames);
+        
+        if (srefs.isEmpty()) {
+            return new ServiceDescriptionImpl(Arrays.asList(names), userProperties);
+        }
+        
+        return srefs.get(0); 
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<ServiceDescription> getRemoteReferences(
+        Bundle b, String[] names, Map<String, Object> userProperties, boolean matchAllNames) {
+        
+        List<Element> references = getAllReferenceElements(b);
+        
+        List<ServiceDescription> srefs = new ArrayList<ServiceDescription>();
+        Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
+        for (Element ref : references) {
+            List<String> iNames = getInterfaceNames(ref.getChildren("provide", ns));
+            if (!serviceNamesMatch(names, iNames, matchAllNames)) {
+                continue;
+            }
+
+            Map<String, Object> remoteProps = getProperties(ref.getChildren("property", ns));
+            remoteProps.putAll(userProperties);
+            srefs.add(new ServiceDescriptionImpl(iNames, remoteProps));
+            
+        }
+        return srefs;
+        
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<ServiceDescription> getAllRemoteReferences(Bundle b) {
+        
+        List<Element> references = getAllReferenceElements(b);
+        
+        List<ServiceDescription> srefs = new ArrayList<ServiceDescription>();
+        Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
+        for (Element ref : references) {
+            List<String> iNames = getInterfaceNames(ref.getChildren("provide", ns));
+            Map<String, Object> remoteProps = getProperties(ref.getChildren("property", ns));
+            srefs.add(new ServiceDescriptionImpl(iNames, remoteProps));
+        }
+        return srefs;
+        
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static List<Element> getAllReferenceElements(Bundle b) {
+        URL resourceURL = b.getEntry(REMOTE_SERVICES_ENTRY);
+        if (resourceURL != null) {
+            try {
+                Document d = new SAXBuilder().build(resourceURL.openStream());
+                Namespace ns = Namespace.getNamespace(REMOTE_SERVICES_NS);
+                
+                return d.getRootElement().getChildren("reference", ns);
+            } catch (Exception ex) {
+                System.out.println("Problem parsing remote-services.xml :" 
+                                   + ex.getMessage());
+            }
+        }
+        return Collections.emptyList(); 
+    }
+    
+    private static boolean serviceNamesMatch(
+        String[] names, List<String> iNames, boolean matchAllNames) {
+        if (names == null || names.length == 0) {
+            return false;
+        }
+        if (matchAllNames) {
+            for (String name : names) {
+                if (!iNames.contains(name)) {
+                    return false;
+                }
+            }
+            return true;
+        } else {
+            for (String name : names) {
+                if (iNames.contains(name)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+    
+    // TODO : consider creating a new List rather than modifyiing the existing one
+    public static void matchServiceDescriptions(List<ServiceDescription> sds,
+                                                Filter filter, 
+                                                boolean matchAll) {
+        
+        for (Iterator<ServiceDescription> it = sds.iterator(); it.hasNext();) {
+            ServiceDescription sd = it.next();
+             
+            if (filter != null && !OsgiUtils.matchAgainstFilter(sd, filter, matchAll)) {
+                it.remove();
+            }
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static boolean matchAgainstFilter(ServiceDescription sd, Filter filter, boolean matchAll) {
+        Dictionary props = new Hashtable();
+        for (Object key : sd.getPropertyKeys()) {
+            if (matchAll || key.toString().startsWith(Constants.REMOTE_PROPERTY_PREFIX)) {
+                props.put(key, sd.getProperty(key.toString()));
+            }
+        }
+        props.put(org.osgi.framework.Constants.OBJECTCLASS, 
+                  new String[]{sd.getInterfaceName()});
+        return filter.match(props);
+    }
+    
+    public static Filter createFilter(BundleContext bc, String filterValue) {
+        
+        if (filterValue == null) {
+            return null;
+        }
+        
+        try {
+            return bc.createFilter(filterValue); 
+        } catch (InvalidSyntaxException ex) {
+            System.out.println("Invalid filter expression " + filterValue);
+        } catch (Exception ex) {
+            System.out.println("Problem creating a Filter from " + filterValue); 
+        }
+        return null;
+    }
+    
+    public static String[] parseIntents(String intentsSequence) {
+        return intentsSequence == null ? new String[]{} : intentsSequence.split(" ");
+    }
+    
+    private static Map<String, Object> getProperties(List<Element> elements) {
+        
+        Map<String, Object> props = new HashMap<String, Object>();
+        
+        for (Element p : elements) {
+            String key = p.getAttributeValue(PROPERTY_NAME_ATTRIBUTE);
+            if (key != null) {
+                props.put(key, p.getTextTrim());
+            }
+        }
+        
+        return props;
+    }
+    
+    private static List<String> getInterfaceNames(List<Element> elements) {
+        
+        List<String> names = new ArrayList<String>();
+        
+        for (Element p : elements) {
+            String name = p.getAttributeValue(PROVIDE_INTERFACE_ATTRIBUTE);
+            if (name != null) {
+                names.add(name);
+            }
+        }
+        
+        return names;
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static <T> OsgiService<T> getOsgiService(
+        BundleContext bc, Class<T> serviceClass) {
+        try {
+            ServiceReference sr = bc.getServiceReference(serviceClass.getName());
+            if (sr != null) {
+                Object o = bc.getService(sr);
+                if (o != null && serviceClass.isAssignableFrom(o.getClass())) {
+                    return new OsgiService(sr, o);
+                }
+            }
+        } catch (Exception ex) {
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.fine("Problem retrieving an OSGI service " + serviceClass.getName()
+                + ", exception : " + ex.getMessage());
+            }
+        }
+        return null;
+    }
+    
+    public static IntentMap getIntentMap(BundleContext bundleContext) {
+        try {
+            OsgiBundleXmlApplicationContext ctx = 
+                new OsgiBundleXmlApplicationContext(INTENT_MAP);
+            ctx.setPublishContextAsService(false);
+            ctx.setBundleContext(bundleContext);
+            ctx.refresh();
+            LOG.fine("application context: " + ctx);
+            IntentMap im = (IntentMap)ctx.getBean("intentMap");
+            LOG.fine("retrieved intent map: " + im);
+            return im;
+        } catch (Throwable t) {
+            LOG.log(Level.WARNING, "intent map load failed: ", t);
+            IntentMap im = new IntentMap();
+            im.setIntents(new HashMap<String, Object>());
+            return im;
+        }
+    }
+    
+    //Eg. "(&(" + Constants.OBJECTCLASS + "=Person)(|(sn=Jensen)(cn=Babs J*)))"
+    public static Filter createFilterFromProperties(BundleContext bc, 
+                                             Dictionary properties) {
+        
+        if (properties == null || properties.isEmpty()) {
+            return null;
+        }
+        
+        StringBuilder sb = new StringBuilder();
+        sb.append("(&");
+        for (Enumeration keys = properties.keys();keys.hasMoreElements();) {
+            String key = keys.nextElement().toString();
+            String value = properties.get(key).toString();
+            sb.append('(').append(key).append('=').append(value).append(')');
+        }
+        sb.append(')');
+        return createFilter(bc, sb.toString());
+    }
+    
+    
+    // TODO : move these property helpers into PropertyUtils ?
+    
+    public static boolean getBooleanProperty(ServiceDescription sd, String name) {
+        Object value = sd.getProperty(name);
+        return toBoolean(value);
+    }
+    
+    public static boolean toBoolean(Object value) {
+        return value instanceof Boolean && ((Boolean)value).booleanValue()
+            || value instanceof String && Boolean.parseBoolean((String)value);
+    }
+    
+    public static String getProperty(ServiceDescription sd, String name) { 
+        return getProperty(sd, name, String.class, null); 
+    }
+    
+    @SuppressWarnings("unchecked")
+    public static <T> T getProperty(ServiceDescription sd, String name, Class<T> type,
+                             T defaultValue) { 
+        Object o = sd.getProperty(name);
+        if (o == null) {
+            return defaultValue;
+        }
+        return type.isAssignableFrom(o.getClass()) ? (T)o : null;
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/OsgiUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,61 @@
+/** 
+  * 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.handlers;
+
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+
+public abstract class AbstractConfigurationHandler implements ConfigurationTypeHandler {
+    
+    private Map<String, Object> handlerProps;
+    
+    protected AbstractConfigurationHandler(Map<String, Object> handlerProps) {
+        this.handlerProps = handlerProps;
+    }
+    
+    protected String getDefaultAddress(Class<?> type) {
+        
+        String host = handlerProps.get(Constants.DEFAULT_HOST_CONFIG).toString();
+        String port = handlerProps.get(Constants.DEFAULT_PORT_CONFIG).toString();
+        StringBuilder buf = new StringBuilder();
+        buf.append("http://").append(host).append(':').append(port).append('/')
+           .append(type.getName().replace('.', '/'));
+        return buf.toString();        
+    }
+    
+    protected boolean useMasterMap() {
+        
+        Object value = handlerProps.get(Constants.USE_MASTER_MAP);
+        if (value == null) {
+            return true;
+        }
+        
+        return OsgiUtils.toBoolean(value);        
+    }
+    
+    protected Object getProxy(Object serviceProxy, Class<?> iType) {
+        return Proxy.newProxyInstance(iType.getClassLoader(),
+                      new Class[] {iType},
+                      new ServiceInvocationHandler(serviceProxy, iType));
+    }
+    
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractConfigurationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactory.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactory.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactory.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactory.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,82 @@
+/** 
+  * 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.handlers;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.discovery.ServiceDescription;
+
+public class ClientServiceFactory implements ServiceFactory {
+
+    private static final Logger LOG = 
+        Logger.getLogger(ClientServiceFactory.class.getName());
+
+    private BundleContext dswContext;
+    private Class<?> iClass;    
+    private ServiceDescription sd;
+    private ConfigurationTypeHandler handler;
+    
+    public ClientServiceFactory(BundleContext dswContext, Class<?> iClass,
+                                ServiceDescription sd, ConfigurationTypeHandler handler) {
+        this.dswContext = dswContext;
+        this.iClass = iClass;
+        this.sd = sd;
+        this.handler = handler;
+    }
+    
+    public Object getService(Bundle requestingBundle, ServiceRegistration sreg) {
+        
+        try {
+            return handler.createProxy(dswContext, 
+                                               requestingBundle.getBundleContext(),
+                                               iClass,
+                                               sd);
+        } catch (Exception ex) {
+            LOG.log(Level.WARNING,
+                    "Problem creating a remote proxy for " 
+                    + sd.getInterfaceName() + " from CXF FindHook: ", 
+                    ex);
+        }
+        
+        return null;
+    }
+
+    public void ungetService(Bundle requestingBundle, 
+                             ServiceRegistration sreg, 
+                             Object serviceObject) {
+        
+        StringBuilder sb = new StringBuilder();
+        sb.append("Releasing a client object");
+        Object objectClass = 
+            sreg.getReference().getProperty(org.osgi.framework.Constants.OBJECTCLASS);
+        if (objectClass != null) {
+            sb.append(", interfaces : ");
+            for (String s : (String[])objectClass) { 
+                sb.append(" " + s);
+            }
+        }
+        LOG.info(sb.toString());
+    }
+
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ClientServiceFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java Mon Sep  1 08:08:01 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.cxf.dosgi.dsw.handlers;
+
+import java.util.Map;
+import java.util.logging.Logger;
+
+
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.osgi.service.discovery.ServiceDescription;
+
+public final class ConfigTypeHandlerFactory {
+    
+    private static final Logger LOG = Logger.getLogger(ConfigTypeHandlerFactory.class.getName());
+    private static final ConfigTypeHandlerFactory FACTORY = new ConfigTypeHandlerFactory();
+    
+    private ConfigTypeHandlerFactory() {
+        
+    }
+    
+    public static ConfigTypeHandlerFactory getInstance() {
+        return FACTORY;
+    }
+    
+    public ConfigurationTypeHandler getHandler(ServiceDescription sd,
+                                               Map<String, Object> handlerProperties) {
+        String type = OsgiUtils.getProperty(sd, Constants.CONFIG_TYPE_PROPERTY);
+        if (type == null || Constants.POJO_CONFIG_TYPE.equalsIgnoreCase(type)) {
+            if (type == null) {
+                LOG.info("Defaulting to pojo configuration type ");
+            }
+            return new PojoConfigurationTypeHandler(handlerProperties);
+        } else if (Constants.WSDL_CONFIG_TYPE.equalsIgnoreCase(type)) {
+            return new WsdlConfigurationTypeHandler(handlerProperties);
+        }
+        
+        LOG.info("Configuration type " + type + " is not supported");
+        
+        return null;
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigTypeHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,35 @@
+/** 
+  * 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.handlers;
+
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.discovery.ServiceDescription;
+
+public interface ConfigurationTypeHandler {
+    Server createServer(BundleContext dswContext,
+                        BundleContext callingContext, 
+                        ServiceDescription sd, 
+                        Class<?> iClass, 
+                        Object serviceBean);
+
+    Object createProxy(BundleContext dswContext,
+                       BundleContext callingContext,
+                       Class<?> iClass, ServiceDescription sd);
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,185 @@
+/** 
+  * 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.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.binding.BindingConfiguration;
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.qos.IntentMap;
+import org.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.discovery.ServiceDescription;
+
+public class PojoConfigurationTypeHandler extends AbstractConfigurationHandler {
+
+    private static final Logger LOG = Logger.getLogger(PojoConfigurationTypeHandler.class.getName());
+    
+    private IntentMap masterMap;
+    
+    public PojoConfigurationTypeHandler(Map<String, Object> handlerProps) {
+        super(handlerProps);
+    }
+    
+    public Object createProxy(BundleContext dswContext,
+                              BundleContext callingContext,
+                              Class<?> iClass, ServiceDescription sd) {
+        
+        
+        String address = getPojoAddress(sd, iClass);
+        if (address == null) {
+            LOG.warning("Remote address is unavailable");
+            return null;
+        }
+        
+        LOG.info("Creating a " + sd.getInterfaceName() + " client, endpoint address is "
+                 + address);
+
+
+        try {
+            ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
+            factory.setServiceClass(iClass);
+            factory.setAddress(address);
+            factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+
+            applyIntents(dswContext,
+                                 callingContext, 
+                         factory.getFeatures(),
+                         factory.getClientFactoryBean(),
+                         sd);
+
+            return getProxy(factory.create(), iClass);
+        } catch (Exception e) {
+            LOG.log(Level.WARNING, "proxy creation failed", e);
+        }
+        return null;
+    }
+
+    public Server createServer(BundleContext dswContext,
+                               BundleContext callingContext, 
+                               ServiceDescription sd, 
+                               Class<?> iClass,
+                               Object serviceBean) {
+        
+        String address = getPojoAddress(sd, iClass);
+        if (address == null) {
+            LOG.warning("Remote address is unavailable");
+            return null;
+        }
+        
+        LOG.info("Creating a " + sd.getInterfaceName()
+            + " endpoint from CXF PublishHook, address is " + address);
+        
+        ServerFactoryBean factory = new ServerFactoryBean();
+        factory.setServiceClass(iClass);
+        factory.setAddress(address);
+        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
+        factory.setServiceBean(serviceBean);
+
+        applyIntents(dswContext, callingContext, factory.getFeatures(), factory, sd);
+
+        return factory.create();
+    }
+
+    private void applyIntents(BundleContext dswContext,
+                                             BundleContext callingContext,
+                                     List<AbstractFeature> features,
+                                     AbstractEndpointFactory factory,
+                                     ServiceDescription sd) {
+        String[] requestedIntents = getRequestedIntents(sd);
+        
+        IntentMap intentMap = OsgiUtils.getIntentMap(callingContext);
+        
+        if (useMasterMap()) {
+            intentMap = mergeWithMaster(dswContext, intentMap);
+        }
+        
+        for (int i = 0; i < requestedIntents.length; i++) {
+            Object intent = intentMap.get(requestedIntents[i]);
+            if (intent instanceof AbstractFeature) {
+                AbstractFeature feature = (AbstractFeature)intent;
+                LOG.info("Applying intent: " + requestedIntents[i]
+                         + " via feature: " + feature);
+                features.add(feature);
+            } else if (intent instanceof BindingConfiguration) {
+                BindingConfiguration bindingCfg = 
+                    (BindingConfiguration)intent;
+                LOG.info("Applying intent: " + requestedIntents[i]
+                         + " via binding config: " + bindingCfg);
+                factory.setBindingConfig(bindingCfg);
+            } else {
+                LOG.info("No mapping for intent: " + requestedIntents[i]);
+            }
+        }
+    }
+
+    private static String[] getRequestedIntents(ServiceDescription sd) {
+        String property = 
+            OsgiUtils.getProperty(sd, Constants.INTENTS_PROPERTY);
+        String[] intents = OsgiUtils.parseIntents(property);
+        for (int i = 0; i < intents.length; i++) {
+            LOG.fine("Intent asserted: " + intents[i]);
+        } 
+        return intents;
+    }
+    
+    private IntentMap mergeWithMaster(BundleContext dswContext, IntentMap intentMap) {
+        
+        synchronized (this) {
+            if (masterMap == null) {
+                LOG.fine("Loading master intent map");
+                masterMap = OsgiUtils.getIntentMap(dswContext);
+            }
+        }
+        if (masterMap != null) {
+            Iterator<String> masterKeys = masterMap.getIntents().keySet().iterator();
+            while (masterKeys.hasNext()) {
+                String masterKey = masterKeys.next();
+                if (intentMap.get(masterKey) == null) {
+                    LOG.fine("Merging in master intent map entry: " + masterKey);
+                    intentMap.getIntents().put(masterKey, masterMap.get(masterKey));
+                } else {
+                    LOG.fine("Overridden master intent map entry: " + masterKey);
+                }
+            }
+        }
+        return intentMap;
+    }
+    
+    private String getPojoAddress(ServiceDescription sd, Class<?> iClass) {
+        String address = OsgiUtils.getProperty(sd, Constants.POJO_ADDRESS_PROPERTY);
+        if (address == null) {
+            address = getDefaultAddress(iClass);
+            if (address != null) {
+                LOG.info("Using a default address : " + address);
+            }
+        }
+        return address;
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/PojoConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,77 @@
+/** 
+  * 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.handlers;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.framework.ServiceException;
+
+public class ServiceInvocationHandler implements InvocationHandler {
+
+    private final static String REMOTE_EXCEPTION_TYPE = "REMOTE";
+    
+    private Map<Method, List<Class<?>>> exceptionsMap
+        = new HashMap<Method, List<Class<?>>>();
+    private Object serviceObject;    
+    
+    public ServiceInvocationHandler(Object serviceObject, Class<?> iType) {
+        this.serviceObject = serviceObject;
+        introspectType(iType);
+    }
+    
+    public Object invoke(Object proxy, Method m, Object[] params) throws Throwable {
+        try {
+            return m.invoke(serviceObject, params); 
+        } catch (Throwable ex) {
+            Throwable theCause = ex.getCause() == null ? ex : ex.getCause();
+            
+            List<Class<?>> excTypes = exceptionsMap.get(m);
+            if (excTypes != null) {
+                for (Class<?> type : excTypes) {
+                    if (type.isAssignableFrom(theCause.getClass())) {
+                        throw theCause;
+                    }
+                }
+            }
+            throw new InvocationTargetException(
+                      new ServiceException(REMOTE_EXCEPTION_TYPE, theCause));
+        }
+    }
+
+    private void introspectType(Class<?> iType) {
+        for (Method m : iType.getDeclaredMethods()) {
+            for (Class<?> excType : m.getExceptionTypes()) {
+                if (Exception.class.isAssignableFrom(excType)) {
+                    List<Class<?>> types = exceptionsMap.get(m);
+                    if (types == null) {
+                        types = new ArrayList<Class<?>>();
+                        exceptionsMap.put(m, types);
+                    }
+                    types.add(excType);
+                }
+            }
+        }
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/ServiceInvocationHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,98 @@
+/** 
+  * 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.handlers;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.discovery.ServiceDescription;
+
+public class WsdlConfigurationTypeHandler extends AbstractConfigurationHandler {
+
+    private static final Logger LOG = Logger.getLogger(WsdlConfigurationTypeHandler.class.getName());
+    
+    public WsdlConfigurationTypeHandler(Map<String, Object> handlerProps) {
+        super(handlerProps);
+    }
+    
+    public Object createProxy(BundleContext dswContext,
+                              BundleContext callingContext,
+                              Class<?> iClass, 
+                              ServiceDescription sd) {
+        
+        String wsdlAddressProp = getWsdlAddress(sd, iClass);
+        if (wsdlAddressProp == null) {
+            LOG.warning("WSDL address is unavailable");
+            return null;
+        }
+        
+        URL wsdlAddress = null;
+        try {
+            wsdlAddress = new URL(wsdlAddressProp);
+        } catch (MalformedURLException ex) {
+            LOG.warning("WSDL address is malformed");
+            return null;
+        }
+        
+        LOG.info("Creating a " + sd.getInterfaceName() + " client, wsdl address is "
+                 + OsgiUtils.getProperty(sd, Constants.WSDL_ADDRESS));
+        
+        String serviceNs = OsgiUtils.getProperty(sd, Constants.SERVICE_NAMESPACE);
+        if (serviceNs == null) {
+            serviceNs = PackageUtils.getNamespace(
+                            PackageUtils.getPackageName(iClass));
+        }
+        QName serviceQname = new QName(serviceNs, iClass.getSimpleName());
+        Service service = Service.create(wsdlAddress, serviceQname);
+        return getProxy(service.getPort(iClass), iClass);
+        
+    }
+
+    public Server createServer(BundleContext dswContext,
+                               BundleContext callingContext,
+                               ServiceDescription sd, 
+                               Class<?> iClass, 
+                               Object serviceBean) {
+        
+        throw new UnsupportedOperationException("No WSDL configuration is currently supported for"
+                  + " creating service endpoints");
+    }
+    
+    private String getWsdlAddress(ServiceDescription sd, Class<?> iClass) {
+        String address = OsgiUtils.getProperty(sd, Constants.WSDL_ADDRESS);
+        if (address == null) {
+            address = getDefaultAddress(iClass);
+            if (address != null) {
+                address += "?wsdl";    
+            }
+        }
+        return address;
+    }
+
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,144 @@
+/** 
+  * 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.hooks;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.handlers.ClientServiceFactory;
+import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServiceDescription;
+
+public class AbstractClientHook extends AbstractHook {
+    
+    private static final Logger LOG = Logger.getLogger(AbstractClientHook.class.getName());
+
+    protected AbstractClientHook(BundleContext bc) {
+        super(bc);
+    }
+    
+    protected List<ServiceDescription> processClientDescriptions(BundleContext requestingContext, 
+                                                            String className, 
+                                                            String filter, 
+                                                            boolean matchAll, 
+                                                            boolean allServices) {
+        List<ServiceDescription> sds = 
+            getServiceDescriptions(requestingContext, className, filter, false);
+        List<ServiceDescription> actualSds = new ArrayList<ServiceDescription>(sds.size()); 
+        
+        for (ServiceDescription sd  : sds) {
+            
+            
+            if (!OsgiUtils.getBooleanProperty(sd, Constants.PUBLISH_PROPERTY)) {
+                continue;
+            }
+            
+            ConfigurationTypeHandler handler = 
+                ServiceHookUtils.getHandler(sd, getHandlerProperties());
+            if (handler == null) {
+                continue;
+            }
+            
+            try {
+                Class<?> iClass = getContext().getBundle().loadClass(className);
+                if (iClass != null) {
+                    BundleContext actualContext = getContext();
+                    if (!allServices) {
+                        Class<?> actualClass = requestingContext.getBundle().loadClass(className);
+                        if (actualClass != iClass) {
+                            LOG.info("Class " + className + " 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;
+                        }
+                    }
+                    synchronized(this) {
+                        ServiceReference sref = actualContext.getServiceReference(sd.getInterfaceName());
+                        if (sref == null || sref.getProperty(Constants.DSW_CLIENT_ID) == null) {
+                            
+                            // at least we won't register the factory for the same interface/filter
+                            // combination twice - ListenerHook.added() and 
+                            // ListenerHook.serviceReferencesRequested() may get called at the same time
+                            
+                            actualContext.registerService(new String[]{sd.getInterfaceName()},
+                                      new ClientServiceFactory(actualContext, iClass, sd, handler),
+                                      new Hashtable<String, Object>(getProperties(sd)));
+                        }
+                        
+                    }
+                    actualSds.add(sd);
+                }
+            } catch (ClassNotFoundException ex) {
+                LOG.warning("No class can be found for " + sd.getInterfaceName());
+                continue;
+            }
+        }
+        return actualSds;
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected Map<String, Object> getProperties(ServiceDescription sd) {
+        Map<String, Object> props = new HashMap<String, Object>();        
+        props.putAll(sd.getProperties());
+        props.put(Constants.DSW_CLIENT_ID, getIdentificationProperty());
+        return props;
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected List<ServiceDescription> getServiceDescriptions(
+        BundleContext context, String className, String filterValue, 
+        boolean matchAll) {
+        
+        // if bundle has remote-services.xml attached then those metadata takes precedence
+        List<ServiceDescription> sds = new ArrayList<ServiceDescription>();
+        if (checkBundle()) {
+            sds.addAll(OsgiUtils.getRemoteReferences(context.getBundle(), 
+                                                     new String[]{className}, 
+                                                     Collections.EMPTY_MAP, 
+                                                     false));
+        }
+        // should we try discovery service even if we've already
+        // found some SDs as it may find more suitable SDs ?
+        if (sds.isEmpty()) {
+            // try discovery service
+            sds.addAll(getFromDiscoveryService(className));
+        }
+        
+        Filter filter = OsgiUtils.createFilter(context, filterValue);
+        if (filter != null) {
+            OsgiUtils.matchServiceDescriptions(sds, filter, true);
+        }
+        
+        return sds;
+    }
+    
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,125 @@
+/** 
+  * 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.hooks;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiService;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.service.ServiceDescriptionImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.discovery.Discovery;
+import org.osgi.service.discovery.ServiceDescription;
+
+public abstract class AbstractHook {
+
+    private volatile BundleContext bc;
+    private volatile boolean checkBundleForMetadata = true;
+    private volatile boolean useMasterMap = true;
+    private volatile String defaultPort;
+    private volatile String defaultHost;
+    
+    public AbstractHook(BundleContext bc) {
+        this.bc = bc;
+    }
+    
+    protected BundleContext getContext() {
+        return bc;
+    }
+    
+    public void updateProperties(Dictionary d) {
+        
+        Object value = d.get(Constants.CHECK_BUNDLE);
+        if (value != null) {
+            checkBundleForMetadata = OsgiUtils.toBoolean(value.toString());
+        }
+        
+        value = d.get(Constants.USE_MASTER_MAP);
+        if (value != null) {
+            useMasterMap = OsgiUtils.toBoolean(value.toString());
+        }
+        
+        value = d.get(Constants.DEFAULT_HOST_CONFIG);
+        defaultHost = value == null ? Constants.DEFAULT_HOST_VALUE
+                                    : value.toString();
+        
+        value = d.get(Constants.DEFAULT_PORT_CONFIG);
+        defaultPort = value == null ? Constants.DEFAULT_PORT_VALUE
+                                    : value.toString();
+    }
+    
+    protected boolean checkBundle() {
+        return checkBundleForMetadata;
+    }
+    
+    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;
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected Collection<ServiceDescription> getFromDiscoveryService(String className) {
+       
+        // not clear what to do about allServices parameter, according to docs its purpose
+        // is to indicate that the call originated from BundleContext.getAllReferences()
+       
+        // TODO : Use a ServiceTracker if we know that 
+        // the requesting bundle is also relying on a ServiceTracker 
+       
+        OsgiService<Discovery> pair = OsgiUtils.getOsgiService(getContext(), Discovery.class);
+        if (pair != null) {
+            try {
+                return pair.getService().findService(new ServiceDescriptionImpl(className));
+            } finally {
+                pair.ungetService(getContext());
+            }
+        }
+       
+        return Collections.EMPTY_LIST;
+    }
+    
+    protected String getIdentificationProperty() {
+        Bundle b = bc.getBundle();
+        Object name = 
+            b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
+        if (name == null) {
+            name = b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);
+        }
+        
+        Object version = b.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
+        
+        StringBuilder sb = new StringBuilder();
+        sb.append(name.toString()).append(", version : " + version.toString());
+        return sb.toString();
+    }
+    
+    
+    
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractHook.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfListenerHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfListenerHook.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfListenerHook.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfListenerHook.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,132 @@
+/** 
+  * 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.hooks;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.hooks.service.ListenerHook;
+
+public class CxfListenerHook extends AbstractClientHook implements ListenerHook {
+
+    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);
+    
+    private ThreadLocal<Boolean> findCallsInProgress
+        = new ThreadLocal<Boolean>() {
+             @Override
+             protected synchronized Boolean initialValue() {
+                 return Boolean.FALSE;
+             }
+         }; 
+    
+    public CxfListenerHook(BundleContext bc) {
+        super(bc);
+    }
+    
+    public void added(ListenerHook.Listener listener) {
+        handleListener(listener);
+    }
+
+    public void initial(ListenerHook.Listener[] listeners) {
+        
+        if (isCallInProgress()) {
+            return;
+        }
+        
+        try {
+            setCallInProgress();
+            
+            for (ListenerHook.Listener listener : listeners) {
+                handleListener(listener);
+            }
+        } finally {
+            setCallCompleted();
+        }
+    }
+
+    public void removed(Listener listener) {
+    }
+
+    private void handleListener(Listener listener) {
+        if (listener.getFilter() == null
+            || listener.getBundleContext() == getContext()) {
+            return;
+        }
+        String className = getClassNameFromFilter(listener.getFilter());
+        if (className == null) {
+            return;
+        }
+        
+        processClientDescriptions(listener.getBundleContext(), 
+                                  className, 
+                                  listener.getFilter(), 
+                                  false, 
+                                  false);
+    }
+    
+    private String getClassNameFromFilter(String filter) {
+        if (filter == null) {
+            return null;
+        }
+        Matcher matcher = CLASS_NAME_PATTERN.matcher(filter);
+        if (matcher.matches() && matcher.groupCount() >= 1) {
+            return matcher.group(1);
+        }
+        
+        return null;
+    }
+    
+    public void serviceReferencesRequested(BundleContext requestingContext,
+                                           String className,
+                                           String filter,
+                                           boolean allServices) {
+        
+        if (className == null) {
+            return;    
+        }
+        
+        if (isCallInProgress()) {
+            return;
+        }
+        try {
+            setCallInProgress();
+            processClientDescriptions(requestingContext, className, filter, false, allServices);
+        } finally {
+            setCallCompleted();
+        }
+        
+    }
+    
+    private Boolean isCallInProgress() {
+        return findCallsInProgress.get();
+    }
+    
+    private void setCallInProgress() {
+        findCallsInProgress.set(Boolean.TRUE);
+    }
+    
+    private void setCallCompleted() {
+        findCallsInProgress.set(Boolean.FALSE);
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfListenerHook.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfListenerHook.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,112 @@
+/** 
+  * 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.hooks;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+
+import org.apache.cxf.dosgi.dsw.Constants;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.ServiceDescription;
+
+public class CxfPublishHook extends AbstractHook {
+    
+    private Map<ServiceReference, EndpointInfo> endpoints
+        = new LinkedHashMap<ServiceReference, EndpointInfo>();
+    
+    public CxfPublishHook(BundleContext bc) {
+        super(bc);
+    }
+        
+    public void publishEndpoint(ServiceReference sref) {
+        
+        if (ServiceHookUtils.isCreatedByDsw(sref)) {
+            return;
+        }
+        
+        ServiceDescription sd = null;
+        if (checkBundle()) {
+            sd = OsgiUtils.getRemoteReference(sref, true);
+        } 
+        // TODO 
+        // update DSW to check 'local' remote-services metadata either 
+        // by accepting Configuration Admin Service updates or checking 
+        // local configuration data, if any available - it will let
+        // this code to check for SDs from the additional source
+        if (sd == null
+            || !OsgiUtils.getBooleanProperty(sd, Constants.PUBLISH_PROPERTY)) {
+            return;
+        }
+
+            
+        Server server = null;
+        boolean isPublished = false;
+        server = ServiceHookUtils.createServer(
+                                 getHandler(sd, getHandlerProperties()), 
+                                 getContext(), 
+                                 sref.getBundle().getBundleContext(), 
+                                 sd, 
+                                 getContext().getService(sref));
+        if (server != null && ServiceHookUtils.publish(getContext(), sd)) {
+            isPublished = true;
+        }
+        
+        synchronized(endpoints) {
+            endpoints.put(sref, new EndpointInfo(getContext(),
+                                                 sd,
+                                                 server,
+                                                 isPublished));
+        }
+    }
+    
+    public void removeEndpoint(ServiceReference sref) {
+        EndpointInfo ei = null;
+        synchronized(endpoints) {
+            ei = endpoints.remove(sref);
+        }
+        if (ei != null) {
+            ServiceHookUtils.unregisterServer(ei);
+        }
+    }
+    
+    public void removeEndpoints() {
+        synchronized(endpoints) {
+            for (EndpointInfo ei : endpoints.values()) {
+                ServiceHookUtils.unregisterServer(ei);
+            }
+            endpoints.clear();
+        }
+        
+    }
+    
+    public Map<ServiceReference, EndpointInfo> getEndpoints() {
+        return Collections.unmodifiableMap(endpoints);
+    }
+    
+    protected ConfigurationTypeHandler getHandler(ServiceDescription sd, 
+                                                  Map<String, Object> props) {
+        return ServiceHookUtils.getHandler(sd, props);
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/CxfPublishHook.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/EndpointInfo.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/EndpointInfo.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/EndpointInfo.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/EndpointInfo.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,59 @@
+/** 
+  * 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.hooks;
+
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.discovery.ServiceDescription;
+
+public class EndpointInfo {
+    
+    private BundleContext bc;
+    private ServiceDescription sd;
+    private Server server;
+    private boolean isPublished;
+    
+    public EndpointInfo(BundleContext bc,
+                        ServiceDescription sd,
+                        Server server,
+                        boolean isPublished) {
+        this.bc = bc;
+        this.sd = sd;
+        this.server = server;
+        this.isPublished = isPublished;
+    }
+    
+    public BundleContext getContext() {
+        return bc;
+    }
+    
+    public ServiceDescription getServiceDescription() {
+        return sd;
+    }
+    
+    public Server getServer() {
+        return server;
+    }
+    
+    public boolean isPublished() {
+        return isPublished;
+    }
+    
+    
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/EndpointInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/EndpointInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,127 @@
+/** 
+  * 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.hooks;
+
+import java.util.Map;
+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.OsgiService;
+import org.apache.cxf.dosgi.dsw.OsgiUtils;
+import org.apache.cxf.dosgi.dsw.handlers.ConfigTypeHandlerFactory;
+import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.discovery.Discovery;
+import org.osgi.service.discovery.ServiceDescription;
+
+public final class ServiceHookUtils {
+    
+    private static final Logger LOG = Logger.getLogger(ServiceHookUtils.class.getName());
+    
+    private ServiceHookUtils() {
+        
+    }
+    
+    public static boolean publish(BundleContext bc, ServiceDescription sd) {
+        
+        boolean published = false;
+        OsgiService<Discovery> pair = OsgiUtils.getOsgiService(bc, Discovery.class);
+        if (pair != null) {
+            try {
+                published = pair.getService().publishService(sd);
+                if (published) {
+                    LOG.info("Remote " + sd.getInterfaceName()
+                             + " endpoint has been published into Discovery service");
+                }
+            } finally {
+                pair.ungetService(bc);
+            }
+        }
+        return published;
+    }
+    
+    public static Server createServer(ConfigurationTypeHandler handler,
+                                      BundleContext dswContext,
+                                      BundleContext callingContext, 
+                                      ServiceDescription sd,
+                                      Object serviceObject) {
+        
+        if (handler == null) {
+            return null;
+        }
+        
+        // this is an extra sanity check, but do we really need it now ?
+        Class<?> interfaceClass = ClassUtils.getInterfaceClass(serviceObject, 
+                                                               sd.getInterfaceName());
+        if (interfaceClass != null) {
+            try {
+                return handler.createServer(dswContext,
+                                            callingContext, 
+                                            sd, 
+                                            interfaceClass, 
+                                            serviceObject);
+            } catch (Exception ex) {
+                LOG.warning("WARNING : Problem creating a remote endpoint for " + sd.getInterfaceName()
+                        + " from CXF PublishHook, reason is " + ex.getMessage());
+            }
+        }
+        
+        return null;
+    }
+    
+    public static void unregisterServer(EndpointInfo ei) {
+        
+        try {
+            Server server = ei.getServer();
+            
+            LOG.info("Stopping CXF Endpoint at " 
+                + server.getDestination().getAddress().getAddress().getValue());
+            server.getDestination().shutdown();
+            server.stop();
+        } catch (Exception ex) {
+            // continue
+        }
+        
+        if (ei.isPublished()) {
+            OsgiService<Discovery> pair = OsgiUtils.getOsgiService(ei.getContext(), 
+                                                                   Discovery.class);
+            if (pair != null) {
+                LOG.info("Unpublishing Service Description for "  
+                          + ei.getServiceDescription().getInterfaceName() 
+                          + " from a Discovery service "); 
+                pair.getService().unpublishService(ei.getServiceDescription());
+                pair.ungetService(ei.getContext());
+            }
+        }
+    }
+    
+    public static ConfigurationTypeHandler getHandler(ServiceDescription sd,
+                                                  Map<String, Object> dswProperties) {
+        return ConfigTypeHandlerFactory.getInstance().getHandler(sd, 
+                                                                 dswProperties);
+    }
+    
+    public static boolean isCreatedByDsw(ServiceReference sref) {
+        return sref != null && sref.getProperty(Constants.DSW_CLIENT_ID) != null;
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/ServiceHookUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,47 @@
+/** 
+  * 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.qos;
+
+import java.util.Map;
+import java.util.logging.Logger;
+
+public final class IntentMap {
+
+    private static final Logger LOG = 
+        Logger.getLogger(IntentMap.class.getName());
+
+    private Map<String, Object> intents; 
+
+    public void setIntents(Map<String, Object> intents) {
+        LOG.info("Injected intents: " + intents);
+        this.intents = intents;
+    }
+
+    public Map<String, Object> getIntents() {
+        return intents;
+    }
+
+    public Object get(String key) {
+        return intents.get(key);
+    }
+
+    public String toString() {
+        return "IntentMap: " + intents;
+    }
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMapBeanInfo.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMapBeanInfo.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMapBeanInfo.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMapBeanInfo.java Mon Sep  1 08:08:01 2008
@@ -0,0 +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.cxf.dosgi.dsw.qos;
+
+public final class IntentMapBeanInfo {
+}

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMapBeanInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMapBeanInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/DistributionProviderImpl.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,43 @@
+/** 
+  * 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.Collections;
+import java.util.Map;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.dsw.DistributionProvider;
+
+
+public class DistributionProviderImpl implements DistributionProvider {
+
+    public Map getPublicationProperties(ServiceReference sr) {
+        return Collections.EMPTY_MAP;
+    }
+
+    public ServiceReference[] getPublishedServices() {
+        return new ServiceReference[]{};
+    }
+
+    public ServiceReference[] getRemoteServices() {
+        return new ServiceReference[]{};
+    }
+
+    
+}

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

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

Added: cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ServiceDescriptionImpl.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ServiceDescriptionImpl.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ServiceDescriptionImpl.java (added)
+++ cxf/sandbox/dosgi/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ServiceDescriptionImpl.java Mon Sep  1 08:08:01 2008
@@ -0,0 +1,94 @@
+/** 
+  * 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.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.service.discovery.ServiceDescription;
+
+public class ServiceDescriptionImpl implements ServiceDescription {
+
+    private List<String> interfaceNames; 
+    private Map<String, Object> properties;
+    
+    @SuppressWarnings("unchecked")
+    public ServiceDescriptionImpl(String interfaceName) {
+        this(Collections.singletonList(interfaceName), Collections.EMPTY_MAP);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public ServiceDescriptionImpl(List<String> interfaceNames) {
+        this(interfaceNames, Collections.EMPTY_MAP);
+    }
+    
+    public ServiceDescriptionImpl(List<String> interfaceNames,
+                                  Map<String, Object> remoteProperties) {
+        this.interfaceNames = interfaceNames;
+        properties = remoteProperties;
+    }
+    
+    public Object getProperty(String key) {
+        return properties.get(key);
+    }
+
+    public Map getProperties() {
+        return Collections.unmodifiableMap(properties);
+    }
+
+    public Collection getPropertyKeys() {
+        return getProperties().keySet();
+    }
+
+    
+    @Override
+    public int hashCode() {
+        return interfaceNames.get(0).hashCode() + 37 * properties.hashCode();
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof ServiceDescription)) {
+            return false;
+        }
+        ServiceDescription other = (ServiceDescription)obj;
+        
+        return interfaceNames.get(0).equals(other.getInterfaceName())
+               && properties.equals(other.getProperties());
+    }
+
+    public String getInterfaceName() {
+        return interfaceNames.get(0);
+    }
+
+    public URL getLocation() {
+        return null;
+    }
+
+    public String getProtocolSpecificInterfaceName() {
+        return null;
+    }
+
+    public String getVersion() {
+        return null;
+    }
+}

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

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



Mime
View raw message