General improvements, smaller refactorings

avoid casting, string switches....
we can use this pattern in org.exist.xquery.modules.jfreechart.JFreeChartFactory.setSeriesColors(java.lang.Object, java.lang.String)