com.sun.tools.internal.xjc.ErrorReceiver Java Examples

The following examples show how to use com.sun.tools.internal.xjc.ErrorReceiver. 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: BGMBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Entry point.
 */
public static Model build( XSSchemaSet _schemas, JCodeModel codeModel,
        ErrorReceiver _errorReceiver, Options opts ) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
        ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);

        Ring.add(XSSchemaSet.class,_schemas);
        Ring.add(codeModel);
        Model model = new Model(opts, codeModel, null/*set later*/, opts.classNameAllocator, _schemas);
        Ring.add(model);
        Ring.add(ErrorReceiver.class,ef);
        Ring.add(CodeModelClassFactory.class,new CodeModelClassFactory(ef));

        BGMBuilder builder = new BGMBuilder(opts.defaultPackage,opts.defaultPackage2,
            opts.isExtensionMode(),opts.getFieldRendererFactory(), opts.activePlugins);
        builder._build();

        if(ef.hadError())   return null;
        else                return model;
    } finally {
        Ring.end(old);
    }
}
 
Example #2
Source File: BIGlobalBinding.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs error check
 */
public void errorCheck() {
    ErrorReceiver er = Ring.get(ErrorReceiver.class);
    for (QName n : enumBaseTypes) {
        XSSchemaSet xs = Ring.get(XSSchemaSet.class);
        XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
        if(st==null) {
            er.error(loc,Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
            continue;
        }

        if(!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
            er.error(loc,Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
            continue;
        }
    }
}
 
Example #3
Source File: BIGlobalBinding.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Moves global BIConversion to the right object.
 */
public void dispatchGlobalConversions( XSSchemaSet schema ) {
    // also set parent to the global conversions
    for( Map.Entry<QName,BIConversion> e : globalConversions.entrySet() ) {

        QName name = e.getKey();
        BIConversion conv = e.getValue();

        XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(),name.getLocalPart());
        if(st==null) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name)
            );
            continue; // abort
        }

        getBuilder().getOrCreateBindInfo(st).addDecl(conv);
    }
}
 
Example #4
Source File: BGMBuilder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Entry point.
 */
public static Model build( XSSchemaSet _schemas, JCodeModel codeModel,
        ErrorReceiver _errorReceiver, Options opts ) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
        ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);

        Ring.add(XSSchemaSet.class,_schemas);
        Ring.add(codeModel);
        Model model = new Model(opts, codeModel, null/*set later*/, opts.classNameAllocator, _schemas);
        Ring.add(model);
        Ring.add(ErrorReceiver.class,ef);
        Ring.add(CodeModelClassFactory.class,new CodeModelClassFactory(ef));

        BGMBuilder builder = new BGMBuilder(opts.defaultPackage,opts.defaultPackage2,
            opts.isExtensionMode(),opts.getFieldRendererFactory(), opts.activePlugins);
        builder._build();

        if(ef.hadError())   return null;
        else                return model;
    } finally {
        Ring.end(old);
    }
}
 
Example #5
Source File: BIGlobalBinding.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Moves global BIConversion to the right object.
 */
public void dispatchGlobalConversions( XSSchemaSet schema ) {
    // also set parent to the global conversions
    for( Map.Entry<QName,BIConversion> e : globalConversions.entrySet() ) {

        QName name = e.getKey();
        BIConversion conv = e.getValue();

        XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(),name.getLocalPart());
        if(st==null) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name)
            );
            continue; // abort
        }

        getBuilder().getOrCreateBindInfo(st).addDecl(conv);
    }
}
 
Example #6
Source File: DOMForest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks the correctness of the XML Schema documents and return true
 * if it's OK.
 *
 * <p>
 * This method performs a weaker version of the tests where error messages
 * are provided without line number information. So whenever possible
 * use {@link SchemaConstraintChecker}.
 *
 * @see SchemaConstraintChecker
 */
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
    try {
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
        ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
        sf.setErrorHandler(filter);
        Set<String> roots = getRootDocuments();
        Source[] sources = new Source[roots.size()];
        int i=0;
        for (String root : roots) {
            sources[i++] = new DOMSource(get(root),root);
        }
        sf.newSchema(sources);
        return !filter.hadError();
    } catch (SAXException e) {
        // the errors should have been reported
        return false;
    }
}
 
Example #7
Source File: BIGlobalBinding.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs error check
 */
