1 7 8 package org.jboss.media.engine; 9 10 import java.net.URL ; 11 import java.util.Iterator ; 12 import java.util.Vector ; 13 14 import javax.management.Attribute ; 15 import javax.management.AttributeNotFoundException ; 16 import javax.management.InstanceNotFoundException ; 17 import javax.management.InvalidAttributeValueException ; 18 import javax.management.MBeanException ; 19 import javax.management.MBeanServer ; 20 import javax.management.MalformedObjectNameException ; 21 import javax.management.ObjectName ; 22 import javax.management.ReflectionException ; 23 24 import org.jboss.deployment.DeploymentException; 25 import org.jboss.logging.Logger; 26 import org.jboss.media.emb.CaptureMetaData; 27 import org.jboss.mx.util.MBeanProxy; 28 import org.jboss.mx.util.MBeanProxyCreationException; 29 import org.w3c.dom.DOMException ; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 import org.w3c.dom.Node ; 33 import org.w3c.dom.NodeList ; 34 35 39 public class MediaXmlLoader 40 { 41 public static final String PUBLISHER_FACTORY_TAG = "publisher-factory"; 42 43 public static final String PUBLISHER_TAG = "publisher"; 44 public static final String PUBLISHER_CLASS = "class"; 45 public static final String PUBLISHER_HOST = "host"; 46 public static final String PUBLISHER_PORT = "port"; 47 public static final String PUBLISHER_CONTEXT = "context"; 48 public static final String PUBLISHER_START = "true"; 49 50 public static final String TRANCODER_TAG = "transcoder-name"; 51 public static final String PLUGIN_REGISTRY_TAG = "plugin-registry-name"; 52 53 public static final String PLUGIN_GRAPH_TAG = "plugin-graph"; 54 public static final String PLUGIN_TAG = "plugin"; 55 public static final String PLUGIN_NAME_ATT = "name"; 56 57 public static final String CAPTURE_DEVICE_TAG = "capture"; 58 public static final String CAPTURE_DEVICE_NAME_ATT = "device"; 59 public static final String CAPTURA_DEVICE_TYPE_ATT = "type"; 60 61 public static final String SOURCE = "source"; 62 public static final String FILE_NAME = "file-name"; 63 64 private static Logger log = Logger.getLogger(MediaXmlLoader.class); 65 66 public static boolean deployXML(Document doc, URL url, MBeanServer server) 67 throws 68 MalformedObjectNameException , 69 DOMException , 70 DeploymentException, 71 MediaPluginGraphException 72 { 73 74 ObjectName m_factory; 75 76 ObjectName m_name; 77 MediaPluginRegistryMBean reg = null; 78 79 m_factory = null; 80 81 String publisher = ""; 82 String publisher_class = ""; 83 String publisher_host = ""; 84 String publisher_port = ""; 85 String publisher_context = ""; 86 87 ObjectName transcoder = null; 88 89 ObjectName pluginRegistry = null; 90 MediaPluginGraph pluginGraph = null; 91 92 CaptureMetaData captureMetadata = null; 93 94 String source = null; 95 96 int pluginNum = 0; 97 98 Vector extraAttributes = new Vector (); 99 boolean shouldStart = false; 100 101 NodeList children = doc.getDocumentElement().getChildNodes(); 102 for (int i = 0; i < children.getLength(); i++) 103 { 104 if (children.item(i).getNodeType() == Node.ELEMENT_NODE) 105 { 106 Element element = (Element ) children.item(i); 107 String tag = element.getTagName(); 108 109 if (tag.equals(PUBLISHER_FACTORY_TAG)) 110 { 111 m_factory = 112 new ObjectName ( 113 element.getChildNodes().item(0).getNodeValue()); 114 115 } 116 117 else if (tag.equals(PUBLISHER_TAG)) 118 { 119 publisher_class = element.getAttribute(PUBLISHER_CLASS); 120 publisher_host = element.getAttribute(PUBLISHER_HOST); 121 publisher_port = element.getAttribute(PUBLISHER_PORT); 122 publisher_context = element.getAttribute(PUBLISHER_CONTEXT); 123 124 NodeList attributes = element.getChildNodes(); 125 126 for (int k = 0; k < attributes.getLength(); k++) 128 { 129 if (attributes.item(k).getNodeType() == Node.ELEMENT_NODE) 130 { 131 Element attribute = (Element ) attributes.item(k); 132 String name = attribute.getAttribute("name"); 133 String value = 134 attribute.getChildNodes().item(0).getNodeValue(); 135 Attribute at = null; 137 try 138 { 139 140 at = new Attribute (name, Integer.decode(value)); 141 } 142 catch (NumberFormatException e) 143 { 144 at = new Attribute (name, value); 145 } 146 147 log.info(name + "=" + value); 149 extraAttributes.add(at); 150 } 151 152 } 153 154 if (element.getAttribute("start").equals("true")) 155 { 156 shouldStart = true; 157 } 158 159 } 160 161 else if (tag.equals(TRANCODER_TAG)) 162 { 163 } 165 166 else if (tag.equals(PLUGIN_REGISTRY_TAG)) 167 { 168 pluginRegistry = 169 new ObjectName ( 170 element.getChildNodes().item(0).getNodeValue()); 171 172 try 173 { 174 reg = 175 (MediaPluginRegistryMBean) MBeanProxy.create( 176 MediaPluginRegistry.class, 177 MediaPluginRegistryMBean.class, 178 pluginRegistry, 179 server); 180 } 181 catch (MBeanProxyCreationException e) 182 { 183 log.error("MBeanProxyCreationException", e); 185 } 186 } 187 188 else if (tag.equals(PLUGIN_GRAPH_TAG)) 189 { 190 pluginGraph = new MediaPluginGraph(); 191 NodeList plugins = element.getChildNodes(); 192 193 for (int k = 0; k < plugins.getLength(); k++) 194 { 195 if (plugins.item(k).getNodeType() == Node.ELEMENT_NODE) 196 { 197 Element pluginElement = (Element ) plugins.item(k); 198 String plugin = pluginElement.getTagName(); 199 200 203 String pluginName = 204 pluginElement.getAttribute(PLUGIN_NAME_ATT); 205 log.info("plugin " + pluginNum + "is " + pluginName); 206 pluginGraph.addPlugin( 207 reg.getPlugin(pluginName), 208 pluginNum); 209 pluginNum++; 210 211 } 213 } 214 } 215 216 else if (tag.equals(CAPTURE_DEVICE_TAG)) 217 { 218 } 220 221 else if (tag.equals(SOURCE)) 222 { 223 source = element.getAttribute(FILE_NAME); 224 } 225 226 else 227 { 228 log.warn("Unknown EMB tag: " + tag); 229 } 230 } 231 } 232 233 log.info(m_factory); 234 log.info(publisher); 235 log.info(publisher_class); 236 log.info(publisher_host); 237 log.info(publisher_port); 238 log.info(publisher_context); 239 240 log.info(transcoder); 241 242 log.info(pluginRegistry); 243 log.info(pluginGraph); 244 245 log.info(captureMetadata); 246 247 log.info(source); 248 249 MediaPublisherFactoryMBean pub = null; 250 251 try 252 { 253 pub = 255 (MediaPublisherFactoryMBean) MBeanProxy.create( 256 MediaPublisherFactory.class, 257 MediaPublisherFactoryMBean.class, 258 m_factory, 259 server); 260 } 261 catch (MBeanProxyCreationException e) 262 { 263 log.error("MBeanProxyCreationException", e); 265 } 266 267 ObjectName result = 268 pub.createPublisher( 269 publisher_class, 270 publisher_context, 271 publisher_host, 272 Integer.parseInt(publisher_port), 273 publisher, 274 source); 275 276 for (Iterator iter = extraAttributes.iterator(); iter.hasNext();) 277 { 278 Attribute at = (Attribute ) iter.next(); 279 280 try 281 { 282 server.setAttribute(result, at); 283 } 284 catch (InstanceNotFoundException e) 285 { 286 log.error(e); 287 } 288 catch (AttributeNotFoundException e) 289 { 290 log.error(e); 291 } 292 catch (InvalidAttributeValueException e) 293 { 294 log.error(e); 295 } 296 catch (MBeanException e) 297 { 298 log.error(e); 299 } 300 catch (ReflectionException e) 301 { 302 log.error(e); 303 } 304 305 } 306 307 MediaPublisherMBean pubObj = null; 308 309 try 310 { 311 pubObj = 312 (MediaPublisherMBean) MBeanProxy.create( 313 MediaPublisher.class, 314 MediaPublisherMBean.class, 315 result, 316 server); 317 } 318 catch (MBeanProxyCreationException e) 319 { 320 log.error("MBeanProxyCreationException", e); 322 } 323 324 pubObj.addPluginGraph(pluginGraph); 325 326 if (shouldStart) 327 { 328 try 329 { 330 pubObj.publish(); 331 } 332 catch (Exception e) 333 { 334 log.error("Could not start publisher", e); 335 } 336 } 337 338 return true; 339 } 340 341 346 public static void undeploy(Document doc, URL url, MBeanServer server) 347 throws MalformedObjectNameException , NullPointerException , DOMException 348 { 349 String publisher_class = ""; 350 String publisher = ""; 351 String publisher_context = ""; 352 353 ObjectName m_factory = null; 354 355 NodeList children = doc.getDocumentElement().getChildNodes(); 356 for (int i = 0; i < children.getLength(); i++) 357 { 358 if (children.item(i).getNodeType() == Node.ELEMENT_NODE) 359 { 360 Element element = (Element ) children.item(i); 361 String tag = element.getTagName(); 362 363 if (tag.equals(PUBLISHER_FACTORY_TAG)) 364 { 365 m_factory = 366 new ObjectName ( 367 element.getChildNodes().item(0).getNodeValue()); 368 369 } 370 371 else if (tag.equals(PUBLISHER_TAG)) 372 { 373 publisher = element.getChildNodes().item(0).getNodeValue(); 374 publisher_class = element.getAttribute(PUBLISHER_CLASS); 375 publisher_context = element.getAttribute(PUBLISHER_CONTEXT); 376 } 377 } 378 } 379 380 MediaPublisherFactoryMBean pub = null; 381 382 try 383 { 384 pub = 386 (MediaPublisherFactoryMBean) MBeanProxy.create( 387 MediaPublisherFactory.class, 388 MediaPublisherFactoryMBean.class, 389 m_factory, 390 server); 391 } 392 catch (MBeanProxyCreationException e) 393 { 394 log.error("MBeanProxyCreationException", e); 396 } 397 398 ObjectName m_name = pub.getObjectName(publisher_class, publisher_context); 399 pub.destroyPublisher(m_name); 400 401 } 402 } 403 | Popular Tags |