![JAR search and dependency download from the Maven repository](/logo.png)
io.bootique.linkmove.connector.URIConnectorFactoryFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bootique-linkmove Show documentation
Show all versions of bootique-linkmove Show documentation
Provides LinkMove integration with Bootique.
/*
* Licensed to ObjectStyle LLC under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ObjectStyle LLC licenses
* this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.bootique.linkmove.connector;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.inject.Injector;
import com.nhl.link.move.connect.StreamConnector;
import com.nhl.link.move.connect.URIConnector;
import com.nhl.link.move.runtime.connect.IConnectorFactory;
import io.bootique.annotation.BQConfig;
import io.bootique.annotation.BQConfigProperty;
import io.bootique.resource.ResourceFactory;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@BQConfig
@JsonTypeName("uri")
public class URIConnectorFactoryFactory implements IConnectorFactoryFactory {
private Map connectors;
public URIConnectorFactoryFactory() {
this.connectors = Collections.emptyMap();
}
@BQConfigProperty
public void setConnectors(Map connectors) {
this.connectors = connectors;
}
@Override
public Class getConnectorType() {
return StreamConnector.class;
}
@Override
public IConnectorFactory getConnectorFactory(Injector injector) {
Map connectorUris = new HashMap<>((int)(connectors.size() / 0.75d) + 1);
connectors.forEach((id, uri) -> connectorUris.put(id, connectorURI(id, uri)));
return id -> {
if (!connectorUris.containsKey(id)) {
throw new IllegalArgumentException("Unknown connector ID: " + id);
}
return new URIConnector(connectorUris.get(id));
};
}
protected URI connectorURI(String id, ResourceFactory resourceFactory) {
try {
return resourceFactory.getUrl().toURI();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid URI for connector with ID: " + id, e);
}
}
public Map getConnectors() {
return connectors;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy