Package nexj.core.rpc

Examples of nexj.core.rpc.TransferObject


   }
  
   public void testTransformSingleMessage()
   {
      // build source message
      TransferObject msg = new TransferObject("TransformTestMsg", 1);
      TransferObject msg1 = null;
      ArrayList col = null;
      ArrayList col1 = null;
     
      msg1 = new TransferObject(2);
      msg1.setValue("primitive", new Integer(0));
      col = new ArrayList(2);
      col.add(new Integer(4));
      col.add(new Integer(5));
      msg1.setValue("primitiveCollection", col);
     
      msg.setValue("message", msg1);
     
      Logger logger = Logger.getLogger("TransformerTest");
     
      logger.info("source: " + msg.toString());
     
      // transform message
      TransferObject res = m_tf.transform(msg, m_metadata.getTransformation("MapMessage"));

      logger.info("result: " + res.toString());
     
      // validate result message
      assertEquals("TransformTestMsg", res.getClassName());
      assertEquals(2, res.getValueCount());
     
      msg = (TransferObject)res.getValue("message");
     
      assertEquals(2, msg.getValueCount());
     
      assertEquals(new Integer(0), msg.getValue("primitive"));
      col = (ArrayList)msg.getValue("primitiveCollection");
     
      assertEquals(2, col.size());
      assertEquals(new Integer(4), col.get(0));
      assertEquals(new Integer(5), col.get(1));

      col = (ArrayList)res.getValue("messageCollection");
      assertEquals(4, col.size());
     
      msg = (TransferObject)col.get(0);
      assertEquals(2, msg.getValueCount());
     
View Full Code Here


       * Test that the XML formats with the same namespace qualifications as described
       * in the XML schema.
       */
      StringWriter writer;
      WriterOutput out;
      TransferObject root, ref;
      Format format = m_context.getMetadata().getFormat("XML");
      MessageFormatter formatter = (MessageFormatter)format.getFormatter().getInstance(m_context);

      root = new TransferObject("XML_Inherit_Schema_Reference", 1);
      ref = new TransferObject("XML_Inherit_Schema1", 2);
      root.setValue("s1", ref);
      ref.setValue("a", "aValue");
      ref.setValue("x", "xValue");
      out = new WriterOutput(writer = new StringWriter());
      formatter.format(root, msg, out);

View Full Code Here

      InputStream istream = in.getInputStream();

      CompositeMessagePart rootPart = msg.getRoot();
      CompositeMessagePart entriesPart = (CompositeMessagePart)rootPart.getPart(0);

      TransferObject root = new TransferObject(msg.getName());
      List entryList = new ArrayList();

      ZipInputStream zipStream = new ZipInputStream(istream);
      ZipEntry zipEntry;

      root.setValue(entriesPart.getName(), entryList);

      try
      {
         while ((zipEntry = zipStream.getNextEntry()) != null)
         {
            String sKeySize = null;
            long lValueSize = 0;
            String sKeyContents = null;
            Primitive sizeType = null;
            TransferObject entry = new TransferObject();

            entryList.add(entry);

            // Iterate the parts, assigning data from the Zip entry
            for (int i = 0; i < entriesPart.getPartCount(); i++)
            {
               PrimitiveMessagePart part = (PrimitiveMessagePart)entriesPart.getPart(i);
               ZipMessagePartMapping mapping = (ZipMessagePartMapping)part.getMapping();
               Object datum = null;
               Primitive partType = part.getType();

               switch (mapping.getValue())
               {
                  case ZipMessagePartMapping.VALUE_CONTENTS:
                     Binary contents = new PagedBinary(zipStream);

                     zipStream.closeEntry();

                     if (s_logger.isDebugEnabled())
                     {
                        s_logger.debug("Extracted contents of \"" + zipEntry.getName() + "\" size=" + contents.getSize());
                     }

                     if (contents.getSize() > 0)
                     {
                        datum = partType.getConverter(Primitive.BINARY).invoke(contents);
                     }

                     sKeyContents = part.getName();
                     break;

                  case ZipMessagePartMapping.VALUE_COMMENT:
                     datum = partType.getConverter(Primitive.STRING).invoke(zipEntry.getComment());
                     break;

                  case ZipMessagePartMapping.VALUE_DIRECTORY:
                     datum = partType.getConverter(Primitive.BOOLEAN).invoke(Boolean.valueOf(zipEntry.isDirectory()));
                     break;

                  case ZipMessagePartMapping.VALUE_EXTRA:
                     if (zipEntry.getExtra() != null)
                     {
                        datum = partType.getConverter(Primitive.BINARY).invoke(new Binary(zipEntry.getExtra()));
                     }

                     break;

                  case ZipMessagePartMapping.VALUE_NAME:
                     datum = partType.getConverter(Primitive.STRING).invoke(convertZipSeparatorToPlatformSeparator(zipEntry.getName()));
                     break;

                  case ZipMessagePartMapping.VALUE_SIZE:
                     datum = partType.getConverter(Primitive.LONG).invoke(Primitive.createLong(zipEntry.getSize()));
                     sKeySize = part.getName();
                     lValueSize = zipEntry.getSize();
                     sizeType = partType;
                     break;

                  case ZipMessagePartMapping.VALUE_TIME:
                     datum = partType.getConverter(Primitive.LONG).invoke(Primitive.createLong(zipEntry.getTime()));
                     break;

                  default:
                     throw new IllegalStateException("Unknown value: " + mapping.getValue());
               }

               entry.setValue(part.getName(), datum);
            }

            // Process the size entry
            if (sKeySize != null && sKeyContents != null)
            {
               Binary contents = (Binary)entry.getValue(sKeyContents);
               long lContentsSize = (contents != null) ? contents.getSize() : 0;

               if (lValueSize == -1)
               {
                  // Populate the size entry from the Binary's size
                  entry.setValue(sKeySize, sizeType.getConverter(Primitive.LONG).invoke(Primitive.createLong(lContentsSize)));
               }
               else
               {
                  // Ensure size entry matches Binary's size
                  if (lValueSize != lContentsSize)
View Full Code Here

         List entryList = (List)tobj.getValue(entriesPart.getName());

         for (int i = 0; i < entryList.size(); i++)
         {
            TransferObject entry = (TransferObject)entryList.get(i);

            if (!entry.hasValue(sKeyName))
            {
               continue;
            }

            ZipEntry zipEntry = new ZipEntry(convertPlatformSeparatorToZipSeparator(Primitive.toString(entry.getValue(sKeyName))));

            if (sKeyComment != null && entry.hasValue(sKeyComment))
            {
               zipEntry.setComment(Primitive.toString(entry.getValue(sKeyComment)));
            }

            if (sKeyExtra != null && entry.hasValue(sKeyExtra))
            {
               zipEntry.setExtra(Primitive.toBinary(entry.getValue(sKeyExtra)).getData());
            }

            if (sKeySize != null && entry.hasValue(sKeySize))
            {
               zipEntry.setSize(Primitive.toLong(entry.getValue(sKeySize)).longValue());
            }

            if (sKeyTime != null && entry.hasValue(sKeyTime))
            {
               zipEntry.setTime(Primitive.toLong(entry.getValue(sKeyTime)).longValue());
            }

            zipStream.putNextEntry(zipEntry);

            // Compress the file contents
            if (entry.hasValue(sKeyContents))
            {
               InputStream contentsStream = null;

               try
               {
                  contentsStream = Primitive.toBinary(entry.getValue(sKeyContents)).getInputStream();
                  IOUtil.copy(zipStream, contentsStream);
                  zipStream.closeEntry();
               }
               finally
               {
View Full Code Here

         throw new IntegrationException("err.integration.minPartCount", new Object[]{part.getFullPath()});
      }

      if (obj != null && part instanceof CompositeMessagePart)
      {
         TransferObject tobj = (TransferObject)obj;
         String sDerivedMessageName = tobj.getClassName();

         if (!StringUtil.isEmpty(sDerivedMessageName))
         {
            Message derivedMessage = m_context.getMetadata().getMessage(sDerivedMessageName);
            Message baseMessage = null;

            if (parentPart == null// root of message (includes root part referencing another message)
            {
               baseMessage = ((RootXMLMessagePartMapping)part.getRoot().getMapping()).getRootMessage();
            }
            else if (part instanceof CompositeMessagePartRef)
            {
               CompositeMessagePart referencedPart = ((CompositeMessagePartRef)part).getRefPart();

               baseMessage = ((RootXMLMessagePartMapping)referencedPart.getMapping()).getRootMessage();
            }

            if (baseMessage != null)
            {
               Message.validatePolymorphism(baseMessage, derivedMessage, part);

               if (baseMessage != derivedMessage)
               {
                  part = derivedMessage.getRoot();
                  bAppendType = true;
                  derivedMapping = (XMLMessagePartMapping)part.getMapping();
               }
            }
         }
      }

      if (((RootXMLMessagePartMapping)part.getRoot().getMapping()).getRootMessage().getDerivation() == Message.DERIVATION_ABSTRACT)
      {
         throw new IntegrationException("err.integration.abstractMessage",
            new Object[]{((RootXMLMessagePartMapping)part.getRoot().getMapping()).getRootMessage().getName(), part.getFullPath()});
      }

      if (part instanceof CompositeMessagePart)
      {
         if (obj != null)
         {
            CompositeMessagePart composite = (CompositeMessagePart)part;
            TransferObject tobj = (TransferObject)obj;
            RootXMLMessagePartMapping rootMapping = null;
            MessagePart headersPart = null;
            boolean bEnvelopeStarted = false;

            // append the namespace and the schema
View Full Code Here

      }

      if (m_nEnvelope == RootXMLMessagePartMapping.ENVELOPE_SOAP12)
      {
         SOAP12FaultException ex = new SOAP12FaultException();
         TransferObject code = (TransferObject)root.getValue("code");

         ex.setFaultCode((String)code.getValue("value"));

         while ((code = (TransferObject)code.findValue("subcode")) != null)
         {
            ex.appendFaultSubcode((String)code.getValue("value"));
         }

         TransferObject reason = (TransferObject)root.getValue("reason");
         List reasonList = (List)reason.getValue("text");

         for (int i = 0; i < reasonList.size(); i++)
         {
            TransferObject text = (TransferObject)reasonList.get(i);

            ex.setReason((String)text.getValue("lang"), (String)text.getValue("value"));
         }

         ex.setNode((String)root.findValue("node"));
         ex.setRole((String)root.findValue("role"));
View Full Code Here

      {
         compositeItr.next();

         for (Iterator instanceItr = ((List)compositeItr.getValue()).iterator(); instanceItr.hasNext();)
         {
            TransferObject tobjToDelete = new TransferObject();

            setEventName(tobjToDelete, "delete");
            m_invocationList.add(tobjToDelete);
            m_instanceByTobjMap.put(tobjToDelete, instanceItr.next());
         }
View Full Code Here

      if (m_chRecord == null)
      {
         m_chRecord = new char[recordMapping.getWidth()];
      }

      TransferObject result = null;
      List listResult;

      try
      {
         FixedMessagePartMapping rootMapping = (FixedMessagePartMapping)rootPart.getMapping();

         if (rootMapping != null)
         {
            m_reader.skip(rootMapping.getPrefix().length());
         }

         listResult = parseRecords(recordMapping);
      }
      catch (IOException innerEx)
      {
         throw new IntegrationException("err.integration.parseRecord",
            new Object[]{msg.getName(), Primitive.createInteger(m_nCurrentRecord)}, innerEx);
      }

      result = new TransferObject(msg.getName(), 1);
      result.setValue(recordPart.getName(), listResult);

      if (s_logger.isDumpEnabled())
      {
         s_logger.dump("Parsed result: ");
         s_logger.dump(result);
View Full Code Here

      if (recordPart.getPartCount() == 0)
      {
         return null;
      }

      TransferObject result = new TransferObject(recordPart.getPartCount());

      for (int i = 0; i < recordPart.getPartCount(); i++)
      {
         PrimitiveMessagePart fieldPart = (PrimitiveMessagePart)recordPart.getPart(i);
         Object datum = sRawRecordArray[i];
         FixedMessagePartMapping mapping = (FixedMessagePartMapping)fieldPart.getMapping();

         if (mapping.getFormat() == null)
         {
            datum = fieldPart.convertValue(datum);
         }
         else
         {
            if (m_primitiveFormatter == null)
            {
               m_primitiveFormatter = new PrimitiveFormatter(m_context);
            }

            datum = m_primitiveFormatter.parse((String)datum, fieldPart);
         }

         result.setValue(fieldPart.getName(), datum);
      }

      return result;
   }
View Full Code Here

    */
   protected TransferObject parse(Input in, CompositeMessagePart rootPart, boolean bRestartable, byte nEnvelope, LookupDeque schemaResourceMap)
   {
      try
      {
         TransferObject tobj = new TransferObject();
         Reader reader = in.getReader();

         if (bRestartable)
         {
            reader = new UnlimitedMarkReader(reader);
         }

         reader = new NoCloseReader(reader);
         initParse(rootPart, tobj, nEnvelope);

         if (bRestartable)
         {
            reader.mark(1024);
         }

         XMLUtil.parse(reader, this, schemaResourceMap);

         if (m_bRestart)
         {
            assert bRestartable;

            reader.reset();
            resetAcceptors();
            XMLUtil.parse(reader, this, ((RootXMLMessagePartMapping)
               m_stack.getMessagePart(0).getMapping()).getSchemaResourceMap());
         }

         assert !m_bRestart;

         for (int i = 0; i < m_acceptorArray.length; i++)
         {
            if (m_acceptorArray[i] != null)
            {
               m_acceptorArray[i].checkFault(tobj);
            }
         }

         assert !StringUtil.isEmpty(tobj.getClassName());

         if (s_logger.isDumpEnabled())
         {
            s_logger.dump("Parse result:");
            s_logger.dump(tobj);
View Full Code Here

TOP

Related Classes of nexj.core.rpc.TransferObject

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.