Package nexj.core.meta.integration.format.xml

Examples of nexj.core.meta.integration.format.xml.XMLMessagePartMapping


    * @param parentPart The parent message part metadata.
    * @throws IOException if the writer fails.
    */
   protected void append1(Object obj, MessagePart part, CompositeMessagePart parentPart) throws IOException
   {
      XMLMessagePartMapping derivedMapping = (XMLMessagePartMapping)part.getMapping();
      String sNamespace = (derivedMapping.getNamespace() == null) ? null : derivedMapping.getNamespace().getName();
      String sNodeName = derivedMapping.getNodeName();
      boolean bAppendType = false;

      if (obj == null && part.isRequired())
      {
         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
            if (parentPart == null)
            {
               rootMapping = (RootXMLMessagePartMapping)derivedMapping;
               headersPart = rootMapping.getHeaderPart();
               bEnvelopeStarted = appendEnvelopeStart(rootMapping, tobj);
               m_writer.setNamespace(sNamespace);
               m_writer.openElement(sNodeName);
               appendNamespaces(rootMapping, false, !bEnvelopeStarted && bAppendType);
               appendSchemaLocation(rootMapping);
            }
            else
            {
               m_writer.setNamespace(sNamespace);
               m_writer.openElement(sNodeName);

               // Top-level elements of the header need to declare the root
               // namespaces, because they are not under the root element.

               rootMapping = (RootXMLMessagePartMapping)parentPart.getRoot().getMapping();

               if (rootMapping.getHeaderPart() == parentPart)
               {
                  appendNamespaces(rootMapping, false, false);
               }
               else
               {
                  rootMapping = null; // prevent call to cleanupNamespaces
               }
            }

            appendAttributes(tobj, composite);

            if (bAppendType)
            {
               appendType((RootXMLMessagePartMapping)derivedMapping);
            }

            if (appendContents(tobj, composite, headersPart))
            {
               m_writer.setNamespace(sNamespace);
               m_writer.endElement(sNodeName);
            }

            if (bEnvelopeStarted)
            {
               appendEnvelopeEnd(rootMapping);
            }

            if (rootMapping != null)
            {
               cleanupNamespaces();
            }
         }
         else if (!derivedMapping.hasRequiredAttributes()) // skip element with null data if it has required attributes
         {
            // write element with null data: either <elementName/> or <elementName xsi:nil="1"/>
            m_writer.setNamespace(sNamespace);
            m_writer.openElement(sNodeName);

            if (derivedMapping.isNillable())
            {
               m_writer.setNamespace(XMLNamespace.XSI_NAME);
               m_writer.writeAttribute("nil", "1");
            }

            m_writer.closeEmptyElement();
         }
      }
      else
      {
         PrimitiveMessagePart primitive = (PrimitiveMessagePart)part;

         if (obj == null)
         {
            if (derivedMapping.isNillable())
            {
               m_writer.setNamespace(sNamespace);
               m_writer.openElement(sNodeName);
               m_writer.setNamespace(XMLNamespace.XSI_NAME);
               m_writer.writeAttribute("nil", "1");
               m_writer.closeEmptyElement();
            }
         }
         else
         {
            m_writer.setNamespace(sNamespace);
            m_writer.openElement(sNodeName);

            // Write xsi:type for ANY parts
            if (primitive.getType() == Primitive.ANY && derivedMapping.getSubtype() == XMLMessagePartMapping.SUBTYPE_XSI)
            {
               appendType((String)s_primitiveNameMap.get(Primitive.primitiveOf(obj)));
            }

            m_writer.closeElement();
View Full Code Here


      boolean bSingle = part.getAggregation() == CompositeMessagePart.SINGLE;

      for (int i = 0, nPartCount = part.getPartCount(); i < nPartCount; ++i)
      {
         MessagePart childPart = part.getPart(i);
         XMLMessagePartMapping childMapping = (XMLMessagePartMapping)childPart.getMapping();
         byte nNodeType = childMapping.getNodeType();

         // Skip the header
         if (childPart == headersPart)
         {
            continue;
         }

         if (nNodeType == XMLMessagePartMapping.ELEMENT)
         {
            if (bSingle)
            {
               bRequired |= childPart.isRequired();
            }

            if (childMapping.isNillable() || tobj.hasValue(childPart.getName()))
            {
               if (bSingle)
               {
                  if (bMatch)
                  {
                     throw new IntegrationException("err.integration.multipleParts",
                           new Object[]{part.getFullPath()});
                  }

                  bMatch = true;
               }

               if (bEmpty)
               {
                  m_writer.closeElement();
               }

               bEmpty = false;
               append(tobj.findValue(childPart.getName()), childPart, part);
            }
            else if (!bSingle && childPart.isRequired())
            {
               throw new IntegrationException("err.integration.minPartCount", new Object[]{childPart.getFullPath()});
            }
         }
         else if (nNodeType == XMLMessagePartMapping.VALUE)
         {
            PrimitiveMessagePart contentPart = (PrimitiveMessagePart)childPart;

            if (contentPart.getType() == Primitive.ANY)
            {
               Object value = tobj.findValue(contentPart.getName());

               if (bEmpty)
               {
                  m_writer.closeElement();
               }

               bEmpty = false;
               appendValue(value, contentPart, true);
            }
         }
      }

      if (bRequired && !bMatch)
      {
         throw new IntegrationException("err.integration.missingPart",
               new Object[]{part.getFullPath()});
      }

      // Append element content, if exists
      XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();
      PrimitiveMessagePart contentPart = mapping.getValuePart();
      Object content = null;

      if (contentPart != null && contentPart.getType() != Primitive.ANY)
      {
         content = tobj.findValue(mapping.getValuePart().getName());
      }

      if (content != null)
      {
         if (bEmpty)
         {
            m_writer.closeElement();
         }

         appendValue(content, mapping.getValuePart(), true);
         bEmpty = false;
      }
      else if (bEmpty)
      {
         m_writer.closeEmptyElement();
View Full Code Here

   protected void appendAttributes(TransferObject tobj, CompositeMessagePart part) throws IOException
   {
      for (int i = 0, nPartCount = part.getPartCount(); i < nPartCount; ++i)
      {
         MessagePart childPart = part.getPart(i);
         XMLMessagePartMapping childMapping = (XMLMessagePartMapping)childPart.getMapping();
         int nChildNodeType = childMapping.getNodeType();

         if (nChildNodeType == XMLMessagePartMapping.ATTRIBUTE)
         {
            if (tobj.hasValue(childPart.getName()))
            {
               m_writer.setNamespace((childMapping.getNamespace() == null) ? null : childMapping.getNamespace().getName());
               m_writer.writeAttribute(childMapping.getNodeName(), toString((PrimitiveMessagePart)childPart, tobj.getValue(childPart.getName())));
            }
            else
            {
               if (childPart.isRequired())
               {
                  throw new IntegrationException("err.integration.minPartCount", new Object[]{childPart.getFullPath()});
               }
            }
         }
      }

      XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();
      MessagePart valuePart = mapping.getValuePart();

      if (valuePart != null && mapping.isNillable() && tobj.findValue(valuePart.getName()) == null)
      {
         m_writer.setNamespace(XMLNamespace.XSI_NAME);
         m_writer.writeAttribute("nil", "1");
      }
   }
View Full Code Here

      if (value == null)
      {
         return null;
      }

      XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();

      if (mapping.getFormat() != null)
      {
         if (m_primitiveFormatter == null)
         {
            m_primitiveFormatter = new PrimitiveFormatter(m_context);
         }

         return m_primitiveFormatter.format(value, part);
      }

      switch (mapping.getSubtype())
      {
         case XMLMessagePartMapping.SUBTYPE_DATE:
            return SOAPUtil.formatDate((Timestamp)part.validateValue(Primitive.toTimestamp(value)));

         case XMLMessagePartMapping.SUBTYPE_TIME:
View Full Code Here

         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)
                  {
                     tobj = null;

                     if (((PrimitiveMessagePart)part).getType() == Primitive.ANY)
                     {
                        if (mapping.getInterface() == null)
                        {
                           startParsingAnyType((mapping.getSubtype() == XMLMessagePartMapping.SUBTYPE_XSI) ?
                              attributes.getValue(XMLNamespace.XSI, "type") : null);
                        }
                     }
                  }
                  else
                  {
                     CompositeMessagePart composite2 = (CompositeMessagePart)part;
                     PrimitiveMessagePart valuePart = mapping.getValuePart();

                     tobj = new TransferObject(composite2.getPartCount());
                     parseAttributes(tobj, composite2, attributes);

                     // Process message inheritance
                     if (composite2 instanceof CompositeMessagePartRef)
                     {
                        CompositeMessagePartRef ref = (CompositeMessagePartRef)composite2;
                        CompositeMessagePart referencedPart = ref.getRefPart();

                        tobj.setClassName(referencedPart.getName());

                        RootXMLMessagePartMapping refRootMapping = (RootXMLMessagePartMapping)referencedPart.getMapping();
                        Message derivedMessage = getDerivedMessage(attributes, refRootMapping, part.getFullPath());

                        if (derivedMessage != null)
                        {
                           Message referencedMessage = refRootMapping.getRootMessage();

                           Message.validatePolymorphism(referencedMessage, derivedMessage, part);
                           tobj.setClassName(derivedMessage.getName());
                           part = derivedMessage.getRoot();
                           valuePart = ((XMLMessagePartMapping)part.getMapping()).getValuePart();
                        }
                     }

                     if (valuePart != null && valuePart.getType() == Primitive.ANY)
                     {
                        XMLMessagePartMapping valuePartMapping = (XMLMessagePartMapping)valuePart.getMapping();

                        if (valuePartMapping.getInterface() == null)
                        {
                           startParsingAnyType(null)// value part cannot parse to a primitive (attributes not allowed if primitive)
                        }
                     }
                  }
View Full Code Here

    * @param sName The node name.
    * @return True if the name and the URI match; false otherwise.
    */
   protected static boolean matches(MessagePart part, String sURI, String sName)
   {
      XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();

      if (!sName.equals(mapping.getNodeName()))
      {
         return false;
      }

      return ((mapping.getNamespace() != null) ? mapping.getNamespace().getURI() : "").equals(sURI);
   }
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()});
            }
