ok i found the answer by myself.
It can be done by accessing the WSO2 registry.
You have to save the loadbalance enpoint into registry.
Then make reference to these links
1) here is illustrated the way you can access the registry:
http://vvratha.blogspot.it/2013/02/accessing-registry-resources-from-class.html
2)here you can find how to convert the OMElment resulting from the regInstance.getResource(resourceKey) into a LoadBalance endpoint
https://svn.wso2.org/repos/wso2/carbon/platform/branches/4.0.0/dependencies/synapse/2.1.1-wso2v1/modules/core/src/test/java/org/apache/synapse/config/xml/endpoints/LoadBalanceEndpointSerializationTest.java
3) by this code you can add a new AddressEndpoint to it:
List<Endpoint>list = le.getChildren(); //le is LoadBalanceEndpoint instance
AddressEndpoint ad = new AddressEndpoint();
EndpointDefinition def = new EndpointDefinition();
def.setAddress("http:///your_address_url");
def.setAddressingOn(false);
def.setTimeoutAction(100);
ad.setDefinition(def);
list.add(ad);
le.setChildren(list);
note: if you want to access the loadbalance endpoint and to modify it in memory, use this:
LoadbalanceEndpoint le =(LoadbalanceEndpoint) synapseMsgContext.getConfiguration().getEndpoint("test");
4) After you have added the address point use the
regInstance.updateResource("key", LoadbalanceEndpointSerializer.getElementFromEndpoint(endpoint));
statement to update the registry.
This is the full code for working on the local registry:
Registry regInstance = synapseMsgContext.getConfiguration()
.getRegistry();
Object obj = (Object) regInstance.getResource(new Entry("diogene/diogeneEndpoints.xml"),null);
LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) LoadbalanceEndpointFactory.getEndpointFromElement((OMElement) obj, false, null);
List<Endpoint>list = endpoint.getChildren();
AddressEndpoint ad = new AddressEndpoint();
EndpointDefinition def = new EndpointDefinition();
def.setAddress("http://your_address_url/");
def.setAddressingOn(false);
def.setTimeoutAction(100);
ad.setDefinition(def);
list.add(ad);
endpoint.setChildren(list);
regInstance.updateResource("key", LoadbalanceEndpointSerializer.getElementFromEndpoint(endpoint));