001    /*
002    @license.text@
003     */
004    package biz.hammurapi.util;
005    
006    import java.rmi.RemoteException;
007    
008    import org.w3c.dom.Element;
009    import org.w3c.dom.Node;
010    
011    import biz.hammurapi.config.ConfigurationException;
012    import biz.hammurapi.config.Context;
013    import biz.hammurapi.config.RmiComponent;
014    
015    /**
016     * Exposes local worker as remote
017     * @author Pavel Vlasov
018     * @revision $Revision$
019     */
020    public class WorkerRemotizer extends RmiComponent implements RemoteWorker {
021            private String masterRef;
022            private Worker master;
023            
024            public WorkerRemotizer() throws RemoteException {
025                    super();
026            }
027    
028            public boolean post(Runnable job) {
029                    return master.post(job);
030            }
031            
032            public void configure(Node configNode, Context context) {
033                    super.configure(configNode, context);
034                    Element ce=(Element) configNode;
035                    if (ce.hasAttribute("worker-ref")) {
036                            masterRef=ce.getAttribute("worker-ref");
037                    }
038            }
039            
040            public void start() throws ConfigurationException {
041                    super.start();
042                    if (owner instanceof Context) {
043                            master=(Worker) ((Context) owner).get(masterRef);
044                    } else {
045                            throw new ConfigurationException("Cannot lookup master - owner is not a context");
046                    }
047            }
048    
049    }