Exemplo n.º 1
0
 public override void run()
 {
     while (true)
     {
         EventObject eventJ = null;
         try {
             eventJ = getEventObject();
         } catch (java.lang.InterruptedException e) {
             e.printStackTrace();
             continue;
         }
         AbstractPreferences pref = (AbstractPreferences)eventJ
                                    .getSource();
         if (eventJ is NodeAddEvent)
         {
             dispatchNodeAdd((NodeChangeEvent)eventJ,
                             pref.nodeChangeListeners);
         }
         else if (eventJ is NodeRemoveEvent)
         {
             dispatchNodeRemove((NodeChangeEvent)eventJ,
                                pref.nodeChangeListeners);
         }
         else if (eventJ is PreferenceChangeEvent)
         {
             dispatchPrefChange((PreferenceChangeEvent)eventJ,
                                pref.preferenceChangeListeners);
         }
     }
 }
Exemplo n.º 2
0
        private AbstractPreferences getNodeFromBackend(bool createNew,
                                                       AbstractPreferences currentNode, String name)
        {        //throws BackingStoreException {
            if (name.length() > MAX_NAME_LENGTH)
            {
                // prefs.8=Name length is too long: {0}
                throw new java.lang.IllegalArgumentException("Name length is too long: " +
                                                             name);
            }
            AbstractPreferences temp;

            if (createNew)
            {
                temp = currentNode.childSpi(name);
                currentNode.cachedNode.put(name, temp);
                if (temp.newNode && currentNode.nodeChangeListeners.size() > 0)
                {
                    currentNode.notifyChildAdded(temp);
                }
            }
            else
            {
                temp = currentNode.getChild(name);
            }
            return(temp);
        }
Exemplo n.º 3
0
        private void removeNodeImpl()// throws BackingStoreException {
        {
            lock (lockJ) {
                checkState();
                String[] childrenNames = childrenNamesSpi();
                for (int i = 0; i < childrenNames.Length; i++)
                {
                    if (null == cachedNode.get(childrenNames[i]))
                    {
                        AbstractPreferences child = childSpi(childrenNames[i]);
                        cachedNode.put(childrenNames[i], child);
                    }
                }

                java.util.Collection <AbstractPreferences> values = cachedNode.values();
                AbstractPreferences[] children = values
                                                 .toArray(new AbstractPreferences[values.size()]);
                foreach (AbstractPreferences child in children)
                {
                    child.removeNodeImpl();
                }
                removeNodeSpi();
                isRemovedJ = true;
                parentPref.cachedNode.remove(nodeName);
            }
            if (parentPref.nodeChangeListeners.size() > 0)
            {
                parentPref.notifyChildRemoved(this);
            }
        }
Exemplo n.º 4
0
        public override Preferences node(String name)
        {
            AbstractPreferences startNode = null;

            lock (lockJ) {
                checkState();
                validateName(name);
                if ("".equals(name)) //$NON-NLS-1$
                {
                    return(this);
                }
                else if ("/".equals(name)) //$NON-NLS-1$
                {
                    return(root);
                }
                if (name.startsWith("/")) //$NON-NLS-1$
                {
                    startNode = root;
                    name      = name.substring(1);
                }
                else
                {
                    startNode = this;
                }
            }
            try {
                return(startNode.nodeImpl(name, true));
            } catch (BackingStoreException e) {
                // should not happen
                return(null);
            }
        }
Exemplo n.º 5
0
 /*
  * ----------------------------------------------------------- Constructors
  * -----------------------------------------------------------
  */
 /*
  * Constructs a new {@code AbstractPreferences} instance using the given
  * parent node and node name.
  *
  * @param parent
  *            the parent node of the new node or {@code null} to indicate
  *            that the new node is a root node.
  * @param name
  *            the name of the new node or an empty string to indicate that
  *            this node is called "root".
  * @throws IllegalArgumentException
  *             if the name contains a slash character or is empty if {@code
  *             parent} is not {@code null}.
  */
 protected AbstractPreferences(AbstractPreferences parent, String name)
 {
     if ((null == parent ^ name.length() == 0) || name.indexOf("/") >= 0) //$NON-NLS-1$
     {
         throw new java.lang.IllegalArgumentException();
     }
     root = null == parent ? this : parent.root;
     nodeChangeListeners       = new LinkedList <EventListener>();
     preferenceChangeListeners = new LinkedList <EventListener>();
     isRemovedJ = false;
     cachedNode = new HashMap <String, AbstractPreferences>();
     nodeName   = name;
     parentPref = parent;
     lockJ      = new Lock();
     userNode   = root.userNode;
 }
