objectstateutils.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,644 行 · 第 1/4 页

JAVA
1,644
字号
						.trace("ObjectStateUtils:findMessage(): returning OUT message  ["
								+ msgName + "]  [" + msgElementName + "] ");
			}

			return out;
		}

		// -------------------------------------
		// next, try the "in" message
		// -------------------------------------
		AxisMessage in = null;
		try {
			in = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
		} catch (Exception ex) {
			// just absorb the exception
		}

		if (in != null) {
			tmpName = in.getName();

			QName tmpQin = in.getElementQName();
			if (tmpQin != null) {
				tmpElementName = tmpQin.toString();
			}
		} else {
			tmpName = null;
			tmpElementName = null;
		}

		// check the criteria for a match

		matching = matchMessageNames(tmpName, tmpElementName, msgName,
				msgElementName);

		if (matching) {
			// trace point
			if (log.isTraceEnabled()) {
				log
						.trace("ObjectStateUtils:findMessage(): returning IN message ["
								+ msgName + "]  [" + msgElementName + "] ");
			}

			return in;
		}

		// if we got here, then no match was found

		// trace point
		if (log.isTraceEnabled()) {
			log.trace("ObjectStateUtils:findMessage(): [" + msgName + "]  ["
					+ msgElementName + "] returning  [null]");
		}

		return null;
	}

	/**
	 * Check the first set of names for a match against the second set of names.
	 * These names are associated with AxisMessage objects. Message names are
	 * expected to be non-null. Element names could be either null or non-null.
	 * 
	 * @param name1
	 *            The name for the first message
	 * @param elementName1
	 *            The element name for the first message
	 * @param name2
	 *            The name for the second message
	 * @param elementName2
	 *            The element name for the second message
	 * @return TRUE if there's a match, FALSE otherwise
	 */
	private static boolean matchMessageNames(String name1, String elementName1,
			String name2, String elementName2) {
		// the name for the message must exist
		if ((name1 != null) && (name2 != null) && (name1.equals(name2))) {
			// there's a match on the name associated with the message object

			// element names need to match, including being null
			if ((elementName1 == null) && (elementName2 == null)) {
				// there's a match for the nulls
				return true;
			} else if ((elementName1 != null) && (elementName2 != null)
					&& (elementName1.equals(elementName2))) {
				// there's a match for the element names
				return true;
			} else {
				// there's some mismatch
				return false;
			}
		} else {
			// either a message name is null or the names don't match
			return false;
		}
	}

	/**
	 * Find the Handler object that matches the criteria
	 * 
	 * @param existingHandlers
	 *            The list of existing handlers and phases
	 * @param handlerClassName
	 *            the class name string for the target object (could be a
	 *            derived class)
	 * @return the Handler object that matches the criteria
	 */
	public static Object findHandler(ArrayList existingHandlers,
			MetaDataEntry metaDataEntry) // String handlerClassName)
	{

		String title = "ObjectStateUtils:findHandler(): ";

		String handlerClassName = metaDataEntry.getClassName();
		String qNameAsString = metaDataEntry.getQNameAsString();

		for (int i = 0; i < existingHandlers.size(); i++) {
			if (existingHandlers.get(i) != null) {
				String tmpClassName = existingHandlers.get(i).getClass()
						.getName();
				String tmpName = ((Handler) existingHandlers.get(i)).getName()
						.toString();

				if ((tmpClassName.equals(handlerClassName))
						&& (tmpName.equals(qNameAsString))) {
					// trace point
					if (log.isTraceEnabled()) {
						log.trace(title + " [" + handlerClassName + "]  name ["
								+ qNameAsString + "]  returned");
					}

					return (Handler) (existingHandlers.get(i));
				}
			}
		}

		// trace point
		if (log.isTraceEnabled()) {
			log.trace(title + " [" + handlerClassName + "]  name ["
					+ qNameAsString
					+ "] was not found in the existingHandlers list");
		}

		return null;
	}

	/**
	 * Find the TransportListener object that matches the criteria <p/> <B>Note<B>
	 * the saved meta information may not match up with any of the objects that
	 * are in the current AxisConfiguration object.
	 * 
	 * @param axisConfig
	 *            The AxisConfiguration object
	 * @param listenerClassName
	 *            the class name string for the target object (could be a
	 *            derived class)
	 * @return the TransportListener object that matches the criteria
	 */
	public static TransportListener findTransportListener(
			AxisConfiguration axisConfig, String listenerClassName) {
		// TODO: investigate a better technique to match up with a
		// TransportListener

		HashMap transportsIn = axisConfig.getTransportsIn();

		// get a collection of the values in the map
		Collection values = transportsIn.values();

		Iterator i = values.iterator();

		while (i.hasNext()) {
			TransportInDescription ti = (TransportInDescription) i.next();

			TransportListener tl = ti.getReceiver();
			String tlClassName = tl.getClass().getName();

			if (tlClassName.equals(listenerClassName)) {
				// trace point
				if (log.isTraceEnabled()) {
					log.trace("ObjectStateUtils:findTransportListener():  ["
							+ listenerClassName + "]  returned");
				}

				return tl;
			}
		}

		// trace point
		if (log.isTraceEnabled()) {
			log
					.trace("ObjectStateUtils:findTransportListener(): returning  [null]");
		}

		return null;
	}

	/**
	 * Compares the two collections to see if they are equivalent.
	 * 
	 * @param a1
	 *            The first collection
	 * @param a2
	 *            The second collection
	 * @param strict
	 *            Indicates whether strict checking is required. Strict checking
	 *            means that the two collections must have the same elements in
	 *            the same order. Non-strict checking means that the two
	 *            collections must have the same elements, but the order is not
	 *            significant.
	 * @return TRUE if the two collections are equivalent FALSE, otherwise
	 */
	public static boolean isEquivalent(ArrayList a1, ArrayList a2,
			boolean strict) {
		if ((a1 != null) && (a2 != null)) {
			// check number of elements in lists
			int size1 = a1.size();
			int size2 = a2.size();

			if (size1 != size2) {
				// trace point
				if (log.isTraceEnabled()) {
					log
							.trace("ObjectStateUtils:isEquivalent(ArrayList,ArrayList): FALSE - size mismatch ["
									+ size1 + "] != [" + size2 + "]");
				}
				return false;
			}

			if (strict) {
				// Strict checking
				// The lists must contain the same elements in the same order.
				return (a1.equals(a2));
			} else {
				// Non-strict checking
				// The lists must contain the same elements but the order is not
				// required.
				Iterator i1 = a1.iterator();

				while (i1.hasNext()) {
					Object obj1 = i1.next();

					if (!a2.contains(obj1)) {
						// trace point
						if (log.isTraceEnabled()) {
							log
									.trace("ObjectStateUtils:isEquivalent(ArrayList,ArrayList): FALSE - mismatch with element ["
											+ obj1.getClass().getName() + "] ");
						}
						return false;
					}
				}

				return true;
			}

		} else if ((a1 == null) && (a2 == null)) {
			return true;
		} else if ((a1 != null) && (a2 == null)) {
			if (a1.size() == 0) {
				return true;
			}
			return false;
		} else if ((a1 == null) && (a2 != null)) {
			if (a2.size() == 0) {
				return true;
			}
			return false;
		} else {
			// mismatch

			// trace point
			if (log.isTraceEnabled()) {
				log
						.trace("ObjectStateUtils:isEquivalent(ArrayList,ArrayList): FALSE - mismatch in lists");
			}
			return false;
		}
	}

	/**
	 * Compares the two collections to see if they are equivalent.
	 * 
	 * @param m1
	 *            The first collection
	 * @param m2
	 *            The second collection
	 * @param strict
	 *            Indicates whether strict checking is required. Strict checking
	 *            means that the two collections must have the same mappings.
	 *            Non-strict checking means that the two collections must have
	 *            the same keys. In both cases, the order is not significant.
	 * @return TRUE if the two collections are equivalent FALSE, otherwise
	 */
	public static boolean isEquivalent(Map m1, Map m2, boolean strict) {
		if ((m1 != null) && (m2 != null)) {
			if (strict) {
				// This is a strict test.
				// Returns true if the given object is also a map and the two
				// Maps
				// represent the same mappings.
				return (m1.equals(m2));
			} else {
				int size1 = m1.size();
				int size2 = m2.size();

				if (size1 != size2) {
					return false;
				}

				// check the keys, ordering is not important between the two
				// maps
				Iterator it1 = m1.keySet().iterator();

				while (it1.hasNext()) {
					Object key1 = it1.next();

					if (m2.containsKey(key1) == false) {
						return false;
					}
				}

				return true;
			}
		} else if ((m1 == null) && (m2 == null)) {
			return true;
		} else {
			// mismatch
			return false;
		}
	}

	/**
	 * Compares the two collections to see if they are equivalent.
	 * 
	 * @param l1
	 *            The first collection
	 * @param l2
	 *            The second collection
	 * @return TRUE if the two collections are equivalent FALSE, otherwise
	 */
	public static boolean isEquivalent(LinkedList l1, LinkedList l2) {
		if ((l1 != null) && (l2 != null)) {
			// This is a strict test.
			// Returns true if the specified object is also a list,
			// both lists have the same size, and all corresponding pairs
			// of elements in the two lists are equal where
			// they contain the same elements in the same order.
			return (l1.equals(l2));
		} else if ((l1 == null) && (l2 == null)) {
			return true;
		} else {
			// mismatch
			return false;
		}
	}

	/**
	 * Trace the NotSerializable exception for the specified object if this is
	 * the first time that the specified object has caused the exception.
	 * 
	 * @param obj
	 *            The object being saved or restored
	 * @param nse
	 *            The exception object with the details of the error
	 * @param objDesc
	 *            The description of the object, eg, like the field name where
	 *            it is being used
	 * @param methodName
	 *            The method name which encountered the exception
	 * @param desc
	 *            Text to be used for tracing
	 */
	public static void traceNotSerializable(Object obj,
			NotSerializableException nse, String objDesc, String methodName,
			String desc) {
		if (log.isTraceEnabled() == false) {
			// if no tracing is being done, there's nothing to do
			// exit quickly
			return;
		}

		if (obj != null) {
			String objName = obj.getClass().getName();

			if (NotSerializableList.get(objName) == null) {
				// set up some information about the exception
				// for now, just use an initial counter, which we aren't doing
				// much with
				// but takes less space than the original object that caused the
				// exception
				// future: consider using a trace information object that would
				// contain a count of the times that a particular class
				// caused the exception, the class name of that class,
				// and the stack trace for the first time - this information
				// could then be accessed from a utility
				Integer counter = new Integer(1);

				// add to table
				NotSerializableList.put(objName, counter);

				// trace point
				log.trace("ObjectStateUtils: ***NotSerializableException*** ["
						+ nse.getMessage() + "] in method [" + methodName
						+ "] for object [" + objName + "]  associated with ["
						+ objDesc + "].  " + desc);
			}

		}

	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?