View Javadoc

1   /* 
2    * Copyright (c) 2007, Fraunhofer-Gesellschaft
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    * 
9    * (1) Redistributions of source code must retain the above copyright
10   *     notice, this list of conditions and the disclaimer at the end.
11   *     Redistributions in binary form must reproduce the above copyright
12   *     notice, this list of conditions and the following disclaimer in
13   *     the documentation and/or other materials provided with the
14   *     distribution.
15   * 
16   * (2) Neither the name of Fraunhofer nor the names of its
17   *     contributors may be used to endorse or promote products derived
18   *     from this software without specific prior written permission.
19   * 
20   * DISCLAIMER
21   * 
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   *  
34   */
35  package org.ogf.graap.wsag.wsrf.sg.impl;
36  
37  import org.apache.log4j.Logger;
38  import org.apache.muse.ws.addressing.EndpointReference;
39  import org.apache.xmlbeans.XmlObject;
40  import org.apache.xmlbeans.XmlOptions;
41  import org.ogf.graap.wsag.api.WsagConstants;
42  import org.w3.x2005.x08.addressing.EndpointReferenceType;
43  import org.w3.x2005.x08.addressing.ReferenceParametersType;
44  import org.w3c.dom.Element;
45  
46  /**
47   * AgreementMembershipContentRule
48   * 
49   * @author Oliver Waeldrich
50   * 
51   */
52  public class AgreementMembershipContentRule extends MembershipContentRule
53  {
54  
55      private static final Logger LOG = Logger.getLogger( AgreementMembershipContentRule.class );
56  
57      /**
58       * default constructor
59       */
60      public AgreementMembershipContentRule()
61      {
62          super();
63      }
64  
65      /**
66       * 
67       * @param xml
68       *            the rule to set
69       * 
70       * @see org.apache.muse.ws.resource.sg.impl.SimpleMembershipContentRule
71       */
72      public AgreementMembershipContentRule( Element xml )
73      {
74          super( xml );
75      }
76  
77      /**
78       * @param memberEPR
79       *            the EPR of the resource that is matched against the membership rule
80       * 
81       * @return <code>true</code> if the specified resource matches the membership rule, otherwise
82       *         <code>false</code>
83       */
84      public boolean isMatch( EndpointReference memberEPR )
85      {
86          boolean result = super.isMatch( memberEPR );
87  
88          //
89          // if this is an agreement resource
90          //
91          if ( result )
92          {
93              //
94              // The factoryEPR and the registryEPR need to have the same
95              // reference parameters in order to have the resource added
96              // to this service group.
97              //
98              EndpointReferenceType factoryEPR = MembershipContentRuleContext.getFactoryEPR();
99              EndpointReferenceType registryEPR = MembershipContentRuleContext.getRegistryEPR();
100 
101             ReferenceParametersType factoryREF = factoryEPR.getReferenceParameters();
102             ReferenceParametersType registryREF = registryEPR.getReferenceParameters();
103 
104             //
105             // Since the resource to be added is a local wsag4j agreement resource,
106             // we simply check the appropriate reference parameter (wsag4j resource id)
107             //
108             XmlObject[] factoryChildren = factoryREF.selectChildren( WsagConstants.WSAG4J_RESOURCE_ID_QNAME );
109             XmlObject[] registryChildren =
110                 registryREF.selectChildren( WsagConstants.WSAG4J_RESOURCE_ID_QNAME );
111 
112             if ( factoryChildren.length != 1 )
113             {
114                 LOG.error( "Expected exacly one occurence of WSAG4J resource id in epr, but found "
115                     + Integer.valueOf( factoryChildren.length ) );
116 
117                 if ( LOG.isDebugEnabled() )
118                 {
119                     LOG.debug( factoryEPR.xmlText( new XmlOptions().setSavePrettyPrint() ) );
120                 }
121 
122                 return false;
123             }
124 
125             if ( registryChildren.length != 1 )
126             {
127                 LOG.error( "Expected exacly one occurence of WSAG4J resource id in epr, but found "
128                     + Integer.valueOf( registryChildren.length ) );
129 
130                 if ( LOG.isDebugEnabled() )
131                 {
132                     LOG.debug( registryEPR.xmlText( new XmlOptions().setSavePrettyPrint() ) );
133                 }
134 
135                 return false;
136             }
137 
138             String factoryID = factoryChildren[0].getDomNode().getFirstChild().getNodeValue();
139             String registryID = registryChildren[0].getDomNode().getFirstChild().getNodeValue();
140 
141             if ( factoryID == null )
142             {
143                 LOG.error( "Factory resource id must not be null in reference parameters." );
144 
145                 if ( LOG.isDebugEnabled() )
146                 {
147                     LOG.debug( factoryEPR.xmlText( new XmlOptions().setSavePrettyPrint() ) );
148                 }
149 
150                 return false;
151             }
152 
153             if ( registryID == null )
154             {
155                 LOG.error( "Registry resource id must not be null in reference parameters." );
156 
157                 if ( LOG.isDebugEnabled() )
158                 {
159                     LOG.debug( registryEPR.xmlText( new XmlOptions().setSavePrettyPrint() ) );
160                 }
161 
162                 return false;
163             }
164 
165             result = result && factoryID.equals( registryID );
166         }
167 
168         return result;
169     }
170 
171 }