axisservicebasedmultilanguageemitter.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,546 行 · 第 1/5 页
JAVA
1,546 行
Document classModel = createDOMDocumentForTestCase();
debugLogDocument("Document for test case:", classModel);
TestClassWriter callbackWriter =
new TestClassWriter(
codeGenConfiguration.isFlattenFiles() ?
getOutputDirectory(codeGenConfiguration.getOutputLocation(),
null) :
getOutputDirectory(codeGenConfiguration.getOutputLocation(),
TEST_SRC_DIR_NAME),
codeGenConfiguration.getOutputLanguage());
callbackWriter.setOverride(codeGenConfiguration.isOverride());
writeFile(classModel, callbackWriter);
}
}
/**
* Creates the XML Model for the test case
*
* @return DOM document
*/
protected Document createDOMDocumentForTestCase() {
String coreClassName = makeJavaClassName(axisService.getName());
Document doc = getEmptyDocument();
Element rootElement = doc.createElement("class");
addAttribute(doc, "package", codeGenConfiguration.getPackageName(), rootElement);
if (this.axisService.getEndpoints().size() > 1) {
addAttribute(doc, "name",
makeJavaClassName(axisService.getName() + axisService.getEndpointName())
+ TEST_SUFFIX, rootElement);
} else {
addAttribute(doc, "name", makeJavaClassName(axisService.getName())
+ TEST_SUFFIX, rootElement);
}
//todo is this right ???
addAttribute(doc, "namespace", axisService.getTargetNamespace(), rootElement);
addAttribute(doc, "interfaceName", coreClassName, rootElement);
if (codeGenConfiguration.isPackClasses()) {
if (this.axisService.getEndpoints().size() > 1) {
addAttribute(doc, "callbackname", makeJavaClassName(
axisService.getName() + axisService.getEndpointName())
+ CALL_BACK_HANDLER_SUFFIX, rootElement);
} else {
addAttribute(doc, "callbackname", makeJavaClassName(axisService.getName())
+ CALL_BACK_HANDLER_SUFFIX, rootElement);
}
} else {
addAttribute(doc, "callbackname", coreClassName + CALL_BACK_HANDLER_SUFFIX,
rootElement);
}
if (this.codeGenConfiguration.isBackwordCompatibilityMode()) {
addAttribute(doc, "stubname",
makeJavaClassName(axisService.getBindingName()) + STUB_SUFFIX,
rootElement);
} else {
if (this.axisService.getEndpoints().size() > 1) {
addAttribute(doc, "stubname", makeJavaClassName(
axisService.getName() + axisService.getEndpointName())
+ STUB_SUFFIX, rootElement);
} else {
addAttribute(doc, "stubname", makeJavaClassName(axisService.getName())
+ STUB_SUFFIX, rootElement);
}
}
//add backwordcompatibility attribute
addAttribute(doc, "isbackcompatible",
String.valueOf(codeGenConfiguration.isBackwordCompatibilityMode()),
rootElement);
fillSyncAttributes(doc, rootElement);
loadOperations(doc, rootElement, null);
// add the databind supporters. Now the databind supporters are completly contained inside
// the stubs implementation and not visible outside
rootElement.appendChild(createDOMElementforDatabinders(doc, false));
doc.appendChild(rootElement);
//////////////////////////////////////////////////////////
// System.out.println(DOM2Writer.nodeToString(rootElement));
////////////////////////////////////////////////////////////
return doc;
}
/**
* Writes the implementations.
*
* @throws Exception
*/
protected void writeInterfaceImplementation() throws Exception {
// first check for the policies in this service and write them
Document interfaceImplModel = createDOMDocumentForInterfaceImplementation();
debugLogDocument("Document for interface implementation:", interfaceImplModel);
InterfaceImplementationWriter writer =
new InterfaceImplementationWriter(
codeGenConfiguration.isFlattenFiles() ?
getOutputDirectory(codeGenConfiguration.getOutputLocation(), null) :
getOutputDirectory(codeGenConfiguration.getOutputLocation(),
codeGenConfiguration.getSourceLocation()),
codeGenConfiguration.getOutputLanguage());
writer.setOverride(codeGenConfiguration.isOverride());
writeFile(interfaceImplModel, writer);
}
/**
* Creates the DOM tree for implementations.
*/
protected Document createDOMDocumentForInterfaceImplementation() throws Exception {
String packageName = codeGenConfiguration.getPackageName();
String localPart = makeJavaClassName(axisService.getName());
String stubName = makeJavaClassName(axisService.getName() + axisService.getEndpointName()) +
STUB_SUFFIX;
Document doc = getEmptyDocument();
Element rootElement = doc.createElement("class");
addAttribute(doc, "package", packageName, rootElement);
addAttribute(doc, "servicename", localPart, rootElement);
//The target nemespace is added as the namespace for this service
addAttribute(doc, "namespace", axisService.getTargetNamespace(), rootElement);
if (this.codeGenConfiguration.isBackwordCompatibilityMode()) {
addAttribute(doc, "interfaceName",
makeJavaClassName(axisService.getEndpointName()) +
STUB_INTERFACE_SUFFIX_BACK,
rootElement);
addAttribute(doc, "name", makeJavaClassName(axisService.getBindingName()) + STUB_SUFFIX,
rootElement);
} else {
if (this.axisService.getEndpoints().size() > 1) {
addAttribute(doc, "interfaceName",
makeJavaClassName(
axisService.getName() + axisService.getEndpointName()),
rootElement);
addAttribute(doc, "name", stubName, rootElement);
} else {
addAttribute(doc, "interfaceName",
makeJavaClassName(axisService.getName()),
rootElement);
addAttribute(doc, "name", makeJavaClassName(axisService.getName()) + STUB_SUFFIX,
rootElement);
}
}
if (codeGenConfiguration.isPackClasses()) {
if (this.axisService.getEndpoints().size() > 1) {
addAttribute(doc, "callbackname",
makeJavaClassName(
axisService.getName() + axisService.getEndpointName()) +
CALL_BACK_HANDLER_SUFFIX, rootElement);
} else {
addAttribute(doc, "callbackname",
makeJavaClassName(axisService.getName()) +
CALL_BACK_HANDLER_SUFFIX, rootElement);
}
} else {
addAttribute(doc, "callbackname", localPart + CALL_BACK_HANDLER_SUFFIX, rootElement);
}
//add backwordcompatibility attribute
addAttribute(doc, "isbackcompatible",
String.valueOf(codeGenConfiguration.isBackwordCompatibilityMode()),
rootElement);
// add the wrap classes flag
if (codeGenConfiguration.isPackClasses()) {
addAttribute(doc, "wrapped", "yes", rootElement);
}
// add SOAP version
addSoapVersion(doc, rootElement);
// add the end point
addEndpoint(doc, rootElement);
// set the sync/async attributes
fillSyncAttributes(doc, rootElement);
// ###########################################################################################
// this block of code specifically applies to the integration of databinding code into the
// generated classes tightly (probably as inner classes)
// ###########################################################################################
// check for the special models in the mapper and if they are present process them
if (mapper.isObjectMappingPresent()) {
// add an attribute to the root element showing that the writing has been skipped
addAttribute(doc, "skip-write", "yes", rootElement);
// process the mapper objects
processModelObjects(mapper.getAllMappedObjects(), rootElement, doc);
}
// #############################################################################################
// load the operations
loadOperations(doc, rootElement, null);
// add the databind supporters. Now the databind supporters are completly contained inside
// the stubs implementation and not visible outside
rootElement.appendChild(createDOMElementforDatabinders(doc, false));
Object moduleCodegenPolicyExtensionElement;
//if some extension has added the stub methods property, add them to the
//main document
if ((moduleCodegenPolicyExtensionElement =
codeGenConfiguration.getProperty("module-codegen-policy-extensions")) != null) {
rootElement.appendChild(
doc.importNode((Element) moduleCodegenPolicyExtensionElement, true));
}
//add another element to have the unique list of faults
rootElement.appendChild(getUniqueListofFaults(doc));
doc.appendChild(rootElement);
//////////////////////////////////////////////////////////
// System.out.println(DOM2Writer.nodeToString(rootElement));
////////////////////////////////////////////////////////////
return doc;
}
/**
* A util method that returns a unique list of faults
*
* @param doc
* @return DOM element
*/
protected Element getUniqueListofFaults(Document doc) {
Element rootElement = doc.createElement("fault-list");
Element faultElement;
String key;
Iterator iterator = fullyQualifiedFaultClassNameMap.keySet().iterator();
while (iterator.hasNext()) {
faultElement = doc.createElement("fault");
key = (String) iterator.next();
//as for the name of a fault, we generate an exception
addAttribute(doc, "name",
(String) fullyQualifiedFaultClassNameMap.get(key),
faultElement);
addAttribute(doc, "shortName",
(String) faultClassNameMap.get(key),
faultElement);
//the type represents the type that will be wrapped by this
//name
String typeMapping =
this.mapper.getTypeMappingName((QName) faultElementQNameMap.get(key));
addAttribute(doc, "type", (typeMapping == null)
? ""
: typeMapping, faultElement);
String attribValue = (String) instantiatableMessageClassNames.
get(key);
addAttribute(doc, "instantiatableType",
attribValue == null ? "" : attribValue,
faultElement);
// add an extra attribute to say whether the type mapping is
// the default
if (mapper.getDefaultMappingName().equals(typeMapping)) {
addAttribute(doc, "default", "yes", faultElement);
}
addAttribute(doc, "value", getParamInitializer(typeMapping),
faultElement);
rootElement.appendChild(faultElement);
}
return rootElement;
}
/**
* add the qNames of the operation fault message names to faultMessages Mep
*
* @param operationFaultMessages
* @param faultMessagesToMep
*/
private void addFaultMessages(List operationFaultMessages, Set faultMessagesToMep) {
AxisMessage faultMessage;
for (Iterator iter = operationFaultMessages.iterator(); iter.hasNext();) {
faultMessage = (AxisMessage) iter.next();
faultMessagesToMep.add(faultMessage.getName());
}
}
/**
* A util method that returns a unique list of faults for a given mep
*
* @param doc
* @return DOM element
*/
protected Element getUniqueListofFaultsofMep(Document doc, String mep) {
// list to keep fault message qnames for this mep
Set faultListForMep = new HashSet();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?