public void errorCheck() {
    ErrorReceiver er = Ring.get(ErrorReceiver.class);
    for (QName n : enumBaseTypes) {
        XSSchemaSet xs = Ring.get(XSSchemaSet.class);
        XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
        if(st==null) {
            er.error(loc,Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
            continue;
        }

        if(!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
            er.error(loc,Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
            continue;
        }
    }
}
 
Example #8
Source File: BIGlobalBinding.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs error check
 */
public void errorCheck() {
    ErrorReceiver er = Ring.get(ErrorReceiver.class);
    for (QName n : enumBaseTypes) {
        XSSchemaSet xs = Ring.get(XSSchemaSet.class);
        XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
        if(st==null) {
            er.error(loc,Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
            continue;
        }

        if(!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
            er.error(loc,Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
            continue;
        }
    }
}
 
Example #9
Source File: BIProperty.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void constantPropertyErrorCheck() {
    if( isConstantProperty!=null && getOwner()!=null ) {
        // run additional check on the isCOnstantProperty value.
        // this value is not allowed if the schema component doesn't have
        // a fixed value constraint.
        //
        // the setParent method associates a customization with the rest of
        // XSOM object graph, so this is the earliest possible moment where
        // we can test this.

        if( !hasFixedValue.find(getOwner()) ) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_ILLEGAL_FIXEDATTR.format()
            );
            // set this value to null to avoid the same error to be reported more than once.
            isConstantProperty = null;
        }
    }
}
 
Example #10
Source File: BIGlobalBinding.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Moves global BIConversion to the right object.
 */
public void dispatchGlobalConversions( XSSchemaSet schema ) {
    // also set parent to the global conversions
    for( Map.Entry<QName,BIConversion> e : globalConversions.entrySet() ) {

        QName name = e.getKey();
        BIConversion conv = e.getValue();

        XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(),name.getLocalPart());
        if(st==null) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name)
            );
            continue; // abort
        }

        getBuilder().getOrCreateBindInfo(st).addDecl(conv);
    }
}
 
Example #11
Source File: DOMForest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks the correctness of the XML Schema documents and return true
 * if it's OK.
 *
 * <p>
 * This method performs a weaker version of the tests where error messages
 * are provided without line number information. So whenever possible
 * use {@link SchemaConstraintChecker}.
 *
 * @see SchemaConstraintChecker
 */
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
    try {
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
        ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
        sf.setErrorHandler(filter);
        Set<String> roots = getRootDocuments();
        Source[] sources = new Source[roots.size()];
        int i=0;
        for (String root : roots) {
            sources[i++] = new DOMSource(get(root),root);
        }
        sf.newSchema(sources);
        return !filter.hadError();
    } catch (SAXException e) {
        // the errors should have been reported
        return false;
    }
}
 
Example #12
Source File: SCDBasedBindingSet.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u =  BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
Example #13
Source File: DOMForest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks the correctness of the XML Schema documents and return true
 * if it's OK.
 *
 * <p>
 * This method performs a weaker version of the tests where error messages
 * are provided without line number information. So whenever possible
 * use {@link SchemaConstraintChecker}.
 *
 * @see SchemaConstraintChecker
 */
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
    try {
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
        ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
        sf.setErrorHandler(filter);
        Set<String> roots = getRootDocuments();
        Source[] sources = new Source[roots.size()];
        int i=0;
        for (String root : roots) {
            sources[i++] = new DOMSource(get(root),root);
        }
        sf.newSchema(sources);
        return !filter.hadError();
    } catch (SAXException e) {
        // the errors should have been reported
        return false;
    }
}
 
Example #14
Source File: TypeUtil.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a {@link JType} object for the string representation
 * of a type.
 */
public static JType getType( JCodeModel codeModel,
    String typeName, ErrorReceiver errorHandler, Locator errorSource ) {

    try {
        return codeModel.parseType(typeName);
    } catch( ClassNotFoundException ee ) {

        // make it a warning
        errorHandler.warning( new SAXParseException(
            Messages.ERR_CLASS_NOT_FOUND.format(typeName)
            ,errorSource));

        // recover by assuming that it's a class that derives from Object
        return codeModel.directClass(typeName);
    }
}
 
Example #15
Source File: BGMBuilder.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Entry point.
 */
public static Model build( XSSchemaSet _schemas, JCodeModel codeModel,
        ErrorReceiver _errorReceiver, Options opts ) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
        ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);

        Ring.add(XSSchemaSet.class,_schemas);
        Ring.add(codeModel);
        Model model = new Model(opts, codeModel, null/*set later*/, opts.classNameAllocator, _schemas);
        Ring.add(model);
        Ring.add(ErrorReceiver.class,ef);
        Ring.add(CodeModelClassFactory.class,new CodeModelClassFactory(ef));

        BGMBuilder builder = new BGMBuilder(opts.defaultPackage,opts.defaultPackage2,
            opts.isExtensionMode(),opts.getFieldRendererFactory(), opts.activePlugins);
        builder._build();

        if(ef.hadError())   return null;
        else                return model;
    } finally {
        Ring.end(old);
    }
}
 
