📄 messagecontext.java
字号:
return (String) getProperty(propName); } /** * Tests to see if the named property is set in the 'bag', returning * <code>false</code> if it is not present at all. * This is equivalent to <code>isPropertyTrue(propName, false)</code>. * * @param propName the name of the property to check * @return true or false, depending on the value of the property */ public boolean isPropertyTrue(String propName) { return isPropertyTrue(propName, false); } /** * Test if a property is set to something we consider to be true in the * 'bag'. * <ul> * <li>If not there then <code>defaultVal</code> is returned.</li> * <li>If there, then...<ul> * <li>if its a <code>Boolean</code>, we'll return booleanValue()</li> * <li>if its an <code>Integer</code>, we'll return <code>false</code> * if its <code>0</code> else <code>true</code></li> * <li>if its a <code>String</code> we'll return <code>false</code> if its * <code>"false"</code>" or <code>"0"</code> else <code>true</code></li> * <li>All other types return <code>true</code></li> * </ul></li> * </ul> * * @param propName the name of the property to check * @param defaultVal the default value * @return true or false, depending on the value of the property */ public boolean isPropertyTrue(String propName, boolean defaultVal) { return JavaUtils.isTrue(getProperty(propName), defaultVal); } /** * Allows you to set a named property to the passed in value. * There are a few known properties (like username, password, etc) * that are variables in Call. The rest of the properties are * stored in a Hashtable. These common properties should be * accessed via the accessors for speed/type safety, but they may * still be obtained via this method. It's up to one of the * Handlers (or the Axis engine itself) to go looking for * one of them. * * @param name Name of the property * @param value Value of the property */ public void setProperty(String name, Object value) { if (name == null || value == null) { return; // Is this right? Shouldn't we throw an exception like: // throw new IllegalArgumentException(msg); } else if (name.equals(Call.USERNAME_PROPERTY)) { if (!(value instanceof String)) { throw new IllegalArgumentException( Messages.getMessage("badProp00", new String[] { name, "java.lang.String", value.getClass().getName()})); } setUsername((String) value); } else if (name.equals(Call.PASSWORD_PROPERTY)) { if (!(value instanceof String)) { throw new IllegalArgumentException( Messages.getMessage("badProp00", new String[] { name, "java.lang.String", value.getClass().getName()})); } setPassword((String) value); } else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) { if (!(value instanceof Boolean)) { throw new IllegalArgumentException( Messages.getMessage("badProp00", new String[] {name, "java.lang.Boolean", value.getClass().getName()})); } setMaintainSession(((Boolean) value).booleanValue()); } else if (name.equals(Call.SOAPACTION_USE_PROPERTY)) { if (!(value instanceof Boolean)) { throw new IllegalArgumentException( Messages.getMessage("badProp00", new String[] {name, "java.lang.Boolean", value.getClass().getName()})); } setUseSOAPAction(((Boolean) value).booleanValue()); } else if (name.equals(Call.SOAPACTION_URI_PROPERTY)) { if (!(value instanceof String)) { throw new IllegalArgumentException( Messages.getMessage("badProp00", new String[] {name, "java.lang.String", value.getClass().getName()})); } setSOAPActionURI((String) value); } else if (name.equals(Call.ENCODINGSTYLE_URI_PROPERTY)) { if (!(value instanceof String)) { throw new IllegalArgumentException( Messages.getMessage("badProp00", new String[] {name, "java.lang.String", value.getClass().getName()})); } setEncodingStyle((String) value); } else { bag.put(name, value); } } // setProperty /** * Returns true if the MessageContext contains a property with the specified name. * @param name Name of the property whose presense is to be tested * @return Returns true if the MessageContext contains the property; otherwise false */ public boolean containsProperty(String name) { Object propertyValue = getProperty(name); return (propertyValue != null); } /** * Returns an <code>Iterator</code> view of the names of the properties in * this <code>MessageContext</code>. * * @return an <code>Iterator</code> over all property names */ public java.util.Iterator getPropertyNames() { // fixme: this is potentially unsafe for the caller - changing the // properties will kill the iterator. Consider iterating over a copy: // return new HashSet(bag.keySet()).iterator(); return bag.keySet().iterator(); } /** * Returns an Iterator view of the names of the properties * in this MessageContext and any parents of the LockableHashtable * @return Iterator for the property names */ public java.util.Iterator getAllPropertyNames() { return bag.getAllKeys().iterator(); } /** * Returns the value associated with the named property - or null if not * defined/set. * * @param name the property name * @return Object value of the property - or null */ public Object getProperty(String name) { if (name != null) { if (name.equals(Call.USERNAME_PROPERTY)) { return getUsername(); } else if (name.equals(Call.PASSWORD_PROPERTY)) { return getPassword(); } else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) { return getMaintainSession() ? Boolean.TRUE : Boolean.FALSE; } else if (name.equals(Call.OPERATION_STYLE_PROPERTY)) { return (getOperationStyle() == null) ? null : getOperationStyle().getName(); } else if (name.equals(Call.SOAPACTION_USE_PROPERTY)) { return useSOAPAction() ? Boolean.TRUE : Boolean.FALSE; } else if (name.equals(Call.SOAPACTION_URI_PROPERTY)) { return getSOAPActionURI(); } else if (name.equals(Call.ENCODINGSTYLE_URI_PROPERTY)) { return getEncodingStyle(); } else if (bag == null) { return null; } else { return bag.get(name); } } else { return null; } } // fixme: this makes no copy of parent, so later modifications to parent // can alter this context - is this intended? If so, it needs documenting. // If not, it needs fixing. /** * Set the Hashtable that contains the default values for our * properties. * * @param parent */ public void setPropertyParent(Hashtable parent) { bag.setParent(parent); } /** * Set the username. * * @param username the new user name */ public void setUsername(String username) { this.username = username; } // setUsername /** * Get the user name. * * @return the user name as a <code>String</code> */ public String getUsername() { return username; } // getUsername /** * Set the password. * * @param password a <code>String</code> containing the new password */ public void setPassword(String password) { this.password = password; } // setPassword /** * Get the password. * * @return the current password <code>String</code> */ public String getPassword() { return password; } // getPassword /** * Get the operation style. This is either the style of the current * operation or if that is not set, the style of the service handler, or * if that is not set, <code>Style.RPC</code>. * * @return the <code>Style</code> of this message */ public Style getOperationStyle() { if (currentOperation != null) { return currentOperation.getStyle(); } if (serviceHandler != null) { return serviceHandler.getStyle(); } return Style.RPC; } // getOperationStyle /** * Get the operation use. * * @return the operation <code>Use</code> */ public Use getOperationUse() { if (currentOperation != null) { return currentOperation.getUse(); } if (serviceHandler != null) { return serviceHandler.getUse(); } return Use.ENCODED; } // getOperationUse /** * Enable or dissable the use of soap action information. When enabled, * the message context will attempt to use the soap action URI * information during binding of soap messages to service methods. When * dissabled, it will make no such attempt. * * @param useSOAPAction <code>true</code> if soap action URI information * should be used, <code>false</code> otherwise */ public void setUseSOAPAction(boolean useSOAPAction) { this.useSOAPAction = useSOAPAction; } // setUseSOAPAction // fixme: this doesn't follow beany naming conventions - should be // isUseSOAPActions or getUseSOAPActions or something prettier /** * Indicates wether the soap action URI is being used or not. * * @return <code>true</code> if it is, <code>false</code> otherwise */ public boolean useSOAPAction() { return useSOAPAction; } // useSOAPAction // fixme: this throws IllegalArgumentException but never raises it - // perhaps in a sub-class? // fixme: IllegalArgumentException is unchecked. Best practice says you // should document unchecked exceptions, but not list them in throws /** * Set the soapAction URI. * * @param SOAPActionURI a <code>String</code> giving the new soap action * URI * @throws IllegalArgumentException if the URI is not liked */ public void setSOAPActionURI(String SOAPActionURI) throws IllegalArgumentException { this.SOAPActionURI = SOAPActionURI; } // setSOAPActionURI /** * Get the soapAction URI. * * @return the URI of this soap action */ public String getSOAPActionURI() { return SOAPActionURI; } // getSOAPActionURI /** * Sets the encoding style to the URI passed in. * * @param namespaceURI URI of the encoding to use. */ public void setEncodingStyle(String namespaceURI) { if (namespaceURI == null) { namespaceURI = Constants.URI_LITERAL_ENC; } else if (Constants.isSOAP_ENC(namespaceURI)) { namespaceURI = soapConstants.getEncodingURI(); } encodingStyle = namespaceURI; } // setEncodingStype /** * Returns the encoding style as a URI that should be used for the SOAP * message. * * @return String URI of the encoding style to use */ public String getEncodingStyle() { return encodingStyle; } // getEncodingStyle public void removeProperty(String propName) { if (bag != null) { bag.remove(propName); } } /** * Return this context to a clean state. */ public void reset() { if (bag != null) { bag.clear(); } serviceHandler = null; havePassedPivot = false; currentOperation = null; } /** * Read the high fidelity property. * <p> * Some behavior may be apropreate for high fidelity contexts that is not * relevant for low fidelity ones or vica-versa. * * @return <code>true</code> if the context is high fidelity, * <code>false</code> otherwise */ public boolean isHighFidelity() { return highFidelity; } /** * Set the high fidelity propert. * <p> * Users of the context may be changing what they do based upon this flag. * * @param highFidelity the new value of the highFidelity property */ public void setHighFidelity(boolean highFidelity) { this.highFidelity = highFidelity; } /** * Gets the SOAP actor roles associated with an execution of the * <code>HandlerChain</code> and its contained <code>Handler</code> * instances. * <p> * <i>Not (yet) implemented method in the SOAPMessageContext interface</i>. * <p> * <b>Note:</b> SOAP actor roles apply to the SOAP node and are managed * using <code>HandlerChain.setRoles()</code> and * <code>HandlerChain.getRoles()</code>. Handler instances in the * <code>HandlerChain</code> use this information about the SOAP actor roles * to process the SOAP header blocks. Note that the SOAP actor roles are * invariant during the processing of SOAP message through the * <code>HandlerChain</code>. * * @return an array of URIs for SOAP actor roles * @see javax.xml.rpc.handler.HandlerChain#setRoles(java.lang.String[]) HandlerChain.setRoles(java.lang.String[]) * @see javax.xml.rpc.handler.HandlerChain#getRoles() HandlerChain.getRoles() */ public String[] getRoles() { //TODO: Flesh this out. return roles; } /** * Set the SOAP actor roles associated with an executioni of * <code>CodeHandlerChain</code> and its contained <code>Handler</code> * instances. * * @param roles an array of <code>String</code> instances, each representing * the URI for a SOAP actor role */ public void setRoles( String[] roles) { this.roles = roles; } /** * if a message (or subclass) has any disposal needs, this method * is where it goes. Subclasses *must* call super.dispose(), and * be prepared to be called from the finalizer as well as earlier */ public synchronized void dispose() { log.debug("disposing of message context"); if(requestMessage!=null) { requestMessage.dispose(); requestMessage=null; } if(responseMessage!=null) { responseMessage.dispose(); responseMessage=null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -