PageRenderTime 72ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/jboss-5.1.0/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 596 lines | 461 code | 58 blank | 77 comment | 29 complexity | 0defdc310a2c0aae67c9e69c6b1432b8 MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2008, Red Hat Middleware LLC, and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.test.profileservice.test;
  23. import java.net.InetAddress;
  24. import java.util.HashMap;
  25. import java.util.Map;
  26. import org.jboss.deployers.spi.management.ManagementView;
  27. import org.jboss.managed.api.ComponentType;
  28. import org.jboss.managed.api.ManagedCommon;
  29. import org.jboss.managed.api.ManagedComponent;
  30. import org.jboss.managed.api.ManagedProperty;
  31. import org.jboss.metatype.api.types.CompositeMetaType;
  32. import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
  33. import org.jboss.metatype.api.types.MetaType;
  34. import org.jboss.metatype.api.types.SimpleMetaType;
  35. import org.jboss.metatype.api.values.ArrayValue;
  36. import org.jboss.metatype.api.values.CollectionValue;
  37. import org.jboss.metatype.api.values.CompositeValue;
  38. import org.jboss.metatype.api.values.MapCompositeValueSupport;
  39. import org.jboss.metatype.api.values.MetaValue;
  40. import org.jboss.metatype.api.values.SimpleValue;
  41. import org.jboss.services.binding.ServiceBindingMetadata;
  42. import org.jboss.services.binding.impl.ServiceBindingSet;
  43. import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
  44. /**
  45. * <p>
  46. * Profile service ServiceBindingManager tests.
  47. * </p>
  48. *
  49. * @see org.jboss.test.profileservice.override.test.ServiceBindingManagedObjectsTestCase
  50. * for tests of updating the metadata
  51. *
  52. * @author Brian Stansberry
  53. * @version $Revision: 89131 $
  54. */
  55. public class ServiceBindingManagedObjectsTestCase extends AbstractProfileServiceTest
  56. {
  57. public static final CompositeMetaType SERVICE_BINDING_METADATA_TYPE;
  58. public static final CompositeMetaType SERVICE_BINDING_SET_TYPE;
  59. static
  60. {
  61. String[] itemNames = {
  62. "bindingSetName",
  63. "serviceName",
  64. "bindingName",
  65. "fullyQualifiedName",
  66. "description",
  67. "hostName",
  68. "port",
  69. "fixedHostName",
  70. "fixedPort"//,
  71. // "serviceBindingValueSourceClassName",
  72. // "serviceBindingValueSourceConfig"
  73. };
  74. String[] itemDescriptions = {
  75. "binding set to which this binding applies, or null for all sets",
  76. "the name of the service to which this binding applies",
  77. "a qualifier identifying which particular binding within the service this is",
  78. "the fully qualified binding name",
  79. "description of the binding",
  80. "the host name or string notation IP address to use for the binding",
  81. "the port to use for the binding",
  82. "whether the host name should remain fixed in all binding sets",
  83. "whether the port should remain fixed in all binding sets"//,
  84. // "fully qualified classname of specialized object used to process binding results",
  85. // ""
  86. };
  87. MetaType[] itemTypes = {
  88. SimpleMetaType.STRING,
  89. SimpleMetaType.STRING,
  90. SimpleMetaType.STRING,
  91. SimpleMetaType.STRING,
  92. SimpleMetaType.STRING,
  93. SimpleMetaType.STRING,
  94. SimpleMetaType.INTEGER_PRIMITIVE,
  95. SimpleMetaType.BOOLEAN_PRIMITIVE,
  96. SimpleMetaType.BOOLEAN_PRIMITIVE//,
  97. // SimpleMetaType.STRING,
  98. // new GenericMetaType(ManagedObject)
  99. };
  100. SERVICE_BINDING_METADATA_TYPE = new ImmutableCompositeMetaType(ServiceBindingMetadata.class.getName(),
  101. "Service Binding Metadata",
  102. itemNames, itemDescriptions, itemTypes);
  103. String[] itemNames2 = {
  104. "name",
  105. "defaultHostName",
  106. "portOffset",
  107. "overrideBindings"
  108. };
  109. String[] itemDescriptions2 = {
  110. "the name of the binding set",
  111. "the host name that should be used for all bindings whose configuration " +
  112. "does not specify fixedHostName=\"true\"",
  113. "value to add to the port configuration for a standard binding to " +
  114. "derive the port to use in this binding set",
  115. "binding configurations that apply only to this binding set, either " +
  116. "non-standard bindings or ones that override standard binding configurations",
  117. };
  118. MetaType[] itemTypes2 = {
  119. SimpleMetaType.STRING,
  120. SimpleMetaType.STRING,
  121. SimpleMetaType.INTEGER_PRIMITIVE,
  122. ServiceBindingMetadataMapper.TYPE
  123. };
  124. SERVICE_BINDING_SET_TYPE = new ImmutableCompositeMetaType(ServiceBindingSet.class.getName(),
  125. "Service Binding Set", itemNames2, itemDescriptions2, itemTypes2);
  126. }
  127. /**
  128. * <p>
  129. * Creates an instance of {@code SecurityManagedObjectsTestCase} with the specified name.
  130. * </p>
  131. *
  132. * @param name a {@code String} representing the name of this {@code TestCase}.
  133. */
  134. public ServiceBindingManagedObjectsTestCase(String name)
  135. {
  136. super(name);
  137. }
  138. /**
  139. * Validates at the {@code ServiceBindingManager} managed component.
  140. *
  141. * @throws Exception if an error occurs while running the test.
  142. */
  143. public void testValidateSBMContent() throws Exception
  144. {
  145. ManagedComponent component = getServiceBindingManagerManagedComponent();
  146. logHierarchy(component);
  147. // verify that the component has the expected properties.
  148. Map<String, ManagedProperty> properties = component.getProperties();
  149. assertNotNull(properties);
  150. getLog().debug("ServiceBindingManager properties: ");
  151. for (Map.Entry<String, ManagedProperty> entry : properties.entrySet())
  152. {
  153. getLog().debug(entry.getKey() + " = " + entry.getValue());
  154. }
  155. ManagedProperty prop = properties.get("activeBindingSetName");
  156. assertNotNull("Missing property activeBindingSetName", prop);
  157. MetaValue val = prop.getValue();
  158. assertNotNull("property activeBindingSetName has no value", val);
  159. assertTrue("property activeBindingSetName value is SimpleValue", val instanceof SimpleValue);
  160. assertEquals("incorrect activeBindingSetName value", "ports-default", ((SimpleValue) val).getValue());
  161. prop = properties.get("standardBindings");
  162. assertNotNull("Missing property standardBindings", prop);
  163. val = prop.getValue();
  164. assertNotNull("property standardBindings has no value", val);
  165. assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
  166. MetaValue[] elements = ((CollectionValue) val).getElements();
  167. assertNotNull(elements);
  168. for (MetaValue mv : elements)
  169. {
  170. getLog().info(mv);
  171. serviceBindingMetadataTest(mv);
  172. }
  173. prop = properties.get("bindingSets");
  174. assertNotNull("Missing property bindingSets", prop);
  175. val = prop.getValue();
  176. assertNotNull("property bindingSets has no value", val);
  177. assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
  178. elements = ((CollectionValue) val).getElements();
  179. assertNotNull("property bindingSets value has elements", elements);
  180. Map<String, Integer> offsets = new HashMap<String, Integer>();
  181. for (MetaValue mv : elements)
  182. {
  183. getLog().info(mv);
  184. serviceBindingSetTest(mv, offsets);
  185. }
  186. assertEquals(Integer.valueOf(0), offsets.get("ports-default"));
  187. assertEquals(Integer.valueOf(100), offsets.get("ports-01"));
  188. assertEquals(Integer.valueOf(200), offsets.get("ports-02"));
  189. assertEquals(Integer.valueOf(300), offsets.get("ports-03"));
  190. prop = properties.get("serviceBindings");
  191. assertNotNull("Missing property serviceBindings", prop);
  192. log.info("serviceBindings: " + prop);
  193. val = prop.getValue();
  194. assertNotNull("property serviceBindings has no value", val);
  195. assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
  196. CompositeValue compVal = (CompositeValue) val;
  197. assertEquals("correct number of sets of actual bindings", offsets.size(), compVal.values().size());
  198. for (String bindingSetName : offsets.keySet())
  199. {
  200. MetaValue mv = compVal.get(bindingSetName);
  201. assertTrue(mv instanceof CollectionValue);
  202. CollectionValue colVal = (CollectionValue) mv;
  203. getLog().info(colVal.getElements());
  204. for (MetaValue element : colVal.getElements())
  205. {
  206. serviceBindingTest(element);
  207. }
  208. }
  209. boolean hasState = properties.get("state") != null;
  210. assertEquals("Unexpected number of properties", hasState ? 5 : 4, properties.size());
  211. }
  212. private ManagedComponent getServiceBindingManagerManagedComponent() throws Exception
  213. {
  214. ManagementView managementView = getManagementView();
  215. ComponentType type = new ComponentType("MCBean", "ServiceBindingManager");
  216. ManagedComponent component = managementView.getComponent("ServiceBindingManager", type);
  217. assertNotNull(component);
  218. return component;
  219. }
  220. private void serviceBindingTest(MetaValue element)
  221. {
  222. getLog().info(element);
  223. assertTrue(element instanceof CompositeValue);
  224. CompositeValue compValue = (CompositeValue) element;
  225. MetaValue metaval = compValue.get("serviceName");
  226. assertNotNull("has serviceName", metaval);
  227. assertTrue(metaval instanceof SimpleValue);
  228. assertTrue(((SimpleValue) metaval).getValue() instanceof String);
  229. metaval = compValue.get("bindingName");
  230. if (metaval != null)
  231. {
  232. assertTrue(metaval instanceof SimpleValue);
  233. Object val = ((SimpleValue) metaval).getValue();
  234. assertTrue(val instanceof String);
  235. }
  236. metaval = compValue.get("fullyQualifiedName");
  237. assertNotNull("has fullyQualifiedName", metaval);
  238. assertTrue(metaval instanceof SimpleValue);
  239. assertTrue(((SimpleValue) metaval).getValue() instanceof String);
  240. metaval = compValue.get("description");
  241. if (metaval != null)
  242. {
  243. assertTrue(metaval instanceof SimpleValue);
  244. Object val = ((SimpleValue) metaval).getValue();
  245. assertTrue(val instanceof String);
  246. }
  247. metaval = compValue.get("hostName");
  248. assertNotNull("has hostName", metaval);
  249. assertTrue(metaval instanceof SimpleValue);
  250. assertTrue(((SimpleValue) metaval).getValue() instanceof String);
  251. metaval = compValue.get("bindAddress");
  252. assertNotNull("has bindAddress", metaval);
  253. assertTrue(metaval instanceof ArrayValue);
  254. Object val = ((ArrayValue) metaval).getValue();
  255. assertTrue(val instanceof byte[]);
  256. metaval = compValue.get("port");
  257. assertNotNull("has port", metaval);
  258. assertTrue(metaval instanceof SimpleValue);
  259. assertEquals("type of port value isn't int", int.class.getName(), metaval.getMetaType().getClassName());
  260. }
  261. private void serviceBindingSetTest(MetaValue metaValue, Map<String, Integer> offsets) throws Exception
  262. {
  263. assertTrue(metaValue instanceof CompositeValue);
  264. CompositeValue bindingSet = (CompositeValue) metaValue;
  265. MetaValue val = bindingSet.get("name");
  266. assertNotNull("property name has no value", val);
  267. assertTrue("property name value is SimpleValue", val instanceof SimpleValue);
  268. Object simpleVal = ((SimpleValue) val).getValue();
  269. assertTrue(simpleVal instanceof String);
  270. String name = (String) simpleVal;
  271. val = bindingSet.get("defaultHostName");
  272. assertNotNull("property defaultHostName has no value", val);
  273. assertEquals("type of defaultHostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
  274. assertTrue("property defaultHostName value is SimpleValue", val instanceof SimpleValue);
  275. assertEquals(InetAddress.getByName(getServerHost()), InetAddress.getByName((String) ((SimpleValue) val).getValue()));
  276. val = bindingSet.get("portOffset");
  277. assertNotNull("property portOffset has no value", val);
  278. assertTrue("property portOffset value is SimpleValue", val instanceof SimpleValue);
  279. simpleVal = ((SimpleValue) val).getValue();
  280. assertTrue(simpleVal instanceof Integer);
  281. assertTrue(((Integer) simpleVal).intValue() > -1);
  282. offsets.put(name, (Integer) simpleVal);
  283. val = bindingSet.get("overrideBindings");
  284. assertNotNull("property overrideBindings has no value", val);
  285. assertTrue("property overrideBindings value is CollectionValue", val instanceof CollectionValue);
  286. MetaValue[] elements = ((CollectionValue) val).getElements();
  287. getLog().info(elements);
  288. for (MetaValue element : elements)
  289. {
  290. serviceBindingMetadataTest(element);
  291. }
  292. }
  293. private Checked serviceBindingMetadataTest(MetaValue metaValue)
  294. {
  295. assertTrue(metaValue instanceof CompositeValue);
  296. CompositeValue bindingMetadata = (CompositeValue) metaValue;
  297. Checked result = new Checked();
  298. MetaValue val = bindingMetadata.get("fullyQualifiedName");
  299. assertNotNull("property fullyQualifiedName has no value", val);
  300. assertTrue("property fullyQualifiedName value is SimpleValue", val instanceof SimpleValue);
  301. assertNotNull("property fullyQualifiedName value is not null", ((SimpleValue) val).getValue());
  302. val = bindingMetadata.get("serviceName");
  303. assertNotNull("property serviceName has no value", val);
  304. assertTrue("property serviceName value is SimpleValue", val instanceof SimpleValue);
  305. assertNotNull("property serviceName value is not null", ((SimpleValue) val).getValue());
  306. val = bindingMetadata.get("bindingName");
  307. if (val != null)
  308. {
  309. result.bindingName = true;
  310. assertNotNull("property bindingName has no value", val);
  311. assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
  312. assertEquals("type of bindingName value isn't String", String.class.getName(), val.getMetaType().getClassName());
  313. }
  314. val = bindingMetadata.get("bindingSetName");
  315. if (val != null)
  316. {
  317. assertNotNull("property bindingSetName has no value", val);
  318. assertTrue("property bindingSetName value is SimpleValue", val instanceof SimpleValue);
  319. assertEquals("type of bindingSetName value isn't String", String.class.getName(), val.getMetaType().getClassName());
  320. }
  321. val = bindingMetadata.get("hostName");
  322. if (val != null)
  323. {
  324. result.hostname = true;
  325. assertTrue("property hostName value is SimpleValue", val instanceof SimpleValue);
  326. assertEquals("type of hostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
  327. }
  328. val = bindingMetadata.get("port");
  329. assertNotNull("property port has no value", val);
  330. assertTrue("property port value is SimpleValue", val instanceof SimpleValue);
  331. assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
  332. assertEquals("type of port value isn't int", int.class.getName(), val.getMetaType().getClassName());
  333. assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
  334. val = bindingMetadata.get("description");
  335. if (val != null)
  336. {
  337. result.hostname = true;
  338. assertNotNull("property hostName has no value", val);
  339. assertTrue("property description value is SimpleValue", val instanceof SimpleValue);
  340. assertEquals("type of description value isn't String", String.class.getName(), val.getMetaType().getClassName());
  341. }
  342. val = bindingMetadata.get("fixedPort");
  343. assertNotNull("property bindingName has no value", val);
  344. assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
  345. assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
  346. assertEquals("type of bindingName value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
  347. assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
  348. val = bindingMetadata.get("fixedHostName");
  349. assertNotNull("property bindingName has no value", val);
  350. assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
  351. assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
  352. assertEquals("type of bindingName value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
  353. assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
  354. return result;
  355. }
  356. // // FIXME: disabled as we don't want to change to name of a server that
  357. // // the testsuite later restarts. Move this somewhere else where we can do it
  358. // public void testUpdateActiveBindingSetName() throws Exception
  359. // {
  360. // ManagedComponent component = getServiceBindingManagerManagedComponent();
  361. //
  362. // ManagedProperty property = component.getProperty("activeBindingSetName");
  363. // assertNotNull(property);
  364. //
  365. // property.setValue(SimpleValueSupport.wrap("ports-01"));
  366. //
  367. // getManagementView().updateComponent(component);
  368. // log.debug("updated component " + component);
  369. //
  370. // component = getServiceBindingManagerManagedComponent();
  371. // assertNotNull(component);
  372. // log.debug("re-acquired component " + component);
  373. //
  374. // property = component.getProperty("activeBindingSetName");
  375. // assertNotNull(property);
  376. //
  377. // SimpleValue val = (SimpleValue) property.getValue();
  378. // assertEquals("ports-01", val.getValue());
  379. // }
  380. private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
  381. Map<String, MetaValue> standardBindings)
  382. {
  383. IndexedArray result = new IndexedArray();
  384. // First confirm the expected binding set is there
  385. ManagedProperty prop = properties.get("bindingSets");
  386. assertNotNull("Missing property bindingSets", prop);
  387. MetaValue val = prop.getValue();
  388. assertNotNull("property bindingSets has no value", val);
  389. assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
  390. MetaValue[] elements = ((CollectionValue) val).getElements();
  391. assertNotNull(elements);
  392. assertEquals(numSets, elements.length);
  393. result.array = elements;
  394. boolean sawAdded = false;
  395. for (int i = 0; i < elements.length; i++)
  396. {
  397. MetaValue mv = elements[i];
  398. if ("ports-test".equals(getSimpleValue(mv, "name")))
  399. {
  400. sawAdded = true;
  401. assertEquals("added binding set has correct defaultHostName",
  402. "localhost", getSimpleValue(mv, "defaultHostName"));
  403. assertEquals("added binding set has correct portOffset",
  404. portOffset, getSimpleValue(mv, "portOffset", Integer.class).intValue());
  405. MetaValue overVal = ((CompositeValue) mv).get("overrideBindings");
  406. assertTrue(overVal instanceof CollectionValue);
  407. MetaValue[] overrides = ((CollectionValue) overVal).getElements();
  408. assertNotNull("added binding set has overrides", overrides);
  409. assertEquals("added binding set has correct # of overrides", 1, overrides.length);
  410. mv = overrides[0];
  411. assertEquals("added binding set has AddedOverrideBinding",
  412. "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
  413. assertNull("AddedOverrideBinding has null bindingName",
  414. getSimpleValue(mv, "bindingName"));
  415. assertEquals("AddedOverrideBinding has correct description",
  416. "description", getSimpleValue(mv, "description"));
  417. assertNull("AddedOverrideBinding has null hostName",
  418. getSimpleValue(mv, "hostName"));
  419. assertEquals("AddedOverrideBinding has correct port",
  420. overrideBindingPort, getSimpleValue(mv, "port", Integer.class).intValue());
  421. assertFalse("AddedOverrideBinding has correct fixedHostName",
  422. getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
  423. assertFalse("AddedOverrideBinding has correct fixedPort",
  424. getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
  425. result.index = i;
  426. break;
  427. }
  428. }
  429. assertTrue(sawAdded);
  430. // Next validate the expected actual bindings are there
  431. prop = properties.get("serviceBindings");
  432. assertNotNull("Missing property serviceBindings", prop);
  433. val = prop.getValue();
  434. assertNotNull("property serviceBindings has no value", val);
  435. assertTrue("property serviceBindings value is Composite", val instanceof CompositeValue);
  436. val = ((CompositeValue) val).get("ports-test");
  437. assertNotNull(val);
  438. assertTrue("property serviceBindings value is CollectionValue", val instanceof CollectionValue);
  439. elements = ((CollectionValue) val).getElements();
  440. assertNotNull("property serviceBindings value has elements", elements);
  441. assertEquals("property serviceBindings value has correct # of elements",
  442. standardBindings.size() + 1, elements.length);
  443. for (MetaValue mv : elements)
  444. {
  445. String fqn = getSimpleValue(mv, "fullyQualifiedName", String.class);
  446. if ("AddedOverrideBinding".equals(fqn))
  447. {
  448. assertEquals("actual AddedOverrideBinding has correct serviceName",
  449. "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
  450. assertNull("actual AddedOverrideBinding has null bindingName",
  451. getSimpleValue(mv, "bindingName"));
  452. assertEquals("actual AddedOverrideBinding has correct description",
  453. "description", getSimpleValue(mv, "description"));
  454. assertEquals("actual AddedOverrideBinding has correct port",
  455. overrideBindingPort + portOffset, getSimpleValue(mv, "port", Integer.class).intValue());
  456. assertEquals("actual AddedOverrideBinding has correct hostName",
  457. "localhost", getSimpleValue(mv, "hostName"));
  458. }
  459. else
  460. {
  461. MetaValue standard = standardBindings.get(fqn);
  462. assertNotNull(standard);
  463. assertEquals("standardBinding " + fqn + " has correct serviceName",
  464. getSimpleValue(standard, "serviceName"), getSimpleValue(mv, "serviceName"));
  465. assertEquals("standardBinding " + fqn + " has correct bindingName",
  466. getSimpleValue(standard, "bindingName"), getSimpleValue(mv, "bindingName"));
  467. assertEquals("standardBinding " + fqn + " has correct description",
  468. getSimpleValue(standard, "description"), getSimpleValue(mv, "description"));
  469. int offset = getSimpleValue(standard, "fixedPort", Boolean.class).booleanValue() ? 0 : portOffset;
  470. assertEquals("standardBinding " + fqn + " has correct port",
  471. getSimpleValue(standard, "port", Integer.class).intValue() + offset,
  472. getSimpleValue(mv, "port", Integer.class).intValue());
  473. String host = getSimpleValue(standard, "fixedHostName", Boolean.class).booleanValue()
  474. ? getSimpleValue(standard, "hostName", String.class)
  475. : "localhost";
  476. assertEquals("standardBinding " + fqn + " has correct hostName",
  477. host, getSimpleValue(mv, "hostName"));
  478. }
  479. }
  480. return result;
  481. }
  482. private void logHierarchy(ManagedComponent mc)
  483. {
  484. ManagedCommon child = mc;
  485. ManagedCommon mcom = mc.getParent();
  486. while (mcom != null)
  487. {
  488. log.debug("parent of " + child.getName() + " is " + mcom.getName());
  489. child = mcom;
  490. mcom = mcom.getParent();
  491. }
  492. }
  493. private Object getSimpleValue(MetaValue val, String key)
  494. {
  495. return getSimpleValue(val, key, Object.class);
  496. }
  497. private <T> T getSimpleValue(MetaValue val, String key, Class<T> type)
  498. {
  499. T result = null;
  500. assertTrue(val instanceof CompositeValue);
  501. CompositeValue cval = (CompositeValue) val;
  502. MetaValue mv = cval.get(key);
  503. if (mv != null)
  504. {
  505. assertTrue(mv instanceof SimpleValue);
  506. Object obj = ((SimpleValue) mv).getValue();
  507. result = type.cast(obj);
  508. }
  509. return result;
  510. }
  511. private static MapCompositeValueSupport cloneCompositeValue(CompositeValue toClone)
  512. {
  513. if (toClone instanceof MapCompositeValueSupport)
  514. {
  515. return (MapCompositeValueSupport) toClone.clone();
  516. }
  517. else
  518. {
  519. CompositeMetaType type = toClone.getMetaType();
  520. Map<String, MetaValue> map = new HashMap<String, MetaValue>();
  521. for (String key : type.keySet())
  522. {
  523. map.put(key, toClone.get(key));
  524. }
  525. return new MapCompositeValueSupport(map, type);
  526. }
  527. }
  528. private class Checked
  529. {
  530. private boolean hostname;
  531. private boolean bindingName;
  532. }
  533. private class IndexedArray
  534. {
  535. int index;
  536. MetaValue[] array;
  537. }
  538. }