com.sun.tools.xjc.api.Mapping Java Examples

The following examples show how to use com.sun.tools.xjc.api.Mapping. 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: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Import the Types from the WSDL definition using the same strategy that Cxf uses taking advantage of JAXB
 */
protected void importTypes(Types types) {
  SchemaCompiler compiler = XJC.createSchemaCompiler();
  ErrorListener elForRun = new ConsoleErrorReporter();
  compiler.setErrorListener(elForRun);

  Element rootTypes = this.getRootTypes();
  this.createDefaultStructures(rootTypes);

  S2JJAXBModel intermediateModel = this.compileModel(types, compiler, rootTypes);
  Collection<? extends Mapping> mappings = intermediateModel.getMappings();

  for (Mapping mapping : mappings) {
    this.importStructure(mapping);
  }
}
 
Example #2
Source File: WSDLImporter.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Import the Types from the WSDL definition using the same strategy that Cxf uses taking advantage of JAXB
 */
protected void importTypes(Types types) {
    SchemaCompiler compiler = XJC.createSchemaCompiler();
    ErrorListener elForRun = new ConsoleErrorReporter();
    compiler.setErrorListener(elForRun);

    Element rootTypes = this.getRootTypes();
    this.createDefaultStructures(rootTypes);

    S2JJAXBModel intermediateModel = this.compileModel(types, compiler, rootTypes);
    Collection<? extends Mapping> mappings = intermediateModel.getMappings();

    for (Mapping mapping : mappings) {
        this.importStructure(mapping);
    }
}
 
Example #3
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
public DefaultValueWriter createDefaultValueWriter(QName qname, boolean element) {
    if (defaultValues == null) {
        return null;
    }
    TypeAndAnnotation typeAnno = rawJaxbModelGenCode.getJavaType(qname);
    if (element) {
        Mapping mapping = rawJaxbModelGenCode.get(qname);
        if (mapping != null) {
            typeAnno = mapping.getType();
        }
    }
    if (typeAnno != null && typeAnno.getTypeClass() instanceof JDefinedClass) {
        JDefinedClass dc = (JDefinedClass)typeAnno.getTypeClass();
        if (dc.isAbstract()) {
            //no default values for abstract classes
            typeAnno = null;
        }
    }
    if (typeAnno != null) {
        final JType type = typeAnno.getTypeClass();
        return new JAXBDefaultValueWriter(type);
    }
    return null;
}
 
Example #4
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
public DefaultValueWriter createDefaultValueWriterForWrappedElement(QName wrapperElement, QName item) {
    if (defaultValues != null) {
        Mapping mapping = rawJaxbModelGenCode.get(wrapperElement);
        if (mapping != null) {
            List<? extends Property> propList = mapping.getWrapperStyleDrilldown();
            for (Property pro : propList) {
                if (pro.elementName().getNamespaceURI().equals(item.getNamespaceURI())
                    && pro.elementName().getLocalPart().equals(item.getLocalPart())) {

                    JType type = pro.type();
                    if (type instanceof JDefinedClass
                        && ((JDefinedClass)type).isAbstract()) {
                        //no default values for abstract classes
                        return null;
                    }
                    return new JAXBDefaultValueWriter(pro.type());
                }
            }
        }
    }
    return null;
}
 
Example #5
Source File: CxfWSDLImporter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void importTypes(Types types) {
  SchemaCompiler compiler = XJC.createSchemaCompiler();
  ErrorListener elForRun = new ConsoleErrorReporter();
  compiler.setErrorListener(elForRun);

  SchemaImpl impl = (SchemaImpl) types.getExtensibilityElements().get(0);
  
  S2JJAXBModel intermediateModel = this.compileModel(types, compiler, impl.getElement());
  Collection<? extends Mapping> mappings = intermediateModel.getMappings();

  for (Mapping mapping : mappings){
    this.importStructure(mapping);
  }
}
 
Example #6
Source File: WSDLImporter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void importStructure(Mapping mapping) {
  QName qname = mapping.getElement();
  JDefinedClass theClass = (JDefinedClass) mapping.getType().getTypeClass();
  SimpleStructureDefinition structure = (SimpleStructureDefinition) this.structures.get(this.namespace + qname.getLocalPart());

  Map<String, JFieldVar> fields = theClass.fields();
  int index = 0;
  for (Entry<String, JFieldVar> entry : fields.entrySet()) {
    Class<?> fieldClass = ReflectUtil.loadClass(entry.getValue().type().boxify().fullName());
    structure.setFieldName(index, entry.getKey(), fieldClass);
    index++;
  }
}
 
