Package nexj.core.util

Examples of nexj.core.util.Lookup2D


    * @see nexj.core.integration.MessageParser#initializeMessageTable(nexj.core.meta.integration.MessageTable)
    */
   public void initializeMessageTable(MessageTable table) throws IntegrationException
   {
      XMLMessageParserTable parserTable = new XMLMessageParserTable();
      Lookup2D map = parserTable.getMessageMap();
      boolean bRestartable = false;
      byte nAcceptedEnvelopes = 0;

      for (Iterator itr = table.getMessageIterator(); itr.hasNext();)
      {
         Message message = (Message)itr.next();
         RootXMLMessagePartMapping mapping = (RootXMLMessagePartMapping)message.getRoot().getMapping();
         Message old = (Message)map.put((mapping.getNamespace() != null) ? mapping.getNamespace().getURI() : "",
            mapping.getNodeName(), message);

         if (old != null)
         {
            if (old.isUpcast(message) && old.getDerivation() != Message.DERIVATION_FINAL)
            {
               // Re-put old
               map.put((mapping.getNamespace() != null) ? mapping.getNamespace().getURI() : "",
                  mapping.getNodeName(), old);
            }
            else if (message.isUpcast(old) && message.getDerivation() != Message.DERIVATION_FINAL)
            {
               // base message "message" is already in table
View Full Code Here


   /**
    * @see nexj.core.meta.workflow.Flow#compile(nexj.core.scripting.Machine)
    */
   protected void compile(Machine machine) throws CompilerException
   {
      Lookup2D map = new HashTab2D(m_functionMap.size());

      // Compile the flow functions
      for (Lookup2D.Iterator itr = m_functionMap.valueIterator(); itr.hasNext();)
      {
         itr.next();

         Event event = (Event)itr.getKey1();
         Pair body = (Pair)machine.invoke((Function)machine.getGlobalEnvironment()
            .getVariable(Symbol.SYS_GENERATE_FLOW_FUNCTION), itr.getValue(), (Object[])null);

         itr.setValue(new Pair(new Compiler().compile(m_variables,
            event.getArguments(true), body, m_posMap, m_urlMap, machine)));
         map.put(event.getRoot(), itr.getKey2(), null);
      }

      for (Lookup2D.Iterator itr = map.valueIterator(); itr.hasNext();)
      {
         itr.next();

         addDerivedFlowFunctions((Pair)itr.getKey2(), (Event)itr.getKey1(),
            (Pair)m_functionMap.get(itr.getKey1(), itr.getKey2()));
View Full Code Here

      catch (Exception e)
      {
         throw new IntegrationException("err.integration.hl7.unparseableMessage", e);
      }

      Lookup2D map = (Lookup2D)table.getParserTable();
      Message message = (Message)map.get(msh.type, msh.event);

      if (message == null)
      {
         String s = msh.structure;

         if (s.length() != 0)
         {
            int i = s.indexOf('_');

            message = (Message)((i < 0) ? map.get(s, "") : map.get(s.substring(0, i), s.substring(i + 1)));
         }

         if (message == null)
         {
            if (msh.event.length() != 0)
            {
               message = (Message)map.get(msh.type, "");
            }

            if (message == null)
            {
               throw new IntegrationException("err.integration.hl7.unsupportedMessage", new Object[]{msh.type, msh.event});
View Full Code Here

   /**
    * @see nexj.core.integration.MessageParser#initializeMessageTable(nexj.core.meta.integration.MessageTable)
    */
   public void initializeMessageTable(MessageTable table) throws IntegrationException
   {
      Lookup2D map = new HashTab2D();

      for (Iterator itr = table.getMessageIterator(); itr.hasNext();)
      {
         Message message = (Message)itr.next();
         HL7MessagePartMapping mapping = (HL7MessagePartMapping)message.getRoot().getMapping();

         if (mapping.getLevel() != HL7MessagePartMapping.LEVEL_MESSAGE)
         {
            throw new MetadataException("err.meta.integration.hl7.messageLevel",
               new Object[]{message.getName()});
         }

         String sName = mapping.getName();

         if (sName == null)
         {
            throw new MetadataException("err.meta.integration.hl7.missingMessageType",
               new Object[]{message.getName()});
         }

         String sType;
         String sEvent;
         int i = sName.indexOf('^');

         if (i < 0)
         {
            sType = sName;
            sEvent = "";
         }
         else
         {
            sType = sName.substring(0, i);

            int k = sName.indexOf('^', i + 1);

            if (k < 0)
            {
               sEvent = sName.substring(i + 1);
            }
            else
            {
               sEvent = sName.substring(i + 1, k);
            }
         }

         Message old = (Message)map.put(sType, sEvent, message);

         if (old != null)
         {
            throw new MetadataException("err.meta.integration.hl7.dupMessageType",
               new Object[]{sType, sEvent, old.getName(), message.getName()});
View Full Code Here

    * Invokes the rules engine.
    * invoke(instance, rulesetName, attribute, attributes)
    */
   public Object invokeRulesEngine(Metaclass metaclass, Instance instance, String sName, Symbol attribute, Pair attributes, ActionContext actx)
   {
      Lookup2D objMap = (Lookup2D)metaclass.getValue("objMap");
      Instance engine = (Instance)objMap.get(instance, sName);
      boolean bCreate = (engine == null);
     
      if (bCreate)
      {
         engine = getRulesEngine(metaclass, instance, sName);
         objMap.put(instance, sName, engine);
      }

      try
      {
         Object[] args = new Object[]{attribute};
         Object obj = engine.invoke("compute", args);
        
         for (; attributes != null; attributes = attributes.getNext())
         {
            args[0] = attributes.getHead();
            engine.invoke("compute", args);
         }

         return obj;
      }
      finally
      {
         if (bCreate)
         {
            objMap.remove(instance, sName);
         }
      }
   }
View Full Code Here

         rs = dbmeta.getColumns(sCatalogName, sSchemaPattern, sTablePattern, "%");
         lastTable = null;
         nCurTable = 0;

         Lookup2D caseInsensitiveSet = new HashTab2D(); // Object[Table][String]

         while (rs.next())
         {
            Table table = schema.findTable(
               getFullTableName(toMetadataCase(rs.getString("TABLE_SCHEM")),
                                toMetadataCase(rs.getString("TABLE_NAME"))));

            if (table == null)
            {
               continue;
            }

            if (progress != null && table != lastTable)
            {
               lastTable = table;
               caseInsensitiveSet.clear();
               progress.progress("info.sql.schemaManager.readingColumns", new Object[]{table.getName()},
                  0.05 + 0.15 * (nCurTable++ / nTableCount));
            }

            String sColName = toMetadataCase(rs.getString("COLUMN_NAME"));
            String sName = null;

            if (sColName != null)
            {
               sName = getCaseSensitiveName(sColName);

               if (isCaseInsensitive(sColName))
               {
                  caseInsensitiveSet.put(table, sName, Boolean.TRUE);
               }
            }

            if (!isValidColumnName(sColName))
            {
               continue;
            }

            Column column = new Column(sName, table);

            column.setNullable(rs.getInt("NULLABLE") != DatabaseMetaData.columnNoNulls);
            column.setDescription(rs.getString("REMARKS"));

            String sTypeName = rs.getString("TYPE_NAME");
            int nType = rs.getInt("DATA_TYPE");
            int nPrecision = rs.getInt("COLUMN_SIZE");
            int nScale = rs.getInt("DECIMAL_DIGITS");
            byte nAllocation = Column.FIXED;
            Primitive type = null;
           
            switch (nType)
            {
               case Types.BIGINT:
                  type = Primitive.LONG;
                  nPrecision = 0;
                  nScale = 0;
                  break;
              
               case Types.BINARY:
                  type = Primitive.BINARY;
                  nScale = 0;
                  break;
              
               case Types.BIT:
               case Types.BOOLEAN:
                  type = Primitive.BOOLEAN;
                  nPrecision = 0;
                  nScale = 0;
                  break;

               case Types.BLOB:
               case Types.LONGVARBINARY:
                  type = Primitive.BINARY;
                 
                  if (nPrecision <= 0x4000)
                  {
                     nPrecision = Integer.MAX_VALUE;
                  }

                  nScale = 0;
                  nAllocation = (nType == Types.BLOB) ? Column.LOCATOR : Column.VARYING;
                  break;

               case Types.CHAR:
                  sTypeName = sTypeName.toLowerCase(Locale.ENGLISH);

                  if (sTypeName.equals("uniqueidentifier"))
                  {
                     type = Primitive.BINARY;
                     nPrecision = 16;
                     nScale = 0;
                  }
                  else
                  {
                     type = Primitive.STRING;
                     nScale = 0;
                  }

                  break;

               case Types.CLOB:
               case Types.LONGVARCHAR:
                  type = Primitive.STRING;
                    
                  if (nPrecision <= 0x4000)
                  {
                     nPrecision = Integer.MAX_VALUE;
                  }
  
                  nScale = 0;
                  nAllocation = (nType == Types.CLOB) ? Column.LOCATOR : Column.VARYING;
                  break;
              
               case Types.DATE:
               case Types.TIME:
               case Types.TIMESTAMP:
                  type = Primitive.TIMESTAMP;
                  nPrecision = 0;
                  nScale = 0;
                  break;
              
               case Types.DECIMAL:
               case Types.NUMERIC:
                  type = Primitive.DECIMAL;
                 
                  if (nScale == 0 && nPrecision <= 20)
                  {
                     if (nPrecision <= 10)
                     {
                        type = Primitive.INTEGER;

                        if (nPrecision <= 3)
                        {
                           nPrecision = 1;
                        }
                        else if (nPrecision <= 5)
                        {
                           nPrecision = 2;
                        }
                        else
                        {
                           nPrecision = 0;
                        }
                     }
                     else
                     {
                        type = Primitive.LONG;
                        nPrecision = 0;
                     }
                  }

                  break;

               case Types.DOUBLE:
               case Types.FLOAT:
                  type = Primitive.DOUBLE;
                  nPrecision = 0;
                  nScale = 0;
                  break;

               case Types.INTEGER:
                  type = Primitive.INTEGER;
                  nPrecision = 0;
                  nScale = 0;
                  break;

               case Types.SMALLINT:
                  type = Primitive.INTEGER;
                  nPrecision = 2;
                  nScale = 0;
                  break;

               case Types.TINYINT:
                  type = Primitive.INTEGER;
                  nPrecision = 1;
                  nScale = 0;
                  break;

               case Types.REAL:
                  type = Primitive.FLOAT;
                  nPrecision = 0;
                  nScale = 0;
                  break;
              
               case Types.VARBINARY:
                  type = Primitive.BINARY;
                  nScale = 0;
                  nAllocation = Column.VARYING;
                  break;

               case Types.VARCHAR:
                  type = Primitive.STRING;
                  nScale = 0;
                  nAllocation = Column.VARYING;
                  break;

               default:
                  sTypeName = sTypeName.toLowerCase(Locale.ENGLISH);

                  if (sTypeName.equals("nchar"))
                  {
                     type = Primitive.STRING;
                     nPrecision >>= 1;
                     nScale = 0;
                  }
                  else if (sTypeName.equals("nvarchar2") || sTypeName.equals("nvarchar"))
                  {
                     type = Primitive.STRING;
                     nPrecision >>= 1;
                     nScale = 0;
                     nAllocation = Column.VARYING;
                  }
                  else if (sTypeName.equals("binary_double"))
                  {
                     type = Primitive.DOUBLE;
                     nPrecision = 0;
                     nScale = 0;
                  }
                  else if (sTypeName.equals("binary_float"))
                  {
                     type = Primitive.FLOAT;
                     nPrecision = 0;
                     nScale = 0;
                  }
                  else if (sTypeName.startsWith("timestamp"))
                  {
                     type = Primitive.TIMESTAMP;
                     nPrecision = 0;
                     nScale = 0;
                  }
                  else if (sTypeName.equals("nclob") || sTypeName.equals("clob"))
                  {
                     type = Primitive.STRING;
                    
                     if (nPrecision <= 0x4000)
                     {
                        nPrecision = Integer.MAX_VALUE;
                     }
  
                     nScale = 0;
                     nAllocation = Column.LOCATOR;
                  }
                  else if (sTypeName.equals("blob"))
                  {
                     type = Primitive.BINARY;
                       
                     if (nPrecision <= 0x4000)
                     {
                        nPrecision = Integer.MAX_VALUE;
                     }
     
                     nScale = 0;
                     nAllocation = Column.LOCATOR;
                  }
              
                  break;
            }

            if (nPrecision < 0)
            {
               nPrecision = 0;
            }

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("Read column \"" + table.getName() + "." + column.getName() + "\" " +
                  sTypeName + "(" + rs.getInt("COLUMN_SIZE") + "," + rs.getInt("DECIMAL_DIGITS") +
                  "), SQLType=" + nType + " -> " + ((type == null) ? "ignored: unsupported type" : type.getName() +
                  "(" + nPrecision + "," + nScale + "), allocation=" + nAllocation));
            }

            if (type != null)
            {
               column.setType(type);
               column.setPrecision(nPrecision);
               column.setScale(nScale);
               column.setAllocation(nAllocation);

               try
               {
                  table.addColumn(column);
                  bPortable &= isPortable(column);
               }
               catch (MetadataException e)
               {
                  s_logger.error("Cannot add column \"" + column.getName() + "\"", e);
               }
            }
         }

         rs.close();
         rs = null;

         // Set the case-sensitive columns

         for (Iterator tableItr = tableMap.iterator(); tableItr.hasNext();)
         {
            Table table = (Table)tableItr.next();

            for (int i = 0; i < table.getColumnCount(); ++i)
            {
               Column column = table.getColumn(i);

               if (!caseInsensitiveSet.contains(table, column.getName()))
               {
                  column.setCaseInsensitive(false);
               }
            }
         }
View Full Code Here

      for (int i = 0; i < objArray.length; ++i)
      {
         dropObject(objArray[i]);
      }

      Lookup2D/*<String, Integer, List<Table>>*/ tableMap =
         new HashTab2D/*<String, Integer, List<Table>>*/(schema.getTableCount());

      if (metadata.isTestEnvironment())
      {
         Upgrade upgrade = metadata.getUpgrade("Main");
         VersionUpgrade version = upgrade.getFirstVersion();
         Lookup/*<Object, UpgradeState>*/ stateMap = Upgrade.getInitialState(version);

         version = findFirstVersion(version, stateMap, (RelationalDatabase)schema.getDataSource());

         for (VersionUpgrade u = version; u != null; u = u.getNext())
         {
            if (u instanceof RelationalSchemaUpgrade)
            {
               RelationalSchemaUpgrade rsu = (RelationalSchemaUpgrade)u;

               if (rsu.getDataSource().getSchema() == schema)
               {
                  RelationalSchemaUpgradeState state =
                     (RelationalSchemaUpgradeState)Upgrade.getState(stateMap, u);

                  for (int i = 0, nCount = rsu.getStepCount(); i < nCount; ++i)
                  {
                     rsu.getStep(i).apply(state); // apply every every step off this upgrade
                  }

                  addDropTable(tableMap, state.getSchema()); // add any differing definitions
               }
            }
         }
      }

      // Need to remove tables from schema prior to dropTable() so that dependency resolution works
      // as expected. For this a modifiable RelationalSchema is required.
      addDropTable(tableMap, (RelationalSchema)schema.clone());

      List/*<Table>*/ tableList = new ArrayList/*<Table>*/();

      for (Iterator/*<List<Table>>*/ itr = tableMap.valueIterator(); itr.hasNext();)
      {
         tableList.addAll((Collection)itr.next());
      }

      Collections.sort(tableList, TABLE_COMPARATOR); // sort table array in predictable order
View Full Code Here

    */
   public Element mergeDescriptorElements(List baseList, List rootList) throws MetadataException
   {
      Document doc = XMLUtil.parse(new StringReader("<Metadata/>"));
      Element descriptorElement = doc.getDocumentElement();
      Lookup2D resourceMap = new HashTab2D();
      Lookup refNameMap = new LinkedHashTab();
      Lookup mixinMap = new LinkedHashTab();
      String sBaseNamespace = null;
      String sBaseVersion = null;
      String sBaseChecksum = null;
      String sBaseName = null;
      String sBaseRevision = null;
      String sBaseDescription = null;
      String sBaseCoreVersion = null;
      String sBaseModule = null;
      String sBaseOverride = null;
      String sRootNamespace = null;
      String sRootVersion = null;
      String sRootDescription = null;
      String sRootName = null;
      String sRootRevision = null;
      String sRootCoreVersion = null;
      String sRootModule = null;
      String sRootOverride = null;
      Element baseElement = getDescriptorElement(false);
      Element rootElement = getDescriptorElement(true);

      if (baseElement != null)
      {
         sBaseNamespace = XMLUtil.getReqStringAttr(baseElement, "namespace");
         sBaseVersion = XMLUtil.getReqStringAttr(baseElement, "version");
         sBaseName = XMLUtil.getReqStringAttr(baseElement, "name");
         sBaseRevision = XMLUtil.getReqStringAttr(baseElement, "revision");
         sBaseCoreVersion = XMLUtil.getStringAttr(baseElement, "coreVersion");
         sBaseModule = normalizeScope(XMLUtil.getStringAttr(baseElement, "module"));
         sBaseOverride = XMLUtil.getStringAttr(baseElement, "override");
         sBaseDescription = XMLUtil.getStringAttr(baseElement, "description");
         sBaseChecksum = getChecksum(false);
         addMixinElements(mixinMap, baseElement);
         addResourceElements(resourceMap, refNameMap, baseElement);
      }

      if (rootElement != null)
      {
         sRootNamespace = XMLUtil.getReqStringAttr(rootElement, "namespace");
         sRootVersion = XMLUtil.getReqStringAttr(rootElement, "version");
         sRootName = XMLUtil.getReqStringAttr(rootElement, "name");
         sRootRevision = XMLUtil.getReqStringAttr(rootElement, "revision");
         sRootCoreVersion = XMLUtil.getStringAttr(rootElement, "coreVersion");
         sRootModule = normalizeScope(XMLUtil.getStringAttr(rootElement, "module"));
         sRootOverride = XMLUtil.getStringAttr(rootElement, "override");
         sRootDescription = XMLUtil.getStringAttr(rootElement, "description");
         addMixinElements(mixinMap, rootElement);
         addResourceElements(resourceMap, refNameMap, rootElement);

         if (baseElement == null)
         {
            sBaseNamespace = XMLUtil.getStringAttr(rootElement, "baseNamespace");
            sBaseVersion = XMLUtil.getStringAttr(rootElement, "baseVersion");
            sBaseChecksum = XMLUtil.getStringAttr(rootElement, "baseChecksum");
         }
      }
      else
      {
         sRootNamespace = sBaseNamespace;
         sRootVersion = sBaseVersion;
         sRootName = sBaseName;
         sRootRevision = sBaseRevision;
         sRootModule = sBaseModule;
         sRootOverride = sBaseOverride;
         sRootDescription = sBaseDescription;
         sBaseNamespace = null;
         sBaseVersion = null;
         sBaseChecksum = null;
         sBaseModule = null;
         sBaseOverride = null;
         sBaseDescription = null;
      }

      if (sRootCoreVersion == null)
      {
         sRootCoreVersion = sBaseCoreVersion;
      }

      if (sRootNamespace != null)
      {
         descriptorElement.setAttribute("name", sRootName);
         descriptorElement.setAttribute("revision", sRootRevision);
         descriptorElement.setAttribute("namespace", sRootNamespace);
         descriptorElement.setAttribute("version", sRootVersion);

         if (sRootCoreVersion != null)
         {
            descriptorElement.setAttribute("coreVersion", sRootCoreVersion);
         }

         if (sRootModule != null)
         {
            descriptorElement.setAttribute("module", sRootModule);
         }

         if (sRootOverride != null)
         {
            descriptorElement.setAttribute("override", sRootOverride);
         }

         if (sRootDescription != null)
         {
            descriptorElement.setAttribute("description", sRootDescription);
         }
      }

      if (sBaseNamespace != null)
      {
         descriptorElement.setAttribute("baseNamespace", sBaseNamespace);
         descriptorElement.setAttribute("baseVersion", sBaseVersion);
         descriptorElement.setAttribute("baseChecksum", sBaseChecksum);
      }

      // Insert the mixin elements
      Element mixinsElement = doc.createElement("Mixins");

      descriptorElement.appendChild(mixinsElement);

      for (Iterator itr = mixinMap.valueIterator(); itr.hasNext(); )
      {
         Element mixinElement = XMLUtil.addChildElement(mixinsElement, null, "Mixin");
         NamedNodeMap map = ((Element)itr.next()).getAttributes();

         for (int i = 0, n = map.getLength(); i < n; ++i)
         {
            Attr attr = (Attr)map.item(i);

            mixinElement.setAttribute(attr.getName(), attr.getValue());
         }
      }

      // Instantiate all the container elements and place them in a map by name
      Lookup refMap = new HashTab(refNameMap.size());

      for (Lookup.Iterator itr = refNameMap.iterator(); itr.hasNext();)
      {
         Element element = doc.createElement((String)itr.next());

         descriptorElement.appendChild(element);
         refMap.put(itr.getKey(), element);
      }

      // Insert the reference elements
      for (Lookup2D.Iterator itr = resourceMap.valueIterator(); itr.hasNext();)
      {
         Element element = (Element)itr.next();
         Element refElement = doc.createElement((String)refNameMap.get(itr.getKey1()));

         ((Element)refMap.get(itr.getKey1())).appendChild(refElement);
View Full Code Here

TOP

Related Classes of nexj.core.util.Lookup2D

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.