1 24 25 package org.objectweb.dream.message.codec; 26 27 import java.util.Map ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.adl.Reconfiguration; 31 import org.objectweb.dream.adl.ReconfigurationFactory; 32 import org.objectweb.fractal.adl.ADLException; 33 import org.objectweb.fractal.api.Component; 34 import org.objectweb.fractal.api.NoSuchInterfaceException; 35 import org.objectweb.fractal.api.control.ContentController; 36 import org.objectweb.fractal.api.control.IllegalBindingException; 37 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 38 import org.objectweb.fractal.util.Fractal; 39 40 44 public class CodecManagerImpl extends AbstractComponent implements CodecManager 45 { 46 47 51 public static final String CODECS_COMPONENT_ITF_NAME = "codecs-component"; 52 53 protected CodecRepository codecRepositoryItf; 54 protected Component codecsCompositeItf; 55 protected ContentController codecsCCItf; 56 57 60 public void addCodec(String codecName, Map context) 61 throws CodecManagerException 62 { 63 Component codec = findCodec(codecName); 64 if (codec != null) 65 { 66 return; 67 } 68 String codecADL = codecRepositoryItf.getCodecADL(codecName); 69 if (codecADL == null) 70 { 71 throw new CodecManagerException(codecName, "Unknown codec."); 72 } 73 createCodec(codecName, codecADL, context); 74 } 75 76 79 public void removeCodec(String codecName) throws CodecManagerException 80 { 81 83 } 84 85 88 public Component getCodec(String codecName) throws CodecManagerException 89 { 90 Component codec = findCodec(codecName); 91 if (codec == null) 92 { 93 throw new CodecManagerException(codecName, "Unknown codec"); 94 } 95 return codec; 96 } 97 98 102 106 protected Component findCodec(String codecName) 107 { 108 Component[] codecs = codecsCCItf.getFcSubComponents(); 109 for (int i = 0; i < codecs.length; i++) 110 { 111 Component component = codecs[i]; 112 String name; 113 try 114 { 115 name = Fractal.getNameController(component).getFcName(); 116 } 117 catch (NoSuchInterfaceException e) 118 { 119 break; 120 } 121 if (codecName.equals(name)) 122 { 123 return component; 124 } 125 } 126 return null; 127 } 128 129 132 protected void createCodec(String codecName, String codecADL, Map context) 133 throws CodecManagerException 134 { 135 context.put("codecName", codecName); 136 try 137 { 138 Reconfiguration reconf = ReconfigurationFactory.getReconfiguration(); 139 reconf.addComponents(codecsCompositeItf, codecADL, context); 140 } 141 catch (ADLException e) 142 { 143 throw new CodecManagerException(codecName, 144 "Unable to create codec caused by :" + e.toString()); 145 } 146 } 147 148 152 155 public String [] listFc() 156 { 157 return new String []{CodecRepository.ITF_NAME, CODECS_COMPONENT_ITF_NAME}; 158 } 159 160 164 public synchronized void bindFc(String clientItfName, Object serverItf) 165 throws NoSuchInterfaceException, IllegalBindingException, 166 IllegalLifeCycleException 167 { 168 if (clientItfName.equals(CodecRepository.ITF_NAME)) 169 { 170 codecRepositoryItf = (CodecRepository) serverItf; 171 } 172 else if (clientItfName.equals(CODECS_COMPONENT_ITF_NAME)) 173 { 174 codecsCompositeItf = (Component) serverItf; 175 try 176 { 177 codecsCCItf = Fractal.getContentController(codecsCompositeItf); 178 } 179 catch (NoSuchInterfaceException e) 180 { 181 throw new IllegalBindingException("The " + CODECS_COMPONENT_ITF_NAME 182 + " client interface must be bound to a composite component"); 183 } 184 } 185 super.bindFc(clientItfName, serverItf); 186 } 187 } | Popular Tags |