Example #16
Source File: SCDBasedBindingSet.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u =  BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
Example #17
Source File: BIProperty.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void constantPropertyErrorCheck() {
    if( isConstantProperty!=null && getOwner()!=null ) {
        // run additional check on the isCOnstantProperty value.
        // this value is not allowed if the schema component doesn't have
        // a fixed value constraint.
        //
        // the setParent method associates a customization with the rest of
        // XSOM object graph, so this is the earliest possible moment where
        // we can test this.

        if( !hasFixedValue.find(getOwner()) ) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_ILLEGAL_FIXEDATTR.format()
            );
            // set this value to null to avoid the same error to be reported more than once.
            isConstantProperty = null;
        }
    }
}
 
Example #18
Source File: BIGlobalBinding.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs error check
 */
public void errorCheck() {
    ErrorReceiver er = Ring.get(ErrorReceiver.class);
    for (QName n : enumBaseTypes) {
        XSSchemaSet xs = Ring.get(XSSchemaSet.class);
        XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
        if(st==null) {
            er.error(loc,Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
            continue;
        }

        if(!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
            er.error(loc,Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
            continue;
        }
    }
}
 
Example #19
Source File: BIGlobalBinding.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Moves global BIConversion to the right object.
 */
public void dispatchGlobalConversions( XSSchemaSet schema ) {
    // also set parent to the global conversions
    for( Map.Entry<QName,BIConversion> e : globalConversions.entrySet() ) {

        QName name = e.getKey();
        BIConversion conv = e.getValue();

        XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(),name.getLocalPart());
        if(st==null) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name)
            );
            continue; // abort
        }

        getBuilder().getOrCreateBindInfo(st).addDecl(conv);
    }
}
 
Example #20
Source File: SCDBasedBindingSet.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u =  BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
Example #21
Source File: DOMForest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks the correctness of the XML Schema documents and return true
 * if it's OK.
 *
 * <p>
 * This method performs a weaker version of the tests where error messages
 * are provided without line number information. So whenever possible
 * use {@link SchemaConstraintChecker}.
 *
 * @see SchemaConstraintChecker
 */
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
    try {
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
        ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
        sf.setErrorHandler(filter);
        Set<String> roots = getRootDocuments();
        Source[] sources = new Source[roots.size()];
        int i=0;
        for (String root : roots) {
            sources[i++] = new DOMSource(get(root),root);
        }
        sf.newSchema(sources);
        return !filter.hadError();
    } catch (SAXException e) {
        // the errors should have been reported
        return false;
    }
}
 
Example #22
Source File: TypeUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a {@link JType} object for the string representation
 * of a type.
 */
public static JType getType( JCodeModel codeModel,
    String typeName, ErrorReceiver errorHandler, Locator errorSource ) {

    try {
        return codeModel.parseType(typeName);
    } catch( ClassNotFoundException ee ) {

        // make it a warning
        errorHandler.warning( new SAXParseException(
            Messages.ERR_CLASS_NOT_FOUND.format(typeName)
            ,errorSource));

        // recover by assuming that it's a class that derives from Object
        return codeModel.directClass(typeName);
    }
}
 
Example #23
Source File: BGMBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Entry point.
 */
public static Model build( XSSchemaSet _schemas, JCodeModel codeModel,
        ErrorReceiver _errorReceiver, Options opts ) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
        ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);

        Ring.add(XSSchemaSet.class,_schemas);
        Ring.add(codeModel);
        Model model = new Model(opts, codeModel, null/*set later*/, opts.classNameAllocator, _schemas);
        Ring.add(model);
        Ring.add(ErrorReceiver.class,ef);
        Ring.add(CodeModelClassFactory.class,new CodeModelClassFactory(ef));

        BGMBuilder builder = new BGMBuilder(opts.defaultPackage,opts.defaultPackage2,
            opts.isExtensionMode(),opts.getFieldRendererFactory(), opts.activePlugins);
        builder._build();

        if(ef.hadError())   return null;
        else                return model;
    } finally {
        Ring.end(old);
    }
}
 
Example #24
Source File: BIGlobalBinding.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Moves global BIConversion to the right object.
 */
