org.openqa.grid.internal.utils.DefaultCapabilityMatcher Java Examples

The following examples show how to use org.openqa.grid.internal.utils.DefaultCapabilityMatcher. 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: RevisedCapabilityMatcher.java    From Selenium-Foundation with Apache License 2.0 6 votes vote down vote up
/**
 * This constructor replaces the {@code SafariSpecificValidator} instance in the <b>validators</b> list of the
 * {@link DefaultCapabilityMatcher} with an instance of a dynamically-generated {@code RevisedSafariValidator}
 * class. This dynamic validator is functionally equivalent, but is implemented without explicit references to
 * the {@code SafariOptions} class.
 */
@SuppressWarnings("unchecked")
public RevisedCapabilityMatcher() {
    super();
    Field field = FieldUtils.getField(DefaultCapabilityMatcher.class, "validators", true);
    if (field != null) {
        field.setAccessible(true);
        try {
            List<Object> list = (List<Object>) field.get(this);
            Iterator<Object> iter = list.iterator();
            while (iter.hasNext()) {
                Object item = iter.next();
                Class<?> clazz = item.getClass();
                if (SAFARI_SPECIFIC_VALIDATOR.equals(clazz.getName())) {
                    Object validator = newSafariValidator(clazz);
                    iter.remove();
                    list.add(validator);
                    break;
                }
            }
        } catch (IllegalArgumentException | IllegalAccessException | ClassCastException | InstantiationException e) {
            // just eat the exception
        }
    }
}