Java Code Examples for javax.xml.bind.annotation.XmlType#name()

The following examples show how to use javax.xml.bind.annotation.XmlType#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeployerValidator.java    From zstack with Apache License 2.0 6 votes vote down vote up
private void validateField(Field f, Object obj) throws IllegalArgumentException, IllegalAccessException {
    XmlType xtype = obj.getClass().getAnnotation(XmlType.class);
    if (xtype == null) {
        return;
    }

    Object val = f.get(obj);
    String elementName = xtype.name();
    logger.debug(String.format("validating %s->%s", elementName, f.getName()));

    XmlElement eat = f.getAnnotation(XmlElement.class);
    if (eat != null && eat.required() && val == null) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", f.getName(), elementName));
    }

    XmlAttribute aat = f.getAnnotation(XmlAttribute.class);
    if (aat != null && aat.required() && val == null) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", aat.name(), elementName));
    }

    if (val != null) {
        validateObject(val);
    }
}
 
Example 2
Source File: CorbaStreamFaultOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected RaisesType getRaisesType(OperationType opType, String exClassName, Throwable ex) {
    RaisesType result = null;
    List<RaisesType> exList = opType.getRaises();
    result = findRaisesType(exList, exClassName);

    if (result == null) {
        //REVISIT, need to find a better way to match the corba binding exception name with the wsdl one
        //if doc-literal, the part element name should be used, but for RPC, the message part name
        try {
            Method faultMethod = ex.getClass().getMethod("getFaultInfo");
            if (faultMethod != null) {
                Class<?> faultClass = faultMethod.getReturnType();
                XmlType exType = faultClass.getAnnotation(XmlType.class);
                exClassName = exType.name();
                result = findRaisesType(exList, exClassName);
            }
        } catch (Exception exp) {
            //Ignore it
        }
    }
    return result;
}
 
Example 3
Source File: DeployerValidator.java    From zstack with Apache License 2.0 6 votes vote down vote up
private void validateCollection(Field f, Object obj) throws IllegalArgumentException, IllegalAccessException {
    XmlType xtype = obj.getClass().getAnnotation(XmlType.class);
    if (xtype == null) {
        return;
    }
    String elementName = xtype.name();
    logger.debug(String.format("validating %s->%s", elementName, f.getName()));

    Collection l = (Collection) f.get(obj);
    XmlElement eat = f.getAnnotation(XmlElement.class);
    if (eat != null && (eat.required() && (l == null || l.isEmpty()))) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", f.getName(), elementName));
    }
    XmlAttribute aat = f.getAnnotation(XmlAttribute.class);
    if (aat != null && (aat.required() && (l == null || l.isEmpty()))) {
        throw new IllegalArgumentException(String.format("field[%s] of element[%s] is mandatory, cannot be missed", aat.name(), elementName));
    }

    if (l != null) {
        Object val = l.iterator().next();
        if (val != null) {
            validateObject(val);
        }
    }
}
 
Example 4
Source File: SchemaCollectionContextProxy.java    From cxf with Apache License 2.0 6 votes vote down vote up
private QName getTypeQName(Class<?> cls, String namespace) {
    QName qn = TYPE_MAP.get(cls);
    if (qn != null) {
        return qn;
    }
    XmlType xtype = cls.getAnnotation(XmlType.class);
    String tn = xtype == null ? "##default" : xtype.name();
    String tns = xtype == null ? "##default" : xtype.namespace();
    if ("##default".equals(tn)) {
        tn = java.beans.Introspector.decapitalize(cls.getSimpleName());
    }
    if ("##default".equals(tns) || StringUtils.isEmpty(tns)) {
        tns = JAXBUtils.getPackageNamespace(cls);
    }
    if ("##default".equals(tns) || StringUtils.isEmpty(tns)) {
        tns = namespace;
    }
    return new QName(tns, tn);
}
 
