1 31 package org.objectweb.proactive.core.component.xml; 32 33 import org.objectweb.fractal.api.Component; 34 import org.objectweb.fractal.api.NoSuchInterfaceException; 35 import org.objectweb.fractal.api.control.BindingController; 36 import org.objectweb.fractal.api.control.IllegalBindingException; 37 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 38 import org.objectweb.proactive.core.component.Constants; 39 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator; 40 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller; 41 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 42 import org.objectweb.proactive.core.xml.io.Attributes; 43 import org.xml.sax.SAXException ; 44 45 48 public class BindingsHandler extends AbstractUnmarshallerDecorator { 51 ComponentsCache componentsCache; 52 public BindingsHandler(ComponentsCache componentsCache) { 53 this.componentsCache = componentsCache; 54 addHandler(ComponentsDescriptorConstants.BINDING_TAG, new BindingHandler()); 55 56 } 57 58 public class BindingHandler extends BasicUnmarshaller { 60 61 private String clientComponent = null; 62 private String clientInterface = null; 63 private String serverComponent = null; 64 private String serverInterface = null; 65 66 public BindingHandler() { 67 } 68 69 private void setClient(String client) { 70 clientComponent = client.substring(0, client.indexOf('.')); 71 clientInterface = client.substring(client.indexOf('.') + 1, client.length()); 72 } 73 74 private void setServer(String server) { 75 serverComponent = server.substring(0, server.indexOf('.')); 76 serverInterface = server.substring(server.indexOf('.') + 1, server.length()); 77 } 78 79 82 public void startContextElement(String name, Attributes attributes) throws SAXException { 83 logger.debug("*****inside binding handler"); 84 85 String client = attributes.getValue(ComponentsDescriptorConstants.BINDING_CLIENT_TAG); 86 if (!checkNonEmpty(client)) { 87 throw new SAXException ("binding client interface unspecified"); 88 } 89 String server = attributes.getValue(ComponentsDescriptorConstants.BINDING_SERVER_TAG); 90 if (!checkNonEmpty(server)) { 91 throw new SAXException ("binding server interfaceunspecified"); 92 } 93 setClient(client); 94 setServer(server); 95 try { 97 if(!componentsCache.containsComponentNamed(serverComponent)) { 98 throw new SAXException ("tried to perform a binding from " + serverComponent +'.' + serverInterface + " , but " + serverComponent + " does not exist"); 99 } 100 ( 101 (BindingController) componentsCache.getComponent(clientComponent).getFcInterface( 102 Constants.BINDING_CONTROLLER)).bindFc( 103 clientInterface, 104 ((Component) componentsCache.getComponent(serverComponent)).getFcInterface(serverInterface)); 105 logger.debug( 106 "**** bound " 107 + clientComponent 108 + "." 109 + clientInterface 110 + " to " 111 + serverComponent 112 + "." 113 + serverInterface); 114 } catch (NoSuchInterfaceException nsie) { 115 nsie.printStackTrace(); 116 throw new SAXException ("error while parsing", nsie); 117 } catch (IllegalLifeCycleException ilce) { 118 ilce.printStackTrace(); 119 throw new SAXException ("error while parsing", ilce); 120 } catch (IllegalBindingException ibe) { 121 ibe.printStackTrace(); 122 throw new SAXException ("error while parsing", ibe); 123 } 124 125 } 126 127 130 public void endElement(String name) throws SAXException { 131 } 132 133 } 134 137 protected void notifyEndActiveHandler(String name, UnmarshallerHandler activeHandler) throws SAXException { 138 } 139 140 143 public Object getResultObject() throws SAXException { 144 return null; 145 } 146 147 150 public void startContextElement(String name, Attributes attributes) throws SAXException { 151 } 152 153 } | Popular Tags |