/** * Returns the {@link BackendFactory} identified by the given URI {@code scheme}. * * @param scheme the URI scheme identifying the factory * * @return the factory * * @throws IllegalArgumentException if {@code scheme} is {@code null}, or if no factory is registered for the {@code * scheme} */ @Nonnull public BackendFactory getFactoryFor(String scheme) { checkNotNull(scheme, "scheme"); if (isRegistered(scheme)) { return factories.get(scheme); } throw new IllegalArgumentException(String.format("No factory is registered to process the URI scheme '%s'", scheme)); }
@Nonnull @Override public URI createLocalUri(URI uri) { if (!supportsLocal) { throw new UnsupportedOperationException(String.format("%s does not support file-based URI", getClass().getSimpleName())); } checkNotNull(uri, "uri"); if (Objects.equals(scheme(), uri.scheme())) { checkArgument(BackendFactoryRegistry.getInstance().isRegistered(uri.scheme()), "Unregistered scheme (%s)", uri.scheme()); return new FileBasedUri(uri); } if (Objects.equals(FileBasedUri.SCHEME, uri.scheme())) { return createLocalUri(new File(uri.toFileString())); } throw new IllegalArgumentException(String.format("Cannot create URI with the scheme %s", uri.scheme())); }
@Nonnull @Override public URI createRemoteUri(InetAddress host, int port, String model) { if (!supportsRemoteUris()) { throw new UnsupportedOperationException(String.format("%s does not support server-based URIs", getClass().getSimpleName())); } checkNotNull(host, "host"); checkGreaterThanOrEqualTo(port, 0, "port (%d) must be between 0-65535", port); checkLessThanOrEqualTo(port, 65535, "port (%d) must be between 0-65535", port); checkNotNull(model, "model"); checkArgument(BackendFactoryRegistry.getInstance().isRegistered(scheme()), "Unregistered scheme (%s)", scheme()); return URI.createHierarchicalURI(scheme(), host.getHostAddress() + ':' + port, null, new String[]{model}, null, null); } }
/** * {@inheritDoc} * <p> * The {@code uri} must be registered in the {@link BackendFactoryRegistry}. */ @Nonnull @Override public PersistentResource createResource(URI uri) { checkNotNull(uri, "uri"); checkArgument(BackendFactoryRegistry.getInstance().isRegistered(uri.scheme()), "Unregistered scheme (%s)", uri.scheme()); return new DefaultPersistentResource(uri); }