Package nexj.core.meta.integration

Examples of nexj.core.meta.integration.MessagePart


      if (mapping.getType() == VCardMessagePartMapping.TYPE_GROUP)
      {
         for (int i = 0, nChildCount = part.getPartCount(); i < nChildCount; i++)
         {
            MessagePart childPart = part.getPart(i);
            Object childObj = tobj.findValue(childPart.getName());

            if (childPart instanceof CompositeMessagePart)
            {
               if (childPart.isCollection())
               {
                  // composite sub-part of group, and it is a collection (multiplicity * group or field w/ parameters)
                  List list = (List)childObj;
                  int nCount = (list != null) ? list.size() : 0;

                  checkMultiplicity(nCount, childPart);

                  for (int k = 0; k < nCount; k++)
                  {
                     format((TransferObject)list.get(k), (CompositeMessagePart)childPart);
                  }
               }
               else
               {
                  // composite sub-part of group (could be another group, a field with parameters, etc.)
                  format((TransferObject)childObj, (CompositeMessagePart)childPart);
               }
            }
            else
            {
               // primitive parts in the group
               writeField(childObj, childPart, (VCardMessagePartMapping)childPart.getMapping());
            }
         }
      }
      else
      {
View Full Code Here


    */
   protected void writeField(Object obj, MessagePart part, VCardMessagePartMapping mapping) throws IOException
   {
      boolean bParameters = (part instanceof CompositeMessagePart);
      CompositeMessagePart parentPart = null;
      MessagePart valuePart;
      Object valueObj;

      if (bParameters)
      {
         valuePart = mapping.getValuePart();
         valueObj = ((TransferObject)obj).findValue(valuePart.getName());
         parentPart = (CompositeMessagePart)part;
      }
      else
      {
         valuePart = part;
         valueObj = obj;
      }

      VCardMessagePartMapping valuePartMapping = (VCardMessagePartMapping)valuePart.getMapping();

      if (valueObj == null && valuePartMapping.getDefault() == null)
      {
         if (valuePart.isRequired())
         {
            throw new IntegrationException("err.integration.minPartCount", new Object[]{valuePart.getFullPath()});
         }

         return;
      }

      m_writer.write((bParameters) ? mapping.getFullName() : valuePartMapping.getFullName());

      int nChildCount = (bParameters) ? parentPart.getPartCount() : 0;

      for (int i = 0; i < nChildCount; i++)
      {
         MessagePart childPart = (MessagePart)parentPart.getPart(i);
         VCardMessagePartMapping childMapping = (VCardMessagePartMapping)childPart.getMapping();

         if (childMapping.getType() == VCardMessagePartMapping.TYPE_PARAMETER)
         {
            Object parameterObj = ((TransferObject)obj).findValue(childPart.getName());

            if (parameterObj != null || childMapping.getDefault() != null)
            {
               m_writer.write(';');
               m_writer.write(childMapping.getName());
               m_writer.write('=');
               writeValue((PrimitiveMessagePart)childPart, childMapping, parameterObj);
            }
            else
            {
               if (childPart.isRequired())
               {
                  throw new IntegrationException("err.integration.minPartCount", new Object[]{childPart.getFullPath()});
               }
            }
         }
      }

View Full Code Here

    */
   protected void setValue(TransferObject tobj, CompositeMessagePart composite, int nSeq, Object value)
   {
      for (int i = 0, n = composite.getPartCount(); i < n; ++i)
      {
         MessagePart part = composite.getPart(i);

         if (((HL7MessagePartMapping)part.getMapping()).getSeq() == nSeq)
         {
            tobj.setValue(part.getName(), value);

            break;
         }
      }
   }
View Full Code Here

      {
         throw new IntegrationException("err.integration.xml.unexpectedElement",
               new Object[] {sURI, sLocalName});
      }

      MessagePart parentPart = m_stack.getTopMessagePart();

      if (m_bNilElement)
      {
         throw new IntegrationException("err.integration.xml.nilElementNotEmpty",
            new Object[] {parentPart.getFullPath()});
      }

      if (parentPart instanceof CompositeMessagePart)
      {
         CompositeMessagePart parentComposite = (CompositeMessagePart)parentPart;

         for (int nIndex = (parentComposite.getAggregation() == CompositeMessagePart.SEQUENTIAL) ? m_stack.getTopIndex() : 0;
            nIndex < parentComposite.getPartCount(); ++nIndex)
         {
            MessagePart part = parentComposite.getPart(nIndex);
            XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();

            if (mapping.getNodeType() == XMLMessagePartMapping.ELEMENT)
            {
               if (matches(part, sURI, sLocalName))
               {
                  TransferObject tobj;
                  MessagePart basePart = part;

                  m_bNilElement = mapping.isNillable() &&
                      (Primitive.toBoolean(attributes.getValue(XMLNamespace.XSI, "nil")) == Boolean.TRUE);

                  if (part instanceof PrimitiveMessagePart)
View Full Code Here

    * return false.
    * @return True if the document root is accepted; false if it is not accepted.
    */
   public boolean acceptRootElement(String sURI, String sLocalName, Attributes attributes, boolean bError)
   {
      MessagePart part = m_stack.getTopMessagePart();
      RootXMLMessagePartMapping rootMapping;

      if (part == null)
      {
         // Identify the XML message being parsed
         Message msg = (Message)m_messageMap.get(sURI, sLocalName);

         if (msg != null)
         {
            part = msg.getRoot();
         }

         if (part == null)
         {
            if (bError)
            {
               throw new IntegrationException("err.integration.xml.unsupportedMessage",
                  new Object[]{sURI, sLocalName});
            }

            return false;
         }

         rootMapping = (RootXMLMessagePartMapping)part.getMapping();
         assert m_stack.getSize() == 1;
         m_stack.setTopMessagePart(part);
         m_stack.setTopBaseMessagePart(part);

         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Identified the XML message as \"" + part.getName() + "\"");
         }

         ((TransferObject)m_stack.getTopObject()).setClassName(part.getName());
         m_headerPart = rootMapping.getHeaderPart();
         m_bRestart = (rootMapping.getSchemaResourceMap() != null) || (m_headerPart != null);
         m_baseRootPart = part;
      }
      else
      {
         // Verify root element of message being parsed
         rootMapping = (RootXMLMessagePartMapping)part.getMapping();

         if (!matches(m_baseRootPart, sURI, sLocalName))
         {
            if (bError)
            {
               throw new IntegrationException("err.integration.xml.invalidDocRoot",
                  new Object[]{sURI, sLocalName});
            }

            return false;
         }

         if (m_headerPart != rootMapping.getHeaderPart())
         {
            m_headerPart = rootMapping.getHeaderPart();
            m_bRestart = true;
         }
      }

      TransferObject tobj = (TransferObject)m_stack.getTopObject();

      if (!m_bRestart)
      {
         parseAttributes(tobj, (CompositeMessagePart)part, attributes);
      }

      Message derivedMessage = getDerivedMessage(attributes, rootMapping, part.getFullPath());
      Message primaryMessage = rootMapping.getRootMessage();

      tobj.setClassName(primaryMessage.getName());

      if (derivedMessage != null)
      {
         CompositeMessagePart derivedMessageRoot = derivedMessage.getRoot();
         RootXMLMessagePartMapping derivedMessageRootMapping = (RootXMLMessagePartMapping)derivedMessageRoot.getMapping();

         Message.validatePolymorphism(primaryMessage, derivedMessage, derivedMessageRoot);
         m_stack.setTopBaseMessagePart(part);
         part = derivedMessageRoot;
         m_stack.setTopMessagePart(part);
         tobj.setClassName(derivedMessage.getName());

         MessagePart headerPart = derivedMessageRootMapping.getHeaderPart();

         if (m_headerPart != headerPart)
         {
            m_headerPart = headerPart;
            m_bRestart = true;
View Full Code Here

      if (anyPart.getType() == Primitive.ANY)
      {
         Interface iface = ((XMLMessagePartMapping)anyPart.getMapping()).getInterface();
         XMLMessageParserTable table = (XMLMessageParserTable)iface.getRequestTable().getParserTable();
         Message msg = (Message)table.getMessageMap().get(sURI, sLocalName);
         MessagePart part = null;

         if (msg == null)
         {
            table = (XMLMessageParserTable)iface.getResponseTable().getParserTable();
            msg = (Message)table.getMessageMap().get(sURI, sLocalName);
         }

         if (msg != null)
         {
            part = msg.getRoot();
         }

         if (part == null)
         {
            return false;
         }

         Message derivedMessage = getDerivedMessage(attributes, (RootXMLMessagePartMapping)part.getMapping(), null);
         MessagePart basePart = part;

         if (derivedMessage != null)
         {
            if (s_logger.isDebugEnabled())
            {
View Full Code Here

   /**
    * @see nexj.core.integration.format.xml.ParseEventAcceptor#acceptEndElement(java.lang.String, java.lang.String, java.lang.String)
    */
   public boolean acceptEndElement(String sURI, String sLocalName, String sQualName) throws SAXException
   {
      MessagePart part = m_stack.getTopMessagePart();
      MessagePart basePart = m_stack.getTopBaseMessagePart();
      Object obj;

      assert basePart == null || basePart.getName() != null;

      if (part instanceof PrimitiveMessagePart)
      {
         PrimitiveMessagePart primitivePart = (PrimitiveMessagePart)part;

         if (primitivePart.getType() == Primitive.ANY)
         {
            if ((obj = getAnyTypeValue()) == null)
            {
               // An element-mapped part with an interface
               obj = m_stack.getTopObject();
            }
         }
         else
         {
            String sValue;

            if (m_bNilElement)
            {
               sValue = null;
            }
            else
            {
               obj = m_stack.getTopObject();
               sValue = (obj == null) ? null : obj.toString();
            }

            obj = convert(primitivePart, sValue);
         }
      }
      else if (part == LAX_PART)
      {
         obj = Undefined.VALUE;
      }
      else
      {
         CompositeMessagePart composite = (CompositeMessagePart)part;
         TransferObject tobj = (TransferObject)m_stack.getTopObject();
         int nPartCount = composite.getPartCount();
         boolean bMatch = false;
         boolean bRequired = false;

         if (tobj != null)
         {
            for (int nIndex = 0; nIndex < nPartCount; ++nIndex)
            {
               MessagePart child = composite.getPart(nIndex);
               int nNodeType = ((XMLMessagePartMapping)child.getMapping()).getNodeType();

               if (!m_bNilElement && nNodeType == XMLMessagePartMapping.ELEMENT// ignore counts for nil elements
               {
                  if (composite.getAggregation() == CompositeMessagePart.SINGLE)
                  {
                     if (tobj.hasValue(child.getName()))
                     {
                        if (bMatch)
                        {
                           throw new IntegrationException("err.integration.multipleParts",
                              new Object[]{composite.getFullPath()});
                        }

                        validatePartCount(child);
                        bMatch = true;
                     }

                     bRequired |= child.isRequired();
                  }
                  else
                  {
                     validatePartCount(child);
                  }
               }
               else if (nNodeType == XMLMessagePartMapping.VALUE)
               {
                  Object value = null;

                  if ((value = getAnyTypeValue()) != null)
                  {
                     // Value-mapped part for literal XML will have just one element when collection
                     if (child.isCollection())
                     {
                        ArrayList list = new ArrayList(1);

                        list.add(value);
                        value = list;
                     }
                  }
                  else
                  {
                     value = m_stack.getTopValue();

                     if (value instanceof StringBuilder)
                     {
                        value = value.toString();
                     }

                     if (value instanceof String)
                     {
                        value = convert((PrimitiveMessagePart)child, (String)value);
                     }
                  }

                  tobj.setValue(child.getName(), value);
                  validatePartCount(child);
               }
            }

            if (bRequired && !bMatch)
View Full Code Here

      m_stack.pop();

      if (!m_stack.isEmpty() && result != Undefined.VALUE)
      {
         TransferObject tobj = (TransferObject)m_stack.getTopObject();
         MessagePart parentPart = m_stack.getTopMessagePart();

         /* If parent is a referenced message part: should use mapping from referrer,
          * but value part must be taken from referenced message part mapping.
          */
         PrimitiveMessagePart valuePart = ((XMLMessagePartMapping)parentPart.getMapping()).getValuePart();

         if (valuePart != null && childPart.getParent() == null)
         {
            // Handle type=any, value-mapped, with interface.
            //
View Full Code Here

      if (m_stack.isEmpty())
      {
         return false;
      }

      MessagePart part = m_stack.getTopMessagePart();

      if (m_bNilElement)
      {
         throw new IntegrationException("err.integration.xml.nilElementNotEmpty",
            new Object[] {part.getFullPath()});
      }

      // Do not process contents of a lax part.
      if (part == LAX_PART)
      {
         return true;
      }

      /*
       * Process character data if the part type is not "any". Otherwise, reject the data.
       * e.g. Reject this: <anyTypePartWithInterface>A<x>...</x>B</anyTypePartWithInterface> (because of A and B)
       */
      boolean bVerifyWhitespace = false;

      if (part instanceof CompositeMessagePart)
      {
         PrimitiveMessagePart valuePart = ((XMLMessagePartMapping)part.getMapping()).getValuePart();

         if (valuePart == null || valuePart.getType() == Primitive.ANY)
         {
            if (!((CompositeMessagePart)part).isLax())
            {
               bVerifyWhitespace = true;
            }
         }
         else
         {
            m_stack.setTopValue(concat(m_stack.getTopValue(), cbuf, nOffset, nLength));
         }
      }
      else
      {
         if (((PrimitiveMessagePart)part).getType() == Primitive.ANY)
         {
            bVerifyWhitespace = true;
         }
         else
         {
            m_stack.setTopObject(concat(m_stack.getTopObject(), cbuf, nOffset, nLength));
         }
      }

      if (bVerifyWhitespace)
      {
         while (nLength-- != 0)
         {
            if (!Character.isWhitespace(cbuf[nOffset++]))
            {
               throw new IntegrationException("err.integration.xml.misplacedCharacterData",
                  new Object[]{part.getFullPath()});
            }
         }
      }

      return true;
View Full Code Here

   {
      int nPartCount = composite.getPartCount();

      for (int i = 0; i < nPartCount; ++i)
      {
         MessagePart part = composite.getPart(i);
         XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();

         if (mapping.getNodeType() == XMLMessagePartMapping.ATTRIBUTE)
         {
            String sValue = attributes.getValue((mapping.getNamespace() != null) ? mapping.getNamespace().getURI() : "", mapping.getNodeName());

            if (part.isRequired() && StringUtil.isEmpty(sValue))
            {
               throw new IntegrationException("err.integration.minPartCount", new Object[]{part.getFullPath()});
            }

            if (sValue != null)
            {
               if (sValue.length() == 0)
               {
                  tobj.setValue(part.getName(), null);
               }
               else
               {
                  tobj.setValue(part.getName(), convert((PrimitiveMessagePart)part, sValue));
               }
            }
         }
      }
   }
View Full Code Here

TOP

Related Classes of nexj.core.meta.integration.MessagePart

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.