1 22 23 package org.objectweb.petals.component.common.bc; 24 25 import org.objectweb.petals.component.common.AbstractComponent; 26 import org.objectweb.petals.component.common.HandlingException; 27 import org.objectweb.petals.component.common.su.BindingComponentServiceUnitManager; 28 import org.objectweb.petals.component.common.util.MessageExchangeWrapper; 29 import org.objectweb.petals.component.common.util.PetalsExtensionsUtil; 30 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions; 31 32 40 public abstract class AbstractBindingComponent extends AbstractComponent { 41 42 46 private BindingComponentInitializer initializer; 47 48 @Override 49 protected BindingComponentServiceUnitManager createServiceUnitManager() { 50 51 return new BindingComponentServiceUnitManager(getContext(), 52 getLogger(), this); 53 } 54 55 @Override 56 protected boolean onExchange(final MessageExchangeWrapper exchange, 57 final Extensions extensions) throws HandlingException { 58 String externalAddress = PetalsExtensionsUtil 59 .extractValueFromKeyValueExtension(extensions, 60 PetalsExtensionsUtil.ADDRESS); 61 62 JBIListener listener = initializer.getJbiListener(); 63 if (listener == null) { 64 throw new HandlingException("No jbi Listener provided. " 65 + "So provides node not allowed"); 66 } 67 68 return listener.onJBIMessage(externalAddress, exchange, extensions); 69 70 } 71 72 @Override 73 protected void init() { 74 super.init(); 75 initializer = new BindingComponentInitializer(); 76 init(initializer); 77 78 } 79 80 97 protected abstract void init(BindingComponentInitializer initializer); 98 99 106 public class BindingComponentInitializer { 107 108 private JBIListener jbiListener; 109 110 private ExternalListenerManager externalListenerManager; 111 112 public ExternalListenerManager getExternalListenerManager() { 113 return externalListenerManager; 114 } 115 116 public void setExternalListenerManager( 117 ExternalListenerManager externalListenerManager) { 118 this.externalListenerManager = externalListenerManager; 119 } 120 121 public JBIListener getJbiListener() { 122 return jbiListener; 123 } 124 125 public void setJbiListener(JBIListener jbiListener) { 126 this.jbiListener = jbiListener; 127 } 128 129 } 130 131 public BindingComponentInitializer getInitializer() { 132 return initializer; 133 } 134 135 } 136 | Popular Tags |