wsdl2codemojo.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 732 行 · 第 1/2 页
JAVA
732 行
getStringArray(packageName)));
//stub language
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.STUB_LANGUAGE_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.STUB_LANGUAGE_OPTION,
getStringArray(language)));
//server side and generate services.xml options
if (generateServerSide) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_CODE_OPTION,
new String[0]));
//services XML generation - effective only when specified as the server side
if (generateServicesXml) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants
.GENERATE_SERVICE_DESCRIPTION_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants
.GENERATE_SERVICE_DESCRIPTION_OPTION,
new String[0]));
}
//generate all option - Only valid when generating serverside code
if (generateAllClasses) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_ALL_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_ALL_OPTION,
new String[0]));
}
}
//generate the test case
if (generateTestcase) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_TEST_CASE_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.GENERATE_TEST_CASE_OPTION,
new String[0]));
}
//Unwrap classes option - this determines whether the generated classes are inside the stub/MR
//or gets generates as seperate classes
if (unpackClasses) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.UNPACK_CLASSES_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.UNPACK_CLASSES_OPTION,
new String[0]));
}
//server side interface option
if (generateServerSideInterface) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVER_SIDE_INTERFACE_OPTION,
new String[0]));
}
if (unwrap) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.UNWRAP_PARAMETERS,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.UNWRAP_PARAMETERS,
new String[0]));
}
if (allPorts) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.All_PORTS_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.All_PORTS_OPTION,
new String[0]));
}
if (backwardCompatible) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.BACKWORD_COMPATIBILITY_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.BACKWORD_COMPATIBILITY_OPTION,
new String[0]));
}
if (flattenFiles) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.FLATTEN_FILES_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.FLATTEN_FILES_OPTION,
new String[0]));
}
if (skipMessageReceiver) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.NO_MESSAGE_RECEIVER_OPTION_LONG,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.NO_MESSAGE_RECEIVER_OPTION_LONG,
new String[0]));
}
if (skipBuildXML) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.NO_BUILD_XML_OPTION_LONG,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.NO_BUILD_XML_OPTION_LONG,
new String[0]));
}
if (skipWSDL) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.NO_WSDLS_OPTION_LONG,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.NO_WSDLS_OPTION_LONG,
new String[0]));
}
if (overWrite) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.OVERRIDE_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.OVERRIDE_OPTION,
new String[0]));
}
if (suppressPrefixes) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SUPPRESS_PREFIXES_OPTION,
new String[0]));
}
if (repositoryPath != null) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.REPOSITORY_PATH_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.REPOSITORY_PATH_OPTION,
new String[]{repositoryPath}));
}
if (externalMapping != null) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.EXTERNAL_MAPPING_OPTION,
new String[]{externalMapping}));
}
if (wsdlVersion != null) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.WSDL_VERSION_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.WSDL_VERSION_OPTION,
new String[]{wsdlVersion}));
}
if (targetSourceFolderLocation != null) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SOURCE_FOLDER_NAME_OPTION,
new String[]{targetSourceFolderLocation}));
}
if (targetResourcesFolderLocation != null) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.RESOURCE_FOLDER_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.RESOURCE_FOLDER_OPTION,
new String[]{targetResourcesFolderLocation}));
}
Iterator iterator = options.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
String key = CommandLineOptionConstants.WSDL2JavaConstants.EXTRA_OPTIONTYPE_PREFIX + entry.getKey();
String value = (String) entry.getValue();
optionMap.put(
key,
new CommandLineOption(
key,
new String[]{value}));
}
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.SERVICE_NAME_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.SERVICE_NAME_OPTION,
new String[] { serviceName }));
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.PORT_NAME_OPTION,
new String[] { portName }));
// set the namespaces
if (!((namespaceToPackages == null) && (namespaceURIs == null))) {
optionMap.put(
CommandLineOptionConstants.WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION,
new CommandLineOption(
CommandLineOptionConstants.WSDL2JavaConstants.NAME_SPACE_TO_PACKAGE_OPTION,
new String[] { getNamespaceToPackagesMap() }));
}
return optionMap;
}
private String getNamespaceToPackagesMap() throws MojoFailureException {
StringBuffer sb = new StringBuffer();
if (namespaceToPackages != null) {
sb.append(namespaceToPackages);
}
if (namespaceURIs != null) {
for (int i = 0; i < namespaceURIs.length; i++) {
NamespaceURIMapping mapping = namespaceURIs[i];
String uri = mapping.getUri();
if (uri == null) {
throw new MojoFailureException(
"A namespace to package mapping requires an uri child element.");
}
String uriPackageName = mapping.getPackageName();
if (uriPackageName == null) {
throw new MojoFailureException(
"A namespace to package mapping requires a packageName child element.");
}
if (sb.length() > 0) {
sb.append(",");
}
sb.append(uri);
sb.append('=');
sb.append(uriPackageName);
}
}
return (sb.length() != 0) ? sb.toString() : null;
}
/**
* Utility method to convert a string into a single item string[]
*
* @param value
* @return Returns String[].
*/
private String[] getStringArray(String value) {
String[] values = new String[1];
values[0] = value;
return values;
}
public void execute() throws MojoFailureException, MojoExecutionException {
fixCompileSourceRoots();
fixDependencies();
showDependencies();
Map commandLineOptions = this.fillOptionMap();
CommandLineOptionParser parser =
new CommandLineOptionParser(commandLineOptions);
try {
new CodeGenerationEngine(parser).generate();
} catch (CodeGenerationException e) {
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
t.printStackTrace();
throw new MojoExecutionException(e.getMessage(), e);
}
}
private void showDependencies() {
Log log = getLog();
if (!log.isDebugEnabled()) {
return;
}
log.debug("The projects dependency artifacts are: ");
for (Iterator iter = project.getDependencyArtifacts().iterator(); iter.hasNext();) {
Artifact artifact = (Artifact)iter.next();
log.debug(" " + artifact.getGroupId() + ":" + artifact.getArtifactId() +
":" + artifact.getVersion() + ":" + artifact.getClassifier() +
":" + artifact.getScope() + ":" + artifact.getType());
}
log.debug("The projects transitive artifacts are: ");
for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
Artifact artifact = (Artifact)iter.next();
log.debug(" " + artifact.getGroupId() + ":" + artifact.getArtifactId() +
":" + artifact.getVersion() + ":" + artifact.getClassifier() +
":" + artifact.getScope() + ":" + artifact.getType());
}
}
private Artifact findArtifact(Collection pCollection, String pGroupId, String pArtifactId) {
for (Iterator iter = pCollection.iterator(); iter.hasNext();) {
Artifact artifact = (Artifact)iter.next();
if (pGroupId.equals(artifact.getGroupId()) &&
pArtifactId.equals(artifact.getArtifactId())) {
return artifact;
}
}
return null;
}
private InheritedArtifact[] getInheritedArtifacts() {
final List list = new ArrayList();
list.addAll(Arrays.asList(inheritedArtifacts));
if ("adb".equals(databindingName)) {
list.addAll(Arrays.asList(adbArtifacts));
} else if ("xmlbeans".equals(databindingName)) {
list.addAll(Arrays.asList(xbeanArtifacts));
}
return (InheritedArtifact[])list.toArray(new InheritedArtifact[ list.size() ]);
}
private InheritedArtifact getInheritedArtifact(InheritedArtifact[] pInheritedArtifacts,
Artifact pArtifact) {
for (int i = 0; i < pInheritedArtifacts.length; i++) {
InheritedArtifact iArtifact = pInheritedArtifacts[i];
if (iArtifact.getGroupId().equals(pArtifact.getGroupId()) &&
iArtifact.getArtifactId().equals(pArtifact.getArtifactId())) {
return iArtifact;
}
}
return null;
}
private void fixDependencies() {
final Set set = new HashSet(project.getDependencyArtifacts());
final InheritedArtifact[] inhArtifacts = getInheritedArtifacts();
for (Iterator iter = pluginArtifacts.iterator(); iter.hasNext();) {
final Artifact artifact = (Artifact)iter.next();
final InheritedArtifact iArtifact = getInheritedArtifact(inhArtifacts, artifact);
if (iArtifact != null) {
iArtifact.setAdded();
final String groupId = artifact.getGroupId();
final String artifactId = artifact.getArtifactId();
if (findArtifact(project.getArtifacts(), groupId, artifactId)
== null) {
getLog().debug("Adding artifact " + groupId + ":" + artifactId);
Artifact artfct =
artifactFactory.createArtifactWithClassifier(groupId, artifactId,
artifact.getVersion(),
artifact.getType(),
artifact.getClassifier());
artfct.setScope(Artifact.SCOPE_COMPILE);
set.add(artfct);
} else {
getLog().debug("The artifact " + artifact.getGroupId() + ":" +
artifact.getArtifactId() + " is already present " +
" in the project and will not be added.");
}
}
}
project.setDependencyArtifacts(set);
}
private void fixCompileSourceRoots() {
File srcDir = new File(outputDirectory, "src");
project.addCompileSourceRoot(srcDir.getPath());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?