xml - Java config storage choice -
first of all, i'm new here writer, not reader. used stackoverflow years find lot of useful information, decided join community.
now question java config storage choice.
the application
currently i'm working on java (fx) project myself. java application used on few desktop machines. goal of application power on/off linux devices on ssh (for example server).
i want make possible user add 5/10 devices information of device (name , ip), ssh credentials power on command , ssh credentials power off command (user, host, key, port, timeout, command).
there javafx gui, gui have menu bar menu called devices select, add, edit or delete device. in center of gui there 2 buttons, used power on/off commands (or switch).
design
- the programming language java.
- the gui based on javafx.
- for power on/off commands use command design pattern.
storage
i tried different storage options (sqlite, properties , xml) storing information of devices. didnt found out option fits best in situation.
the sqlite storage felt big this.
if go seperated properties/xml storage, there wille around 5/10 different properties/xml files. application has switch between files.
if decide go multiple properties files, structure of file this:
device.name = server device.host = host.com power_on.key = /path/to/rsa power_on.user = user power_on.host = host.com power_on.port = 22 power_on.timeout = 10000 power_on.command = execute power on command power_off.key = /path/to/rsa power_off.user = user power_off.host = host.com power_off.port = 22 power_off.timeout = 10000 power_off.command = execute power off command
if decide go multiple xml files, structure of file this:
<device> <name>server</name> <host>host.com</host> <commands> <poweron> <key>/path/to/rsa</key> <user>user</user> <host>host.com</host> <port>22</port> <timeout>10000</timeout> <command>execute power on command</command> </poweron> <poweroff> <key>/path/to/rsa</key> <user>user</user> <host>host.com</host> <port>22</port> <timeout>10000</timeout> <command>execute power off command</command> </poweroff> </commands> </device>
if decide go 1 properties file, structure of file this:
# device 1 server.device.name = server server.device.host = host.com server.power_on.key = /path/to/rsa server.power_on.user = user server.power_on.host = host.com server.power_on.port = 22 server.power_on.timeout = 10000 server.power_on.command = execute power on command server.power_off.key = /path/to/rsa server.power_off.user = user server.power_off.host = host.com server.power_off.port = 22 server.power_off.timeout = 10000 server.power_off.command = execute power off command # device 2 pc.device.name = pc pc.device.host = host.com pc.power_on.key = /path/to/rsa pc.power_on.user = user pc.power_on.host = host.com pc.power_on.port = 22 pc.power_on.timeout = 10000 pc.power_on.command = execute power on command pc.power_off.key = /path/to/rsa pc.power_off.user = user pc.power_off.host = host.com pc.power_off.port = 22 pc.power_off.timeout = 10000 pc.power_off.command = execute power off command
if decide go 1 xml file, structure of file this:
<devices> <device> <name>server</name> <host>host.com</host> <commands> <poweron> <key>/path/to/rsa</key> <user>user</user> <host>host.com</host> <port>22</port> <timeout>10000</timeout> <command>execute power on command</command> </poweron> <poweroff> <key>/path/to/rsa</key> <user>user</user> <host>host.com</host> <port>22</port> <timeout>10000</timeout> <command>execute power off command</command> </poweroff> </commands> </device> <device> <name>pc</name> <host>host.com</host> <commands> <poweron> <key>/path/to/rsa</key> <user>user</user> <host>host.com</host> <port>22</port> <timeout>10000</timeout> <command>execute power on command</command> </poweron> <poweroff> <key>/path/to/rsa</key> <user>user</user> <host>host.com</host> <port>22</port> <timeout>10000</timeout> <command>execute power off command</command> </poweroff> </commands> </device> </devices>
question
my question is; storage choice (and/or design pattern) fits best in situation? makes me confused because tried different things without solution yet.
i hope guys can me out this. feedback, suggestions etc welcome. thank in advance!
you have several options. mentioned, properties files simplest approach. no additional libraries needed, in jdk.
on other hand however, if want more, use
- yaml
- json
- xml
- something custom
i go against xml if configuration hand-edited frequently. personal preference storing configuration in single json file, each device having own dict. json has editor , tool support.
Comments
Post a Comment