MatchUserRule(final MatchRule parent, final String userSpec) { super(parent.without(MatchNoUserRule.class)); this.userSpec = userSpec; }
MatchNoUserRule(final MatchRule parent) { super(parent.without(MatchUserRule.class)); }
MatchNetworkRule(final MatchRule parent, CidrAddress cidrAddress) { super(parent.without(MatchHostRule.class)); this.cidrAddress = cidrAddress; }
/** * Create a new rule which is the same as this rule, but also matches the given Internet network address. * * @param cidrAddress the network to match * @return the new rule */ public final MatchRule matchNetwork(CidrAddress cidrAddress) { if (cidrAddress == null) { return without(MatchHostRule.class).without(MatchNetworkRule.class); } else { return new MatchNetworkRule(this, cidrAddress); } }
MatchHostRule(final MatchRule parent, String hostSpec) { super(parent.without(MatchNetworkRule.class)); final Matcher matcher = validHostSpecPattern.matcher(hostSpec); if (! matcher.matches()) { throw log.invalidHostSpec(hostSpec); } suffixMatch = matcher.group(1) != null; this.hostSpec = matcher.group(2).toLowerCase(Locale.ROOT); }
MatchRule without(Class<? extends MatchRule> clazz) { if (clazz.isInstance(this)) return parent; MatchRule newParent = parent.without(clazz); if (parent == newParent) return this; return reparent(newParent); }
/** * Create a new rule which is the same as this rule, but also matches the given path name. * * @param pathSpec the path name to match * @return the new rule */ public final MatchRule matchPath(String pathSpec) { if (pathSpec == null || pathSpec.equals("**") || pathSpec.equals("/**")) { return without(MatchPathRule.class); } return new MatchPathRule(this, pathSpec); }
/** * Create a new rule which is the same as this rule, but also matches the given protocol (scheme) name. * * @param protoName the protocol name to match * @return the new rule */ public final MatchRule matchProtocol(String protoName) { if (protoName == null || protoName.equals("*")) { return without(MatchSchemeRule.class); } return new MatchSchemeRule(this, protoName); }
/** * Create a new rule which is the same as this rule, but also matches the given URN name. * * @param name the URN name to match * @return the new rule */ public final MatchRule matchUrnName(String name) { return name == null ? without(MatchSchemeSpecificPartRule.class) : new MatchSchemeSpecificPartRule(this, name); }
/** * Create a new rule which is the same as this rule, but also matches the given Internet address. * * @param inetAddress the address to match * @return the new rule */ public final MatchRule matchAddress(InetAddress inetAddress) { if (inetAddress == null) { return without(MatchHostRule.class).without(MatchNetworkRule.class); } else { return new MatchNetworkRule(this, CidrAddress.create(inetAddress, inetAddress instanceof Inet6Address ? 128 : 32)); } }
/** * Create a new rule which is the same as this rule, but also matches the given abstract type and type authority. * * @param typeName the type to match * @param authorityName the type authority name to match * @return the new rule */ public final MatchRule matchAbstractType(String typeName, String authorityName) { MatchRule baseRule; if (typeName == null || typeName.equals("*")) { baseRule = without(MatchAbstractTypeRule.class); } else { baseRule = new MatchAbstractTypeRule(this, typeName); } if (authorityName == null || authorityName.equals("*")) { return baseRule.without(MatchAbstractTypeAuthorityRule.class); } else { return new MatchAbstractTypeAuthorityRule(baseRule, authorityName); } }
/** * Create a new rule which is the same as this rule, but also matches the given host name. If the given string * appears to be an IP address or a CIDR network specification, then it is treated as such. * * @param hostSpec the host name to match * @return the new rule */ public final MatchRule matchHost(String hostSpec) { if (hostSpec == null || hostSpec.equals("*")) { return without(MatchHostRule.class).without(MatchNetworkRule.class); } final CidrAddress cidrAddress = Inet.parseCidrAddress(hostSpec); if (cidrAddress != null) { return new MatchNetworkRule(this, cidrAddress); } final InetAddress inetAddress = Inet.parseInetAddress(hostSpec); if (inetAddress != null) { return new MatchNetworkRule(this, CidrAddress.create(inetAddress, inetAddress instanceof Inet6Address ? 128 : 32)); } return new MatchHostRule(this, hostSpec); }
/** * Create a new rule which is the same as this rule, but also matches the given Internet network address. * * @param cidrAddress the network to match * @return the new rule */ public final MatchRule matchNetwork(CidrAddress cidrAddress) { if (cidrAddress == null) { return without(MatchHostRule.class).without(MatchNetworkRule.class); } else { return new MatchNetworkRule(this, cidrAddress); } }
/** * Create a new rule which is the same as this rule, but also matches the given URN name. * * @param name the URN name to match * @return the new rule */ public final MatchRule matchUrnName(String name) { return name == null ? without(MatchSchemeSpecificPartRule.class) : new MatchSchemeSpecificPartRule(this, name); }
/** * Create a new rule which is the same as this rule, but also matches the given protocol (scheme) name. * * @param protoName the protocol name to match * @return the new rule */ public final MatchRule matchProtocol(String protoName) { if (protoName == null || protoName.equals("*")) { return without(MatchSchemeRule.class); } return new MatchSchemeRule(this, protoName); }
MatchRule without(Class<? extends MatchRule> clazz) { if (clazz.isInstance(this)) return parent; MatchRule newParent = parent.without(clazz); if (parent == newParent) return this; return reparent(newParent); }
/** * Create a new rule which is the same as this rule, but also matches the given path name. * * @param pathSpec the path name to match * @return the new rule */ public final MatchRule matchPath(String pathSpec) { if (pathSpec == null || pathSpec.equals("**") || pathSpec.equals("/**")) { return without(MatchPathRule.class); } return new MatchPathRule(this, pathSpec); }
/** * Create a new rule which is the same as this rule, but also matches the given path name. * * @param pathSpec the path name to match * @return the new rule */ public final MatchRule matchPath(String pathSpec) { if (pathSpec == null || pathSpec.equals("**") || pathSpec.equals("/**")) { return without(MatchPathRule.class); } return new MatchPathRule(this, pathSpec); }