frazman
frazman

Reputation: 33223

Design advice for writing an interface in java

I am new to java but I am actually liking it because, believe it or not, it is improving the way I code. (I guess because it forces you to write the code OO way)

Anyways, I am writing a java library which looks like this. On the base there is core library and then some toolkits built on top of it.

Now all the toolkits have part of code in common.

For example, reading the config file for that toolkit. Example: toolkitA/config/config.cfg

config.cfg
inputDir = /path/to/input
outputDir = /path/to/output



toolkitB/config/config.cfg

config.cfg
inputDir = /path/to/input
// no output here.. maybe this toolkit is just to analyze the input

The issue is.. alot of these configs are unknown as I am still in process of creating a toolkit and even I dont know what toolkit will be there in future.

As of now, the code flow is as follows.

 main--> readconfig-->parseconfig--> execute the source code with params. 
  parsed from the source parseconfig

My key question is as these config files are in the toolkits level, these config doesnt connects at all with the source code library. The core library is oblivious of the fact that these parameters are actually set up by user in config file. Now... maybe its because of java but I find this very superficial. What I would want is something like this

  main--> a core config file setter which reads and parses this tool kit config file --> 
  the core library then interacts with these  objects rather than the superficial level.

How do I achieve this.

(being an avid stackoverflow user.. I know.. its not really "error" related question but I dont know what to search also or how to set such config stuff.. all i have is the idea on how I want this thing to be implemented.. :( )

Upvotes: 0

Views: 71

Answers (1)

ggrandes
ggrandes

Reputation: 2133

Well... your cfg files are like Properties, this accept "InputStream" in load

Second, you can post these configs in classpath and load as InputStreams with getResourceAsStream

InputStream is = Object.class.getClass().getResourceAsStream(CONFIG_FILE);
Properties cfg = new Properties();
cfg.load(is);

Upvotes: 2

Related Questions