Example #7
Source File: CxfWSDLImporter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void importTypes(Types types) {
    SchemaCompiler compiler = XJC.createSchemaCompiler();
    ErrorListener elForRun = new ConsoleErrorReporter();
    compiler.setErrorListener(elForRun);

    SchemaImpl impl = (SchemaImpl) types.getExtensibilityElements().get(0);

    S2JJAXBModel intermediateModel = this.compileModel(types, compiler, impl.getElement());
    Collection<? extends Mapping> mappings = intermediateModel.getMappings();

    for (Mapping mapping : mappings) {
        this.importStructure(mapping);
    }
}
 
Example #8
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String getType(QName qname, boolean element) {
    TypeAndAnnotation typeAnno = rawJaxbModelGenCode.getJavaType(qname);
    if (element) {
        Mapping mapping = rawJaxbModelGenCode.get(qname);
        if (mapping != null) {
            typeAnno = mapping.getType();
        }
    }

    if (typeAnno != null && typeAnno.getTypeClass() != null) {
        return typeAnno.getTypeClass().fullName();
    }
    return null;

}
 
Example #9
Source File: JAXBDataBinding.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String getWrappedElementType(QName wrapperElement, QName item) {
    Mapping mapping = rawJaxbModelGenCode.get(wrapperElement);
    if (mapping != null) {
        List<? extends Property> propList = mapping.getWrapperStyleDrilldown();
        if (propList != null) {
            for (Property pro : propList) {
                if (pro.elementName().getNamespaceURI().equals(item.getNamespaceURI())
                    && pro.elementName().getLocalPart().equals(item.getLocalPart())) {
                    return pro.type().fullName();
                }
            }
        }
    }
    return null;
}
 
Example #10
Source File: WSDLImporter.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void importStructure(Mapping mapping) {
    QName qname = mapping.getElement();
    JDefinedClass theClass = (JDefinedClass) mapping.getType().getTypeClass();
    SimpleStructureDefinition structure = (SimpleStructureDefinition) this.structures.get(this.namespace + qname.getLocalPart());

    Map<String, JFieldVar> fields = theClass.fields();
    int index = 0;
    for (Entry<String, JFieldVar> entry : fields.entrySet()) {

        final JType fieldType = entry.getValue().type();
        final Class<?> fieldClass = ReflectUtil.loadClass(fieldType.boxify().fullName());
        final Class<?> fieldParameterClass;
        if (fieldType instanceof JClass) {
            final JClass fieldClassType = (JClass) fieldType;
            final List<JClass> fieldTypeParameters = fieldClassType.getTypeParameters();
            if (fieldTypeParameters.size() > 1) {
                throw new FlowableException(
                        String.format("Field type '%s' with more than one parameter is not supported: %S",
                                fieldClassType, fieldTypeParameters));
            } else if (fieldTypeParameters.isEmpty()) {
                fieldParameterClass = null;
            } else {
                final JClass fieldParameterType = fieldTypeParameters.get(0);

                // Hack because JClass.fullname() doesn't return the right class fullname for a nested class to be
                // loaded from classloader. It should be contain "$" instead of "." as separator
                boolean isFieldParameterTypeNeestedClass = false;
                final Iterator<JDefinedClass> theClassNeestedClassIt = theClass.classes();
                do {
                    final JDefinedClass neestedType = theClassNeestedClassIt.next();
                    if (neestedType.name().equals(fieldParameterType.name())) {
                        isFieldParameterTypeNeestedClass = true;
                    }
                } while (!isFieldParameterTypeNeestedClass);
                if (isFieldParameterTypeNeestedClass) {
                    // The parameter type is a nested class
                    fieldParameterClass = ReflectUtil
                            .loadClass(theClass.erasure().fullName() + "$" + fieldParameterType.name());
                } else {
                    // The parameter type is not a nested class
                    fieldParameterClass = ReflectUtil.loadClass(fieldParameterType.erasure().fullName());
                }
            }
        } else {
            fieldParameterClass = null;
        }

        structure.setFieldName(index, entry.getKey(), fieldClass, fieldParameterClass);
        index++;
    }
}