artifactprocessor.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 396 行 · 第 1/2 页
JAVA
396 行
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.axis2.jaxws.runtime.description.marshal.impl;
import org.apache.axis2.java.security.AccessController;
import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.description.EndpointDescription;
import org.apache.axis2.jaxws.description.FaultDescription;
import org.apache.axis2.jaxws.description.OperationDescription;
import org.apache.axis2.jaxws.description.ServiceDescription;
import org.apache.axis2.jaxws.runtime.description.marshal.AnnotationDesc;
import org.apache.axis2.jaxws.runtime.description.marshal.FaultBeanDesc;
import org.apache.axis2.jaxws.utility.ClassUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
/**
* Examines a ServiceDesc and locates and/or builds the JAX-WS artifacts. The JAX-WS artifacts are:
* - request wrapper classes - response wrapper classes - fault beans for non-JAX-WS compliant
* exceptions
*/
class ArtifactProcessor {
private static final Log log = LogFactory.getLog(ArtifactProcessor.class);
private ServiceDescription serviceDesc;
private Map<OperationDescription, String> requestWrapperMap =
new HashMap<OperationDescription, String>();
private Map<OperationDescription, String> responseWrapperMap =
new HashMap<OperationDescription, String>();
private Map<FaultDescription, FaultBeanDesc> faultBeanDescMap =
new HashMap<FaultDescription, FaultBeanDesc>();
/**
* Artifact Processor
*
* @param serviceDesc
*/
ArtifactProcessor(ServiceDescription serviceDesc) {
this.serviceDesc = serviceDesc;
}
Map<OperationDescription, String> getRequestWrapperMap() {
return requestWrapperMap;
}
Map<OperationDescription, String> getResponseWrapperMap() {
return responseWrapperMap;
}
Map<FaultDescription, FaultBeanDesc> getFaultBeanDescMap() {
return faultBeanDescMap;
}
void build() {
for (EndpointDescription ed : serviceDesc.getEndpointDescriptions()) {
if (ed.getEndpointInterfaceDescription() != null) {
for (OperationDescription opDesc : ed.getEndpointInterfaceDescription()
.getOperations()) {
String declaringClassName = opDesc.getJavaDeclaringClassName();
String packageName = getPackageName(declaringClassName);
String simpleName = getSimpleClassName(declaringClassName);
String methodName = opDesc.getJavaMethodName();
// There is no default for @RequestWrapper/@ResponseWrapper classname None is listed in Sec. 7.3 on p. 80 of
// the JAX-WS spec, BUT Conformance(Using javax.xml.ws.RequestWrapper) in Sec 2.3.1.2 on p. 13
// says the entire annotation "...MAY be omitted if all its properties would have default vaules."
// We will assume that this statement gives us the liberty to find a wrapper class/build a wrapper class or
// implement an engine w/o the wrapper class.
// @RequestWrapper className processing
String requestWrapperName = opDesc.getRequestWrapperClassName();
if (requestWrapperName == null) {
if (packageName.length() > 0) {
requestWrapperName =
packageName + "." + javaMethodToClassName(methodName);
} else {
requestWrapperName = javaMethodToClassName(methodName);
}
}
String foundRequestWrapperName = findArtifact(requestWrapperName);
if (foundRequestWrapperName == null) {
foundRequestWrapperName = missingArtifact(requestWrapperName);
}
if (foundRequestWrapperName != null) {
requestWrapperMap.put(opDesc, foundRequestWrapperName);
}
// @ResponseWrapper className processing
String responseWrapperName = opDesc.getResponseWrapperClassName();
if (responseWrapperName == null) {
if (packageName.length() > 0) {
responseWrapperName = packageName + "." +
javaMethodToClassName(methodName) + "Response";
} else {
responseWrapperName = javaMethodToClassName(methodName) + "Response";
}
}
String foundResponseWrapperName = findArtifact(responseWrapperName);
if (foundResponseWrapperName == null) {
foundResponseWrapperName = missingArtifact(responseWrapperName);
}
if (foundResponseWrapperName != null) {
responseWrapperMap.put(opDesc, foundResponseWrapperName);
}
for (FaultDescription faultDesc : opDesc.getFaultDescriptions()) {
FaultBeanDesc faultBeanDesc = create(faultDesc, opDesc);
faultBeanDescMap.put(faultDesc, faultBeanDesc);
}
}
}
}
}
private FaultBeanDesc create(FaultDescription faultDesc, OperationDescription opDesc) {
/* FaultBeanClass algorithm
* 1) The class defined on @WebFault of the exception
* 2) If not present or invalid, the class defined by getFaultInfo.
* 3) If not present, the class is found by looking for the
* a class named <exceptionName>Bean in the interface's package.
* 4) If not present, the class is found by looking for the
* a class named <exceptionName>Bean in the interface + jaxws package
*/
String faultBeanClassName = faultDesc.getFaultBean();
if (faultBeanClassName == null || faultBeanClassName.length() == 0) {
faultBeanClassName = faultDesc.getFaultInfo();
}
if (faultBeanClassName == null || faultBeanClassName.length() == 0) {
String declaringClassName = opDesc.getJavaDeclaringClassName();
String packageName = getPackageName(declaringClassName);
String simpleName = getSimpleClassName(faultDesc.getExceptionClassName());
if (packageName.length() > 0) {
faultBeanClassName = packageName + "." + simpleName + "Bean";
} else {
faultBeanClassName = simpleName + "Bean";
}
}
String foundClassName = findArtifact(faultBeanClassName);
if (foundClassName == null) {
faultBeanClassName = missingArtifact(faultBeanClassName);
}
if (foundClassName != null) {
faultBeanClassName = foundClassName;
}
/* Local NameAlgorithm:
* 1) The name defined on the @WebFault of the exception.
* 2) If not present, the name defined via the @XmlRootElement of the fault bean class.
* 3) If not present, the <exceptionName>Bean
*/
String faultBeanLocalName = faultDesc.getName();
if (faultBeanLocalName == null || faultBeanLocalName.length() == 0) {
if (faultBeanClassName != null && faultBeanClassName.length() > 0) {
try {
Class faultBean = loadClass(faultBeanClassName);
AnnotationDesc aDesc = AnnotationDescImpl.create(faultBean);
if (aDesc.hasXmlRootElement()) {
faultBeanLocalName = aDesc.getXmlRootElementName();
}
} catch (Throwable t) {
ExceptionFactory.makeWebServiceException(t);
}
}
}
if (faultBeanLocalName == null || faultBeanLocalName.length() == 0) {
faultBeanLocalName = getSimpleClassName(faultDesc.getExceptionClassName()) + "Bean";
}
/* Algorithm for fault bean namespace
* 1) The namespace defined on the @WebFault of the exception.
* 2) If not present, the namespace defined via the @XmlRootElement of the class name.
* 3) If not present, the namespace of the method's declared class + "/jaxws"
*/
String faultBeanNamespace = faultDesc.getTargetNamespace();
if (faultBeanNamespace == null || faultBeanNamespace.length() == 0) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?