Java Code Examples for com.sun.xml.internal.bind.v2.util.EditDistance#findNearest()

The following examples show how to use com.sun.xml.internal.bind.v2.util.EditDistance#findNearest() . 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: JAXBContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 2
Source File: JAXBContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 3
Source File: ClassInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example 4
Source File: JAXBContextImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 5
Source File: ClassInfoImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example 6
Source File: JAXBContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 7
Source File: ClassInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example 8
Source File: ClassInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example 9
Source File: JAXBContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 10
Source File: ClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example 11
Source File: JAXBContextImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 12
Source File: ClassInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example 13
Source File: JAXBContextImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a type name that this context recognizes which is
 * "closest" to the given type name.
 *
 * <p>
 * This method is used for error recovery.
 */
public String getNearestTypeName(QName name) {
    String[] all = new String[typeMap.size()];
    int i=0;
    for (QName qn : typeMap.keySet()) {
        if(qn.getLocalPart().equals(name.getLocalPart()))
            return qn.toString();  // probably a match, as people often gets confused about namespace.
        all[i++] = qn.toString();
    }

    String nearest = EditDistance.findNearest(name.toString(), all);

    if(EditDistance.editDistance(nearest,name.toString())>10)
        return null;    // too far apart.

    return nearest;
}
 
Example 14
Source File: AbstractExtensionBindingChecker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}
 
Example 15
Source File: AbstractExtensionBindingChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}
 
Example 16
Source File: AbstractExtensionBindingChecker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}
 
Example 17
Source File: AbstractExtensionBindingChecker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}
 
Example 18
Source File: AbstractExtensionBindingChecker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}
 
Example 19
Source File: AbstractExtensionBindingChecker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}
 
Example 20
Source File: AbstractExtensionBindingChecker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that the given URI is indeed a valid extension namespace URI,
 * and if so enable it.
 * <p>
 * This method does all the error handling.
 */
protected final void checkAndEnable(String uri) throws SAXException {
    if( !isRecognizableExtension(uri) ) {
        String nearest = EditDistance.findNearest(uri, recognizableExtensions);
        // not the namespace URI we know of
        error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri,nearest) );
    } else
    if( !isSupportedExtension(uri) ) {
        // recognizable but not not supported, meaning
        // the plug-in isn't enabled

        // look for plug-in that handles this URI
        Plugin owner = null;
        for( Plugin p : options.getAllPlugins() ) {
            if(p.getCustomizationURIs().contains(uri)) {
                owner = p;
                break;
            }
        }
        if(owner!=null)
            // we know the plug-in that supports this namespace, but it's not enabled
            error( Messages.ERR_PLUGIN_NOT_ENABLED.format(owner.getOptionName(),uri));
        else {
            // this shouldn't happen, but be defensive...
            error( Messages.ERR_UNSUPPORTED_EXTENSION.format(uri) );
        }
    }

    // as an error recovery enable this namespace URI anyway.
    enabledExtensions.add(uri);
}