Package nexj.core.util

Examples of nexj.core.util.Lookup$Iterator


         in = null;
      }

      // Overwrite the system string table with the repository string table

      Lookup map = (Lookup)m_stringMap.get(sLocale);
      String sResName = null;

      if (map != null)
      {
         try
         {
            for (Iterator itr = map.iterator(); itr.hasNext();)
            {
               sResName = (String)itr.next();
               in = getHelper().getResourceAsStream(sResName);
               properties.load(in);
               in.close();
View Full Code Here


   /**
    * Links the steps in the flow and check for link inconsistencies.
    */
   protected void link()
   {
      final Lookup map = new HashTab();

      // Link the steps with unspecified successors
      visit(new Activity.Visitor()
      {
         public void visit(Activity activity)
         {
            // Generate unique token name among the concurrent activities
            if (activity instanceof Concurrent)
            {
               Fork fork = activity.getFork();
              
               for (int i = 0, n = fork.getConcurrentCount(); i != n; ++i)
               {
                  if (fork.getConcurrent(i) == activity)
                  {
                     activity.setTokenName(fork.getActivity().getTokenName() + ":" + i);
                     break;
                  }
               }
            }
            else
            {
               Activity parent = activity.getParent();
              
               if (parent != null)
               {
                  activity.setTokenName(parent.getTokenName());
               }
            }

            for (int i = 0; i < activity.getStepCount(); ++i)
            {
               Step step = activity.getStep(i);

               if (i == 0)
               {
                  map.put(step, Boolean.TRUE);
               }

               if (step.getNext() == null)
               {
                  if (!(step instanceof Redirector))
                  {
                     if (i == activity.getStepCount() - 1)
                     {
                        if (activity.getContainer() != null)
                        {
                           step.setNext(activity.getContainer().getNext());
                        }
                     }
                     else
                     {
                        step.setNext(activity.getStep(i + 1));
                     }
                  }
               }
               else if (activity.getFork() != null)
               {
                  // Take into account the added Join element
                  if (step.getNext() == activity.getFork().getNext().getNext())
                  {
                     step.setNext(activity.getFork().getNext());
                  }
                  // See if this element should terminate the fork
                  else if (step.getNext().getFork() != activity.getFork())
                  {
                     Join join = new Join(step.getFork());

                     join.setAny(true);
                     join.setNext(step.getNext());
                     step.setNext(join);
                     activity.addStep(++i, join);
                  }
               }
            }
         }
      });

      // Check the successor step validity and mark the reachable steps
      visit(new Step.Visitor()
      {
         public void visit(Step step)
         {
            if (!map.contains(step))
            {
               map.put(step, Boolean.FALSE);
            }

            Step next = step.getNext();

            if (next != null)
            {
               if (!next.getActivity().getRootConcurrent().contains(step.getActivity()))
               {
                  throw new MetadataException("err.meta." + getPropName() + ".invalidNextStep",
                     new Object[]{next.getName(), getStepName(step),
                     step.getActivity().getFlow().getFullName()});
               }

               map.put(next, Boolean.TRUE);
            }
         }
      });

      // Find the unreachable steps
      for (Lookup.Iterator itr = map.valueIterator(); itr.hasNext();)
      {
         if (itr.next() == Boolean.FALSE)
         {
            Step step = (Step)itr.getKey();

View Full Code Here

    * @param base The equivalent source from the base transformation.
    */
   public void resolveInheritance(TransformationSource base)
   {
      List sourceList = new ArrayList(4);
      Lookup sourceMap = new HashTab(4);

      for (int i = 0, nSize = base.getChildCount(); i < nSize; i++)
      {
         TransformationSource baseChildSource = base.getChild(i);
         TransformationSource childSource = findChild(baseChildSource.getPart().getName());

         if (childSource == null)
         {
            TransformationSource sourceCopy = (TransformationSource)baseChildSource.clone();

            sourceList.add(sourceCopy);
            sourceMap.put(sourceCopy.getPart().getName(), sourceCopy);

            sourceCopy.setParent(this);
            sourceCopy.updateParts(getPart().getChild(baseChildSource.getPart().getName()));
            sourceCopy.setNull(false);
         }
         else
         {
            m_childMap.remove(childSource.getPart().getName());
            sourceList.add(childSource);
            sourceMap.put(childSource.getPart().getName(), childSource);
            childSource.resolveInheritance(baseChildSource);
         }
      }

      if (m_childList != null)
      {
         // Move children of this source after the children defined in base.
         for (Lookup.Iterator itr = m_childMap.valueIterator(); itr.hasNext(); )
         {
            TransformationSource source = (TransformationSource)itr.next();

            sourceList.add(source);
            sourceMap.put(source.getPart().getName(), source);
         }
      }

      m_childList = sourceList;
      m_childMap = sourceMap;
View Full Code Here

      copy.m_pathArray = null;

      if (copy.m_childList != null)
      {
         List childList = new ArrayList(copy.m_childList.size());
         Lookup childMap = new HashTab(copy.m_childMap.size());

         for (Iterator itr = copy.m_childList.iterator(); itr.hasNext(); )
         {
            TransformationSource sourceOld = (TransformationSource)itr.next();
            TransformationSource source = (TransformationSource)sourceOld.clone();

            childList.add(source);
            childMap.put(source.getPart().getName(), source);

            source.setParent(copy);
            source.setLevel(sourceOld.getLevel());
         }
View Full Code Here

            ((Field)itr.getValue()).setNext(null);
         }

         Arrays.sort(keyArray, FIELD_KEY_COMPARATOR);

         Lookup fieldMap = new LinkedHashTab(keyArray.length);
         Field firstOutput = null;
         Field lastOutput = null;

         for (i = 0; i < keyArray.length; ++i)
         {
            Object key = keyArray[i];
            Field field = (Field)m_fieldMap.get(key);

            fieldMap.put(key, field);

            if (field.isOutput() && field.getNext() == null && field != lastOutput)
            {
               if (lastOutput == null)
               {
View Full Code Here

   protected InstanceList readCached()
   {
      assert isCached();

      InvocationContext context = getInvocationContext();
      Lookup identityMap = new HashTab(4);
      boolean bCached = true;

      for (;;)
      {
         boolean bInstanceCaching = true;
         boolean bFiltered = false;
         boolean bMissed = false;
         List tobjList = null;

         if (m_persistenceMapping.getCaching() == PersistenceMapping.CACHING_CLASS)
         {
            Object classKey = Instance.getClassKey(m_metaclass, null);
            Pair classResult = getCached(classKey);
            Object queryKey = classKey;
            Pair queryResult = classResult;

            if (m_metaclass.getWhere() != null)
            {
               Query query = Query.createRead(m_metaclass, null, null, null, -1, 0, false, SEC_NONE, context);

               query.setLimit(-1);
               query.setCached(false);
               query.setCursor(false);
               query.prepare(false);

               if (query.getWhere() != null)
               {
                  queryKey = Instance.getClassKey(m_metaclass, query.toString(query.getWhere()));
                  queryResult = getCached(queryKey);
               }
            }

            if (bCached && queryResult != null && classResult != null &&
               ObjUtil.equal(queryResult.getTail(), classResult.getTail()))
            {
               tobjList = (List)queryResult.getHead();
            }

            if (tobjList == null)
            {
               Pair attributes = getCachedAttributes();
               InstanceList instanceList = readUncached(attributes, null);
               int nCount = instanceList.size();

               tobjList = new ArrayList(nCount);

               for (int i = 0; i < nCount; ++i)
               {
                  tobjList.add(RPCUtil.transfer(instanceList.get(i), attributes, identityMap,
                     RPCUtil.TF_ALL | RPCUtil.TF_LAZY | RPCUtil.TF_OLD));
                  identityMap.clear();
               }

               instanceList = null;

               Lookup cacheMap = new HashTab(2);

               queryResult = new Pair(tobjList);

               if (classKey != queryKey)
               {
                  classResult = getCached(classKey);

                  if (classResult == null)
                  {
                     classResult = new Pair(null, new Object());
                     cacheMap.put(classKey, classResult);
                  }
               }

               if (classResult != null)
               {
                  queryResult.setTail(classResult.getTail());
               }
               else
               {
                  queryResult.setTail(new Object());
               }

               cacheMap.put(queryKey, queryResult);
               cache(cacheMap, tobjList);
               bMissed = true;
            }

            bInstanceCaching = tobjList.size() > 64 && isUnique();
         }

         if (bInstanceCaching)
         {
            TransferObject tobj = null;
            Object instanceKey = null;
            Pair instanceResult = null;
            Object oidKey = null;
            Pair oidResult = null;
            OID oid;

            if (m_oid != null)
            {
               oid = m_oid;
            }
            else
            {
               oidKey = Pair.list(Symbol._CLASS, m_metaclass.getSymbol(), toString(m_where));
               oidResult = getCached(oidKey);
               oid = (oidResult == null) ? null : (OID)oidResult.getHead();
            }

            if (oid != null)
            {
               instanceKey = Instance.getInstanceKey(m_metaclass, oid);
               instanceResult = getCached(instanceKey);

               if (bCached && instanceResult != null &&
                  (m_oid != null || ObjUtil.equal(instanceResult.getTail(), oidResult.getTail())))
               {
                  tobj = (TransferObject)instanceResult.getHead();
               }
            }

            if (tobj == null)
            {
               tobj = NULL_TO;

               if (tobjList == null)
               {
                  Pair attributes = getCachedAttributes();
                  InstanceList instanceList;

                  if (m_oid != null)
                  {
                     instanceList = readUncached(attributes, Pair.attribute("").eq(m_oid));
                  }
                  else
                  {
                     int nLimitSaved = m_nLimit;
                     int nOffsetSaved = m_nOffset;
                     int nMaxCountSaved = m_nMaxCount;
                     byte nCachedSaved = m_nCached;

                     m_nLimit = -1;
                     m_nOffset = 0;
                     setCached(false);

                     try
                     {
                        instanceList = m_adapter.read(this);
                     }
                     finally
                     {
                        m_nLimit = nLimitSaved;
                        m_nOffset = nOffsetSaved;
                        m_nMaxCount = nMaxCountSaved;
                        m_nCached = nCachedSaved;
                     }

                     bFiltered = true;

                     for (Iterator itr = getAssocIterator(ASSOC_QUERY); itr.hasNext();)
                     {
                        Query assoc = (Query)itr.next();

                        if (assoc.isJoin() && !assoc.isInverse() && !assoc.getAttribute().isLazy())
                        {
                           assoc.join();
                        }
                     }
                  }

                  if (!instanceList.isEmpty())
                  {
                     tobj = (TransferObject)RPCUtil.transfer(instanceList.get(0), attributes,
                        identityMap, RPCUtil.TF_ALL | RPCUtil.TF_LAZY | RPCUtil.TF_OLD);
                     identityMap.clear();
                     oid = tobj.getOID();
                  }

                  bMissed = true;
               }
               else
               {
                  if (m_oid != null)
                  {
                     for (int i = 0, n = tobjList.size(); i < n; ++i)
                     {
                        TransferObject cur = (TransferObject)tobjList.get(i);

                        if (m_oid.equals(cur.getOID()))
                        {
                           tobj = cur;

                           break;
                        }
                     }
                  }
                  else
                  {
                     for (int i = 0, n = tobjList.size(); i < n; ++i)
                     {
                        TransferObject cur = (TransferObject)tobjList.get(i);

                        m_instance = cur;

                        if (m_where == null || !Boolean.FALSE.equals(m_where.getValue()))
                        {
                           tobj = cur;

                           break;
                        }
                     }

                     bFiltered = true;
                  }
               }

               if (oid != null)
               {
                  if (instanceKey == null)
                  {
                     instanceKey = Instance.getInstanceKey(m_metaclass, oid);
                  }

                  Lookup cacheMap = new HashTab(2);

                  instanceResult = (m_oid != null) ? null : getCached(instanceKey);

                  if (instanceResult == null)
                  {
                     instanceResult = new Pair(tobj);

                     if (tobj != NULL_TO)
                     {
                        if (m_persistenceMapping.getLockingAttribute() != null)
                        {
                           instanceResult.setTail(tobj.findValue(m_persistenceMapping.getLockingAttribute().getName()));
                        }

                        if (instanceResult.getTail() == null)
                        {
                           instanceResult.setTail(new Object());
                        }
                     }

                     cacheMap.put(instanceKey, instanceResult);
                  }

                  if (m_oid == null)
                  {
                     cacheMap.put(oidKey, new Pair(oid, instanceResult.getTail()));
                  }

                  cache(cacheMap, tobj);
               }
            }
View Full Code Here

    * @throws ClassCastException if the argument is not a proper list or contains
    * elements other than Symbol objects.
    */
   public static EnumSet createMasterSet(Object elements)
   {
      Lookup map = new HashTab();
      int nIndex = 0;

      for (Pair pair; elements != null; elements = pair.getTail())
      {
         if (!(elements instanceof Pair))
         {
            throw new ScriptingException("err.scripting.enum.badList");
         }

         pair = (Pair)elements;

         Object head = pair.getHead();

         if (!(head instanceof Symbol))
         {
            throw new ScriptingException("err.scripting.enum.unsupportedValueType");
         }

         String sValue = ((Symbol)head).getName();

         if (!map.contains(sValue))
         {
            map.put(sValue, Primitive.createInteger(nIndex++));
         }
      }

      return new EnumSet(map);
   }
View Full Code Here

      // Process sources
      m_root.resolveInheritance(base.m_root);

      // Process mappings
      Lookup mappingMap = m_mappingMap;
      Set mappingSet = new HashHolder(m_mappingList.size()); // TransformationMapping[]

      mappingSet.addAll(m_mappingList);
      m_mappingList.clear();
      m_mappingMap = new HashTab(mappingSet.size());

      for (int i = 0, nCount = base.m_mappingList.size(); i < nCount; ++i)
      {
         TransformationMapping baseMapping = (TransformationMapping)base.m_mappingList.get(i);
         TransformationMapping mapping = null;

         if (baseMapping.getName() != null)
         {
            mapping = (TransformationMapping)mappingMap.get(baseMapping.getName());
         }

         if (mapping == null)
         {
            // Copy base transformation mapping to derived transformation
View Full Code Here

    */
   public void generate(Machine machine)
   {
      verifyNotReadOnly();

      Lookup messageMap = new LinkedHashTab();
      List defaultList = new ArrayList(4);

      // Group the branches by message
      for (int i = 0, n = getBranchCount(); i != n; ++i)
      {
         Branch branch = getBranch(i);
         Message message = (branch instanceof Case) ? ((Case)branch).getMessage() : null;

         if (message != null)
         {
            List list = (List)messageMap.get(message.getName());

            if (list == null)
            {
               list = new ArrayList(4);
               messageMap.put(message.getName(), list);
            }
           
            list.add(branch);
         }
         else
         {
            defaultList.add(branch);
         }
      }

      // Generate the grouped branches

      Pair body = Jump.BODY;
      Pair cond = new Pair(Symbol.COND, generate(defaultList));

      if (messageMap.size() == 0)
      {
         body = new Pair(cond, body);
      }
      else
      {
         // (case (this':class) (("msg1") (cond ...)) ... (("msgN") (cond ...)))

         Pair code = new Pair(Pair.list(Symbol.THIS, Pair.quote(Symbol._CLASS)));

         body = new Pair(new Pair(Symbol.CASE, code), body);

         for (Lookup.Iterator itr = messageMap.iterator(); itr.hasNext();)
         {
            itr.next();

            Pair tail = new Pair(Pair.list(Pair.list(itr.getKey()),
               new Pair(Symbol.COND, generate((List)itr.getValue()))));
View Full Code Here

         if (aspect.getValidation() != Undefined.VALUE)
         {
            if (bValidationDiff || !m_base.hasAspect(aspect))
            {
               Lookup aspectTextPosMap = aspect.getTextPositionMap();

               if (m_textPosMap != null && aspectTextPosMap != null)
               {
                  String sAspectURL = "class:" + aspect.getName() + "$validation";

                  for (Lookup.Iterator it = aspectTextPosMap.iterator(); it.hasNext();)
                  {
                     it.next();

                     m_textPosMap.put(it.getKey(), it.getValue());
                     urlMap.put(it.getValue(), sAspectURL);
View Full Code Here

TOP

Related Classes of nexj.core.util.Lookup$Iterator

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.