Backport of various fixes on 11.x branch for GEOT-4770 and GEOT-4774

Please look at the following JIRAs:

http://jira.codehaus.org/browse/GEOT-4770
http://jira.codehaus.org/browse/GEOT-4774