View Full Code Here

      {
         value = null;
      }
      else
      {
         XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();

         if (mapping.getFormat() != null)
         {
            if (m_primitiveFormatter == null)
            {
               m_primitiveFormatter = new PrimitiveFormatter(m_context);
            }

            return m_primitiveFormatter.parse(sValue, part);
         }

         switch (mapping.getSubtype())
         {
            case XMLMessagePartMapping.SUBTYPE_DATE:
               try
               {
                  value = SOAPUtil.parseDateTime(sValue, true, false, m_context.getTimeZone());
View Full Code Here

    * @return The composite type definition.
    */
   protected CompositeType createCompositeType(CompositeMessagePart part, Message message)
   {
      String sOldNamespaceURI = m_sNamespaceURI;
      XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();
      String sName = null;
      boolean bEnvelopeHeaders =
            part == ((RootXMLMessagePartMapping)part.getRoot().getMapping()).getHeaderPart();

      if (message != null)
      {
         assert message.getRoot() == part;

         sName = ((RootXMLMessagePartMapping)mapping).getXSDType();

         if (sName == null)
         {
            sName = message.getName();
         }
      }

      XMLNamespace namespace = mapping.getNamespace();
      Schema schema = (namespace == null) ? m_universe.getSchema(m_sNamespaceURI, null) :
         m_universe.getSchema(namespace.getURI(), namespace.getName());
      CompositeType type;

      if (sName != null)
      {
         CompositeType existingType = (CompositeType)schema.findItem(sName, SchemaItem.COMPOSITE_TYPE);

         if (existingType != null)
         {
            return existingType;
         }

         type = new CompositeType(sName);
         schema.addItem(type);
      }
      else
      {
         type = new CompositeType(sName);
      }

      if (message != null)
      {
         type.setDescription(part.getDescription());
      }

      if (namespace != null)
      {
         m_sNamespaceURI = namespace.getURI();
      }

      switch (part.getAggregation())
      {
         case CompositeMessagePart.SEQUENTIAL:
            type.setAggregation(CompositeType.AGGREGATION_SEQUENTIAL);
            break;

         case CompositeMessagePart.RANDOM:
            type.setAggregation(CompositeType.AGGREGATION_RANDOM);
            break;

         case CompositeMessagePart.SINGLE:
            type.setAggregation(CompositeType.AGGREGATION_CHOICE);
            break;

         default:
            throw new IllegalStateException("Unknown aggregation");
      }

      type.setLax(part.isLax());

      for (int i = 0, nCount = part.getPartCount(); i < nCount; i++)
      {
         MessagePart child = part.getPart(i);

         // Omit parts declared in base message
         if (message != null && child.getDeclarator() != message)
         {
            continue;
         }

         boolean bChildEnvelopeHeaders = child.getRoot() == part &&
            child == ((RootXMLMessagePartMapping)mapping).getHeaderPart();
         XMLMessagePartMapping childMapping = (XMLMessagePartMapping)child.getMapping();

         if (child instanceof PrimitiveMessagePart)
         {
            if (bChildEnvelopeHeaders)
            {
               continue;
            }

            if (childMapping.getNodeType() == XMLMessagePartMapping.VALUE)
            {
               type.setValueType(getAtomicType((PrimitiveMessagePart)child));
            }
            else
            {
               Markup markup = createMarkup((PrimitiveMessagePart)child);

               if (!isEnvelopeMarkup(markup))
               {
                  type.addChild(markup);
               }

               if (bEnvelopeHeaders)
               {
                  addEnvelopeHeader(child, (Element)markup, false);
               }
            }
         }
         else if (child instanceof CompositeMessagePart)
         {
            CompositeType childType;
            Element childElement;

            if (child instanceof CompositeMessagePartRef)
            {
               CompositeMessagePart referentPart = ((CompositeMessagePartRef)child).getRefPart();
               Message referentMessage = ((RootXMLMessagePartMapping)referentPart.getMapping()).getRootMessage();

               childType = createCompositeType(referentPart, referentMessage);
               childElement = new Element(childMapping.getNodeName());
               childElement.setType(childType);
               childElement.setDescription(child.getDescription());

               if (bEnvelopeHeaders)
               {
                  addEnvelopeHeader(child, childElement, true);
               }
            }
            else
            {
               XMLNamespace childNamespace = childMapping.getNamespace();
               String sURI = (childNamespace == null) ? null : childNamespace.getURI();

               if (sURI != null && !sURI.equals(m_sNamespaceURI))
               {
                  // Element reference (different namespace)
                  String sCurrentNamespace = m_sNamespaceURI;
                  Schema otherNSSchema = m_universe.getSchema(sURI, childNamespace.getName());

                  m_sNamespaceURI = sURI;
                  childType = createCompositeType((CompositeMessagePart)child, null);

                  Element otherNSElement = new Element(childMapping.getNodeName());

                  setElementProperties(otherNSElement, (CompositeMessagePart)child);
                  otherNSElement.setType(childType);
                  otherNSElement.setDescription(child.getDescription());
                  otherNSSchema.addItem(otherNSElement);

                  childElement = new ElementRef(otherNSElement);
                  m_sNamespaceURI = sCurrentNamespace;

                  if (bEnvelopeHeaders)
                  {
                     addEnvelopeHeader(child, childElement, false);
                  }
               }
               else
               {
                  // Anonymous type (same namespace)
                  childType = createCompositeType((CompositeMessagePart)child, null);
                  childElement = new Element(childMapping.getNodeName());
                  childElement.setType(childType);
                  childElement.setDescription(child.getDescription());

                  if (bEnvelopeHeaders)
                  {
View Full Code Here

    * @param part The part.
    * @return The markup definition.
    */
   protected Markup createMarkup(PrimitiveMessagePart part)
   {
      XMLMessagePartMapping mapping = (XMLMessagePartMapping)part.getMapping();
      XMLNamespace namespace = mapping.getNamespace();
      String sURI = (namespace == null) ? null : namespace.getURI();

      if (sURI != null && !sURI.equals(m_sNamespaceURI))
      {
         String sCurrentNamespace = m_sNamespaceURI;

         try
         {
            m_sNamespaceURI = sURI;

            if (mapping.getNodeType() == XMLMessagePartMapping.VALUE)
            {
               throw new IllegalStateException();
            }

            byte nType = (mapping.getNodeType() == XMLMessagePartMapping.ELEMENT) ? SchemaItem.ELEMENT : SchemaItem.ATTRIBUTE;
            Schema schema = m_universe.getSchema(sURI, namespace.getName());
            Markup composite = (Markup)schema.findItem(mapping.getNodeName(), nType);

            if (composite == null)
            {
               composite = createMarkup(part);
               schema.addItem(composite);
            }

            if (composite instanceof Element)
            {
               ElementRef ref = new ElementRef((Element)composite);

               setElementProperties(ref, part);

               return ref;
            }

            if (composite instanceof Attribute)
            {
               AttributeRef ref = new AttributeRef((Attribute)composite);

               setAttributeProperties(ref, part);

               return ref;
            }
         }
         finally
         {
            m_sNamespaceURI = sCurrentNamespace;
         }
      }

      if (mapping.getNodeType() == XMLMessagePartMapping.ELEMENT)
      {
         Element element = new Element(mapping.getNodeName());

         setElementProperties(element, part);

         return element;
      }

      if (mapping.getNodeType() == XMLMessagePartMapping.ATTRIBUTE)
      {
         Attribute attribute = new Attribute(mapping.getNodeName());

         setAttributeProperties(attribute, part);

         return attribute;
      }
View Full Code Here

TOP

Related Classes of nexj.core.meta.integration.format.xml.XMLMessagePartMapping

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.