Search in sources :

Example 1 with Operator

use of org.apache.ivy.osgi.filter.CompareFilter.Operator in project ant-ivy by apache.

the class RequirementAdapter method parseCompareFilter.

private void parseCompareFilter(CompareFilter compareFilter, boolean not) throws UnsupportedFilterException {
    String att = compareFilter.getLeftValue();
    if ("symbolicname".equals(att)) {
        att = BundleInfo.BUNDLE_TYPE;
    }
    switch(att) {
        case BundleInfo.BUNDLE_TYPE:
        case BundleInfo.EXECUTION_ENVIRONMENT_TYPE:
        case BundleInfo.PACKAGE_TYPE:
        case BundleInfo.SERVICE_TYPE:
            if (not) {
                throw new UnsupportedFilterException("Not filter on requirement comparison is not supported");
            }
            if (compareFilter.getOperator() != Operator.EQUALS) {
                throw new UnsupportedFilterException("Filtering is only supported with the operator '='");
            }
            if (type != null) {
                throw new UnsupportedFilterException("Multiple requirement type are not supported");
            }
            type = att;
            name = compareFilter.getRightValue();
            break;
        case "version":
            Version version = new Version(compareFilter.getRightValue());
            Operator operator = compareFilter.getOperator();
            if (not) {
                switch(operator) {
                    case EQUALS:
                        throw new UnsupportedFilterException("Not filter on equals comparison is not supported");
                    case GREATER_OR_EQUAL:
                        operator = Operator.LOWER_THAN;
                        break;
                    case GREATER_THAN:
                        operator = Operator.LOWER_OR_EQUAL;
                        break;
                    case LOWER_OR_EQUAL:
                        operator = Operator.GREATER_THAN;
                        break;
                    case LOWER_THAN:
                        operator = Operator.GREATER_OR_EQUAL;
                        break;
                }
            }
            switch(operator) {
                case EQUALS:
                    if (startVersion != null || endVersion != null) {
                        throw new UnsupportedFilterException("Multiple version matching is not supported");
                    }
                    startVersion = version;
                    startExclusive = false;
                    endVersion = version;
                    endExclusive = false;
                    break;
                case GREATER_OR_EQUAL:
                    if (startVersion != null) {
                        throw new UnsupportedFilterException("Multiple version matching is not supported");
                    }
                    startVersion = version;
                    startExclusive = false;
                    break;
                case GREATER_THAN:
                    if (startVersion != null) {
                        throw new UnsupportedFilterException("Multiple version matching is not supported");
                    }
                    startVersion = version;
                    startExclusive = true;
                    break;
                case LOWER_OR_EQUAL:
                    if (endVersion != null) {
                        throw new UnsupportedFilterException("Multiple version matching is not supported");
                    }
                    endVersion = version;
                    endExclusive = false;
                    break;
                case LOWER_THAN:
                    if (endVersion != null) {
                        throw new UnsupportedFilterException("Multiple version matching is not supported");
                    }
                    endVersion = version;
                    endExclusive = true;
                    break;
            }
            break;
        default:
            throw new UnsupportedFilterException("Unsupported attribute: " + att);
    }
}
Also used : Operator(org.apache.ivy.osgi.filter.CompareFilter.Operator) Version(org.apache.ivy.osgi.util.Version)

Aggregations

Operator (org.apache.ivy.osgi.filter.CompareFilter.Operator)1 Version (org.apache.ivy.osgi.util.Version)1