📄 javageneratorfactory.java
字号:
} // if (!processed) Vector elements = tEntry.getContainedElements(); if (elements != null) { for (int i = 0; i < elements.size(); i++) { ElementDecl elem = (ElementDecl) elements.get(i); String varName = emitter.getJavaVariableName(typeQName, elem.getQName(), true); elem.setName(varName); } } Vector attributes = tEntry.getContainedAttributes(); if (attributes != null) { for (int i = 0; i < attributes.size(); i++) { ContainedAttribute attr = (ContainedAttribute) attributes.get(i); String varName = emitter.getJavaVariableName(typeQName, attr.getQName(), false); attr.setName(varName); } } } // Set the entry with the same name as the ref'd entry // but add the appropriate amount of dimensions entry.setName(tEntry.getName() + dims); return uniqueNum; } /** * Gets class name from Java class. * If the class is an array, get its component type's name * @param clazz a java class * @return the class name in string */ private static String getJavaClassName(Class clazz) { Class class1 = clazz; while (class1.isArray()) { class1 = class1.getComponentType(); } String name = class1.getName(); name.replace('$', '.'); return name; } /** * setFaultContext: * Processes the symbol table and sets the COMPLEX_TYPE_FAULT * on each TypeEntry that is a complexType and is referenced in * a fault message. TypeEntries that are the base or derived * from such a TypeEntry are also marked with COMPLEX_TYPE_FAULT. * The containing MessageEntry is marked with cOMPLEX_TYPE_FAULT, and * all MessageEntries for faults are tagged with the * EXCEPTION_CLASS_NAME variable, which indicates the java exception * class name. * * @param symbolTable SymbolTable */ private void setFaultContext(SymbolTable symbolTable) { Iterator it = symbolTable.getHashMap().values().iterator(); while (it.hasNext()) { Vector v = (Vector) it.next(); for (int i = 0; i < v.size(); ++i) { SymTabEntry entry = (SymTabEntry) v.elementAt(i); // Inspect each BindingEntry in the Symbol Table if (entry instanceof BindingEntry) { BindingEntry bEntry = (BindingEntry) entry; HashMap allOpFaults = bEntry.getFaults(); Iterator ops = allOpFaults.values().iterator(); // set the context for all faults for this binding. while (ops.hasNext()) { ArrayList faults = (ArrayList) ops.next(); for (int j = 0; j < faults.size(); ++j) { FaultInfo info = (FaultInfo) faults.get(j); setFaultContext(info, symbolTable); } } } } } } // setFaultContext /** * setFaultContext: * Helper routine for the setFaultContext method above. * Examines the indicated fault and sets COMPLEX_TYPE_FAULT * EXCEPTION_DATA_TYPE and EXCEPTION_CLASS_NAME as appropriate. * * @param fault FaultInfo to analyze * @param symbolTable SymbolTable */ private void setFaultContext(FaultInfo fault, SymbolTable symbolTable) { QName faultXmlType = null; Vector parts = new Vector(); // Get the parts of the fault's message. // An IOException is thrown if the parts cannot be // processed. Skip such parts for this analysis try { symbolTable.getParametersFromParts( parts, fault.getMessage().getOrderedParts(null), false, fault.getName(), null); } catch (IOException e) { } // Inspect each TypeEntry referenced in a Fault Message Part String exceptionClassName = null; for (int j = 0; j < parts.size(); j++) { TypeEntry te = ((Parameter) (parts.elementAt(j))).getType(); // If the TypeEntry is an element, advance to the type. // This occurs if the message part uses the element= attribute TypeEntry elementTE = null; if (te instanceof Element) { elementTE = te; te = te.getRefType(); } // remember the QName of the type. faultXmlType = te.getQName(); // Determine if the te should be processed using the // simple type mapping or the complex type mapping // NOTE: treat array types as simple types if ((te.getBaseType() != null) || te.isSimpleType() || ((te.getDimensions().length() > 0) && (te.getRefType().getBaseType() != null))) { // Simple Type Exception } else { // Complex Type Exception Boolean isComplexFault = (Boolean) te.getDynamicVar( JavaGeneratorFactory.COMPLEX_TYPE_FAULT); if ((isComplexFault == null) || !isComplexFault.booleanValue()) { // Mark the type as a complex type fault te.setDynamicVar(JavaGeneratorFactory.COMPLEX_TYPE_FAULT, Boolean.TRUE); if (elementTE != null) { te.setDynamicVar( JavaGeneratorFactory.COMPLEX_TYPE_FAULT, Boolean.TRUE); } // Mark all derived types as Complex Faults HashSet derivedSet = org.apache.axis.wsdl.symbolTable.Utils.getDerivedTypes( te, symbolTable); Iterator derivedI = derivedSet.iterator(); while (derivedI.hasNext()) { TypeEntry derivedTE = (TypeEntry) derivedI.next(); derivedTE.setDynamicVar( JavaGeneratorFactory.COMPLEX_TYPE_FAULT, Boolean.TRUE); } // Mark all base types as Complex Faults TypeEntry base = SchemaUtils.getComplexElementExtensionBase(te.getNode(), symbolTable); while (base != null) { base.setDynamicVar( JavaGeneratorFactory.COMPLEX_TYPE_FAULT, Boolean.TRUE); base = SchemaUtils.getComplexElementExtensionBase( base.getNode(), symbolTable); } } // The exception class name is the name of the type exceptionClassName = te.getName(); } } String excName = getExceptionJavaNameHook(fault.getMessage().getQName()); // for derived class if (excName != null) { exceptionClassName = excName; } // Set the name of the exception and // whether the exception is a complex type MessageEntry me = symbolTable.getMessageEntry(fault.getMessage().getQName()); if (me != null) { me.setDynamicVar(JavaGeneratorFactory.EXCEPTION_DATA_TYPE, faultXmlType); if (exceptionClassName != null) { me.setDynamicVar(JavaGeneratorFactory.COMPLEX_TYPE_FAULT, Boolean.TRUE); me.setDynamicVar(JavaGeneratorFactory.EXCEPTION_CLASS_NAME, exceptionClassName); } else { me.setDynamicVar(JavaGeneratorFactory.EXCEPTION_CLASS_NAME, emitter.getJavaName(me.getQName())); } } } protected String getExceptionJavaNameHook(QName qname) { return null; } /** * Method determineInterfaceNames * * @param symbolTable */ protected void determineInterfaceNames(SymbolTable symbolTable) { Iterator it = symbolTable.getHashMap().values().iterator(); while (it.hasNext()) { Vector v = (Vector) it.next(); for (int i = 0; i < v.size(); ++i) { SymTabEntry entry = (SymTabEntry) v.elementAt(i); if (entry instanceof BindingEntry) { // The SEI (Service Endpoint Interface) name // is always the portType name. BindingEntry bEntry = (BindingEntry) entry; PortTypeEntry ptEntry = symbolTable.getPortTypeEntry( bEntry.getBinding().getPortType().getQName()); String seiName = getServiceEndpointInterfaceJavaNameHook(ptEntry, bEntry); if (seiName == null) { seiName = ptEntry.getName(); } bEntry.setDynamicVar(JavaBindingWriter.INTERFACE_NAME, seiName); } else if (entry instanceof ServiceEntry) { ServiceEntry sEntry = (ServiceEntry) entry; String siName = getServiceInterfaceJavaNameHook(sEntry); // for derived class if (siName != null) { sEntry.setName(siName); } Service service = sEntry.getService(); Map portMap = service.getPorts(); Iterator portIterator = portMap.values().iterator(); while (portIterator.hasNext()) { Port p = (Port) portIterator.next(); Binding binding = p.getBinding(); BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName()); // If this isn't a SOAP binding, skip it if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) { continue; } String portName = getPortJavaNameHook(p.getName()); // for derived class if (portName != null) { bEntry.setDynamicVar(JavaServiceWriter.PORT_NAME + ":" + p.getName(), portName); } } } } } } // determineInterfaceNames protected String getServiceEndpointInterfaceJavaNameHook(PortTypeEntry ptEntry, BindingEntry bEntry) { return null; } protected String getServiceInterfaceJavaNameHook(ServiceEntry sEntry) { return null; } protected String getPortJavaNameHook(String portName) { return null; } /** * Messages, PortTypes, Bindings, and Services can share the same name. If they do in this * Definition, force their names to be suffixed with _PortType and _Service, respectively. * * @param symbolTable */ protected void resolveNameClashes(SymbolTable symbolTable) { // Keep a list of anonymous types so we don't try to resolve them twice. HashSet anonTypes = new HashSet(); List collisionCandidates = new ArrayList(); // List of vector of SymbolTable entry List localParts = new ArrayList(); // all localparts in all symboltable entries for (Iterator i = symbolTable.getHashMap().keySet().iterator(); i.hasNext(); ) { QName qName = (QName)i.next(); String localPart = qName.getLocalPart(); if (!localParts.contains(localPart)) localParts.add(localPart); } Map pkg2NamespacesMap = emitter.getNamespaces().getPkg2NamespacesMap(); for (Iterator i = pkg2NamespacesMap.values().iterator(); i.hasNext(); ) { Vector namespaces = (Vector)i.next(); // namepaces mapped to same package // Combine entry vectors, which have the same entry name, into a new entry vector. for (int j = 0; j < localParts.size(); j++) { Vector v = new Vector(); for (int k = 0; k < namespaces.size(); k++) { QName qName = new QName((String)namespaces.get(k), (String)localParts.get(j)); if (symbolTable.getHashMap().get(qName) != null) { v.addAll((Vector)symbolTable.getHashMap().get(qName)); } } if(v.size()>0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -