you can define a Custom DestinationDataProvider to hold more than one Connection Profile. We dont use Property - Files here ,but I think this example should work.
Here a DataProvider to hold different Property Files, stored in a HashMap. The method JCoDestinationManager.getDestination calls the method getDestinationProperties inside the DataProvider and expects to get a Properties Object back. The method addConnectionProperties adds new Properties Objects to the HashMap.
Here you can also implement a method to read one big Property file.
But I'm too lazy for that ;)
Here an example
public class SapSystemDestinationDataProvider implements DestinationDataProvider {
private DestinationDataEventListener el;
private final HashMap<String, Properties> connectionProperties = new HashMap<>();
@Override
public Properties getDestinationProperties(String destinationName) {
if (connectionProperties.size() > 0) {
Properties con = connectionProperties.get(destinationName.toLowerCase().trim());
if (con != null) {
return con;
}
}
return null;
}
@Override
public boolean supportsEvents() {
return true;
}
@Override
public void setDestinationDataEventListener(DestinationDataEventListener dl) {
this.el = dl;
}
public void addConnectionProperties(String destName, Properties properties) {
connectionProperties.put(destName.toLowerCase().trim(), properties);
}
}
Then register the provider in your main programm
SapSystemDestinationDataProvider sapSystemProvider = new SapSystemDestinationDataProvider();
com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(sapSystemProvider );
Now read all your property files from disk and place the files in the Custom DestinationDataProvider.
InputStream input = new FileInputStream("path/to/connection_1.properties")) {
Properties prop = new Properties();
prop.load(input);
InputStream input2 = new FileInputStream("path/to/connection2.properties")) {
Properties prop2 = new Properties();
prop2.load(input2);
sapSystemProvider.addConnectionProperties("CONNECTION_1",prop);
sapSystemProvider.addConnectionProperties("CONNECTION_2", prop2);
Now you have 2 connections. You can access the connections via JCoDestinationManager.getDestination.
JCoDestination dest1 = JCoDestinationManager.getDestination("CONNECTION_1");
JCoDestination dest2 = JCoDestinationManager.getDestination("CONNECTION_2");
I never tried it, cause i use an external database to build up the Propertie Objects, but i think it should work. Let me know, how it works ;)