Example 5
Source File: TypeInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 6
Source File: TypeInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 7
Source File: TypeInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 8
Source File: TypeInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 9
Source File: PluginContext.java    From jaxb2-rich-contract-plugin with MIT License 5 votes vote down vote up
private static String getLocalName(final Class<?> boundClass) {
	final XmlRootElement elementAnnotation = boundClass.getAnnotation(XmlRootElement.class);
	if (elementAnnotation != null && !"##default".equals(elementAnnotation.name())) {
		return elementAnnotation.name();
	} else {
		final XmlType xmlTypeAnnotation = boundClass.getAnnotation(XmlType.class);
		if (xmlTypeAnnotation != null && !"##default".equals(xmlTypeAnnotation.name())) {
			return xmlTypeAnnotation.name();
		} else {
			return boundClass.getSimpleName();
		}
	}
}
 
Example 10
Source File: TypeInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 11
Source File: TypeInfoImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 12
Source File: DefinitionGenerator.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Processes a model class which can be converted into a Swagger definition. A model class must be a JAXB XmlType. This method may be called recursively.
 *
 * @param clazz the class to process.
 *
 * @throws MojoExecutionException if the class isn't an XmlType.
 */
private void processDefinitionClass(Class<?> clazz) throws MojoExecutionException
{
    log.debug("Processing model class \"" + clazz.getName() + "\"");
    XmlType xmlType = clazz.getAnnotation(XmlType.class);
    if (xmlType == null)
    {
        log.debug("Model class \"" + clazz.getName() + "\" is not an XmlType so it will be skipped.");
    }
    else
    {
        String name = xmlType.name();
        if (!swagger.getDefinitions().containsKey(name))
        {
            ModelImpl model = new ModelImpl();

            if (exampleClassNames.contains(clazz.getSimpleName()))
            {
                // Only provide examples for root elements. If we do them for child elements, the JSON examples use the XML examples which is a problem.
                model.setExample(new ExampleXmlGenerator(log, clazz).getExampleXml());
            }

            swagger.addDefinition(name, model);
            model.name(name);

            if (xsdParser != null)
            {
                model.setDescription(xsdParser.getAnnotation(name));
            }

            for (Field field : clazz.getDeclaredFields())
            {
                processField(field, model);
            }
        }
    }
}
 
Example 13
Source File: TypeInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a (potentially-null) {@link XmlType} annotation on a class
 * and determine the actual value.
 *
 * @param clazz
 *      The class on which the XmlType annotation is checked.
 * @param t
 *      The {@link XmlType} annotation on the clazz. This value
 *      is taken as a parameter to improve the performance for the case where
 *      't' is pre-computed.
 */
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
    String nsUri="##default";
    String local="##default";
    if(t!=null) {
        nsUri = t.namespace();
        local = t.name();
    }

    if(local.length()==0)
        return null; // anonymous


    if(local.equals("##default"))
        // if defaulted ...
        local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));

    if(nsUri.equals("##default")) {
        // if defaulted ...
        XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
        if(xs!=null)
            nsUri = xs.namespace();
        else {
            nsUri = builder.defaultNsUri;
        }
    }

    return new QName(nsUri.intern(),local.intern());
}
 
Example 14
Source File: XmlTypeUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static QName getTypeName(Class<?> targetClass) {
	Validate.notNull(targetClass);
	final Package targetPackage = targetClass.getPackage();
	final XmlType xmlTypeAnnotation = targetClass
			.getAnnotation(XmlType.class);

	final String localPart;
	final String namespaceURI;
	final String prefix;

	if (xmlTypeAnnotation == null) {
		localPart = NameConverter.standard.toVariableName(targetClass
				.getSimpleName());
		namespaceURI = getNamespace(targetPackage);
	} else {
		final String name = xmlTypeAnnotation.name();
		if (name == null || "".equals(name)) {
			localPart = null;
		} else {
			if ("##default".equals(name)) {
				localPart = NameConverter.standard
						.toVariableName(targetClass.getSimpleName());
			} else {
				localPart = name;
			}
		}

		final String namespace = xmlTypeAnnotation.namespace();

		if (namespace == null || "".equals(namespace)) {
			namespaceURI = "";
		} else {
			if ("##default".equals(namespace)) {
				namespaceURI = getNamespace(targetPackage);
			} else {
				namespaceURI = namespace;
			}
		}
	}

	if (localPart == null) {
		return null;
	} else {
		prefix = getPrefix(targetPackage, namespaceURI);
	}

	return prefix == null ? new QName(namespaceURI, localPart) : new QName(
			namespaceURI, localPart, prefix);
}
 