Exemplo n.º 6
0
 /*
  * Returns the child node with the specified name or {@code null} if it
  * doesn't exist. Implementers can assume that the name supplied to this
  * method will be a valid node name string (conforming to the node naming
  * format) and will not correspond to a node that has been cached or
  * removed.
  *
  * @param name
  *            the name of the desired child node.
  * @return the child node with the given name or {@code null} if it doesn't
  *         exist.
  * @throws BackingStoreException
  *             if the backing store is unavailable or causes an operation
  *             failure.
  */
 protected AbstractPreferences getChild(String name)
 {        // throws BackingStoreException {
     lock (lockJ) {
         checkState();
         AbstractPreferences result         = null;
         String[]            childrenNamesJ = childrenNames();
         for (int i = 0; i < childrenNamesJ.Length; i++)
         {
             if (childrenNamesJ[i].equals(name))
             {
                 result = childSpi(name);
                 break;
             }
         }
         return(result);
     }
 }
Exemplo n.º 7
0
        public override bool nodeExists(String name)//throws BackingStoreException {
        {
            if (null == name)
            {
                throw new java.lang.NullPointerException();
            }
            AbstractPreferences startNode = null;

            lock (lockJ) {
                if (isRemoved())
                {
                    if ("".equals(name)) //$NON-NLS-1$
                    {
                        return(false);
                    }
                    // prefs.9=This node has been removed
                    throw new java.lang.IllegalStateException("This node has been removed");                     //$NON-NLS-1$
                }
                validateName(name);
                if ("".equals(name) || "/".equals(name)) //$NON-NLS-1$ //$NON-NLS-2$
                {
                    return(true);
                }
                if (name.startsWith("/")) //$NON-NLS-1$
                {
                    startNode = root;
                    name      = name.substring(1);
                }
                else
                {
                    startNode = this;
                }
            }
            try {
                Preferences result = startNode.nodeImpl(name, false);
                return(null == result ? false : true);
            } catch (java.lang.IllegalArgumentException e) {
                return(false);
            }
        }
Exemplo n.º 8
0
        private AbstractPreferences nodeImpl(String path, bool createNew)
        {                                                      //throws BackingStoreException {
            String[]            names       = path.split("/"); //$NON-NLS-1$
            AbstractPreferences currentNode = this;
            AbstractPreferences temp        = null;

            for (int i = 0; i < names.Length; i++)
            {
                String name = names[i];
                lock (currentNode.lockJ) {
                    temp = currentNode.cachedNode.get(name);
                    if (temp == null)
                    {
                        temp = getNodeFromBackend(createNew, currentNode, name);
                    }
                }
                currentNode = temp;
                if (null == currentNode)
                {
                    break;
                }
            }
            return(currentNode);
        }
Exemplo n.º 9
0
 private AbstractPreferences getNodeFromBackend(bool createNew,
     AbstractPreferences currentNode, String name)
 {
     //throws BackingStoreException {
     if (name.length() > MAX_NAME_LENGTH) {
     // prefs.8=Name length is too long: {0}
         throw new java.lang.IllegalArgumentException("Name length is too long: "+
             name);
     }
     AbstractPreferences temp;
     if (createNew) {
     temp = currentNode.childSpi(name);
     currentNode.cachedNode.put(name, temp);
     if (temp.newNode && currentNode.nodeChangeListeners.size() > 0) {
         currentNode.notifyChildAdded(temp);
     }
     } else {
     temp = currentNode.getChild(name);
     }
     return temp;
 }
Exemplo n.º 10
0
 /*
  * ----------------------------------------------------------- Constructors
  * -----------------------------------------------------------
  */
 /**
  * Constructs a new {@code AbstractPreferences} instance using the given
  * parent node and node name.
  *
  * @param parent
  *            the parent node of the new node or {@code null} to indicate
  *            that the new node is a root node.
  * @param name
  *            the name of the new node or an empty string to indicate that
  *            this node is called "root".
  * @throws IllegalArgumentException
  *             if the name contains a slash character or is empty if {@code
  *             parent} is not {@code null}.
  */
 protected AbstractPreferences(AbstractPreferences parent, String name)
 {
     if ((null == parent ^ name.length() == 0) || name.indexOf("/") >= 0) { //$NON-NLS-1$
     throw new java.lang.IllegalArgumentException();
     }
     root = null == parent ? this : parent.root;
     nodeChangeListeners = new LinkedList<EventListener>();
     preferenceChangeListeners = new LinkedList<EventListener>();
     isRemovedJ = false;
     cachedNode = new HashMap<String, AbstractPreferences>();
     nodeName = name;
     parentPref = parent;
     lockJ = new Lock();
     userNode = root.userNode;
 }