You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/06/16 00:17:07 UTC

svn commit: r414694 [7/7] - in /webservices/muse/trunk/modules/muse-wsrf: ./ src-api/ src-api/org/ src-api/org/apache/ src-api/org/apache/muse/ src-api/org/apache/muse/ws/ src-api/org/apache/muse/ws/resource/ src-api/org/apache/muse/ws/resource/basefau...

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/Messages.properties
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/Messages.properties?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/Messages.properties (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/Messages.properties Thu Jun 15 15:16:59 2006
@@ -0,0 +1,15 @@
+NullElement = The DOM Element is null.
+NullDocument = The DOM Document to be used as an Element factory is null.
+NoMemberEPR = There is no Element describing the wssg:ServiceGroupEntry member's EPR in the response.
+NullMemberEPR = The EPR for the member service is null.
+NoEntryEPR = There is no Element describing the wssg:ServiceGroupEntry's EPR in the response.
+NullResource = The Resource proxy is null.
+NoMemberService = No Resource proxy was specified for contacting the service group member this wssg:Entry represents. You must call setMember() with this reference before calling initialize().
+NoServiceGroup = No ServiceGroup reference was specified for contacting the service group that contains this wssg:Entry. You must call setOwner() with this reference before calling initialize().
+NullServiceGroup = The ServiceGroup reference is null.
+NullMemberServiceEPR = The EPR for the wssg:Entry's member service is null.
+NoEntryEndpoint = There is no resource that implements the WS-SG ServiceGroupEntry portType defined in muse.xml. In order to manage service group entries, a touchpoint must expose a resource of type org.apache.muse.ws.resource.sg.Entry (or a sub-type); this resource will represent all new entries created in the service group.
+FoundEntryEndpoint = Successfully found the WS-SG ServiceGroupEntry endpoint at 'XXX' with resource name 'XXX'. All Entry resources will be managed by this endpoint.
+EntryNotFound = The Entry reference was not found in the ServiceGroup, so it could not be removed.
+ContentCreationFailed = The resource that this wssg:Entry represents could not be reached to get the value of the wssg:Content properties. It is possible that the resource has been destroyed.
+NoContent = The resource does not have an instance of the wssg:Content property - all entries must have one wssg:Content element in their WS-RP document.

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleEntry.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleEntry.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleEntry.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleEntry.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,180 @@
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.muse.ws.resource.sg.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.WsResource;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.impl.SimpleWsResource;
+import org.apache.muse.ws.resource.remote.WsResourceClient;
+import org.apache.muse.ws.resource.sg.Entry;
+import org.apache.muse.ws.resource.sg.ServiceGroup;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+import org.apache.muse.ws.resource.sg.faults.ContentCreationFailedFault;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.util.xml.XmlUtils;
+
+/**
+ *
+ * SimpleEntry is Muse's default implementation of the WS-ServiceGroups 
+ * Entry resource type. This class is exposed as a first-class resource 
+ * to web service clients. It extends the 
+ * {@linkplain SimpleWsResource basic resource} defined by Muse 
+ * and adds support for the Entry-specific properties. Because entries are 
+ * also serialized as properties in the service group itself, this class 
+ * also provides XML serialization.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleEntry 
+    extends AbstractWsResourceCapability implements Entry
+{
+    //
+    // Used to look up all exception messages
+    //
+    protected static Messages _MESSAGES = MessagesFactory.get(SimpleEntry.class);
+        
+    private static final Element[] _EMPTY_CONTENT = new Element[0];
+    
+    private WsResourceClient _member = null;
+    
+    private WsResource _serviceGroup = null;
+    
+    public QName[] getPropertyNames()
+    {
+        return PROPERTIES;
+    }
+    
+    public void shutdown()
+        throws SoapFault
+    {
+        ServiceGroup sg = 
+            (ServiceGroup)getServiceGroup().getCapability(WssgConstants.SERVICE_GROUP_URI);
+        sg.removeEntry(getWsResource());
+        
+        super.shutdown();
+    }
+
+    public Element getContent()
+        throws BaseFault
+    {
+        ServiceGroup sg = (ServiceGroup)getServiceGroup().getCapability(WssgConstants.SERVICE_GROUP_URI);
+        QName[] contentNames = sg.getContentElements();
+        
+        Element[] content = _EMPTY_CONTENT;
+        
+        try
+        {
+            if (contentNames.length != 0)
+                content = getMemberClient().getMultipleResourceProperties(contentNames);
+        }
+        
+        catch (SoapFault fault)
+        {
+            throw new ContentCreationFailedFault(fault);
+        }
+        
+        if (content.length == 0)
+            return null;
+        
+        Document doc = content[0].getOwnerDocument();
+        Element root = XmlUtils.createElement(doc, WssgConstants.CONTENT_QNAME);
+        
+        for (int n = 0; n < content.length; ++n)
+            root.appendChild(content[n]);
+        
+        return root;
+    }
+
+    protected WsResourceClient getMemberClient()
+    {
+        return _member;
+    }
+    
+    protected WsResource getServiceGroup()
+    {
+        return _serviceGroup;
+    }
+    
+    public EndpointReference getMemberEPR()
+    {
+        return getMemberClient().getEndpointReference();
+    }
+    
+    public EndpointReference getServiceGroupEPR()
+    {
+        return getServiceGroup().getEndpointReference();
+    }
+
+    public void setMemberEPR(EndpointReference memberEPR)
+    {
+        if (memberEPR == null)
+            throw new NullPointerException(_MESSAGES.get("NullResource"));
+        
+        _member = new WsResourceClient(memberEPR, getServiceGroupEPR(), getEnvironment());
+    }
+    
+    public void setServiceGroup(WsResource serviceGroup)
+    {
+        if (serviceGroup == null)
+            throw new NullPointerException(_MESSAGES.get("NullServiceGroup"));
+        
+        _serviceGroup = serviceGroup;
+    }
+    
+    public Element toXML()
+    {
+        return toXML(XmlUtils.EMPTY_DOC);
+    }
+    
+    public Element toXML(Document doc)
+    {
+        if (doc == null)
+            throw new NullPointerException(_MESSAGES.get("NullDocument"));
+        
+        Element root = XmlUtils.createElement(doc, WssgConstants.ENTRY_QNAME);
+        
+        EndpointReference sg = getServiceGroupEPR();
+        XmlUtils.setElement(root, WssgConstants.SG_ENTRY_EPR_QNAME, sg);
+        
+        EndpointReference member = getMemberEPR();
+        XmlUtils.setElement(root, WssgConstants.MEMBER_SERVICE_EPR_QNAME, member);
+        
+        try
+        {
+            XmlUtils.setElement(root, WssgConstants.CONTENT_QNAME, getContent());
+        }
+        
+        catch (SoapFault error)
+        {
+            Object[] filler = { error.getMessage() };
+            getLog().fine(_MESSAGES.get("ContentCreationFailed", filler));
+        }
+        
+        return root;
+    }
+}

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleMembershipContentRule.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleMembershipContentRule.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleMembershipContentRule.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleMembershipContentRule.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,213 @@
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.muse.ws.resource.sg.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.Environment;
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.resource.remote.WsResourceClient;
+import org.apache.muse.ws.resource.sg.MembershipContentRule;
+import org.apache.muse.ws.resource.sg.ServiceGroup;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.util.xml.XmlUtils;
+
+/**
+ *
+ * SimpleMembershipContentRule is ...
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleMembershipContentRule implements MembershipContentRule
+{
+    //
+    // Used to look up all exception messages
+    //
+    private static Messages _MESSAGES = 
+        MessagesFactory.get(SimpleMembershipContentRule.class);
+    
+    private QName[] _EMPTY_CONTENT = new QName[0];
+    
+    private QName[] _content = _EMPTY_CONTENT;
+    
+    private QName _portType = null;
+    
+    private ServiceGroup _serviceGroup = null;
+    
+    public SimpleMembershipContentRule(ServiceGroup serviceGroup)
+    {
+        _serviceGroup = serviceGroup;
+    }
+    
+    public SimpleMembershipContentRule(Element xml)
+    {
+        if (xml == null)
+            throw new NullPointerException(_MESSAGES.get("NullElement"));
+        
+        String portTypeName = xml.getAttribute(WssgConstants.MEMBERSHIP_INTERFACE);
+        
+        if (portTypeName.length() > 0)
+            _portType = XmlUtils.parseQName(portTypeName, xml);
+        
+        String contentList = xml.getAttribute(WssgConstants.CONTENT_ELEMENTS);
+        
+        if (contentList.length() > 0)
+        {
+            String[] contentNames = contentList.split(" ");
+            _content = new QName[contentNames.length];
+            
+            for (int n = 0; n < contentNames.length; ++n)
+                _content[n] = XmlUtils.parseQName(contentNames[n], xml);
+        }
+    }
+        
+    public QName[] getContentElements()
+    {
+        return _content;
+    }
+    
+    public QName getMemberInterface()
+    {
+        return _portType;
+    }
+    
+    public ServiceGroup getServiceGroup()
+    {
+        return _serviceGroup;
+    }
+    
+    /**
+     * 
+     * @param epr
+     *        The EPR for the resource against which this membership content 
+     *        rule will be evaluated.
+     * 
+     * @return True if the given resource's WS-RP document matches the rules 
+     *         in the MCR.
+     *
+     */
+    public boolean isMatch(EndpointReference epr)
+    {
+        if (epr == null)
+            throw new NullPointerException(_MESSAGES.get("NullResource"));
+        
+        ServiceGroup sg = getServiceGroup();
+        EndpointReference sgEPR = sg.getResource().getEndpointReference();
+        Environment env = sg.getEnvironment();
+        
+        WsResourceClient resource = new WsResourceClient(epr, sgEPR, env);
+        QName[] content = getContentElements();
+        
+        try
+        {
+            //
+            // all we have to do is try and read all the properties 
+            // in the list - if any of them is undefined, this will 
+            // fault, and we don't have a match. there is no fault if 
+            // the property is defined but has zero instances
+            //
+            // note that we only do the test if there are some property 
+            // names - an empty array means "any resource is allowed"
+            //
+            if (content.length > 0)
+                resource.getMultipleResourceProperties(content);
+        }
+        
+        //
+        // in this case, there is no error - this just means that 
+        // the resource does not match the membership rule
+        //
+        catch (SoapFault error)
+        {
+            return false;
+        }
+        
+        return true;
+    }
+    
+    public void setContentElements(QName[] content)
+    {
+        if (content == null)
+            content = _EMPTY_CONTENT;
+        
+        _content = content;
+    }
+    
+    public void setMemberInterface(QName portType)
+    {
+        _portType = portType;
+    }
+
+    public Element toXML()
+    {
+        return toXML(XmlUtils.EMPTY_DOC);
+    }
+
+    public Element toXML(Document factory)
+    {
+        Element root = XmlUtils.createElement(factory, WssgConstants.CONTENT_RULE_QNAME);
+        
+        QName interfaceName = getMemberInterface();
+        
+        if (interfaceName != null)
+        {
+            root.setAttribute(WssgConstants.MEMBERSHIP_INTERFACE, XmlUtils.toString(interfaceName));
+            
+            String prefix = interfaceName.getPrefix();
+            String namespace = interfaceName.getNamespaceURI();
+            XmlUtils.setNamespaceAttribute(root, prefix, namespace);
+        }
+        
+        QName[] content = getContentElements();
+        StringBuffer contentAttr = new StringBuffer();
+        Map prefixes = new HashMap();
+        
+        for (int n = 0; n < content.length; ++n)
+        {
+            contentAttr.append(XmlUtils.toString(content[n]));
+            
+            if (n < content.length - 1)
+                contentAttr.append(' ');
+            
+            prefixes.put(content[n].getPrefix(), content[n].getNamespaceURI());
+        }
+        
+        root.setAttribute(WssgConstants.CONTENT_ELEMENTS, contentAttr.toString());
+        
+        Iterator i = prefixes.keySet().iterator();
+        
+        while (i.hasNext())
+        {
+            String next = (String)i.next();
+            XmlUtils.setNamespaceAttribute(root, next, (String)prefixes.get(next));
+        }
+        
+        return root;
+    }
+}

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroup.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroup.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroup.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroup.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,338 @@
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.muse.ws.resource.sg.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.Resource;
+import org.apache.muse.core.ResourceManager;
+import org.apache.muse.core.ResourceManagerListener;
+import org.apache.muse.util.messages.Messages;
+import org.apache.muse.util.messages.MessagesFactory;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.resource.WsResource;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.ext.faults.ResourceInitializationFault;
+import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.lifetime.ScheduledTermination;
+import org.apache.muse.ws.resource.lifetime.WsrlConstants;
+import org.apache.muse.ws.resource.sg.Entry;
+import org.apache.muse.ws.resource.sg.MembershipContentRule;
+import org.apache.muse.ws.resource.sg.ServiceGroup;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+import org.apache.muse.ws.resource.sg.faults.AddRefusedFault;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+
+/**
+ *
+ * SimpleServiceGroup is Muse's default implementation of the 
+ * WS-ServiceGroup ServiceGroup resource type. It provides SOAP-level 
+ * access to the entries it contains and lifecycle management for the 
+ * Entry resources.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleServiceGroup 
+    extends AbstractWsResourceCapability implements ServiceGroup, ResourceManagerListener
+{
+    //
+    // Used to look up all exception messages
+    //
+    private static Messages _MESSAGES = 
+        MessagesFactory.get(SimpleServiceGroup.class);
+        
+    private MembershipContentRule[] _contentRules = new MembershipContentRule[0];
+    
+    private Set _entries = new HashSet();
+    
+    private String _entryPath = null;
+    
+    public QName[] getPropertyNames()
+    {
+        return PROPERTIES;
+    }
+    
+    public WsResource addEntry(EndpointReference memberEPR, 
+                               Element content, 
+                               Date termination) 
+        throws AddRefusedFault, 
+               BaseFault
+    {
+        WsResource entry = createEntry(memberEPR, content, termination);
+        _entries.add(entry);        
+        return entry;
+    }
+    
+    protected WsResource createEntry(EndpointReference epr, 
+                                     Element content, 
+                                     Date termination)
+        throws AddRefusedFault, 
+               ResourceInitializationFault, 
+               BaseFault
+    {
+        //
+        // NOTE: this implementation ignores the provided content 
+        //       because it reads the members' content elements 
+        //       via WS-RP in order to ensure compliance.
+        //
+        
+        if (epr == null)
+            throw new NullPointerException(_MESSAGES.get("NullMemberServiceEPR"));
+        
+        WsResource sg = getWsResource();
+                
+        if (!isMatch(epr))
+            throw new AddRefusedFault(_MESSAGES.get("ContentCreationFailed"));
+
+        ResourceManager manager = sg.getResourceManager();
+        String endpoint = getEntryContextPath();
+        WsResource resource = null;
+        
+        try
+        {
+            resource = (WsResource)manager.createResource(endpoint);
+        }
+        
+        catch (SoapFault error)
+        {
+            throw new ResourceInitializationFault(error);
+        }
+        
+        Entry entry = (Entry)resource.getCapability(WssgConstants.ENTRY_URI);
+        
+        entry.setServiceGroup(sg);
+        entry.setMemberEPR(epr);
+        
+        try
+        {
+            resource.initialize();
+            manager.addResource(resource.getEndpointReference(), resource);
+        }
+        
+        catch (SoapFault error)
+        {
+            throw new ResourceInitializationFault(error);
+        }
+        
+        //
+        // set termination time AFTER we initialize so that we can rely 
+        // on the base Resource class' implementation of WS-RL (which 
+        // tries to apply the change immediately, rather than storing it 
+        // in a field and setting it during initialization)
+        //
+        if (resource.hasCapability(WsrlConstants.SCHEDULED_TERMINATION_URI))
+        {
+            ScheduledTermination wsrl = 
+                (ScheduledTermination)resource.getCapability(WsrlConstants.SCHEDULED_TERMINATION_URI);
+            wsrl.setTerminationTime(termination);
+        }
+        
+        return resource;
+    }
+    
+    public void shutdown()
+        throws SoapFault
+    {
+        WsResource[] entries = getEntry();
+        
+        for (int n = 0; n < entries.length; ++n)
+            entries[n].shutdown();
+        
+        super.shutdown();
+    }
+
+    public QName[] getContentElements()
+    {
+        MembershipContentRule[] rules = getMembershipContentRule();
+        Collection allContent = new ArrayList();
+
+        for (int n = 0; n < rules.length; ++n)
+        {
+            QName[] content = rules[n].getContentElements();
+            allContent.addAll(Arrays.asList(content));
+        }
+        
+        QName[] array = new QName[allContent.size()];
+        return (QName[])allContent.toArray(array);
+    }
+
+    public WsResource[] getEntry()
+    {
+        WsResource[] asArray = new WsResource[_entries.size()];
+        return (WsResource[])_entries.toArray(asArray);
+    }
+    
+    public WsResource getEntry(EndpointReference memberEPR)
+        throws BaseFault
+    {
+        WsResource[] entries = getEntry();
+        
+        for (int n = 0; n < entries.length; ++n)
+        {
+            Entry entry = (Entry)entries[n].getCapability(WssgConstants.ENTRY_URI);
+            EndpointReference nextEPR = entry.getMemberEPR();
+            
+            if (nextEPR.equals(memberEPR))
+                return entries[n];
+        }
+        
+        return null;
+    }
+
+    public MembershipContentRule[] getMembershipContentRule()
+    {
+        return _contentRules;
+    }
+    
+    protected MembershipContentRule createMembershipContentRule()
+    {
+        return new SimpleMembershipContentRule(this);
+    }
+    
+    protected MembershipContentRule createMembershipContentRule(Element xml)
+    {
+        return new SimpleMembershipContentRule(xml);
+    }
+    
+    protected String getEntryContextPath()
+    {
+        return _entryPath;
+    }
+    
+    public void initialize()
+        throws SoapFault
+    {
+        super.initialize();
+        
+        //
+        // make sure the Entry endpoint is exposed, since our entries 
+        // are all first-class resources
+        //
+        WsResource resource = getWsResource();
+        ResourceManager manager = resource.getResourceManager();
+        
+        _entryPath = manager.getResourceContextPath(Entry.class);
+        
+        if (_entryPath == null)
+            throw new RuntimeException(_MESSAGES.get("NoEntryEndpoint"));
+        
+        manager.addListener(this);
+    }
+    
+    public boolean isMatch(EndpointReference epr)
+    {
+        MembershipContentRule[] rules = getMembershipContentRule();
+        
+        for (int n = 0; n < rules.length; ++n)
+            if (!rules[n].isMatch(epr))
+                return false;
+            
+        return true;
+    }
+
+    public void removeEntry(WsResource entry)
+    {
+        if (entry == null)
+            throw new NullPointerException(_MESSAGES.get("NullEntry"));
+        
+        if (!_entries.remove(entry))
+            throw new RuntimeException(_MESSAGES.get("EntryNotFound"));
+    }
+    
+    public void resourceAdded(EndpointReference epr, Resource resource)
+        throws SoapFault
+    {
+        //
+        // don't add entries for wssg:Entry resources, or we'll 
+        // create an infinite recursion
+        //
+        if (resource.hasCapability(WssgConstants.SERVICE_GROUP_URI) || 
+            resource.hasCapability(WssgConstants.ENTRY_URI))
+            return;
+        
+        Date termination = null;
+        
+        if (resource.hasCapability(WsrlConstants.SCHEDULED_TERMINATION_URI))
+        {
+            ScheduledTermination wsrl = 
+                (ScheduledTermination)resource.getCapability(WsrlConstants.SCHEDULED_TERMINATION_URI);
+            termination = wsrl.getTerminationTime();
+        }
+        
+        addEntry(epr, null, termination);
+    }
+    
+    public void resourceRemoved(EndpointReference epr)
+        throws SoapFault
+    {
+        //
+        // if the SG is destroyed, it means we're being told about 
+        // our own destruction - don't do anything
+        //
+        if (hasBeenShutdown())
+            getWsResource().getResourceManager().removeListener(this);
+        
+        else
+        {
+            WsResource entry = getEntry(epr);
+            
+            //
+            // if there was no value in the SG for the EPR, it was 
+            // either a wssg:Entry resource (entries do not have 
+            // entries themselves, or we'd have infinite recursion)
+            // or a member that was removed by a remote client before 
+            // the member was destroyed
+            //
+            if (entry != null)
+                removeEntry(entry);
+        }
+    }
+    
+    protected Element[] getEntryElements()
+    {
+        WsResource[] entries = getEntry();
+        Element[] entryXML = new Element[entries.length];
+        
+        for (int n = 0; n < entries.length; ++n)
+        {
+            Entry entryCap = (Entry)entries[n].getCapability(WssgConstants.ENTRY_URI);
+            entryXML[n] = entryCap.toXML();
+        }
+        
+        return entryXML;
+    }
+    
+    public Element[] getProperty(QName property) 
+        throws BaseFault
+    {
+        if (property.equals(WssgConstants.ENTRY_QNAME))
+            return getEntryElements();
+        
+        return super.getProperty(property);
+    }
+}

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroupRegistration.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroupRegistration.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroupRegistration.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/impl/SimpleServiceGroupRegistration.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,82 @@
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.muse.ws.resource.sg.impl;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.routing.MessageHandler;
+import org.apache.muse.util.ReflectUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.resource.WsResource;
+import org.apache.muse.ws.resource.basefaults.BaseFault;
+import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
+import org.apache.muse.ws.resource.sg.ServiceGroup;
+import org.apache.muse.ws.resource.sg.ServiceGroupRegistration;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+import org.apache.muse.ws.resource.sg.faults.AddRefusedFault;
+import org.apache.muse.ws.resource.sg.faults.ContentCreationFailedFault;
+import org.apache.muse.ws.resource.sg.faults.UnsupportedMemberInterfaceFault;
+
+public class SimpleServiceGroupRegistration extends
+        AbstractWsResourceCapability implements ServiceGroupRegistration
+{
+    private ServiceGroup _sg = null;
+    
+    protected MessageHandler createAddHandler()
+    {
+        MessageHandler handler = new AddHandler();
+        
+        Method method = ReflectUtils.getFirstMethod(getClass(), "add");
+        handler.setMethod(method);
+        
+        return handler;
+    }
+    
+    protected ServiceGroup getServiceGroup()
+    {
+        return _sg;
+    }
+    
+    public void initialize()
+        throws SoapFault
+    {
+        super.initialize();
+        
+        _sg = (ServiceGroup)getWsResource().getCapability(WssgConstants.SERVICE_GROUP_URI);
+        
+        if (_sg == null) // FIXME: message
+            throw new IllegalStateException("No WS-SG capability.");
+        
+        setMessageHandler(createAddHandler());
+    }
+    
+    public EndpointReference add(EndpointReference memberEPR, 
+                                 Element content, 
+                                 Date terminationTime) 
+        throws AddRefusedFault, 
+               ContentCreationFailedFault, 
+               UnsupportedMemberInterfaceFault, 
+               BaseFault
+    {
+        WsResource entry = getServiceGroup().addEntry(memberEPR, content, terminationTime);
+        return entry.getEndpointReference();
+    }
+}

Added: webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/remote/ServiceGroupClient.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/remote/ServiceGroupClient.java?rev=414694&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/remote/ServiceGroupClient.java (added)
+++ webservices/muse/trunk/modules/muse-wsrf/src-impl/org/apache/muse/ws/resource/sg/remote/ServiceGroupClient.java Thu Jun 15 15:16:59 2006
@@ -0,0 +1,116 @@
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.muse.ws.resource.sg.remote;
+
+import java.net.URI;
+import java.util.Date;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.resource.remote.WsResourceClient;
+import org.apache.muse.ws.resource.sg.MembershipContentRule;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+import org.apache.muse.ws.resource.sg.impl.AddRequest;
+import org.apache.muse.ws.resource.sg.impl.AddResponse;
+import org.apache.muse.ws.resource.sg.impl.SimpleMembershipContentRule;
+import org.apache.muse.ws.addressing.soap.SoapClient;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.core.Environment;
+import org.apache.muse.util.xml.XmlUtils;
+
+/**
+ *
+ * ServiceGroupClient is ...
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class ServiceGroupClient extends WsResourceClient
+{
+    public ServiceGroupClient(EndpointReference destination)
+    {
+        super(destination);
+    }
+
+    public ServiceGroupClient(EndpointReference destination,
+                              EndpointReference source)
+    {
+        super(destination, source);
+    }
+
+    public ServiceGroupClient(EndpointReference destination,
+                              EndpointReference source, 
+                              Environment environment)
+    {
+        super(destination, source, environment);
+    }
+
+    public ServiceGroupClient(EndpointReference destination,
+                              EndpointReference source, 
+                              SoapClient soapClient)
+    {
+        super(destination, source, soapClient);
+    }
+
+    public WsResourceClient add(EndpointReference memberEPR, Date termination)
+        throws SoapFault
+    {
+        URI action = URI.create(WssgConstants.ADD_URI);
+        AddRequest add = new AddRequest(memberEPR, termination);
+        
+        Element responseXML = invoke(action, add.toXML());
+        AddResponse response = new AddResponse(responseXML);
+        return response.getEntryClient();
+    }
+    
+    public WsResourceClient[] getMembers()
+        throws SoapFault
+    {
+        Element[] entries = getResourceProperty(WssgConstants.ENTRY_QNAME);
+        WsResourceClient[] proxies = new WsResourceClient[entries.length];
+        
+        EndpointReference src = getSource();
+        EndpointReference dest = null;
+        
+        for (int n = 0; n < entries.length; ++n)
+        {
+            Element eprXML = XmlUtils.getElement(entries[n], WssgConstants.MEMBER_SERVICE_EPR_QNAME);
+            dest = new EndpointReference(eprXML);
+            proxies[n] = new WsResourceClient(dest, src);            
+        }
+        
+        return proxies;        
+    }
+
+    public boolean isMatch(EndpointReference epr) 
+        throws SoapFault
+    {
+        Element[] results = getResourceProperty(WssgConstants.CONTENT_RULE_QNAME);
+        
+        for (int n = 0; n < results.length; ++n)
+        {
+            MembershipContentRule mcr = new SimpleMembershipContentRule(results[n]);
+            
+            if (!mcr.isMatch(epr))
+                return false;
+        }
+        
+        return true;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org