Package nexj.core.util

Examples of nexj.core.util.HashTab


            }
            else
            {
               if (m_methodMap == null)
               {
                  m_methodMap = new HashTab(2);
               }

               sName = sName.toUpperCase(Locale.ENGLISH);
               m_methodMap.put(sName, sComponentName);
View Full Code Here


    * @param updater The updater that sets the properties.
    * @throws JMSException
    */
   public static void setMessageProperties(Message message, MessagePropertyUpdater updater) throws JMSException
   {
      Lookup propMap = new HashTab();

      for (Enumeration enm = message.getPropertyNames(); enm.hasMoreElements();)
      {
         String sName = (String)enm.nextElement();

         propMap.put(sName, message.getObjectProperty(sName));
      }

      updater.getProperties(message);
      message.clearProperties();

      for (Lookup.Iterator itr = propMap.iterator(); itr.hasNext();)
      {
         itr.next();
         message.setObjectProperty((String)itr.getKey(), itr.getValue());
      }

View Full Code Here

    * @param context The invocation context.
    * @see #complete()
    */
   public InstanceFactory(int nMode, InvocationContext context)
   {
      m_identityMap = new HashTab();
      m_fixupList = new ArrayList();
      m_nMode = nMode;
      m_context = context;
   }
View Full Code Here

    * Constructs the factory for instantiation from cache.
    * @param context The invocation context.
    */
   public InstanceFactory(InvocationContext context)
   {
      m_identityMap = new HashTab();
      m_fixupList = null;
      m_nMode = STATE;
      m_context = context;
   }
View Full Code Here

      try
      {
         con = getConnection();
         rs = con.getConnection().getMetaData().getIndexInfo(table.getOwnerName(), null, table.getTableName(), false, true);
         indexMap = new HashTab();

         for (int i = 0; rs.next();)
         {
            if (rs.getShort("ORDINAL_POSITION") == 1) // this is first column of index (every index has first column)
            {
View Full Code Here

               bInstanceFilter = tobj.hasValue("instances");
            }
         }

         int nInvocationCount = request.getInvocationCount();
         Lookup identityMap = new HashTab(nInvocationCount << 1);
         Lookup eventMap = new HashTab(nInvocationCount);
         Event[] eventArray = new Event[nInvocationCount];

         argArray = new Object[nInvocationCount][];
         InstanceFactory instanceFactory = new InstanceFactory(identityMap,
            new ArrayList(nInvocationCount << 3), InstanceFactory.STATE | InstanceFactory.PRE,
            m_context);

         // Instantiate the request objects
         for (int i = 0; i < nInvocationCount; ++i)
         {
            Request.Invocation invocation = request.getInvocation(i);
            TransferObject tobj = invocation.getObject();
            String sEventName = invocation.getEventName();

            if (sEventName == null)
            {
               sEventName = tobj.getEventName();
            }

            if (tobj == null || tobj.getClassName() == null || sEventName == null)
            {
               throw new RequestException("err.rpc.requestTO");
            }

            m_context.setTransient(bTransient);

            Object[] arguments = invocation.getArguments();
            Metaclass metaclass = metadata.getMetaclass(tobj.getClassName());
            Selector selector = metaclass.getSelector(sEventName);
            Member member;
            int nArgCount;

            if (arguments != null)
            {
               nArgCount = arguments.length;
               member = selector.getMember(nArgCount);

               if (member.isStatic() && tobj.getValueCount() != 0)
               {
                  throw new RequestException("err.rpc.requestTO");
               }
            }
            else
            {
               nArgCount = tobj.getValueCount();
               member = selector.findMember(0);

               if (member == null || member.isStatic())
               {
                  member = selector.getMember(nArgCount);

                  if (!member.isStatic())
                  {
                     throw new RequestException("err.rpc.argCount",
                        new Object[]{member.getName(), metaclass.getName()});
                  }
               }
               else
               {
                  nArgCount = 0;
               }
            }

            if (member.isAttribute())
            {
               throw new RequestException("err.rpc.attributeInvocation",
                  new Object[]{member.getName(), metaclass.getName()});
            }

            if (m_context.isProtected() && member.getVisibility() != Metaclass.PUBLIC)
            {
               throw new SecurityViolationException("err.rpc.eventVisibility",
                  new Object[]{member.getName(), metaclass.getName()});
            }

            Event event = (Event)member;
            Object[] args = new Object[nArgCount + 1];

            if (arguments != null)
            {
               for (int k = 0; k < nArgCount; ++k)
               {
                  args[k + 1] = instanceFactory.instantiate(arguments[k]);
               }
            }

            if (event.isStatic())
            {
               args[0] = metaclass;

               if (arguments == null)
               {
                  int nEventArgCount = event.getArgumentCount();

                  if (event.isVarArg())
                  {
                     --nEventArgCount;
                  }

                  for (int k = 0; k < nEventArgCount; ++k)
                  {
                     args[k + 1] = instanceFactory.instantiate(tobj.getValue(event.getArgument(k).getName()));
                  }

                  if (event.isVarArg())
                  {
                     int nArg = nEventArgCount;

                     for (PropertyIterator itr = tobj.getIterator(); itr.hasNext();)
                     {
                        itr.next();

                        Argument arg = event.findArgument(itr.getName());

                        if (arg == null || arg == event.getArgument(nEventArgCount))
                        {
                           args[++nArg] = new Pair(Symbol.define(itr.getName()), instanceFactory.instantiate(itr.getValue()));
                        }
                     }
                  }
               }

               // Allow auditing of static events
               identityMap.put(tobj, null);
            }
            else
            {
               args[0] = instanceFactory.instantiate(tobj);
            }

            eventArray[i] = event;
            argArray[i] = args;
            eventMap.put(tobj, event);
         }

         Lookup diffMap = null;

         // Instantiate the transfer objects from the instance filters
         if (bInstanceFilter)
         {
            diffMap = new HashTab();

            for (int i = 0; i < nFilterCount; ++i)
            {
               m_context.setTransient(bTransient);

               TransferObject tobj = request.getFilter(i);
               Object instances = tobj.findValue("instances");

               if (instances != null)
               {
                  List instanceList = (List)instances;
                  int nCount = instanceList.size();

                  for (int k = 0; k < nCount; ++k)
                  {
                     tobj = (TransferObject)instanceList.get(k);

                     Instance inst = instanceFactory.instantiate(tobj);

                     instanceList.set(k, inst);

                     if (inst != null)
                     {
                        diffMap.put(inst, tobj);
                     }
                  }
               }
            }
         }

         instanceFactory.complete();
         instanceFactory = null;
         GenericServer.auditRequest(identityMap, eventMap, m_context);
         identityMap = null;

         Object[] resultArray = new Object[nInvocationCount << 1];

         // Unset the pending event flag on the request argument instances
         for (int i = 0; i < nInvocationCount; ++i)
         {
            Object[] args = argArray[i];
            Object obj = args[0];

            if (obj instanceof Instance)
            {
               Instance instance = (Instance)obj;

               if (args.length == 1 && eventArray[i].getName().equals(instance.getPendingEventName()))
               {
                  resultArray[i << 1] = instance;
               }

               instance.suspendEvent();
            }
         }

         m_context.setTransient(false);
         uow.invokePendingEvents(false, false);

         // Invoke the events and accumulate the results
         for (int i = 0; i < nInvocationCount; ++i)
         {
            TransferObject tobj = request.getObject(i);
            Event event = eventArray[i];
            Pair attributes = EMPTY_PAIR;
            Object[] args = argArray[i];
            Object obj = args[0];
            int nAttrIndex = -1;

            m_context.setTransient(event.isTransient(bTransient));

            if (event.getArgumentCount() != 0)
            {
               Argument arg = event.findArgument("attributes");

               if (arg != null)
               {
                  nAttrIndex = arg.getOrdinal() + 1;

                  Object value = args[nAttrIndex];

                  attributes = (value instanceof Pair) ? (Pair)value : null;
               }
            }

            if (nAttrIndex < 0)
            {
               Object value = tobj.findValue("attributes", EMPTY_PAIR);

               if (value != EMPTY_PAIR)
               {
                  nAttrIndex = 0;
                  attributes =  (Pair)value;
               }
            }

            if (event.isStatic() && m_context.isProtected() && m_context.isSecure())
            {
               Metaclass metaclass = event.getMetaclass();
               Argument result = event.getResult();

               if (result != null && !result.getType().isPrimitive())
               {
                  metaclass = (Metaclass)result.getType();
               }

               if (nAttrIndex > 0)
               {
                  Pair security = metaclass.checkReadAccess(attributes, m_context.getPrivilegeSet());
  
                  if (security != null)
                  {
                     args[nAttrIndex] = Pair.nconc(security, attributes);
                  }
               }

               metaclass.checkExpressionAccess(findArg(event, "where", args, tobj),  m_context.getPrivilegeSet());
               metaclass.checkOrderByAccess(findArg(event, "orderBy", args, tobj), m_context.getPrivilegeSet());
            }

            boolean bInvoked = false;
            boolean bDeleted = false;

            m_context.setUnitOfWork(uow);
            m_context.setTransient(event.isTransient(bTransient));

            if (obj instanceof Instance)
            {
               Instance instance = (Instance)obj;
               UnitOfWork instanceUOW = instance.getUnitOfWork();

               // Use the instance UoW
               if (!event.isStatic() && instanceUOW != null && instanceUOW != uow)
               {
                  m_context.setUnitOfWork(instanceUOW);
               }

               bInvoked = instance.invokeSuspendedEvent();
               bDeleted = (instance.getState() == Instance.DELETED);

               if (nAttrIndex <= 0)
               {
                  Attribute attribute = instance.getMetaclass().findAttribute("attributes");

                  if (attribute != null && !attribute.isStatic())
                  {
                     attributes = (Pair)instance.getValue(attribute.getOrdinal());
                  }
               }
            }

            if (resultArray[i << 1] == null)
            {
               if (!bDeleted)
               {
                  resultArray[i << 1] = event.invoke(args, m_context.getMachine());
               }
            }
            else
            {
               if (!bInvoked && !bDeleted)
               {
                  event.invoke(args, m_context.getMachine());
               }

               eventArray[i] = null;
            }

            resultArray[(i << 1) + 1] = attributes;
         }

         // Pre-commit all units of work in the context
         for (int i = m_context.getUnitOfWorkCount() - 1; i >= 0; i--)
         {
            UnitOfWork work = m_context.getUnitOfWork(i);

            m_context.setUnitOfWork(work);

            if (work.isTransient())
            {
               work.invokePendingEvents(true, false);
               work.computeHiddenness();
               work.accumulateChanges();
            }
            else
            {
               work.commit(false);
            }
         }

         m_context.setUnitOfWork(uow);

         // Transfer the results into the response object.
         // This is done as a separate step after the commit
         // so that the objects are in the correct state (e.g. with OIDs).
         Response response = new Response();

         identityMap = new HashTab();

         for (int i = 0; i < nInvocationCount; ++i)
         {
            Object result = resultArray[i << 1];
            Pair attributes = request.getInvocation(i).getAttributes();
            int nTF = RPCUtil.TF_HIDDEN;
           
            if (attributes == null)
            {
               attributes = (Pair)resultArray[(i << 1) + 1];

               if (attributes == EMPTY_PAIR)
               {
                  attributes = null;
                  nTF |= RPCUtil.TF_READABLE;
               }
            }
            else if (m_context.isProtected() && m_context.isSecure())
            {
               if (result instanceof Instance)
               {
                  Instance instance = (Instance)result;

                  instance.invoke("load", Pair.nconc(instance.getMetaclass()
                     .checkReadAccess(attributes, m_context.getPrivilegeSet()), attributes));
               }
               else if (result instanceof InstanceList)
               {
                  InstanceList list = (InstanceList)result;
                  Lookup classMap = new HashTab(4);

                  for (int k = 0, n = list.size(); k < n; ++k)
                  {
                     Instance instance = list.getInstance(k);
                     Metaclass metaclass = instance.getMetaclass();
                     Pair all = (Pair)classMap.get(metaclass);

                     if (all == null)
                     {
                        all = Pair.nconc(metaclass.checkReadAccess(
                           attributes, m_context.getPrivilegeSet()), attributes);

                        classMap.put(metaclass, all);
                     }

                     instance.invoke("load", all);
                  }
               }
View Full Code Here

   {
      verifyNotReadOnly();

      if (m_hintMap == null)
      {
         m_hintMap = new HashTab/*<String, Boolean>*/(2);
      }

      if (m_hintMap.put(sHint, Boolean.valueOf(bEnabled)) != null)
      {
         throw new MetadataException("err.meta.tableHintDup", new Object[]{sHint, m_sName});
View Full Code Here

      schema.setPortable(false);

      try
      {
         Lookup tableMap = new HashTab();

         dbmeta = m_connection.getMetaData();

         // Read the tables

         if (progress != null)
         {
            progress.progress("info.sql.schemaManager.readingTables", null, 0);
         }

         sCatalogName = toDatabaseCase(sCatalogName);
         sSchemaPattern = toDatabaseCase(sSchemaPattern);
         sTablePattern = toDatabaseCase(sTablePattern);

         rs = dbmeta.getTables(sCatalogName, sSchemaPattern, sTablePattern, new String[]{"TABLE"});

         if (progress != null)
         {
            progress.progress("info.sql.schemaManager.readingTables", null, 0.01);
         }

         while (rs.next())
         {
            String sReadCatalogName = rs.getString("TABLE_CAT");
            String sSchemaName = toMetadataCase(rs.getString("TABLE_SCHEM"));
            String sTableName = rs.getString("TABLE_NAME");

            if (!isValidTableName(sTableName))
            {
               continue;
            }

            if (nameSet != null && !nameSet.contains(sTableName))
            {
               continue;
            }

            sTableName = toMetadataCase(sTableName);

            Table table = new Table(schema);

            table.setName(getFullTableName(sSchemaName, sTableName));
            table.setDescription(rs.getString("REMARKS"));
            table.setType(Table.EXTERNAL);
            ++nTableCount;

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("Read table \"" + ((sReadCatalogName == null) ? "" : sReadCatalogName) +
                  "." + ((sSchemaName == null) ? "" : sSchemaName) + "." + sTableName +
                  "\" -> \"" + table.getName() + "\"");
            }

            try
            {
               schema.addTable(table);
               tableMap.put(table, new String[]{sReadCatalogName, sSchemaName});
               bPortable &= isPortable(table);
            }
            catch (MetadataException e)
            {
               s_logger.error("Cannot add table \"" + table.getName() + "\"", e);
            }
         }

         rs.close();
         rs = null;

         if (nTableCount == 0)
         {
            nTableCount = 1;
         }

         // Read the columns

         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);
               }
            }
         }

         // Read the indexes

         nCurTable = 0;

         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table table = (Table)itr.next();
            String[] names = (String[])tableMap.get(table);
            Index index = null;
            boolean bIgnore = false;
           
            if (progress != null)
            {
               progress.progress("info.sql.schemaManager.readingIndexes", new Object[]{table.getName()},
                  0.20 + 0.50 * (nCurTable++ / nTableCount));
            }

            rs = getIndexInfo(
                    names[0], toDatabaseCase(names[1]), toDatabaseCase(table.getTableName()));

            while (rs.next())
            {
               String sIndexName = toMetadataCase(rs.getString("INDEX_NAME"));

               if (sIndexName == null)
               {
                  continue;
               }
              
               String sColumnName = rs.getString("COLUMN_NAME");
               boolean bAscending = !"D".equals(rs.getString("ASC_OR_DESC"));
               boolean bUnique = !rs.getBoolean("NON_UNIQUE");
               int nType = rs.getInt("TYPE");

               sIndexName = generateIndexName(table.getTableName(), sIndexName, null);

               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Read index column \"" + sIndexName + "." +
                     sColumnName + "\", ascending=" + bAscending);
               }

               if (index != null && !index.getName().equals(sIndexName))
               {
                  if (!bIgnore)
                  {
                     if (addIndex(table, index))
                     {
                        bPortable &= isPortable(index);
                     }
                  }

                  index = null;
                  bIgnore = false;
               }

               if (index == null)
               {
                  index = new Index(sIndexName, (nType == DatabaseMetaData.tableIndexClustered)
                                                ? Index.CLUSTER : Index.BTREE, table);
                  index.setUnique(bUnique);
               }

               if (!isValidColumnName(sColumnName))
               {
                  if (isCaseInsensitive(sColumnName))
                  {
                     sColumnName = getCaseSensitiveName(sColumnName);
                  }
                  else if (isFunctionalIndexSupported())
                  {
                     String sExpr = rs.getString("EXPR");

                     if (sExpr != null && sExpr.length() != 0)
                     {
                        String sName = getCaseSensitiveNameFromExpression(sExpr);

                        if (sName == null)
                        {
                           bIgnore = true;
                        }
                        else
                        {
                           sColumnName = sName;
                        }
                     }
                  }
                  else
                  {
                     bIgnore = true;
                  }
               }

               sColumnName = toMetadataCase(sColumnName);

               if (!bIgnore)
               {
                  try
                  {
                     index.addIndexColumn(new IndexColumn(table.getColumn(sColumnName), bAscending));
                  }
                  catch (MetadataException e)
                  {
                     s_logger.error("Cannot find column \"" + sColumnName +
                        "\", ignoring index \"" + sIndexName + "\"", e);
                     bIgnore = true;
                  }
               }
            }

            if (index != null && !bIgnore)
            {
               if (addIndex(table, index))
               {
                  bPortable &= isPortable(index);
               }
            }

            rs.close();
            rs = null;

            // Read the primary key

            rs = getPrimaryKeys(names[0], names[1], table.getTableName());
            index = null;
            bIgnore = false;

            try
            {
               while (rs.next())
               {
                  String sColumnName = toMetadataCase(rs.getString("COLUMN_NAME"));
                 
                  if (index == null)
                  {
                     String sIndexName = rs.getString("PK_NAME");

                     if (sIndexName == null)
                     {
                        sIndexName = table.getName() + ".PK";
                        index = new Index(sIndexName, Index.BTREE, table);
                     }
                     else
                     {
                        sIndexName = generateIndexName(table.getTableName(), sIndexName, "PK");
                        index = table.findIndex(sIndexName);

                        if (index == null)
                        {
                           index = new Index(sIndexName, Index.BTREE, table);
                        }
                        else
                        {
                           table.setPrimaryKey(index);
                           bIgnore = true;

                           break;
                        }
                     }
                  }

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Read primary key column \"" + index.getName() + "." + sColumnName + "\"");
                  }

                  index.setUnique(true);
                  index.addIndexColumn(new IndexColumn(table.getColumn(sColumnName), true));
               }
            }
            catch (MetadataException e)
            {
               s_logger.error("Cannot add primary key to table \"" + table.getName() + "\"", e);
               bIgnore = true;
            }

            if (index != null)
            {
               if (!bIgnore)
               {
                  if (addIndex(table, index))
                  {
                     table.setPrimaryKey(index);
                     bPortable &= isPortable(index);
                  }
               }
            }
            else
            {
               for (int i = 0; i < table.getIndexCount(); ++i)
               {
                  index = table.getIndex(i);
                 
                  if (index.isUnique())
                  {
                     table.setPrimaryKey(index);
                    
                     break;
                  }
               }
            }
           
            if (s_logger.isDebugEnabled())
            {
               if (table.getPrimaryKey() != null)
               {
                  s_logger.debug("The primary key of table \"" + table.getName() +
                     "\" is \"" + table.getPrimaryKey().getName() + "\"");
               }
               else
               {
                  s_logger.debug("Table \"" + table.getName() + "\" has no primary key");
               }
            }

            rs.close();
            rs = null;
         }

         // Read the foreign keys

         nCurTable = 0;

         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table table = (Table)itr.next();
            String[] names = (String[])tableMap.get(table);
            Index index = null;
            boolean bIgnore = false;

            if (progress != null)
            {
View Full Code Here

      m_helper = new XMLMetadataHelper(rootURL, baseURL, m_properties, null, handler);
      m_metadata = createXMLMetadata(sURI, rootURL, baseURL, (m_bValidatedOnly) ? m_helper : null);
      m_metadata.setConfigurationURL(configURL);
      m_machine = new Machine(m_metadata.getGlobalEnvironment(),
         new InvocationContext(m_metadata, m_metadata.getGlobalEnvironment()));
      m_enumerationValueMap = new HashTab(16);
      m_inheritanceCheckList = new ArrayList();
      m_inheritanceFixupList = new ArrayList();
      m_inheritance1stPassFixupList = new ArrayList();
      m_inheritance2ndPassFixupList = new ArrayList(1);
      m_inheritance4thPassFixupList = new ArrayList(1);
      m_attributeGenerationList = new ArrayList();
      m_attributeFixupList = new ArrayList();
      m_attributeResolutionList = new ArrayList(1);
      m_actionFixupList = new ArrayList();
      m_persistenceMappingLoadList = new ArrayList();
      m_persistenceMappingFixupList = new ArrayList();
      m_persistenceMappingGenerationList = new ArrayList();
      m_attributeDependencyList = new ArrayList(1);
      m_attributeDependencySet = new HashHolder();
      m_class2ndPassList = new ArrayList(1);
      m_ioFixupList = new ArrayList();
      m_environmentFixupList = new ArrayList();
      m_privilegeFixupList = new ArrayList();
      m_preInheritanceMessageFixupList = new ArrayList();
      m_postInheritanceMessageFixupList = new ArrayList();
      m_transformationFixupList = new ArrayList();
      m_postInheritanceTransformationFixupList = new ArrayList();
      m_componentFixupList = new ArrayList();
      m_singletonFixupList = new ArrayList();
      m_tmpDocument = XMLUtil.parse(new StringReader("<TmpDocument/>"));

      m_metadata.setEncrypted((nFlags & ENCRYPTED) != 0);
      m_metadata.setEnvironmentOnly(m_bEnvironmentOnly);

      if ((nFlags & WARNING) != 0)
      {
         m_helper.setWarnings(new GenericException(null)
         {
            private final static long serialVersionUID = -2984934222963813773L;

            public void addException(Throwable e)
            {
               e.setStackTrace(ObjUtil.EMPTY_STACK_TRACE);
               super.addException(e);
            }
         });
      }

      // Prepare the progress listener
      ProgressProxy progressProxy = new ProgressProxy(progress);

      if (progress != null)
      {
         progress = progressProxy;
      }

      // Load the repository descriptors and process the elements in them

      if (progress != null)
      {
         progress.progress("info.meta.loadingDescriptors", null, 0);
      }

      Element baseDescElement = m_helper.getDescriptorElement(false);
      Element rootDescElement = m_helper.getDescriptorElement(true);

      progressProxy.setRange(0.01, 0.02);

      m_metadata.setListing(m_helper.getListing(new XMLMetadataHelper.MixinHandler()
         {
            /**
             * Metadata repository information, indexed by namespace.
             */
            private Lookup m_metadataMap = new HashTab();

            private String getMetadataName(String sNamespace)
            {
               MetadataInfo info = ((MetadataInfo)m_metadataMap.get(sNamespace));

               return (info == null || info.metadata == null) ? sNamespace : info.metadata.getName();
            }

            public void handleRepository(XMLMixin mixin)
            {
               String sNamespace = mixin.getNamespace();
               XMLMetadataHelper helper = mixin.getHelper();
               MetadataInfo info = (MetadataInfo)m_metadataMap.get(sNamespace);

               if (info == null)
               {
                  info = new MetadataInfo();
               }

               // get the metadata instance
               if (m_metadataMap.size() == 0)
               {
                  info.metadata = m_metadata;
               }
               else
               {
                  URL rootURL = helper.getRootURL();

                  info.metadata = createXMLMetadata(rootURL.getPath(), rootURL, helper.getBaseURL(), helper);
               }

               // load the version
               loadVersion(info.metadata, helper);
               m_metadataMap.put(sNamespace, info);

               // validate loaded mixin
               if (m_metadata != info.metadata)
               {
                  // Adopt the highest coreVersion available from any of the repositories.
                  if (m_metadata.getCoreVersion() == null || (info.metadata.getCoreVersion() != null &&
                     StringUtil.compareVersionRanges(m_metadata.getCoreVersion(), info.metadata.getCoreVersion()) < 0))
                  {
                     m_metadata.setCoreVersion(info.metadata.getCoreVersion());
                  }

                  if (info.ref == null)
                  {
                     throw new MetadataValidationException("err.meta.mixinNamespace", new Object[]{info.metadata.getName(), sNamespace});
                  }

                  String sVersion = info.ref.getVersion();
                  String sChecksum = info.ref.getChecksum();

                  // validate that repository matches mixin declaration
                  if ((sVersion != null && !sVersion.equals(info.metadata.getVersion()))
                     || (sChecksum != null && !sChecksum.equals(info.metadata.getChecksum())))
                  {
                     throw new MetadataValidationException("err.meta.mixinLinkVersion", new Object[]{
                        info.metadata.getName(),
                        info.metadata.getVersion(),
                        info.metadata.getChecksum(),
                        sVersion,
                        sChecksum,
                        getMetadataName(info.parentNamespace)
                     });
                  }
               }
            }

            public void handleMixinReference(XMLMixin ref, XMLMixin parent)
            {
               String sParentNamespace = parent.getNamespace();
               String sNamespace = ref.getNamespace();
               String sVersion = ref.getVersion();
               String sChecksum = ref.getChecksum();
               MetadataInfo info = (MetadataInfo)m_metadataMap.get(sNamespace);

               if (info == null)
               {
                  info = new MetadataInfo();
                  info.parentNamespace = sParentNamespace;
                  info.ref = (XMLMixin)ref.clone();
                  m_metadataMap.put(sNamespace, info);

                  // mixin declared at top-level is also base
                  if (sParentNamespace.equals(m_metadata.getNamespace()) && sNamespace.equals(m_metadata.getBaseNamespace()))
                  {
                     m_helper.addException(new MetadataValidationException("err.meta.mixinDup",
                        new Object[] {sNamespace, getMetadataName(sParentNamespace)}));
                  }

                  // mixin matches base, but has different version/checksum
                  if (sNamespace.equals(m_metadata.getBaseNamespace()) &&
                     (!sVersion.equals(m_metadata.getBaseVersion()) || !sChecksum.equals(m_metadata.getBaseChecksum())))
                  {
                     m_helper.addException(new MetadataValidationException("err.meta.mixinBaseVersion",
                        new Object[]{sNamespace, sVersion, sChecksum, m_metadata.getBaseVersion(), m_metadata.getBaseChecksum()}));
                  }
               }
               else if (info.ref != null)
               {
                  if (sParentNamespace.equals(info.parentNamespace))
                  {
                     // mixin declared twice in same repository
                     m_helper.addException(new MetadataValidationException("err.meta.mixinDup",
                        new Object[] {sNamespace, getMetadataName(sParentNamespace)}));
                  }

                  // mixin declared more than once with different version/checksum
                  if ((info.ref.getVersion() != null && !info.ref.getVersion().equals(sVersion)) ||
                     (info.ref.getChecksum() != null && !info.ref.getChecksum().equals(sChecksum)))
                  {
                     m_helper.addException(new MetadataValidationException("err.meta.mixinVersion", new Object[] {
                        sNamespace,
                        sVersion,
                        sChecksum,
                        getMetadataName(sParentNamespace),
                        info.ref.getVersion(),
                        info.ref.getChecksum(),
                        getMetadataName(info.parentNamespace)
                     }));
                  }
               }
            }

            public void handleMixinOverrideConflict(XMLMixin ref, XMLMixin mixin)
            {
               throw new MetadataValidationException("err.meta.mixinOverride", new Object[]{ref.getName(), mixin.getName()});
            }

            public void handleCircularReference(XMLMixin mixin)
            {
               throw new MetadataValidationException("err.meta.mixinCycle", new Object[]{mixin.getName()});
            }

            public void handleResourceConflict(XMLResource first, XMLResource second)
            {
               m_helper.addException(new MetadataValidationException("err.meta.mixinConflict",
                  new Object[]{
                     first.getName(),
                     getMetadataName(first.getNamespace()),
                     getMetadataName(second.getNamespace())
                  }));
            }

            public void handleLinkFailure(XMLMixin ref, Exception e)
            {
               if (e instanceof MetadataValidationException)
               {
                  m_helper.addException((MetadataValidationException)e);
               }
               else
               {
                  throw new MetadataException("err.meta.mixin", new Object[]{ref}, e);
               }
            }

            public void handleAlternateResource(XMLResource first, XMLResource second)
            {
            }

            public void handleResourceOverride(XMLResource source, XMLResource overridden)
            {
            }

            final class MetadataInfo
            {
               /**
                * The metadata instance of the repository.
                */
               private XMLMetadata metadata;

               /**
                * The namespace of the repository that linked this repository.
                */
               private String parentNamespace;

               /**
                * The reference that caused this repository to be linked.
                */
               private XMLMixin ref;
            }
         }));

      m_helper.setMetadataCoreVersion(
         m_metadata.getCoreVersion(), m_metadata.getUpgradeResources());

      progressProxy.shiftRange(0.05);

      if (!m_bEnvironmentOnly && !bDataSourceOnly)
      {
         Lookup localeMap = new HashTab();
         m_helper.addResources(localeMap, ".locale", "Locale", "locale");
         loadStrings(localeMap.iterator());

         Lookup stringResMap = new HashTab();
         m_helper.addResources(stringResMap, ".strings", "Strings", "strings");
         loadStrings(stringResMap.iterator());

         if (StringTable.getInstance() == null)
         {
            StringTable.setInstance(m_metadata.getStringTable(Metadata.DEFAULT_LOCALE));
            StringTable.setTimeZone(TZ.UTC);
         }
      }

      progressProxy.shiftRange(0.10);

      m_helper.loadEncryptedResourceURL(configURL, "Server", "server", new ResourceHandler()
      {
         public void handleResource(final Element element, final String sName)
         {
            if (element.getNodeName().equals("Environment"))
            {
               String sConnectionsURL = m_properties.getProperty(CONNECTIONS_URL_PROPERTY);

               if (StringUtil.isEmpty(sConnectionsURL))
               {
                  m_properties.setProperty(CONNECTIONS_URL_PROPERTY, m_sConfigURL);
               }
            }

            NamedNodeMap attrMap = element.getAttributes();

            for (int i = 0; i != attrMap.getLength(); ++i)
            {
               Node node = attrMap.item(i);
               String sOldValue = m_properties.getProperty(node.getNodeName());

               if (StringUtil.isEmpty(sOldValue))
               {
                  m_properties.setProperty(node.getNodeName(), node.getNodeValue());
               }
            }
         }
      }, m_properties);

      m_decryptionDispatcher = new CharacterStreamCipherDispatcher();
      m_decryptionDispatcher.init(m_properties);
      m_helper.setEncryptionSchemeSet(new HashHolder(4));

      loadServer(m_properties);

      String sConnectionsURL = m_properties.getProperty(CONNECTIONS_URL_PROPERTY);
      URL connectionsURL = null;

      if (!StringUtil.isEmpty(sConnectionsURL))
      {
         connectionsURL = XMLMetadataHelper.getURL(sConnectionsURL, false, handler);
         sConnectionsURL = connectionsURL.toString();

         if (s_logger.isInfoEnabled())
         {
            s_logger.info("Connections URL: \"" + sConnectionsURL + "\"");
         }
      }

      m_helper.loadSystemResource("system.dstypes",
         "DataSourceTypes", "dataSourceTypes", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadDataSourceTypes(element);
         }
      });

      m_helper.loadResources(".dstype", "DataSourceType", "dataSourceType", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadDataSourceType(element, sName);
         }
      }, progress);

      m_helper.loadResources(".datasource", "DataSource", "dataSource", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadDataSource(element, sName);
         }
      }, progress);

      if (!m_bIntegrationExcluded)
      {
         m_helper.loadSystemResource("system.chtypes",
            "ChannelTypes", "channelTypes", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadChannelTypes(element);
            }
         });

         m_helper.loadResources(".chtype", "ChannelType", "channelType", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadChannelType(element, sName);
            }
         }, progress);

         // Load the SOA definition XML metadata (which may include definitions of other XML metadata)
         m_soaLoader = new XMLSOAMetadataLoader(m_helper);
         m_helper.loadResources(".soadef", "SOADefinition", "soadef", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               m_soaLoader.loadDefinition(element, sName);
            }
         }, progress);
         m_soaLoader.resolveReferences();

         // dispatcher channel properties loaded from environment.
         ChannelType type = m_metadata.getChannelType("ObjectQueue");

         m_dispatcherChannel.setType(type);
         m_metadata.addChannel(m_dispatcherChannel);

         m_helper.loadResources(".channel", "Channel", "channel", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadChannel(element, sName);
            }
         }, progress);
      }

      final Set componentNameSet = new HashHolder();
     
      m_helper.loadResources(".comp", "Component", "component", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            if (m_bEnvironmentOnly)
            {
               XMLMetadataHelper.verifyRootElement(element, "Component");

               m_metadata.addComponent(new Component(sName));
            }
           
            componentNameSet.add(sName);
         }
      }, progress);
     
      if (componentNameSet.contains("System.ObjectQueueDispatcher") &&
         Boolean.parseBoolean(properties.getProperty("queueing.enabled", "true")))
      {
      // only enable the dispatcher if the metadata supports it.
         m_dispatcherChannel.setSendable(true);
         m_dispatcherChannel.setReceivable(true);
      }

      if (connectionsURL != null)
      {
         boolean bEnvironment = (sConnectionsURL.equals(m_sConfigURL) ||
            sConnectionsURL.toLowerCase(Locale.ENGLISH).endsWith(".environment"));

         m_helper.loadEncryptedResourceURL(connectionsURL,
            (bEnvironment) ? "Environment" : "Connections",
            (bEnvironment) ? "environment" : "connections",
            new ResourceHandler()
         {
            public void handleResource(final Element element, final String sName)
            {
               loadConnections(element, sName);
            }
         }, m_properties);
      }
      else
      {
         loadConnections(null, null);
      }

      // .server file overrides highest scheme used in the connections file
      m_metadata.setEncryptionScheme(m_properties.getProperty("cipher.scheme",
            CharacterStreamCipherDispatcher.computeMostSecure(m_helper.getEncryptionSchemeSet())));

      if (!bDataSourceOnly)
      {
         loadUIMetadata(baseDescElement, rootDescElement);
      }

      progressProxy.shiftRange(0.12);

      m_helper.fixup(m_ioFixupList.iterator());
      m_ioFixupList = null;

      m_helper.loadResources(".extlib", "ExternalLibrary", "externalLibrary", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadExternalLibrary(element, sName);
         }
      }, progress);

      m_nStage = STAGE_LOADED_ENVIRONMENT;
      progressProxy.progress(null, null, 1.0);

      if (m_bEnvironmentOnly || bDataSourceOnly)
      {
         m_nStage = STAGE_LOAD_ENVIRONMENT_FIXUPS;
         m_helper.fixup(m_environmentFixupList.iterator()); // safe to run since no J2EE container
         m_nStage = STAGE_FINISHED;

         return m_metadata;
      }

      progressProxy.shiftRange(0.13);

      m_helper.loadResources(".security", "SecurityDescriptor", "securityDescriptor", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadSecurityDescriptor(element);
         }
      }, progress);

      m_helper.fixup(m_privilegeFixupList.iterator());
      m_privilegeFixupList = null;
      PrivilegeGroup.resolve(m_metadata);

      if (progress != null)
      {
         progressProxy.shiftRange(0.15);
         progress.progress("info.meta.loadingSystemResources", null, 0);
      }

      Context contextSaved = ThreadContextHolder.getContext();

      try
      {
         ThreadContextHolder.setContext(m_machine.getContext());

         m_helper.loadSystemResource("scheme.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         // Load the Dynamic Object System
         m_helper.loadSystemResource("object.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         // Load the Services Oriented Architecture functionality
         m_helper.loadSystemResource("soa.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         m_helper.loadSystemResource("server.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         m_helper.loadSystemResource(Metadata.ROOT_CLASS_NAME + ".meta",
            "Class", "class", new ResourceHandler()
         {
            public void handleResource(Element rootElement, String sName)
            {
               loadClass(rootElement, sName);
            }
         });

         loadExtendedSystemMetadata();

         progressProxy.shiftRange(0.16);

         m_helper.loadResources(".scm", "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, false);
            }
         }, progress);
      }
      finally
      {
         ThreadContextHolder.setContext(contextSaved);
      }

      progressProxy.shiftRange(0.23);

      m_helper.loadResources(".meta", "Class", "class", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            String sElement = element.getNodeName();

            if (sElement.equals("Class"))
            {
               loadClass(element, sName);
            }
            else if (sElement.equals("Aspect"))
            {
               loadClassAspect(element, sName);
            }
            else
            {
               throw new MetadataException("err.meta.metaDocRoot", new Object[]{sElement});
            }
         }
      }, progress);

      progressProxy.shiftRange(0.24);

      m_helper.loadResources(".enum", "Enumeration", "enum", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadEnumeration(element, sName);
         }
      }, progress);

      progressProxy.shiftRange(0.25);

      loadUIEventMetadata(baseDescElement, rootDescElement, progress);

      if (progress != null)
      {
         progressProxy.shiftRange(0.26);
         progress.progress("info.meta.resolvingResourceReferences", null, 0);
      }

      m_helper.fixup(m_inheritanceCheckList.iterator());
      m_inheritanceCheckList = null;
      m_helper.fixup(m_attributeGenerationList.iterator());
      m_attributeGenerationList = null;

      m_helper.fixup(Collections.singleton(new ClassFixup()
      {
         public void fixup()
         {
            m_classAspectArray = ClassAspect.resolveAspects(m_metadata);
         }
      }).iterator());

      m_helper.fixup(m_inheritanceFixupList.iterator());
      m_inheritanceFixupList = null;
      m_enumerationValueMap = null;
      m_helper.fixup(m_attributeFixupList.iterator());
      m_attributeFixupList = null;
      m_helper.fixup(m_actionFixupList.iterator());
      m_actionFixupList = null;

      if (m_classAspectArray != null)
      {
         ClassAspect.resolveMembers(m_classAspectArray);
      }

      m_helper.fixup(m_persistenceMappingLoadList.iterator());
      m_persistenceMappingLoadList = null;
      m_helper.fixup(m_attributeResolutionList.iterator());
      m_attributeResolutionList = null;
      m_helper.fixup(m_inheritance1stPassFixupList.iterator());
      m_inheritance1stPassFixupList = null;

      progressProxy.shiftRange(0.27);

      m_helper.loadResources(".action", "Action", "action", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadFlowMacro(element, sName);
         }
      }, progress);

      progressProxy.shiftRange(0.32);

      m_helper.loadResources(".workflow", "Workflow", "workflow", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadWorkflow(element, sName);
         }
      }, progress);

      progressProxy.shiftRange(0.33);

      if (!m_bIntegrationExcluded)
      {
         m_helper.loadSystemResource("system.formats",
            "Formats", "formats", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadFormats(element);
            }
         });

         m_helper.loadResources(".format", "Format", "format", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadFormat(element, sName);
            }
         }, progress);

         progressProxy.shiftRange(0.34);

         final Lookup importedMessageMap = new HashTab();

         m_helper.loadResources(".xsd", "XSD", "xsd", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sRelativePath)
            {
               loadXSD(m_helper.getResource(sRelativePath).getURL(), sName, importedMessageMap);
            }
         }, progress);

         m_helper.loadResources(".wsdl", "WSDL", "wsdl", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sRelativePath)
            {
               loadXSD(m_helper.getResource(sRelativePath).getURL(), sName, importedMessageMap);
            }
         }, progress);

         m_helper.loadResources(".soaimpl", "SOAImplementation", "soaimpl", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               m_soaLoader.loadImplementation(element, sName, m_metadata.getGlobalEnvironment());
            }
         }, progress);

         contextSaved = ThreadContextHolder.getContext();

         try
         {
            ThreadContextHolder.setContext(m_machine.getContext());
            m_soaLoader.initDefinitions(m_machine);
         }
         finally
         {
            ThreadContextHolder.setContext(contextSaved);
         }

         m_helper.loadResources(".message", "Message", "message", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadMessage(element, sName);
            }
         }, progress);

         // Explicitly-defined Message metadata shall override Message metadata from imported XSDs and WSDLs
         for (Lookup.Iterator itr = importedMessageMap.iterator(); itr.hasNext(); )
         {
            String sName = (String)itr.next();

            if (m_metadata.findMessage(sName) == null)
            {
View Full Code Here

            event.setResult(loadArgument(resultElement, null));
         }
      });

      String sArgList = XMLUtil.getStringAttr(eventElement, "args");
      final Lookup/*<String, Argument>*/ argMap = new HashTab/*<String, Argument>*/();

      XMLUtil.withFirstChildElement(eventElement, "Arguments", false, new ElementHandler()
      {
         public void handleElement(Element argsElement)
         {
            XMLUtil.forEachChildElement(argsElement, "Argument",
               m_helper.new ElementHandler("argument")
            {
               protected void handleElement(Element argElement, String sArgName)
               {
                  argMap.put(sArgName, loadArgument(argElement, sArgName));
               }
            });
         }
      });

      if (sArgList != null)
      {
         for (StringTokenizer tokenizer = new StringTokenizer(sArgList); tokenizer.hasMoreTokens();)
         {
            String sArgName = tokenizer.nextToken();
            Argument arg = (Argument)argMap.remove(sArgName);

            XMLMetadataHelper.validateName(sArgName);
            event.addArgument((arg == null) ? new Argument(sArgName) : arg);
         }
      }

      MetadataCompoundValidationException e = null;

      for (Iterator/*<Argument>*/ itr = argMap.valueIterator(); itr.hasNext();)
      {
         if (e == null)
         {
            e = new MetadataCompoundValidationException();
         }
View Full Code Here

TOP

Related Classes of nexj.core.util.HashTab

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.