Commit 882c823d authored by Nico Mack's avatar Nico Mack

Added support for multiple connectors and connections to Executors

parent 2c5db0df
CONNECTOR_BUILDER_NAMESPACE=lu.list.itis.dkd.tui.cps.system.connector.builder
CONNECTOR_BUILDER_POSTFIX=Connector
URL_ELEMENT=url
DRIVER_CLASS_ELEMENT=driverClass
USER_NAME_ELEMENT=username
PASSWORD_ELEMENT=password
AUTO_COMMIT_ELEMENT=autoCommit
...@@ -10,6 +10,8 @@ EXECUTOR_NAMESPACE=lu.list.itis.dkd.tui.cps.system.executor ...@@ -10,6 +10,8 @@ EXECUTOR_NAMESPACE=lu.list.itis.dkd.tui.cps.system.executor
NAMESPACE_SEPARATOR=. NAMESPACE_SEPARATOR=.
EXECUTOR_POSTFIX=Executor EXECUTOR_POSTFIX=Executor
CONNECTORS_ELEMENT=connectors
CONNECTOR_ELEMENT=connector
EQUATIONS_ELEMENT=equations EQUATIONS_ELEMENT=equations
EQUATION_ELEMENT=equation EQUATION_ELEMENT=equation
MODE_ATTRIBUTE=mode MODE_ATTRIBUTE=mode
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.bootstrapping;
import lu.list.itis.dkd.tui.cps.system.connector.Connector;
import lu.list.itis.dkd.tui.cps.system.connector.builder.BaseConnectorBuilder;
import lu.list.itis.dkd.tui.cps.system.connector.utility.ConnectorBundle;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.eclipse.swt.internal.C;
import org.jdom2.Element;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.2
* @version 2.3.0
*/
public class ConnectorBootstrapper {
/**
* Method used to determine the appropriate builder for a given object and then issue a build call.
*
* @param bootstrapContext
* @param callback
*
* @param connectorNode
* The node from a larger document that contains, as children, all the necessary information
* to resolve the correct builder and build the final tether.
* @return The final tether as defined by the children of the element node.
* @throws ClassNotFoundException
* Thrown when the class of the builder for the widget or those of the nested corona
* builder(s) could not be found.
* @throws SecurityException
* Thrown when the constructor cannot be retrieved due to some security constraints.
* @throws NoSuchMethodException
* Thrown when no constructor with the given parameter type is available.
* @throws InvocationTargetException
* Thrown if the invocation of any constructor through reflection throws an exception.
* @throws IllegalArgumentException
* Thrown when the provided argument is not eligible for the builder's constructor.
* @throws IllegalAccessException
* Thrown if this Constructor object is enforcing Java language access control and the
* underlying constructor is inaccessible.
* @throws InstantiationException
* Thrown if the class that declares the underlying constructor represents an abstract
* class.
* @throws BuildException
*/
@SuppressWarnings("unchecked")
public static Connector<C> buildConnectorFromElement(Element connectorNode, BootstrapContext bootstrapContext, BootstrapCallback callback) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, BuildException {
Connector<C> instance = null;
Element type = connectorNode.getChild(Externalization.TYPE_NODE);
Class<?> builder = Class.forName(ConnectorBundle.CONNECTOR_BUILDER_NAMESPACE + Externalization.NAMESPACE_SEPARATOR + type.getValue() + ConnectorBundle.CONNECTOR_BUILDER_POSTFIX + Externalization.BUILDER_CLASS_POSTFIX);
if ((bootstrapContext == null) || (bootstrapContext.size() == 0)) {
Constructor<BaseConnectorBuilder<?>> constructor = (Constructor<BaseConnectorBuilder<?>>) builder.getConstructor(new Class[] {Element.class});
instance = constructor.newInstance(new Object[] {connectorNode}).build();
} else {
Constructor<BaseConnectorBuilder<?>> constructor = (Constructor<BaseConnectorBuilder<?>>) builder.getConstructor(new Class[] {Element.class, BootstrapContext.class, BootstrapCallback.class});
instance = constructor.newInstance(new Object[] {connectorNode, bootstrapContext, callback}).build();
}
return instance;
}
}
\ No newline at end of file
...@@ -21,13 +21,16 @@ ...@@ -21,13 +21,16 @@
package lu.list.itis.dkd.tui.cps.system; package lu.list.itis.dkd.tui.cps.system;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault; import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.bootstrapping.ConnectorBootstrapper;
import lu.list.itis.dkd.tui.cps.InputChangeListener; import lu.list.itis.dkd.tui.cps.InputChangeListener;
import lu.list.itis.dkd.tui.cps.InputEvent; import lu.list.itis.dkd.tui.cps.InputEvent;
import lu.list.itis.dkd.tui.cps.Phenomenon; import lu.list.itis.dkd.tui.cps.Phenomenon;
import lu.list.itis.dkd.tui.cps.system.connector.Connector;
import lu.list.itis.dkd.tui.cps.system.executor.Executor; import lu.list.itis.dkd.tui.cps.system.executor.Executor;
import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle; import lu.list.itis.dkd.tui.cps.utility.EquationSystemBundle;
import lu.list.itis.dkd.tui.cps.variable.NumericalVariable; import lu.list.itis.dkd.tui.cps.variable.NumericalVariable;
import lu.list.itis.dkd.tui.cps.variable.Variable; import lu.list.itis.dkd.tui.cps.variable.Variable;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Point; import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.utility.StringUtils; import lu.list.itis.dkd.tui.utility.StringUtils;
...@@ -43,6 +46,7 @@ import org.slf4j.LoggerFactory; ...@@ -43,6 +46,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
...@@ -72,7 +76,9 @@ public class EquationSystemBuilder { ...@@ -72,7 +76,9 @@ public class EquationSystemBuilder {
private Document equationDocument; private Document equationDocument;
private Executor defaultExecutor; private Executor defaultExecutor;
private HashMap<String, Connector<?>> connectors;
private HashMap<String, Executor> executors; private HashMap<String, Executor> executors;
private HashMap<String, Executor> connectedExecutors;
private ConcurrentHashMap<String, Variable<?>> independentVariables; private ConcurrentHashMap<String, Variable<?>> independentVariables;
private ConcurrentHashMap<String, Variable<?>> dependentVariables; private ConcurrentHashMap<String, Variable<?>> dependentVariables;
...@@ -100,7 +106,9 @@ public class EquationSystemBuilder { ...@@ -100,7 +106,9 @@ public class EquationSystemBuilder {
this.properties = properties; this.properties = properties;
this.defaultExecutor = this.instantiateDefaultExecutor(properties); this.defaultExecutor = this.instantiateDefaultExecutor(properties);
connectors = new HashMap<>();
executors = new HashMap<>(); executors = new HashMap<>();
connectedExecutors = new HashMap<>();
executors.put(DEFAULT_EXECUTOR, this.defaultExecutor); executors.put(DEFAULT_EXECUTOR, this.defaultExecutor);
independentVariables = new ConcurrentHashMap<>(); independentVariables = new ConcurrentHashMap<>();
...@@ -482,6 +490,23 @@ public class EquationSystemBuilder { ...@@ -482,6 +490,23 @@ public class EquationSystemBuilder {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private void extractConnectors(List<Element> connectorElements) throws EquationSystemException {
try {
for (Element connectorElement : connectorElements) {
Connector<?> connector = ConnectorBootstrapper.buildConnectorFromElement(connectorElement, null, null);
connector.connect();
LOGGER.info("{} {} connected!", connector.getClass().getSimpleName(), connector.getName()); //$NON-NLS-1$
connectors.put(connector.getName(), connector);
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | BuildException e) {
EquationSystemException exception = new EquationSystemException("Failed to extract connectors!"); //$NON-NLS-1$
exception.setStackTrace(e.getStackTrace());
throw exception;
}
}
// ---------------------------------------------------------------------------
private void extractOutputs(List<Element> outputs) throws EquationSystemException { private void extractOutputs(List<Element> outputs) throws EquationSystemException {
if ((outputs == null) || (outputs.size() != 1)) { if ((outputs == null) || (outputs.size() != 1)) {
throw new EquationSystemException("The equation system MUST contain exactly one outputs section!"); //$NON-NLS-1$ throw new EquationSystemException("The equation system MUST contain exactly one outputs section!"); //$NON-NLS-1$
...@@ -499,11 +524,9 @@ public class EquationSystemBuilder { ...@@ -499,11 +524,9 @@ public class EquationSystemBuilder {
} }
outputVariables.put(identifier, this.createVariable(outputAttributes)); outputVariables.put(identifier, this.createVariable(outputAttributes));
dependentVariables.put(identifier, this.createVariable(outputAttributes)); dependentVariables.put(identifier, this.createVariable(outputAttributes));
} }
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
private void extractEquations(List<Element> equationElements) throws EquationSystemException { private void extractEquations(List<Element> equationElements) throws EquationSystemException {
...@@ -714,26 +737,43 @@ public class EquationSystemBuilder { ...@@ -714,26 +737,43 @@ public class EquationSystemBuilder {
} }
String script = null; String script = null;
String executor = null; String executorType = null;
Element invokeTag = equation.getChild(EquationSystemBundle.INVOKE_ELEMENT); Element invokeTag = equation.getChild(EquationSystemBundle.INVOKE_ELEMENT);
if (invokeTag != null) { if (invokeTag != null) {
script = invokeTag.getText(); script = invokeTag.getText();
executor = invokeTag.getAttributeValue(EquationSystemBundle.EXECUTOR_ATTRIBUTE); executorType = invokeTag.getAttributeValue(EquationSystemBundle.EXECUTOR_ATTRIBUTE);
if (!Strings.isNullOrEmpty(executor)) { if (!Strings.isNullOrEmpty(executorType)) {
if (!executors.containsKey(executor)) { if (!executors.containsKey(executorType)) {
executors.put(executor, this.instantiateExecutor(properties, executor)); executors.put(executorType, this.instantiateExecutor(properties, executorType));
} }
} else { } else {
executor = DEFAULT_EXECUTOR; executorType = DEFAULT_EXECUTOR;
} }
} }
Executor equationExecutor = null;
Element connectorTag = equation.getChild(EquationSystemBundle.CONNECTOR_ELEMENT);
if (connectorTag != null) {
String connectorName = connectorTag.getAttributeValue(EquationSystemBundle.NAME_ATTRIBUTE);
if (!Strings.isNullOrEmpty(connectorName))
if (!connectedExecutors.containsKey(connectorName)) {
Executor executor = this.instantiateExecutor(properties, executorType);
executor.setConnector(connectors.get(connectorName));
connectedExecutors.put(connectorName, executor);
}
equationExecutor = connectedExecutors.get(connectorName);
} else {
equationExecutor = executors.get(executorType);
}
Mapping variableMapping = new Mapping(equationInputs, equationOutputs); Mapping variableMapping = new Mapping(equationInputs, equationOutputs);
final LinearEquationSystem equationSystem = new LinearEquationSystem(lockToNesting); final LinearEquationSystem equationSystem = new LinearEquationSystem(lockToNesting);
Equation newEquation = new Equation(equationName, variableMapping, script); Equation newEquation = new Equation(equationName, variableMapping, script);
newEquation.setExecutor(executors.get(executor)); newEquation.setExecutor(equationExecutor);
newEquation.setIsolated(isolated); newEquation.setIsolated(isolated);
equationSystem.addEquation(newEquation); equationSystem.addEquation(newEquation);
equationSystem.setPriority(priority); equationSystem.setPriority(priority);
...@@ -863,6 +903,11 @@ public class EquationSystemBuilder { ...@@ -863,6 +903,11 @@ public class EquationSystemBuilder {
rootNode = rootNode.getChild(EquationSystemBundle.SYSTEM_ELEMENT); rootNode = rootNode.getChild(EquationSystemBundle.SYSTEM_ELEMENT);
} }
Element connectorsNode = rootNode.getChild(EquationSystemBundle.CONNECTORS_ELEMENT);
if (connectorsNode != null) {
extractConnectors(connectorsNode.getChildren(EquationSystemBundle.CONNECTOR_ELEMENT));
}
extractOutputs(rootNode.getChildren(EquationSystemBundle.OUTPUTS_ELEMENT)); extractOutputs(rootNode.getChildren(EquationSystemBundle.OUTPUTS_ELEMENT));
extractEquations(rootNode.getChild(EquationSystemBundle.EQUATIONS_ELEMENT).getChildren(EquationSystemBundle.EQUATION_ELEMENT)); extractEquations(rootNode.getChild(EquationSystemBundle.EQUATIONS_ELEMENT).getChildren(EquationSystemBundle.EQUATION_ELEMENT));
} }
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector;
import lu.list.itis.dkd.tui.cps.system.connector.builder.BaseConnectorBuilder;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition *
// ***************************************************************************
public abstract class Connector<C> {
private String name;
private boolean connected;
private C connection;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public Connector() {
connected = false;
}
// ---------------------------------------------------------------------------
public Connector(BaseConnectorBuilder<?> builder) {
this.name = builder.name;
this.connected = false;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public String getName() {
return this.name;
}
// ---------------------------------------------------------------------------
public void connect() {
this.connected = true;
}
// ---------------------------------------------------------------------------
public C getConnection() {
return this.connection;
}
// ---------------------------------------------------------------------------
public boolean isConnected() {
return this.connected;
}
// ---------------------------------------------------------------------------
public void disconnect() {
this.connected = false;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector;
import lu.list.itis.dkd.tui.cps.system.connector.builder.BaseJdbcConnectorBuilder;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition *
// ***************************************************************************
public class JdbcConnector extends Connector<Connection> {
private String url;
private String driverClass;
private String username;
private String password;
private boolean autoCommit;
private ComboPooledDataSource connectionPool;
// ***************************************************************************
// * Constants
// ***************************************************************************
private static final int MAX_CONNECTION_ATTEMPTS = 3;
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcConnector.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
public JdbcConnector(BaseJdbcConnectorBuilder<?> builder) {
super(builder);
this.url = builder.url;
this.driverClass = builder.driverClass;
this.username = builder.username;
this.password = builder.password;
this.autoCommit = builder.autoCommit;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private ComboPooledDataSource setupConnectionPool() {
ComboPooledDataSource pool;
pool = new ComboPooledDataSource();
try {
pool.setDriverClass(driverClass);
pool.setJdbcUrl(url);
pool.setUser(username);
pool.setPassword(password);
} catch (PropertyVetoException e) {
LOGGER.error("Failed to setup connection pool for {} driver class!", driverClass); //$NON-NLS-1$
}
return pool;
}
// ---------------------------------------------------------------------------
private void tearDownConnectionPool(ComboPooledDataSource pool) {
if (pool != null) {
pool.close();
LOGGER.info("Connection Pool successfully closed!"); //$NON-NLS-1$
}
}
// ---------------------------------------------------------------------------
private Connection getConnectionFromPool() {
Connection connection = null;
int attempt = 0;
int numberOfConnections = 0;
do {
try {
connection = connectionPool.getConnection();
connection.setAutoCommit(autoCommit);
numberOfConnections = connectionPool.getNumConnections();
} catch (SQLException exception) {
LOGGER.warn("Failed to acquire connection from Connection Pool for Datasource {}! Reconnection pool...", url); //$NON-NLS-1$
this.tearDownConnectionPool(connectionPool);
connectionPool = this.setupConnectionPool();
attempt++;
}
} while ((connection == null) && (attempt < MAX_CONNECTION_ATTEMPTS));
if (attempt >= MAX_CONNECTION_ATTEMPTS) {
LOGGER.error("Failed to acquire connection for {} attempts in a row. Giving up!", MAX_CONNECTION_ATTEMPTS); //$NON-NLS-1$
return null;
}
LOGGER.info("Datasource {} currently has a pool of {} open connections!", url, numberOfConnections); //$NON-NLS-1$
return connection;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// *Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
@Override
public void connect() {
connectionPool = this.setupConnectionPool();
super.connect();
}
// ---------------------------------------------------------------------------
@Override
public Connection getConnection() {
return this.getConnectionFromPool();
}
// ---------------------------------------------------------------------------
@Override
public void disconnect() {
super.disconnect();
this.tearDownConnectionPool(connectionPool);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.cps.system.connector.Connector;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public abstract class BaseConnectorBuilder<B extends BaseConnectorBuilder<B>> {
public String name;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseConnectorBuilder(Element rootElement) throws BuildException {
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public BaseConnectorBuilder(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.name = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.NAME_ATTRIBUTE, BootstrappingUtils.MANDATORY, null);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
public abstract Connector build();
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2019. All rights reserved. If you wish
* to use this code for any purpose, please contact the author(s).
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package lu.list.itis.dkd.tui.cps.system.connector.builder;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.cps.system.connector.JdbcConnector;
import lu.list.itis.dkd.tui.cps.system.connector.utility.ConnectorBundle;
import lu.list.itis.dkd.tui.exception.BuildException;
import org.jdom2.Element;
/**
* @author mack
* @since [major].[minor]
* @version [major].[minor].[micro]
*/
public abstract class BaseJdbcConnectorBuilder<B extends BaseJdbcConnectorBuilder<B>> extends BaseConnectorBuilder<B> {
public String url;
public String driverClass;
public String username;
public String password;
public boolean autoCommit;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------