1 package org.objectweb.celtix.bus.ws.rm; 2 3 import java.util.List ; 4 import java.util.logging.Level ; 5 import java.util.logging.Logger ; 6 7 import javax.wsdl.Definition; 8 import javax.wsdl.Port; 9 import javax.wsdl.WSDLException; 10 import javax.wsdl.extensions.ExtensibilityElement; 11 import javax.wsdl.extensions.UnknownExtensibilityElement; 12 import javax.xml.bind.JAXBContext; 13 import javax.xml.bind.JAXBElement; 14 import javax.xml.bind.JAXBException; 15 import javax.xml.bind.Unmarshaller; 16 17 import org.w3c.dom.Element ; 18 import org.w3c.dom.NodeList ; 19 20 import org.objectweb.celtix.Bus; 21 import org.objectweb.celtix.common.logging.LogUtils; 22 import org.objectweb.celtix.configuration.Configuration; 23 import org.objectweb.celtix.configuration.ConfigurationProvider; 24 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 25 import org.objectweb.celtix.ws.rm.policy.RMAssertionType; 26 import org.objectweb.celtix.wsdl.EndpointReferenceUtils; 27 28 public class RMPolicyProvider implements ConfigurationProvider { 29 30 private static final Logger LOG = LogUtils.getL7dLogger(RMPolicyProvider.class); 31 private Port port; 32 private Definition def; 33 34 public RMPolicyProvider(Bus b, EndpointReferenceType epr) { 35 try { 36 port = EndpointReferenceUtils.getPort(b.getWSDLManager(), epr); 37 def = EndpointReferenceUtils.getWSDLDefinition(b.getWSDLManager(), epr); 38 } catch (WSDLException ex) { 39 LOG.log(Level.SEVERE, "POLICY_PROVIDER_CREATION_EXC", ex); 40 } 41 } 42 43 public void init(Configuration configuration) { 44 } 46 47 public Object getObject(String name) { 48 if (!"rmAssertion".equals(name)) { 49 return null; 50 } 51 52 Element policyElem = getPolicy(port.getBinding().getExtensibilityElements(), null); 53 if (null == policyElem) { 54 policyElem = getPolicy(port.getExtensibilityElements(), null); 55 } 56 if (null != policyElem) { 57 return getRMAssertion(policyElem); 58 } 59 60 return null; 61 62 } 63 64 private Element getPolicy(List <?> extensibilityElements, String name) { 65 for (Object ep : extensibilityElements) { 66 ExtensibilityElement ext = (ExtensibilityElement)ep; 67 if (ext instanceof UnknownExtensibilityElement) { 68 UnknownExtensibilityElement uExt = (UnknownExtensibilityElement)ext; 69 if (RMUtils.getPolicyConstants().getPolicyQName().equals(ext.getElementType())) { 70 Element elem = uExt.getElement(); 71 String id = elem.getAttributeNS(RMUtils.getPolicyConstants().getWSUNamespaceURI(), "Id"); 72 if (null == name || name.equals(id)) { 73 return elem; 74 } 75 } else if (RMUtils.getPolicyConstants().getPolicyReferenceQName() 76 .equals(ext.getElementType())) { 77 Element elem = uExt.getElement(); 78 String uri = elem.getAttribute("URI"); 79 if (uri.startsWith("#") && uri.length() > 1) { 80 Element referenced = getPolicy(def.getExtensibilityElements(), uri.substring(1)); 81 if (null != referenced) { 82 return referenced; 83 } 84 } else { 85 LOG.log(Level.SEVERE, "POLICY_REFERENCE_RESOLUTION_EXC", uri); 86 } 87 } 88 } 89 } 90 return null; 91 } 92 93 private RMAssertionType getRMAssertion(Element policyElement) { 94 RMAssertionType rma = null; 95 NodeList nl = policyElement.getElementsByTagNameNS(RMUtils.getRMConstants().getRMPolicyNamespaceURI(), 96 "RMAssertion"); 97 if (nl.getLength() > 0) { 98 JAXBContext context = null; 99 String packageName = RMUtils.getWSRMPolicyFactory().getClass().getPackage().getName(); 100 try { 101 context = JAXBContext.newInstance(packageName, getClass().getClassLoader()); 102 Unmarshaller u = context.createUnmarshaller(); 103 Object obj = u.unmarshal(nl.item(0)); 104 if (obj instanceof JAXBElement<?>) { 105 JAXBElement<?> el = (JAXBElement<?>)obj; 106 obj = el.getValue(); 107 } 108 rma = (RMAssertionType)obj; 109 } catch (JAXBException ex) { 110 LOG.log(Level.SEVERE, "RMASSERTION_UNMARSHAL_EXC", ex); 111 } 112 } 113 return rma; 114 } 115 116 public boolean setObject(String name, Object value) { 117 return false; 118 } 119 120 public boolean save() { 121 return false; 123 } 124 125 } 126 | Popular Tags |