objectstateutils.java

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

JAVA
1,644
字号
					// trace point
					if (log.isTraceEnabled()) {
						log.trace("ObjectStateUtils:writeLinkedList(): object["
								+ obj.getClass().getName()
								+ "]  ***Exception***  ["
								+ exc.getClass().getName() + " : "
								+ exc.getMessage() + "]  " + OBJ_SAVE_PROBLEM,
								exc);
						// exc.printStackTrace();
					}
				}
			}

			// put the end-of-marker in the stream
			out.writeBoolean(EMPTY_OBJECT);
		}
		// trace point
		if (log.isTraceEnabled()) {
			log.trace("ObjectStateUtils:writeLinkedList(): List [" + desc
					+ "]   members saved [" + savedListSize + "]");
		}
	}

	/**
	 * Reads a linked list of objects from the specified input stream. Returns
	 * null if no array is available. <p/> The format of the information to be
	 * read from the input stream should be
	 * <LI> class name
	 * <LI> active or empty
	 * <LI> data <p/> NOTE: each object in the list should implement either
	 * java.io.Serializable or java.io.Externalizable in order to be saved <p/>
	 * 
	 * @param in
	 *            The input stream
	 * @param desc
	 *            A text description to use for logging
	 * @return The linked list or null, if not available
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public static LinkedList readLinkedList(ObjectInput in, String desc)
			throws IOException {
		// The format of the data is
		//
		// Non-null list:
		// UTF - description string
		// boolean - active flag
		// objects - objects from list
		// - ACTIVE_OBJECT
		// - data
		// EMPTY_OBJEXT - end of array marker
		//    
		// Null list:
		// UTF - description string
		// boolean - empty flag
		//

		LinkedList list = null;

		String str_desc = in.readUTF();

		boolean isActive = in.readBoolean();

		if (isActive == ACTIVE_OBJECT) {
			list = new LinkedList();

			// stop when we get to the end-of-list marker
			while (in.readBoolean()) {

				// get the object
				try {
					byte[] data = (byte[]) in.readObject();

					// convert the byte[] back into the real object
					ByteArrayInputStream test_inBuffer = new ByteArrayInputStream(
							data);
					ObjectInputStream test_objIn = new ObjectInputStream(
							test_inBuffer);
					Object obj = test_objIn.readObject();
					test_objIn.close();
					test_inBuffer.close();

					// add the entry to the list
					list.add(obj);

					// trace point
					if (log.isTraceEnabled()) {
						log.trace("ObjectStateUtils:readArrayList(): [" + desc
								+ "]  index [" + list.size() + "]  for saved ["
								+ str_desc + "]");
					}
				} catch (Exception ex) {
					// use this as a generic point for all exceptions

					// trace point
					if (log.isTraceEnabled()) {
						log.trace(
								"ObjectStateUtils:readArrayList(): [" + desc
										+ "]  object index [" + list.size()
										+ "]   for saved [" + str_desc
										+ "]  ***Exception***  ["
										+ ex.getClass().getName() + " : "
										+ ex.getMessage() + "]  "
										+ OBJ_RESTORE_PROBLEM, ex);
						// ex.printStackTrace();
					}
				}

			} // end while keep going
		}

		// trace point
		if (log.isTraceEnabled()) {
			int size = (list == null) ? -1 : list.size();
			log.trace("ObjectStateUtils:readArrayList(): [" + desc
					+ "]  returning  [listsize=" + size + "]  for saved ["
					+ str_desc + "]");
		}
		return list;
	}

	// --------------------------------------------------------------------
	// Finder methods
	// --------------------------------------------------------------------

	/**
	 * Find the AxisOperation object that matches the criteria
	 * 
	 * @param axisConfig
	 *            The AxisConfiguration object
	 * @param opClassName
	 *            the class name string for the target object (could be a
	 *            derived class)
	 * @param opQName
	 *            the name associated with the operation
	 * @return the AxisOperation object that matches the given criteria
	 */
	public static AxisOperation findOperation(AxisConfiguration axisConfig,
			String opClassName, QName opQName) {
		HashMap services = axisConfig.getServices();

		Iterator its = services.values().iterator();

		while (its.hasNext()) {
			AxisService service = (AxisService) its.next();

			Iterator ito = service.getOperations();

			while (ito.hasNext()) {
				AxisOperation operation = (AxisOperation) ito.next();

				String tmpOpName = operation.getClass().getName();
				QName tmpOpQName = operation.getName();

				if ((tmpOpName.equals(opClassName))
						&& (tmpOpQName.equals(opQName))) {
					// trace point
					if (log.isTraceEnabled()) {
						log
								.trace("ObjectStateUtils:findOperation(axisCfg): returning  ["
										+ opClassName
										+ "]   ["
										+ opQName.toString() + "]");
					}

					return operation;
				}
			}
		}

		// trace point
		if (log.isTraceEnabled()) {
			log.trace("ObjectStateUtils:findOperation(axisCfg): ["
					+ opClassName + "]   [" + opQName.toString()
					+ "]  returning  [null]");
		}

		return null;
	}

	/**
	 * Find the AxisOperation object that matches the criteria
	 * 
	 * @param service
	 *            The AxisService object
	 * @param opClassName
	 *            The class name string for the target object (could be a
	 *            derived class)
	 * @param opQName
	 *            the name associated with the operation
	 * @return the AxisOperation object that matches the given criteria
	 */
	public static AxisOperation findOperation(AxisService service,
			String opClassName, QName opQName) {
		if (service == null) {
			return null;
		}

		Iterator ito = service.getOperations();

		while (ito.hasNext()) {
			AxisOperation operation = (AxisOperation) ito.next();

			String tmpOpName = operation.getClass().getName();
			QName tmpOpQName = operation.getName();

			if ((tmpOpName.equals(opClassName)) && (tmpOpQName.equals(opQName))) {
				// trace point
				if (log.isTraceEnabled()) {
					log
							.trace("ObjectStateUtils:findOperation(service): returning  ["
									+ opClassName
									+ "]   ["
									+ opQName.toString() + "]");
				}

				return operation;
			}
		}

		// trace point
		if (log.isTraceEnabled()) {
			log.trace("ObjectStateUtils:findOperation(service): ["
					+ opClassName + "]   [" + opQName.toString()
					+ "]  returning  [null]");
		}

		return null;
	}

	/**
	 * Find the AxisService object that matches the criteria
	 * 
	 * @param axisConfig
	 *            The AxisConfiguration object
	 * @param serviceClassName
	 *            the class name string for the target object (could be a
	 *            derived class)
	 * @param serviceName
	 *            the name associated with the service
	 * @return the AxisService object that matches the criteria
	 */
	public static AxisService findService(AxisConfiguration axisConfig,
			String serviceClassName, String serviceName) {
		HashMap services = axisConfig.getServices();

		Iterator its = services.values().iterator();

		while (its.hasNext()) {
			AxisService service = (AxisService) its.next();

			String tmpServClassName = service.getClass().getName();
			String tmpServName = service.getName();

			if ((tmpServClassName.equals(serviceClassName))
					&& (tmpServName.equals(serviceName))) {
				// trace point
				if (log.isTraceEnabled()) {
					log.trace("ObjectStateUtils:findService(): returning  ["
							+ serviceClassName + "]   [" + serviceName + "]");
				}

				return service;
			}
		}

		// trace point
		if (log.isTraceEnabled()) {
			log.trace("ObjectStateUtils:findService(): [" + serviceClassName
					+ "]   [" + serviceName + "]  returning  [null]");
		}

		return null;
	}

	/**
	 * Find the AxisServiceGroup object that matches the criteria <p/> <B>Note<B>
	 * the saved service group meta information may not match up with any of the
	 * serviceGroups that are in the current AxisConfiguration object.
	 * 
	 * @param axisConfig
	 *            The AxisConfiguration object
	 * @param serviceGrpClassName
	 *            the class name string for the target object (could be a
	 *            derived class)
	 * @param serviceGrpName
	 *            the name associated with the service group
	 * @return the AxisServiceGroup object that matches the criteria
	 */
	public static AxisServiceGroup findServiceGroup(
			AxisConfiguration axisConfig, String serviceGrpClassName,
			String serviceGrpName) {
		Iterator its = axisConfig.getServiceGroups();

		while (its.hasNext()) {
			AxisServiceGroup serviceGroup = (AxisServiceGroup) its.next();

			String tmpSGClassName = serviceGroup.getClass().getName();
			String tmpSGName = serviceGroup.getServiceGroupName();

			if (tmpSGClassName.equals(serviceGrpClassName)) {
				boolean found = false;

				// the serviceGroupName can be null, so either both the
				// service group names are null or they match
				if ((tmpSGName == null) && (serviceGrpName == null)) {
					found = true;
				} else if ((tmpSGName != null)
						&& (tmpSGName.equals(serviceGrpName))) {
					found = true;
				}

				if (found) {
					// trace point
					if (log.isTraceEnabled()) {
						log
								.trace("ObjectStateUtils:findServiceGroup(): returning  ["
										+ serviceGrpClassName
										+ "]   ["
										+ serviceGrpName + "]");
					}

					return serviceGroup;
				}
			}
		}

		// trace point
		if (log.isTraceEnabled()) {
			log.trace("ObjectStateUtils:findServiceGroup(): ["
					+ serviceGrpClassName + "]   [" + serviceGrpName
					+ "]  returning  [null]");
		}

		return null;
	}

	/**
	 * Find the AxisMessage object that matches the criteria
	 * 
	 * @param op
	 *            The AxisOperation object
	 * @param msgName
	 *            The name associated with the message
	 * @param msgElementName
	 *            The name associated with the message element
	 * @return the AxisMessage object that matches the given criteria
	 */
	public static AxisMessage findMessage(AxisOperation op, String msgName,
			String msgElementName) {
		// Several kinds of AxisMessages can be associated with a particular
		// AxisOperation. The kinds of AxisMessages that are typically
		// accessible are associated with "in" and "out".
		// There are also different kinds of AxisOperations, and each
		// type of AxisOperation can have its own mix of AxisMessages
		// depending on the style of message exchange pattern (mep)

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

			return null;
		}

		if (msgName == null) {
			// nothing to match with, expect to match against a name
			// trace point
			if (log.isTraceEnabled()) {
				log.trace("ObjectStateUtils:findMessage(): [" + msgName
						+ "]  [" + msgElementName
						+ "] returning  [null] - message name is not set");
			}

			return null;
		}

		String tmpName = null;
		String tmpElementName = null;

		// -------------------------------------
		// first try the "out" message
		// -------------------------------------
		AxisMessage out = null;
		try {
			out = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
		} catch (Exception ex) {
			// just absorb the exception
		}

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

			QName tmpQout = out.getElementQName();
			if (tmpQout != null) {
				tmpElementName = tmpQout.toString();
			}
		}

		// check the criteria for a match

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

		if (matching) {
			// trace point
			if (log.isTraceEnabled()) {
				log

⌨️ 快捷键说明

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