Example 15
Source File: WebServiceWrapperGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null)
        return false;

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
Example 16
Source File: WebServiceWrapperGenerator.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null)
        return false;

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
Example 17
Source File: WebServiceWrapperGenerator.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null)
        return false;

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
Example 18
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null) {
        return false;
    }

    addGeneratedFile(className);

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
Example 19
Source File: WebServiceWrapperGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null)
        return false;

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}
 
Example 20
Source File: WebServiceWrapperGenerator.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private boolean generateExceptionBean(TypeElement thrownDecl, String beanPackage) {
    if (!builder.isServiceException(thrownDecl.asType()))
        return false;

    String exceptionName = ClassNameInfo.getName(thrownDecl.getQualifiedName().toString());
    if (processedExceptions.contains(exceptionName))
        return false;
    processedExceptions.add(exceptionName);
    WebFault webFault = thrownDecl.getAnnotation(WebFault.class);
    String className = beanPackage+ exceptionName + BEAN.getValue();

    Collection<MemberInfo> members = ap_generator.collectExceptionBeanMembers(thrownDecl);
    boolean isWSDLException = isWSDLException(members, thrownDecl);
    String namespace = typeNamespace;
    String name = exceptionName;
    FaultInfo faultInfo;
    if (isWSDLException) {
        TypeMirror beanType =  getFaultInfoMember(members).getParamType();
        faultInfo = new FaultInfo(TypeMonikerFactory.getTypeMoniker(beanType), true);
        namespace = webFault.targetNamespace().length()>0 ?
                           webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
                      webFault.name() : name;
        faultInfo.setElementName(new QName(namespace, name));
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (webFault != null) {
        namespace = webFault.targetNamespace().length()>0 ?
                    webFault.targetNamespace() : namespace;
        name = webFault.name().length()>0 ?
               webFault.name() : name;
        className = webFault.faultBean().length()>0 ?
                    webFault.faultBean() : className;

    }
    JDefinedClass cls = getCMClass(className, CLASS);
    faultInfo = new FaultInfo(className, false);

    if (duplicateName(className)) {
        builder.processError(WebserviceapMessages.WEBSERVICEAP_METHOD_EXCEPTION_BEAN_NAME_NOT_UNIQUE(
                typeElement.getQualifiedName(), thrownDecl.getQualifiedName()));
    }

    boolean canOverWriteBean = builder.canOverWriteClass(className);
    if (!canOverWriteBean) {
        builder.log("Class " + className + " exists. Not overwriting.");
        seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
        return false;
    }
    if (seiContext.getExceptionBeanName(thrownDecl.getQualifiedName()) != null)
        return false;

    //write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    for (String doc : GeneratorBase.getJAXWSClassComment(ToolVersion.VERSION.MAJOR_VERSION)) {
        comment.add(doc);
    }

    // XmlElement Declarations
    writeXmlElementDeclaration(cls, name, namespace);

    // XmlType Declaration
    //members = sortMembers(members);
    XmlType xmlType = thrownDecl.getAnnotation(XmlType.class);
    String xmlTypeName = (xmlType != null && !xmlType.name().equals("##default")) ? xmlType.name() : exceptionName;
    String xmlTypeNamespace = (xmlType != null && !xmlType.namespace().equals("##default")) ? xmlType.namespace() : typeNamespace;
    writeXmlTypeDeclaration(cls, xmlTypeName, xmlTypeNamespace, members);

    writeMembers(cls, members);

    seiContext.addExceptionBeanEntry(thrownDecl.getQualifiedName(), faultInfo, builder);
    return true;
}