1 17 package org.apache.servicemix.client; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.component.ComponentContext; 21 import javax.naming.InitialContext ; 22 23 import org.apache.servicemix.jbi.container.JBIContainer; 24 import org.springframework.beans.factory.FactoryBean; 25 import org.springframework.beans.factory.InitializingBean; 26 27 36 public class ClientFactoryBean implements FactoryBean, InitializingBean { 37 38 private String name = ClientFactory.DEFAULT_JNDI_NAME; 39 private JBIContainer container; 40 private ClientFactory factory; 41 private ComponentContext context; 42 43 public ClientFactoryBean() { 44 } 45 46 49 public ComponentContext getContext() { 50 return context; 51 } 52 53 56 public void setContext(ComponentContext context) { 57 this.context = context; 58 } 59 60 63 public JBIContainer getContainer() { 64 return container; 65 } 66 67 70 public void setContainer(JBIContainer container) { 71 this.container = container; 72 } 73 74 77 public ClientFactory getFactory() { 78 return factory; 79 } 80 81 84 public void setFactory(ClientFactory factory) { 85 this.factory = factory; 86 } 87 88 91 public String getName() { 92 return name; 93 } 94 95 98 public void setName(String name) { 99 this.name = name; 100 } 101 102 public Object getObject() throws Exception { 103 return factory.createClient(); 104 } 105 106 public Class getObjectType() { 107 return ServiceMixClient.class; 108 } 109 110 public boolean isSingleton() { 111 return false; 112 } 113 114 public void afterPropertiesSet() throws Exception { 115 if (factory == null) { 116 if (context != null) { 117 factory = new ClientFactory() { 118 public ServiceMixClient createClient() throws JBIException { 119 return new ServiceMixClientFacade(context); 120 } 121 }; 122 } else if (container != null) { 123 factory = container.getClientFactory(); 124 } else { 125 factory = (ClientFactory) new InitialContext ().lookup(name); 126 } 127 } 128 } 129 130 } 131 | Popular Tags |