private static Children getChildren(DataObject dobj, boolean noBeanInfo) { if (noBeanInfo) { return Children.LEAF; } InstanceCookie inst = (InstanceCookie)dobj.getCookie(InstanceCookie.class); if (inst == null) return Children.LEAF; try { Class clazz = inst.instanceClass(); if (BeanContext.class.isAssignableFrom(clazz) || BeanContextProxy.class.isAssignableFrom(clazz)) { return new InstanceChildren (); } else { return Children.LEAF; } } catch (Exception ex) { return Children.LEAF; } }
private void init() { try { InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class); if (ic == null) { bean = null; return; } Class clazz = ic.instanceClass(); if (BeanContext.class.isAssignableFrom(clazz)) { bean = ic.instanceCreate(); } else if (BeanContextProxy.class.isAssignableFrom(clazz)) { bean = ((BeanContextProxy) ic.instanceCreate()).getBeanContextProxy(); } else { bean = null; } } catch (Exception ex) { bean = null; Exceptions.printStackTrace(ex); } if (bean != null) { // attaches a listener to the bean ((BeanContext) bean).addBeanContextMembershipListener (contextL); } updateKeys(); }
public void testGetChildBeanContextChild_BeanContextChild() { MockBeanContextChild child = new MockBeanContextChild(); BeanContextChild result = MockBeanContextSupport .publicGetChildBeanContextChild(child); assertSame(child, result); // Regression for HARMONY-1393 class TestBeanException extends BeanContextChildSupport implements BeanContextProxy { private static final long serialVersionUID = -8544245159647566063L; private final BeanContextChildSupport childSupport = new BeanContextChildSupport(); public BeanContextChild getBeanContextProxy() { return childSupport; } } TestBeanException bean = new TestBeanException(); try { MockBeanContextSupport.publicGetChildBeanContextChild(bean); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // expected } }
private static Children getChildren(DataObject dobj, boolean noBeanInfo) { if (noBeanInfo) { return Children.LEAF; } InstanceCookie inst = (InstanceCookie)dobj.getCookie(InstanceCookie.class); if (inst == null) return Children.LEAF; try { Class clazz = inst.instanceClass(); if (BeanContext.class.isAssignableFrom(clazz) || BeanContextProxy.class.isAssignableFrom(clazz)) { return new InstanceChildren ((InstanceDataObject) dobj); } else { return Children.LEAF; } } catch (Exception ex) { return Children.LEAF; } }
private static Children getChildren(Object bean) { if (bean instanceof BeanContext) { return new BeanChildren((BeanContext) bean); } if (bean instanceof BeanContextProxy) { BeanContextChild bch = ((BeanContextProxy) bean).getBeanContextProxy(); if (bch instanceof BeanContext) { return new BeanChildren((BeanContext) bch); } } return Children.LEAF; }
private static Children getChildren (Object bean, SerialDataNode task) { if (bean instanceof BeanContext) return new BeanChildren ((BeanContext)bean, new BeanFactoryImpl(task)); if (bean instanceof BeanContextProxy) { java.beans.beancontext.BeanContextChild bch = ((BeanContextProxy)bean).getBeanContextProxy(); if (bch instanceof BeanContext) return new BeanChildren ((BeanContext)bch, new BeanFactoryImpl(task)); } return Children.LEAF; }
public void testAdd_BCP() { MockBeanContextSupport support = new MockBeanContextSupport(); support.waitOnChildInHooks = false; MockBeanContextMembershipListener l1 = new MockBeanContextMembershipListener(); MockPropertyChangeListener l2 = new MockPropertyChangeListener(); MockVetoableChangeListener l3 = new MockVetoableChangeListener(); support.addBeanContextMembershipListener(l1); support.addPropertyChangeListener("children", l2); support.addVetoableChangeListener("children", l3); BeanContextChild childPeer = new MockBeanContextChild(); BeanContextProxy child = new MockBeanContextProxy(childPeer); support.add(child); support.records.assertRecord("initialize", null); support.records.assertRecord("validatePendingAdd", child, Boolean.TRUE); support.records.assertRecord("createBCSChild", child, childPeer, support.children().get(child)); support.records.assertRecord("createBCSChild", childPeer, child, support.children().get(childPeer)); support.records.assertRecord("childJustAddedHook", child, support .children().get(child), null); support.records.assertRecord("childJustAddedHook", childPeer, support .children().get(childPeer), null); support.records.assertEndOfRecords(); assertTrue(l1.lastEventAdd); assertMembershipEvent(l1.lastEvent, support, null, Arrays .asList(new Object[] { child, childPeer })); assertNull(l2.lastEvent); assertNull(l3.lastEvent); assertSame(support, childPeer.getBeanContext()); assertEquals(2, support.size()); }
public void testSize() { @SuppressWarnings("serial") class TestBean extends Component implements BeanContextProxy { public BeanContextChildSupport childSupport = new BeanContextChildSupport(); public BeanContextChild getBeanContextProxy() { return childSupport; } } // Regression test for HARMONY-1829 BeanContextSupport obj = new BeanContextSupport(); obj.add(new TestBean()); assertEquals(2, obj.size()); }
private static Children getChildren (Object bean) { if (bean instanceof BeanContext) return new BeanChildren ((BeanContext)bean); if (bean instanceof BeanContextProxy) { BeanContextChild bch = ((BeanContextProxy)bean).getBeanContextProxy(); if (bch instanceof BeanContext) return new BeanChildren ((BeanContext)bch); } return Children.LEAF; }
public void propertyChange(PropertyChangeEvent evt) { if (evt != null && !evt.getPropertyName().equals(InstanceDataObject.PROP_COOKIE)) return; if (contextL != null && bean != null) ((BeanContext) bean).removeBeanContextMembershipListener (contextL); try { InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class); if (ic == null) { bean = null; return; } Class clazz = ic.instanceClass(); if (BeanContext.class.isAssignableFrom(clazz)) { bean = ic.instanceCreate(); } else if (BeanContextProxy.class.isAssignableFrom(clazz)) { bean = ((BeanContextProxy) dobj.instanceCreate()).getBeanContextProxy(); } else { bean = null; } } catch (Exception ex) { bean = null; ErrorManager.getDefault().notify(ex); } if (bean != null) { // attaches a listener to the bean ((BeanContext) bean).addBeanContextMembershipListener (contextL); } updateKeys(); }
private static Children getChildren (Object bean, InstanceDataObject task) { if (bean instanceof BeanContext) return new BeanChildren ((BeanContext)bean, new BeanFactoryImpl(task)); if (bean instanceof BeanContextProxy) { java.beans.beancontext.BeanContextChild bch = ((BeanContextProxy)bean).getBeanContextProxy(); if (bch instanceof BeanContext) return new BeanChildren ((BeanContext)bch, new BeanFactoryImpl(task)); } return Children.LEAF; }
public void testRemoveObject_BCP() { MockBeanContextSupport support = new MockBeanContextSupport(); support.waitOnChildInHooks = false; MockBeanContextMembershipListener l1 = new MockBeanContextMembershipListener(); support.addBeanContextMembershipListener(l1); BeanContextChild childPeer = new MockBeanContextChild(); BeanContextProxy child = new MockBeanContextProxy(childPeer); support.add(child); support.records.assertRecord("initialize", null); support.records.assertRecord("validatePendingAdd", child, Boolean.TRUE); support.records.assertRecord("createBCSChild", child, childPeer, support.children().get(child)); support.records.assertRecord("createBCSChild", childPeer, child, support.children().get(childPeer)); support.records.assertRecord("childJustAddedHook", child, support .children().get(child), null); support.records.assertRecord("childJustAddedHook", childPeer, support .children().get(childPeer), null); support.records.assertEndOfRecords(); assertTrue(l1.lastEventAdd); assertMembershipEvent(l1.lastEvent, support, null, Arrays .asList(new Object[] { child, childPeer })); support.records.clear(); l1.clearLastEvent(); Object bcsChild = support.children().get(child); Object bcsChildPeer = support.children().get(childPeer); support.remove(child); support.records.assertRecord("validatePendingRemove", child, Boolean.TRUE); support.records.assertRecord("childJustRemovedHook", child, bcsChild, null); support.records.assertRecord("childJustRemovedHook", childPeer, bcsChildPeer, null); support.records.assertEndOfRecords(); assertTrue(l1.lastEventRemove); assertMembershipEvent(l1.lastEvent, support, null, Arrays .asList(new Object[] { child, childPeer })); assertNull(childPeer.getBeanContext()); assertEquals(0, support.size()); }
public void testRemoveObject_BCP2() { MockBeanContextSupport support = new MockBeanContextSupport(); support.waitOnChildInHooks = false; MockBeanContextMembershipListener l1 = new MockBeanContextMembershipListener(); support.addBeanContextMembershipListener(l1); BeanContextChild childPeer = new MockBeanContextChild(); BeanContextProxy child = new MockBeanContextProxy(childPeer); support.add(child); support.records.assertRecord("initialize", null); support.records.assertRecord("validatePendingAdd", child, Boolean.TRUE); support.records.assertRecord("createBCSChild", child, childPeer, support.children().get(child)); support.records.assertRecord("createBCSChild", childPeer, child, support.children().get(childPeer)); support.records.assertRecord("childJustAddedHook", child, support .children().get(child), null); support.records.assertRecord("childJustAddedHook", childPeer, support .children().get(childPeer), null); support.records.assertEndOfRecords(); assertTrue(l1.lastEventAdd); assertMembershipEvent(l1.lastEvent, support, null, Arrays .asList(new Object[] { child, childPeer })); support.records.clear(); l1.clearLastEvent(); Object bcsChild = support.children().get(child); Object bcsChildPeer = support.children().get(childPeer); support.remove(childPeer); support.records.assertRecord("validatePendingRemove", childPeer, Boolean.TRUE); support.records.assertRecord("childJustRemovedHook", childPeer, bcsChildPeer, null); support.records.assertRecord("childJustRemovedHook", child, bcsChild, null); support.records.assertEndOfRecords(); assertTrue(l1.lastEventRemove); assertMembershipEvent(l1.lastEvent, support, null, Arrays .asList(new Object[] { child, childPeer })); assertNull(childPeer.getBeanContext()); assertEquals(0, support.size()); }