private void fireNodeEvents(List<EventBag<NodeChangeListener, NodeChangeEvent>> events) { if (noEvents) { return; } for(EventBag<NodeChangeListener, NodeChangeEvent> bag : events) { for(NodeChangeEvent event : bag.getEvents()) { for(NodeChangeListener l : bag.getListeners()) { try { if ((event instanceof NodeChangeEventExt) && ((NodeChangeEventExt) event).isRemovalEvent()) { l.childRemoved(event); } else { l.childAdded(event); } } catch (Throwable t) { LOG.log(Level.WARNING, null, t); } } } } }
protected ScheduledFuture<?> testNodeAdded(final NodeChangeListener listener, final Preferences parent, final String childName, final int count) { final ArgumentCaptor<NodeChangeEvent> captor = ArgumentCaptor.forClass(NodeChangeEvent.class); final Runnable task = new Runnable() { @Override public void run() { verify(listener, times(count)).childAdded(captor.capture()); final NodeChangeEvent event = captor.getValue(); assertEquals(event.getParent(), parent); assertEquals(event.getChild().name(), childName); } }; return schedule(task); }
protected ScheduledFuture<?> testNodeRemoved(final NodeChangeListener listener, final Preferences parent, final String childName, final int count) { final ArgumentCaptor<NodeChangeEvent> captor = ArgumentCaptor.forClass(NodeChangeEvent.class); final Runnable task = new Runnable() { @Override public void run() { verify(listener, times(count)).childRemoved(captor.capture()); final NodeChangeEvent event = captor.getValue(); assertEquals(event.getParent(), parent); assertEquals(event.getChild().name(), childName); } }; return schedule(task); }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "Verifies serialization", method = "!Serialization", args = {} ) public void testSerialization() throws Exception { event = new NodeChangeEvent(Preferences.systemRoot(), null); try { SerializationTest.copySerializable(event); fail("No expected NotSerializableException"); } catch (NotSerializableException e) { } }
@Override public void sync() throws BackingStoreException { ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>> prefEvents = new ArrayList<EventBag<PreferenceChangeListener, PreferenceChangeEvent>>(); ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>> nodeEvents = new ArrayList<EventBag<NodeChangeListener, NodeChangeEvent>>(); synchronized (tree.treeLock()) { _sync(prefEvents, nodeEvents); } fireNodeEvents(nodeEvents); firePrefEvents(prefEvents); }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "NodeChangeEvent", args = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class} ) public void testConstructor() { event = new NodeChangeEvent(Preferences.systemRoot(), Preferences .userRoot()); assertSame(Preferences.systemRoot(), event.getParent()); assertSame(Preferences.userRoot(), event.getChild()); assertSame(Preferences.systemRoot(), event.getSource()); }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "Testing Interface", method = "childAdded", args = {java.util.prefs.NodeChangeEvent.class} ) public void testChildAdded() { l.childAdded(new NodeChangeEvent(Preferences.userRoot(), Preferences .userRoot())); }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "Testing Interface", method = "childRemoved", args = {java.util.prefs.NodeChangeEvent.class} ) public void testChildRemoved() { l.childRemoved(new NodeChangeEvent(Preferences.userRoot(), Preferences .userRoot())); }
public void childAdded(NodeChangeEvent e) { synchronized (addLock) { switch (testNum) { case TEST_GET_CHILD: Preferences child = e.getChild(); if (child == null) { addResult = false; } else { if (child.name() == "mock1") { addResult = true; } } break; case TEST_GET_PARENT: Preferences parent = e.getParent(); if (parent == null) { addResult = false; } else { if (parent.name() == "mock") { addResult = true; } } break; } ++added; addLock.notifyAll(); } }
public void childRemoved(NodeChangeEvent e) { synchronized (removeLock) { switch (testNum) { case TEST_GET_CHILD: Preferences child = e.getChild(); if (child == null) { removeResult = false; } else { if (child.name() == "mock1") { removeResult = true; } } break; case TEST_GET_PARENT: Preferences parent = e.getParent(); if (parent == null) { addResult = false; } else { if (parent.name() == "mock") { addResult = true; } } break; } removed++; removeLock.notifyAll(); } }
public void testConstructor() { event = new NodeChangeEvent(Preferences.systemRoot(), Preferences .userRoot()); assertSame(Preferences.systemRoot(), event.getParent()); assertSame(Preferences.userRoot(), event.getChild()); assertSame(Preferences.systemRoot(), event.getSource()); }
public void testSerialization() throws Exception { event = new NodeChangeEvent(Preferences.systemRoot(), null); try { SerializationTest.copySerializable(event); fail("No expected NotSerializableException"); } catch (NotSerializableException e) { } }
public void childAdded(NodeChangeEvent e) { synchronized (addLock) { ++added; addDispatched = true; addLock.notifyAll(); } }
public void childRemoved(NodeChangeEvent e) { synchronized (removeLock) { removed++; removeDispatched = true; removeLock.notifyAll(); } }
private ProxyPreferencesImpl node(String pathName, boolean create, List<EventBag<NodeChangeListener, NodeChangeEvent>> events) { if (pathName.length() > 0 && pathName.charAt(0) == '/') { //NOI18N // absolute path, if this is not the root then find the root // and pass the call to it if (parent != null) { Preferences root = this; while (root.parent() != null) { root = root.parent(); } return ((ProxyPreferencesImpl) root).node(pathName, create, events); } else { // this is the root, change the pathName to a relative path and proceed pathName = pathName.substring(1); } } if (pathName.length() > 0) { String childName; String pathFromChild; int idx = pathName.indexOf('/'); //NOI18N if (idx != -1) { childName = pathName.substring(0, idx); pathFromChild = pathName.substring(idx + 1); } else { childName = pathName; pathFromChild = null; } ProxyPreferencesImpl child = children.get(childName); if (child == null) { if (removedChildren.contains(childName) && !create) { // this child has been removed return null; } Preferences childDelegate = null; try { if (delegate != null && delegate.nodeExists(childName)) { childDelegate = delegate.node(childName); } } catch (BackingStoreException bse) { // ignore } if (childDelegate != null || create) { child = tree.get(this, childName, childDelegate); children.put(childName, child); removedChildren.remove(childName); // fire event if we really created the new child node if (childDelegate == null) { EventBag<NodeChangeListener, NodeChangeEvent> bag = new EventBag<NodeChangeListener, NodeChangeEvent>(); bag.addListeners(nodeListeners); bag.addEvent(new NodeChangeEventExt(this, child, false)); events.add(bag); } } else { // childDelegate == null && !create return null; } } else { assert !child.removed; } return pathFromChild != null ? child.node(pathFromChild, create, events) : child; } else { return this; } }
public void childAdded(NodeChangeEvent evt) { try { callback.call(); } catch (Exception e) { /* ignore */ } }
public void childRemoved(NodeChangeEvent evt) { try { callback.call(); } catch (Exception e) { /* ignore */ } }
public void childAdded(NodeChangeEvent e) { }
public void childRemoved(NodeChangeEvent e) { }
public void childAdded(NodeChangeEvent arg0) { flagAdded = true; }
public void childRemoved(NodeChangeEvent arg0) { flagRemoved = true; }
public void testChildAdded() { l.childAdded(new NodeChangeEvent(Preferences.userRoot(), Preferences .userRoot())); }
public void testChildRemoved() { l.childRemoved(new NodeChangeEvent(Preferences.userRoot(), Preferences .userRoot())); }