@Override public String getProvider() { final String v = this.value("Vendor"); if(StringUtils.isBlank(v)) { return parent.getProvider(); } return v; }
/** * @param enabled List of protocols * @param identifier Serialized protocol reference or scheme * @param provider Custom inherited protocol definition * @return Matching protocol or null if no match */ public Protocol forName(final List<Protocol> enabled, final String identifier, final String provider) { final Protocol match = // Matching hash code backward compatibility enabled.stream().filter(protocol -> String.valueOf(protocol.hashCode()).equals(identifier)).findFirst().orElse( // Matching vendor string for third party profiles enabled.stream().filter(protocol -> new ProfileProtocolPredicate().test(protocol) && StringUtils.equals(protocol.getProvider(), provider)).findFirst().orElse( // Matching vendor string usage in CLI enabled.stream().filter(protocol -> StringUtils.equals(protocol.getProvider(), identifier)).findFirst().orElse( // Fallback for bug in 6.1 enabled.stream().filter(protocol -> StringUtils.equals(String.format("%s-%s", protocol.getIdentifier(), protocol.getProvider()), identifier)).findFirst().orElse( // Matching scheme with fallback to generic protocol type this.forScheme(enabled, identifier, enabled.stream().filter(protocol -> StringUtils.equals(protocol.getType().name(), identifier)).findFirst().orElse(null)) ) ) ) ); if(null == match) { if(enabled.isEmpty()) { log.error(String.format("List of registered protocols in %s is empty", this)); } log.error(String.format("Missing registered protocol for identifier %s", identifier)); } return match; }
@Override public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof Protocol)) { return false; } Protocol protocol = (Protocol) o; if(this.getIdentifier() != null ? !this.getIdentifier().equals(protocol.getIdentifier()) : protocol.getIdentifier() != null) { return false; } if(this.getScheme() != null ? !this.getScheme().equals(protocol.getScheme()) : protocol.getScheme() != null) { return false; } if(this.getProvider() != null ? !this.getProvider().equals(protocol.getProvider()) : protocol.getProvider() != null) { return false; } return true; }
protected static String getScheme(final Protocol protocol) { if(new BundledProtocolPredicate().test(protocol)) { for(String scheme : protocol.getSchemes()) { // Return first custom scheme registered return scheme; } // Return default name return protocol.getIdentifier(); } // Find parent protocol definition for profile final Protocol standard = ProtocolFactory.get().forName(protocol.getIdentifier()); if(Arrays.equals(protocol.getSchemes(), standard.getSchemes())) { // No custom scheme set in profile return protocol.getProvider(); } for(String scheme : protocol.getSchemes()) { // First custom scheme in profile return scheme; } // Default vendor string of third party profile return protocol.getProvider(); } }
@Override public boolean equals(Object o) { if(this == o) { return true; } if(!(o instanceof Protocol)) { return false; } Protocol protocol = (Protocol) o; if(this.getIdentifier() != null ? !this.getIdentifier().equals(protocol.getIdentifier()) : protocol.getIdentifier() != null) { return false; } if(this.getScheme() != null ? !this.getScheme().equals(protocol.getScheme()) : protocol.getScheme() != null) { return false; } if(this.getContext() != null ? !this.getContext().equals(protocol.getContext()) : protocol.getContext() != null) { return false; } if(this.getAuthorization() != null ? !this.getAuthorization().equals(protocol.getAuthorization()) : protocol.getAuthorization() != null) { return false; } if(this.getProvider() != null ? !this.getProvider().equals(protocol.getProvider()) : protocol.getProvider() != null) { return false; } if(this.getDefaultHostname() != null ? !this.getDefaultHostname().equals(protocol.getDefaultHostname()) : protocol.getDefaultHostname() != null) { return false; } return true; }
@Override public <T> T serialize(final Serializer dict) { dict.setStringForKey(protocol.getIdentifier(), "Protocol"); if(StringUtils.isNotBlank(protocol.getProvider())) { if(!StringUtils.equals(protocol.getProvider(), protocol.getIdentifier())) { dict.setStringForKey(protocol.getProvider(), "Provider");