sipXconfig
Friday, May 26, 2006
Java formatting progress
Java 1.4
private String getUrl() {
Object params = new Object[] {
m_host, Integer.toString(m_port)
};
return MessageFormat.format("ldap://{0}:{1}", params);
}
Java 1.5 argv and autoboxing...
private String getUrl() {
return MessageFormat.format("ldap://{0}:{1}", m_host, m_port);
}
Java 1.5 String.format
private String getUrl() {
return String.format("ldap://%s:%d", m_host, m_port);
}
you can get rid of String. using static import but I am not sure I like it
import static java.lang.String.format;
....
private String getUrl() {
return format("ldap://%s:%d", m_host, m_port);
}
of course Ruby is still better:
def get_url
"ldap://#{@host}:#{@port}"
end
Thursday, May 11, 2006
Settings Refactoring
sipXconfig can configure 6 different hardward devices and at least that many servers. There are potentially thousands of settings that can be changed. Naturally we invented a meta-model to describe these settings and how they work so we wouldn't have to code each setting in java.
Typically the problem with meta-models is that when you actually *want* to code in java for a particular because of special handling you have to deal with a cumbersome syntax.
For example, let's say I want to convert the GMT offset from minutes to hours for a phone, in java I would like to do this:
public int getGmtOffset() {
return m_zone.getGmtOffset() / 60;
}
but instead I have to do this:
Setting s = getSettings().getSetting("sntp/gmtOffset");
s.setValue(String.valueOf(m_zone.getGmtOffset() / 60));
no big deal when it's just one or two setttings, but the more and more setting you write using the meta model language, the harder it is to maintain.
So... I refactored settings so that you can write in java for most things. It relies on Java annotations, it was pretty simple. Now I'm converting all the old code, so I can simplify the system. I was pleasantly please after refactoring the code for one of the more complex devices: Polycom Soundpoint with this warning from Eclipse: