📄 javastubwriter.java
字号:
// TODO: After WSDL4J supports soap12, change this code UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj; QName name = unkElement.getElementType(); if (name.getNamespaceURI().equals( Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("binding")) { pw.println( " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);"); pw.println( " _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);"); } } } } pw.println( " for (int i = 0; i < cachedSerFactories.size(); ++i) {"); pw.println( " java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);"); pw.println( " javax.xml.namespace.QName qName ="); pw.println( " (javax.xml.namespace.QName) cachedSerQNames.get(i);"); pw.println( " java.lang.Object x = cachedSerFactories.get(i);"); pw.println( " if (x instanceof Class) {"); pw.println( " java.lang.Class sf = (java.lang.Class)"); pw.println( " cachedSerFactories.get(i);"); pw.println( " java.lang.Class df = (java.lang.Class)"); pw.println( " cachedDeserFactories.get(i);"); pw.println( " _call.registerTypeMapping(cls, qName, sf, df, false);"); pw.println(" }"); pw.println( " else if (x instanceof javax.xml.rpc.encoding.SerializerFactory) {"); pw.println( " org.apache.axis.encoding.SerializerFactory sf = (org.apache.axis.encoding.SerializerFactory)"); pw.println( " cachedSerFactories.get(i);"); pw.println( " org.apache.axis.encoding.DeserializerFactory df = (org.apache.axis.encoding.DeserializerFactory)"); pw.println( " cachedDeserFactories.get(i);"); pw.println( " _call.registerTypeMapping(cls, qName, sf, df, false);"); pw.println(" }"); pw.println(" }"); pw.println(" }"); pw.println(" }"); } pw.println(" return _call;"); pw.println(" }"); pw.println(" catch (java.lang.Throwable _t) {"); pw.println(" throw new org.apache.axis.AxisFault(\"" + Messages.getMessage("badCall01") + "\", _t);"); pw.println(" }"); pw.println(" }"); pw.println(); List operations = binding.getBindingOperations(); for (int i = 0; i < operations.size(); ++i) { BindingOperation operation = (BindingOperation) operations.get(i); Parameters parameters = bEntry.getParameters(operation.getOperation()); // Get the soapAction from the <soap:operation> String soapAction = ""; String opStyle = null; Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator(); for (; operationExtensibilityIterator.hasNext();) { Object obj = operationExtensibilityIterator.next(); if (obj instanceof SOAPOperation) { soapAction = ((SOAPOperation) obj).getSoapActionURI(); opStyle = ((SOAPOperation) obj).getStyle(); break; } else if (obj instanceof UnknownExtensibilityElement) { // TODO: After WSDL4J supports soap12, change this code UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj; QName name = unkElement.getElementType(); if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("operation")) { if (unkElement.getElement().getAttribute("soapAction") != null) { soapAction = unkElement.getElement().getAttribute( "soapAction"); } opStyle = unkElement.getElement().getAttribute("style"); } } } Operation ptOperation = operation.getOperation(); OperationType type = ptOperation.getStyle(); // These operation types are not supported. The signature // will be a string stating that fact. if ((OperationType.NOTIFICATION.equals(type)) || (OperationType.SOLICIT_RESPONSE.equals(type))) { pw.println(parameters.signature); pw.println(); } else { writeOperation(pw, operation, parameters, soapAction, opStyle, type == OperationType.ONE_WAY, i); } } } // writeFileBody /** * Compute the number of addBindings methods we need to generate for the * set of TypeEntries used by the generated stub. * * @param deferredBindings a <code>List</code> value * @return an <code>int</code> value */ private int calculateBindingMethodCount(List deferredBindings) { int methodCount = deferredBindings.size() / MAXIMUM_BINDINGS_PER_METHOD; if ((deferredBindings.size() % MAXIMUM_BINDINGS_PER_METHOD) != 0) { methodCount++; } return methodCount; } /** * for each of the TypeEntry objects in the deferredBindings list, we need * to write code that will associate a class with a schema namespace/name. * This method writes a number of private methods out that do this in * batches of size MAXIMUM_BINDINGS_PER_METHOD so that generated classes * do not end up with a single method that exceeds the 64K limit that the * VM imposes on all methods. * * @param pw a <code>PrintWriter</code> value * @param deferredBindings a <code>List</code> of TypeEntry objects */ protected void writeBindingMethods(PrintWriter pw, List deferredBindings) { int methodCount = calculateBindingMethodCount(deferredBindings); for (int i = 0; i < methodCount; i++) { pw.println(" private void addBindings" + i + "() {"); // each method gets its own local variables for use in generating // the binding code writeSerializationDecls(pw, false, null); for (int j = 0; j < MAXIMUM_BINDINGS_PER_METHOD; j++) { int absolute = i * MAXIMUM_BINDINGS_PER_METHOD + j; if (absolute == deferredBindings.size()) { break; // last one } writeSerializationInit( pw, (TypeEntry) deferredBindings.get(absolute)); } pw.println(" }"); } } /** * Method writeOperationMap * * @param pw */ protected void writeOperationMap(PrintWriter pw) { List operations = binding.getBindingOperations(); pw.println(" static {"); pw.println( " _operations = new org.apache.axis.description.OperationDesc[" + operations.size() + "];"); for (int j = 0, k = 0; j < operations.size(); ++j) { if ((j % OPERDESC_PER_BLOCK) == 0) { k++; pw.println(" _initOperationDesc" + k + "();"); } } for (int i = 0, k = 0; i < operations.size(); ++i) { if ((i % OPERDESC_PER_BLOCK) == 0) { k++; pw.println(" }\n"); pw.println(" private static void _initOperationDesc" + k + "(){"); pw.println( " org.apache.axis.description.OperationDesc oper;"); pw.println( " org.apache.axis.description.ParameterDesc param;"); } BindingOperation operation = (BindingOperation) operations.get(i); Parameters parameters = bEntry.getParameters(operation.getOperation()); // Get the soapAction from the <soap:operation> String opStyle = null; Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator(); for (; operationExtensibilityIterator.hasNext();) { Object obj = operationExtensibilityIterator.next(); if (obj instanceof SOAPOperation) { opStyle = ((SOAPOperation) obj).getStyle(); break; } else if (obj instanceof UnknownExtensibilityElement) { // TODO: After WSDL4J supports soap12, change this code UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj; QName name = unkElement.getElementType(); if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && name.getLocalPart().equals("operation")) { opStyle = unkElement.getElement().getAttribute("style"); } } } Operation ptOperation = operation.getOperation(); OperationType type = ptOperation.getStyle(); // These operation types are not supported. The signature // will be a string stating that fact. if ((OperationType.NOTIFICATION.equals(type)) || (OperationType.SOLICIT_RESPONSE.equals(type))) { pw.println(parameters.signature); pw.println(); } String operName = operation.getName(); String indent = " "; pw.println( indent + "oper = new org.apache.axis.description.OperationDesc();"); pw.println(indent + "oper.setName(\"" + operName + "\");"); // loop over paramters and set up in/out params for (int j = 0; j < parameters.list.size(); ++j) { Parameter p = (Parameter) parameters.list.get(j); // Get the QName representing the parameter type QName paramType = Utils.getXSIType(p); // Set the javaType to the name of the type String javaType = Utils.getParameterTypeName(p); if (javaType != null) { javaType += ".class, "; } else { javaType = "null, "; } // Get the text representing newing a QName for the name and type String paramNameText = Utils.getNewQNameWithLastLocalPart(p.getQName()); String paramTypeText = Utils.getNewQName(paramType); // Generate the addParameter call with the // name qname, typeQName, optional javaType, and mode boolean isInHeader = p.isInHeader(); boolean isOutHeader = p.isOutHeader(); pw.println(" param = new org.apache.axis.description.ParameterDesc(" + paramNameText + ", " + modeStrings[p.getMode()] + ", " + paramTypeText + ", " + javaType + isInHeader + ", " + isOutHeader + ");"); QName itemQName = Utils.getItemQName(p.getType()); if (itemQName != null) { pw.println(" param.setItemQName(" + Utils.getNewQName(itemQName) + ");"); } if (p.isOmittable()) pw.println(" param.setOmittable(true);"); if (p.isNillable()) pw.println(" param.setNillable(true);"); pw.println(" oper.addParameter(param);"); } // set output type Parameter returnParam = parameters.returnParam; if (returnParam != null) { // Get the QName for the return Type QName returnType = Utils.getXSIType(returnParam); // Get the javaType String javaType = Utils.getParameterTypeName(returnParam); if (javaType == null) { javaType = ""; } else { javaType += ".class"; } pw.println(" oper.setReturnType(" + Utils.getNewQName(returnType) + ");"); pw.println(" oper.setReturnClass(" + javaType + ");"); QName returnQName = returnParam.getQName(); if (returnQName != null) { pw.println(" oper.setReturnQName(" + Utils.getNewQNameWithLastLocalPart(returnQName) + ");"); } if (returnParam.isOutHeader()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -