1 24 25 package org.objectweb.dream.pushwithreturn; 26 27 import org.objectweb.dream.AbstractComponent; 28 import org.objectweb.dream.message.ExtensibleMessage; 29 import org.objectweb.dream.message.Message; 30 import org.objectweb.dream.message.manager.MessageManager; 31 import org.objectweb.fractal.api.NoSuchInterfaceException; 32 import org.objectweb.fractal.api.control.IllegalBindingException; 33 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 34 35 39 public class KeyGeneratorIntegerImpl extends AbstractComponent 40 implements 41 KeyGenerator 42 { 43 44 public static final KeyInteger ALL_INTEGER_KEY = new KeyInteger(0, true); 45 46 47 int lastInSequence = 0; 48 49 50 MessageManager messageManagerItf; 51 52 58 public Key generateKey(Message message) throws Exception 59 { 60 KeyChunk keyChunk = (KeyChunk) message.getChunk(KeyChunk.DEFAULT_NAME); 61 if (keyChunk != null) 62 { 63 return keyChunk.getKey(); 64 } 65 if (message instanceof ExtensibleMessage) 66 { 67 KeyInteger key = new KeyInteger(++lastInSequence, false); 68 keyChunk = (KeyChunk) messageManagerItf.createChunk(KeyChunk.TYPE); 69 keyChunk.setKey(key); 70 ((ExtensibleMessage) message).addChunk(KeyChunk.DEFAULT_NAME, 71 KeyChunk.TYPE, keyChunk); 72 return key; 73 } 74 else 75 { 76 throw new Exception ("Unable to add KeyChunk to message " + message); 77 } 78 } 79 80 84 88 public void bindFc(String clientItfName, Object serverItf) 89 throws NoSuchInterfaceException, IllegalBindingException, 90 IllegalLifeCycleException 91 { 92 super.bindFc(clientItfName, serverItf); 93 if (clientItfName.equals(MessageManager.ITF_NAME)) 94 { 95 messageManagerItf = (MessageManager) serverItf; 96 } 97 } 98 99 102 public String [] listFc() 103 { 104 return new String []{MessageManager.ITF_NAME}; 105 } 106 107 } | Popular Tags |