Package org.infinispan.tree

Examples of org.infinispan.tree.Fqn


      }
   }


   public void testStopClearsData() throws Exception {
      Fqn a = Fqn.fromString("/a");
      Fqn b = Fqn.fromString("/a/b");
      String key = "key", value = "value";
      cache.getRoot().addChild(a).put(key, value);
      cache.getRoot().addChild(b).put(key, value);
      cache.getRoot().put(key, value);


* @since 4.0
*/
public class FqnExternalizer implements Externalizer {

   public void writeObject(ObjectOutput output, Object object) throws IOException {
      Fqn fqn = (Fqn) object;
      output.writeShort(fqn.size());
      for (Object element : fqn.peekElements()) output.writeObject(element);
   }

      }
     
      // is the name a context?
      try
      {
         Fqn temp = Fqn.fromRelativeFqn(FQN_ROOT, Fqn.fromString(name.toString()));
         // TODO why not jst call remove -- why hasChild first?
         if (this.cache.getRoot().hasChild(temp))
         {
            this.cache.removeNode(temp);
            return;
         }
      }
      catch (CacheException ce)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace(ce.getMessage(), ce);
         }

         // don't chain CacheException since Infinispan may not be on remote client's classpath
         NamingException ne = new NamingException(ce.getClass().getName() + ": " + ce.getMessage());
         ne.fillInStackTrace();
         throw ne;
      }
     
      int size = name.size();
     
      // get the context and key
      Fqn ctx;
      String key = name.get(size - 1);
      boolean ctxIsRoot = false;
      if (size > 1) // find subcontext to which the key is bound
      {
         String prefix = name.getPrefix(size - 1).toString();
         Fqn fqn = Fqn.fromString(prefix);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      }
      else
      {
         ctx = FQN_ROOT;

      }
  
      int size = name.size();
  
      // get the context and key
      Fqn ctx;
      String key = name.get(size - 1);
      if (size > 1) // find subcontext to which the key is bound
      {
         String prefix = name.getPrefix(size - 1).toString();
         Fqn fqn = Fqn.fromString(prefix);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      }
      else
      {
         ctx = FQN_ROOT;

      {
         LOG.trace("list, name="+name);
      }
  
      // get the context
      Fqn ctx;
      String ctxName = "";
      int size = name.size();
      if (size >= 1)
      {
         ctxName = name.toString();
         Fqn fqn = Fqn.fromString(ctxName);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      }
      else
      {
         ctx = FQN_ROOT;

      {
         LOG.trace("listBindings, name="+name);
      }
     
      // get the context
      Fqn ctx;
      String ctxName = "";
      int size = name.size();
      if (size >= 1)
      {
         ctxName = name.toString();
         Fqn fqn = Fqn.fromString(ctxName);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      }
      else
      {
         ctx = FQN_ROOT;

         throw new InvalidNameException("Name is empty");
      }

      // does the new context already exist?
      String str = name.toString();
      Fqn fqn = Fqn.fromString(str);
      Fqn ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
      if (this.cache.getRoot().hasChild(ctx))
      {
         throw new NameAlreadyBoundException(str);
      }
     
      // does the prefix context already exist?
      Fqn pctx;
      String newctx = name.get(size - 1);
      if (size > 1) // find subcontext to which the context will be added
      {
         String prefix = name.getPrefix(size - 1).toString();
         Fqn fqn2 = Fqn.fromString(prefix);
         pctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn2);
         boolean exists = this.cache.getRoot().hasChild(pctx);
         if (!exists)
         {
            throw new NotContextException(name.getPrefix(size - 1).toString());
         }
      }
      else
      {
         pctx = FQN_ROOT;
      }

      Fqn newf = Fqn.fromRelativeFqn(pctx, Fqn.fromString(newctx));
      try
      {
         this.cache.put(newf, new HashMap<String, Binding>());
      }
      catch (CacheException ce)

      }

      int size = name.size();
     
      // get the context and key
      Fqn ctx;
      String key = name.get(size - 1);
      boolean isRootCtx = false;

      if (size > 1) // find subcontext to which the key will be added
      {
         String prefix = name.getPrefix(size - 1).toString();
         Fqn fqn = Fqn.fromString(prefix);
         ctx = Fqn.fromRelativeFqn(FQN_ROOT, fqn);
         boolean exists = this.cache.getRoot().hasChild(ctx);
         if (!exists)
         {
            throw new NotContextException(name.getPrefix(size - 1).toString() + " not a context");

         // expected
      }
   }

   public void testReplacingDirectAncestor() {
      Fqn fqn = Fqn.fromString("/a/b/c");
      Fqn newParent = Fqn.fromString("/hot/dog");
      Fqn expectedNewChild = Fqn.fromString("/hot/dog/c");

      assert expectedNewChild.equals(fqn.replaceAncestor(fqn.getParent(), newParent));
   }

      assert expectedNewChild.equals(fqn.replaceAncestor(fqn.getParent(), newParent));
   }

   public void testReplacingindirectAncestor() {
      Fqn fqn = Fqn.fromString("/a/b/c");
      Fqn newParent = Fqn.fromString("/hot/dog");
      Fqn expectedNewChild = Fqn.fromString("/hot/dog/b/c");

      Fqn replaced = fqn.replaceAncestor(fqn.getParent().getParent(), newParent);
      assert expectedNewChild.equals(replaced) : "Expected " + expectedNewChild + " but was " + replaced;
   }

TOP

Related Classes of org.infinispan.tree.Fqn

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.