refactoring the code

git-svn-id: https://svn.wso2.org/repos/wso2/carbon/platform/trunk@180095 a5903396-d722-0410-b921-86c7d4935375
fixing CARBON-14333, patch provided by Ananda Manoj

git-svn-id: https://svn.wso2.org/repos/wso2/carbon/platform/trunk@180096 a5903396-d722-0410-b921-86c7d4935375