Save This Page
Home » axis2-1.5-src » org.apache » axis2 » description » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements. See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership. The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License. You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied. See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   package org.apache.axis2.description;
   21   
   22   import java.util.ArrayList;
   23   import java.util.Date;
   24   import java.util.HashMap;
   25   import java.util.Map;
   26   
   27   import org.apache.axiom.om.OMAbstractFactory;
   28   import org.apache.axiom.om.OMElement;
   29   import org.apache.axiom.om.OMFactory;
   30   import org.apache.axiom.om.OMNamespace;
   31   import org.apache.axis2.AxisFault;
   32   import org.apache.axis2.engine.AxisConfiguration;
   33   import org.apache.axis2.util.PolicyUtil;
   34   import org.apache.axis2.util.WSDL20Util;
   35   import org.apache.axis2.util.WSDLSerializationUtil;
   36   import org.apache.axis2.wsdl.WSDLConstants;
   37   import org.apache.neethi.Policy;
   38   
   39   public class AxisBindingMessage extends AxisDescription {
   40   
   41   	private String name;
   42   
   43   	private String direction;
   44   
   45   	private Map<String, Object> options;
   46   
   47   	private AxisMessage axisMessage;
   48   
   49   	// Used to indicate whether this message is a fault or not. Needed for the
   50   	// WSDL 2.0 serializer
   51   	private boolean fault = false;
   52   
   53   	private Policy effectivePolicy = null;
   54   	private Date lastPolicyCalcuatedTime = null;
   55   
   56   	public boolean isFault() {
   57   		return fault;
   58   	}
   59   
   60   	public void setFault(boolean fault) {
   61   		this.fault = fault;
   62   	}
   63   
   64   	public String getName() {
   65   		return name;
   66   	}
   67   
   68   	public void setName(String name) {
   69   		this.name = name;
   70   	}
   71   
   72   	public AxisMessage getAxisMessage() {
   73   		return axisMessage;
   74   	}
   75   
   76   	public void setAxisMessage(AxisMessage axisMessage) {
   77   		this.axisMessage = axisMessage;
   78   	}
   79   
   80   	public String getDirection() {
   81   		return direction;
   82   	}
   83   
   84   	public void setDirection(String direction) {
   85   		this.direction = direction;
   86   	}
   87   
   88   	public AxisBindingMessage() {
   89   		options = new HashMap<String, Object>();
   90   	}
   91   
   92   	public void setProperty(String name, Object value) {
   93   		options.put(name, value);
   94   	}
   95   
   96   	/**
   97   	 * @param name
   98   	 *            name of the property to search for
   99   	 * @return the value of the property, or null if the property is not found
  100   	 */
  101   	public Object getProperty(String name) {
  102   		Object obj = options.get(name);
  103   		if (obj != null) {
  104   			return obj;
  105   		}
  106   
  107   		return null;
  108   	}
  109   
  110   	public Object getKey() {
  111   		return null; // To change body of implemented methods use File |
  112   		// Settings | File Templates.
  113   	}
  114   
  115   	public void engageModule(AxisModule axisModule) throws AxisFault {
  116   		throw new UnsupportedOperationException("Sorry we do not support this");
  117   	}
  118   
  119   	public boolean isEngaged(String moduleName) {
  120   		throw new UnsupportedOperationException(
  121   				"axisMessage.isEngaged() is not supported");
  122   
  123   	}
  124   
  125   	/**
  126   	 * Generates the bindingMessage element (can be input, output, infault or
  127   	 * outfault)
  128   	 * 
  129   	 * @param tns -
  130   	 *            The targetnamespace
  131   	 * @param wsoap -
  132   	 *            The SOAP namespace (WSDL 2.0)
  133   	 * @param whttp -
  134   	 *            The HTTP namespace (WSDL 2.0)
  135   	 * @param nameSpaceMap -
  136   	 *            The namespacemap of the service
  137   	 * @return The generated bindingMessage element
  138   	 */
  139   	public OMElement toWSDL20(OMNamespace wsdl, OMNamespace tns,
  140   			OMNamespace wsoap, OMNamespace whttp, Map<String, String> nameSpaceMap) {
  141   		String property;
  142   		ArrayList list;
  143   		OMFactory omFactory = OMAbstractFactory.getOMFactory();
  144   		OMElement bindingMessageElement;
  145   
  146   		// If this is a fault, create a fault element and add fault specific
  147   		// properties
  148   		if (this.isFault()) {
  149   			if (this.getParent() instanceof AxisBinding) {
  150   				bindingMessageElement = omFactory.createOMElement(
  151   						WSDL2Constants.FAULT_LOCAL_NAME, wsdl);
  152   			} else if (WSDLConstants.WSDL_MESSAGE_DIRECTION_IN.equals(this
  153   					.getDirection())) {
  154   				bindingMessageElement = omFactory.createOMElement(
  155   						WSDL2Constants.IN_FAULT_LOCAL_NAME, wsdl);
  156   			} else {
  157   				bindingMessageElement = omFactory.createOMElement(
  158   						WSDL2Constants.OUT_FAULT_LOCAL_NAME, wsdl);
  159   			}
  160   			bindingMessageElement.addAttribute(omFactory.createOMAttribute(
  161   					WSDL2Constants.ATTRIBUTE_REF, null, tns.getPrefix() + ":"
  162   							+ this.name));
  163   
  164   			WSDL20Util.extractWSDL20SoapFaultInfo(options,
  165   					bindingMessageElement, omFactory, wsoap);
  166   
  167   			Integer code = (Integer) this.options
  168   					.get(WSDL2Constants.ATTR_WHTTP_CODE);
  169   			if (code != null) {
  170   				bindingMessageElement.addAttribute(omFactory.createOMAttribute(
  171   						WSDL2Constants.ATTRIBUTE_CODE, whttp, code.toString()));
  172   			}
  173   
  174   			// Checks whether the message is an input message
  175   		} else if (WSDLConstants.WSDL_MESSAGE_DIRECTION_IN.equals(this
  176   				.getDirection())) {
  177   			bindingMessageElement = omFactory.createOMElement(
  178   					WSDL2Constants.IN_PUT_LOCAL_NAME, wsdl);
  179   
  180   			// Message should be an output message
  181   		} else {
  182   			bindingMessageElement = omFactory.createOMElement(
  183   					WSDL2Constants.OUT_PUT_LOCAL_NAME, wsdl);
  184   		}
  185   
  186   		// Populate common properties
  187   		property = (String) this.options
  188   				.get(WSDL2Constants.ATTR_WHTTP_CONTENT_ENCODING);
  189   		if (property != null) {
  190   			bindingMessageElement
  191   					.addAttribute(omFactory.createOMAttribute(
  192   							WSDL2Constants.ATTRIBUTE_CONTENT_ENCODING, whttp,
  193   							property));
  194   		}
  195   		list = (ArrayList) this.options.get(WSDL2Constants.ATTR_WHTTP_HEADER);
  196   		if (list != null && list.size() > 0) {
  197   			WSDLSerializationUtil.addHTTPHeaderElements(omFactory, list, whttp,
  198   					bindingMessageElement, nameSpaceMap);
  199   		}
  200   		list = (ArrayList) this.options.get(WSDL2Constants.ATTR_WSOAP_HEADER);
  201   		if (list != null && list.size() > 0) {
  202   			WSDLSerializationUtil.addSOAPHeaderElements(omFactory, list, wsoap,
  203   					bindingMessageElement, nameSpaceMap);
  204   		}
  205   		list = (ArrayList) this.options.get(WSDL2Constants.ATTR_WSOAP_MODULE);
  206   		if (list != null && list.size() > 0) {
  207   			WSDLSerializationUtil.addSOAPModuleElements(omFactory, list, wsoap,
  208   					bindingMessageElement);
  209   		}
  210   		WSDLSerializationUtil.addWSDLDocumentationElement(this,
  211   				bindingMessageElement, omFactory, wsdl);
  212   		WSDLSerializationUtil.addPoliciesAsExtensibleElement(this,
  213   				bindingMessageElement);
  214   		return bindingMessageElement;
  215   	}
  216   
  217   	public AxisBindingOperation getAxisBindingOperation() {
  218   		return (AxisBindingOperation) parent;
  219   	}
  220   
  221   	public Policy getEffectivePolicy() {
  222   	       if (lastPolicyCalcuatedTime == null || isPolicyUpdated()) {
  223   			effectivePolicy = calculateEffectivePolicy();
  224   		}
  225   		return effectivePolicy;
  226   	}
  227   
  228   	public Policy calculateEffectivePolicy() {
  229   		PolicySubject policySubject = null;
  230   		ArrayList policyList = new ArrayList();
  231   
  232   		// AxisBindingMessage
  233   		policySubject = getPolicySubject();
  234   		policyList.addAll(policySubject.getAttachedPolicyComponents());
  235   
  236   		// AxisBindingOperation policies
  237   		AxisBindingOperation axisBindingOperation = getAxisBindingOperation();
  238   		if (axisBindingOperation != null) {
  239   			policyList.addAll(axisBindingOperation.getPolicySubject()
  240   					.getAttachedPolicyComponents());
  241   		}
  242   
  243   		// AxisBinding
  244   		AxisBinding axisBinding = (axisBindingOperation == null) ? null
  245   				: axisBindingOperation.getAxisBinding();
  246   		if (axisBinding != null) {
  247   			policyList.addAll(axisBinding.getPolicySubject()
  248   					.getAttachedPolicyComponents());
  249   		}
  250   
  251   		// AxisEndpoint
  252   		AxisEndpoint axisEndpoint = (axisBinding == null) ? null : axisBinding
  253   				.getAxisEndpoint();
  254   		if (axisEndpoint != null) {
  255   			policyList.addAll(axisEndpoint.getPolicySubject()
  256   					.getAttachedPolicyComponents());
  257   		}
  258   
  259   		// AxisMessage
  260   		if (axisMessage != null) {
  261   			policyList.addAll(axisMessage.getPolicySubject()
  262   					.getAttachedPolicyComponents());
  263   		}
  264   
  265   		// AxisOperation
  266   		AxisOperation axisOperation = (axisMessage == null) ? null
  267   				: axisMessage.getAxisOperation();
  268   		if (axisOperation != null) {
  269   			policyList.addAll(axisOperation.getPolicySubject()
  270   					.getAttachedPolicyComponents());
  271   		}
  272   
  273   		// AxisService
  274   		AxisService axisService = (axisOperation == null) ? null
  275   				: axisOperation.getAxisService();
  276   		if (axisService != null) {
  277   			policyList.addAll(axisService.getPolicySubject()
  278   					.getAttachedPolicyComponents());
  279   		}
  280   
  281   		// AxisConfiguration
  282   		AxisConfiguration axisConfiguration = (axisService == null) ? null
  283   				: axisService.getAxisConfiguration();
  284   		if (axisConfiguration != null) {
  285   			policyList.addAll(axisConfiguration.getPolicySubject()
  286   					.getAttachedPolicyComponents());
  287   		}
  288   
  289   		lastPolicyCalcuatedTime = new Date();
  290   		return PolicyUtil.getMergedPolicy(policyList, axisService);
  291   	}
  292   	
  293   	private boolean isPolicyUpdated() {
  294   		if (getPolicySubject().getLastUpdatedTime().after(
  295   				lastPolicyCalcuatedTime)) {
  296   			return true;
  297   		}
  298   		// AxisBindingOperation
  299   		AxisBindingOperation axisBindingOperation = getAxisBindingOperation();
  300   		if (axisBindingOperation != null
  301   				&& axisBindingOperation.getPolicySubject().getLastUpdatedTime()
  302   						.after(lastPolicyCalcuatedTime)) {
  303   			return true;
  304   		}
  305   		// AxisBinding
  306   		AxisBinding axisBinding = (axisBindingOperation == null) ? null
  307   				: axisBindingOperation.getAxisBinding();
  308   		if (axisBinding != null
  309   				&& axisBinding.getPolicySubject().getLastUpdatedTime().after(
  310   						lastPolicyCalcuatedTime)) {
  311   			return true;
  312   		}
  313   		// AxisEndpoint
  314   		AxisEndpoint axisEndpoint = (axisBinding == null) ? null : axisBinding
  315   				.getAxisEndpoint();
  316   		if (axisEndpoint != null
  317   				&& axisEndpoint.getPolicySubject().getLastUpdatedTime().after(
  318   						lastPolicyCalcuatedTime)) {
  319   			return true;
  320   		}
  321   		// AxisMessage
  322   		if (axisMessage != null
  323   				&& axisMessage.getPolicySubject().getLastUpdatedTime().after(
  324   						lastPolicyCalcuatedTime)) {
  325   			return true;
  326   		}
  327   		// AxisOperation
  328   		AxisOperation axisOperation = (axisMessage == null) ? null
  329   				: axisMessage.getAxisOperation();
  330   		if (axisOperation != null
  331   				&& axisOperation.getPolicySubject().getLastUpdatedTime().after(
  332   						lastPolicyCalcuatedTime)) {
  333   			return true;
  334   		}
  335   		// AxisService
  336   		AxisService axisService = (axisOperation == null) ? null
  337   				: axisOperation.getAxisService();
  338   		if (axisService != null
  339   				&& axisService.getPolicySubject().getLastUpdatedTime().after(
  340   						lastPolicyCalcuatedTime)) {
  341   			return true;
  342   		}
  343   		// AxisConfiguration
  344   		AxisConfiguration axisConfiguration = (axisService == null) ? null
  345   				: axisService.getAxisConfiguration();
  346   		if (axisConfiguration != null
  347   				&& axisConfiguration.getPolicySubject().getLastUpdatedTime()
  348   						.after(lastPolicyCalcuatedTime)) {
  349   			return true;
  350   		}
  351   		return false;
  352   	}
  353   }

Save This Page
Home » axis2-1.5-src » org.apache » axis2 » description » [javadoc | source]