public void dispatchGlobalConversions( XSSchemaSet schema ) {
    // also set parent to the global conversions
    for( Map.Entry<QName,BIConversion> e : globalConversions.entrySet() ) {

        QName name = e.getKey();
        BIConversion conv = e.getValue();

        XSSimpleType st = schema.getSimpleType(name.getNamespaceURI(),name.getLocalPart());
        if(st==null) {
            Ring.get(ErrorReceiver.class).error(
                getLocation(),
                Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(name)
            );
            continue; // abort
        }

        getBuilder().getOrCreateBindInfo(st).addDecl(conv);
    }
}
 
Example #25
Source File: BIGlobalBinding.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Performs error check
 */
public void errorCheck() {
    ErrorReceiver er = Ring.get(ErrorReceiver.class);
    for (QName n : enumBaseTypes) {
        XSSchemaSet xs = Ring.get(XSSchemaSet.class);
        XSSimpleType st = xs.getSimpleType(n.getNamespaceURI(), n.getLocalPart());
        if(st==null) {
            er.error(loc,Messages.ERR_UNDEFINED_SIMPLE_TYPE.format(n));
            continue;
        }

        if(!SimpleTypeBuilder.canBeMappedToTypeSafeEnum(st)) {
            er.error(loc,Messages.ERR_CANNOT_BE_BOUND_TO_SIMPLETYPE.format(n));
            continue;
        }
    }
}
 
Example #26
Source File: SCDBasedBindingSet.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u =  BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
Example #27
Source File: DOMForest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks the correctness of the XML Schema documents and return true
 * if it's OK.
 *
 * <p>
 * This method performs a weaker version of the tests where error messages
 * are provided without line number information. So whenever possible
 * use {@link SchemaConstraintChecker}.
 *
 * @see SchemaConstraintChecker
 */
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
    try {
        boolean disableXmlSecurity = false;
        if (options != null) {
            disableXmlSecurity = options.disableXmlSecurity;
        }
        SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
        ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
        sf.setErrorHandler(filter);
        Set<String> roots = getRootDocuments();
        Source[] sources = new Source[roots.size()];
        int i=0;
        for (String root : roots) {
            sources[i++] = new DOMSource(get(root),root);
        }
        sf.newSchema(sources);
        return !filter.hadError();
    } catch (SAXException e) {
        // the errors should have been reported
        return false;
    }
}
 
Example #28
Source File: SCDBasedBindingSet.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies the additional binding customizations.
 */
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
    if(topLevel!=null) {
        this.errorReceiver = errorReceiver;
        Unmarshaller u =  BindInfo.getCustomizationUnmarshaller();
        this.unmarshaller = u.getUnmarshallerHandler();
        ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
        v.setErrorHandler(errorReceiver);
        loader = new ForkContentHandler(v,unmarshaller);

        topLevel.applyAll(schema.getSchemas());

        this.loader = null;
        this.unmarshaller = null;
        this.errorReceiver = null;
    }
}
 
Example #29
Source File: TypeUtil.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Obtains a {@link JType} object for the string representation
 * of a type.
 */
public static JType getType( JCodeModel codeModel,
    String typeName, ErrorReceiver errorHandler, Locator errorSource ) {

    try {
        return codeModel.parseType(typeName);
    } catch( ClassNotFoundException ee ) {

        // make it a warning
        errorHandler.warning( new SAXParseException(
            Messages.ERR_CLASS_NOT_FOUND.format(typeName)
            ,errorSource));

        // recover by assuming that it's a class that derives from Object
        return codeModel.directClass(typeName);
    }
}
 
Example #30
Source File: BGMBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Entry point.
 */
public static Model build( XSSchemaSet _schemas, JCodeModel codeModel,
        ErrorReceiver _errorReceiver, Options opts ) {
    // set up a ring
    final Ring old = Ring.begin();
    try {
        ErrorReceiverFilter ef = new ErrorReceiverFilter(_errorReceiver);

        Ring.add(XSSchemaSet.class,_schemas);
        Ring.add(codeModel);
        Model model = new Model(opts, codeModel, null/*set later*/, opts.classNameAllocator, _schemas);
        Ring.add(model);
        Ring.add(ErrorReceiver.class,ef);
        Ring.add(CodeModelClassFactory.class,new CodeModelClassFactory(ef));

        BGMBuilder builder = new BGMBuilder(opts.defaultPackage,opts.defaultPackage2,
            opts.isExtensionMode(),opts.getFieldRendererFactory(), opts.activePlugins);
        builder._build();

        if(ef.hadError())   return null;
        else                return model;
    } finally {
        Ring.end(old);
    }
}