Package nexj.core.meta.integration

Examples of nexj.core.meta.integration.PrimitiveMessagePart


         m_reader.skip(recordMapping.getPrefix().length());
      }

      for (int i = 0; i < recordPart.getPartCount(); i++)
      {
         PrimitiveMessagePart fieldPart = (PrimitiveMessagePart)recordPart.getPart(i);

         if ((sResultArray[i] = readField(fieldPart)) == null && m_bEOF)
         {
            return null;
         }
View Full Code Here


      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

  
   private PrimitiveMessagePart createPrimitiveMessagePart(CompositeMessagePartInstance parent, XSElementDeclaration elemDecl)
   {
      assert !isComposite(elemDecl, parent == null);
     
      PrimitiveMessagePart part = new PrimitiveMessagePart(elemDecl.getName());

      part.setParent(parent);
      part.setDescription(parseDescription(elemDecl.getAnnotation()));
     
      setMapping(part, null, elemDecl);
     
      if (elemDecl.getTypeDefinition() instanceof XSSimpleTypeDefinition)
      {
         String[] sEnumerationArray = XSDUtil.getEnumeration((XSSimpleTypeDefinition)elemDecl.getTypeDefinition());

         for (int nEnumIndex = 0; nEnumIndex < sEnumerationArray.length; ++nEnumIndex)
         {
            part.addEnumeration(sEnumerationArray[nEnumIndex]);
         }
      }

      return part;
   }
View Full Code Here

      while (parent.hasPart(sPartName))
      {
         sPartName = "_" + sPartName;
      }

      PrimitiveMessagePart valuePart = new PrimitiveMessagePart(sPartName);

      valuePart.setType(Primitive.STRING);
      valuePart.setMinCount(0);
      valuePart.setMaxCount(1);

      parent.addPart(valuePart);

      XMLMessagePartMapping mapping = new XMLMessagePartMapping();

      valuePart.setMapping(mapping);
      mapping.setNodeType(XMLMessagePartMapping.VALUE);
      mapping.init(valuePart);
   }
View Full Code Here

        
         if (!contains(baseAttributeUses, attr))
         {
            XSAttributeDeclaration attrDecl = attr.getAttrDeclaration();
            String sName = attrDecl.getName();
            PrimitiveMessagePart part = new PrimitiveMessagePart(sName);

            if (!addPart(parent, part))
            {
               if (s_logger.isWarnEnabled())
               {
                  s_logger.warn("Ignoring duplicate XSD attribute definition \"" + attr.getName() +
                     "\" in element type \"" + def.getName() + "\"");
               }

               continue;
            }

            part.setParent(parent);

            if (attr.getRequired())
            {
               part.setMinCount(1);
            }

            part.setMaxCount(1);
            part.setDescription(parseDescription(attrDecl.getAnnotation()));

            XMLMessagePartMapping mapping = new XMLMessagePartMapping();

            mapping.setNodeName(sName);
            initMapping(mapping, part, XMLMessagePartMapping.ATTRIBUTE, attrDecl.getNamespace(), attrDecl.getTypeDefinition());

            String[] enumerations = XSDUtil.getEnumeration(attrDecl);

            for (int nEnumIndex = 0; nEnumIndex < enumerations.length; ++nEnumIndex)
            {
               part.addEnumeration(enumerations[nEnumIndex]);
            }
         }
      }
   }
View Full Code Here

  
      part.setMapping(mapping);

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

         if (isAnyType(typeDef))
         {
            m_bAnyTypeFound = true;
            primitivePart.setType(Primitive.ANY);
         }
         else
         {
            switch (parsePrimitiveBuildInKind(typeDef, null))
            {
               case XSConstants.STRING_DT:
                  primitivePart.setType(Primitive.STRING);
                  break;
  
               case XSConstants.HEXBINARY_DT:
                  primitivePart.setType(Primitive.BINARY);
                  mapping.setSubtype(XMLMessagePartMapping.SUBTYPE_HEX);
                  break;
  
               case XSConstants.BASE64BINARY_DT:
                  primitivePart.setType(Primitive.BINARY);
                  mapping.setSubtype(XMLMessagePartMapping.SUBTYPE_BASE64);
                  break;
  
               case XSConstants.INT_DT:
               case XSConstants.BYTE_DT:
               case XSConstants.UNSIGNEDBYTE_DT:
               case XSConstants.SHORT_DT:
               case XSConstants.UNSIGNEDSHORT_DT:
               case XSConstants.GDAY_DT:
               case XSConstants.GMONTH_DT:
               case XSConstants.GYEAR_DT:
                  primitivePart.setType(Primitive.INTEGER);
                  break;
  
               case XSConstants.LONG_DT:
               case XSConstants.UNSIGNEDINT_DT:
                  primitivePart.setType(Primitive.LONG);
                  break;
  
               case XSConstants.DECIMAL_DT:
               case XSConstants.INTEGER_DT:
               case XSConstants.NEGATIVEINTEGER_DT:
               case XSConstants.POSITIVEINTEGER_DT:
               case XSConstants.NONNEGATIVEINTEGER_DT:
               case XSConstants.NONPOSITIVEINTEGER_DT:
                  primitivePart.setType(Primitive.DECIMAL);
                  break;
  
               case XSConstants.FLOAT_DT:
                  primitivePart.setType(Primitive.FLOAT);
                  break;
  
               case XSConstants.DOUBLE_DT:
                  primitivePart.setType(Primitive.DOUBLE);
                  break;
  
               case XSConstants.DATE_DT:
                  primitivePart.setType(Primitive.TIMESTAMP);
                  mapping.setSubtype(XMLMessagePartMapping.SUBTYPE_DATE);
                  break;
  
               case XSConstants.TIME_DT:
                  primitivePart.setType(Primitive.TIMESTAMP);
                  mapping.setSubtype(XMLMessagePartMapping.SUBTYPE_TIME);
                  break;
  
               case XSConstants.DATETIME_DT:
                  primitivePart.setType(Primitive.TIMESTAMP);
                  mapping.setSubtype(XMLMessagePartMapping.SUBTYPE_DATETIME);
                  break;
  
               case XSConstants.BOOLEAN_DT:
                  primitivePart.setType(Primitive.BOOLEAN);

                  if (typeDef instanceof XSSimpleTypeDefinition && typeDef.getBaseType() != null
                     && typeDef.getBaseType().derivedFrom(XML_SCHEMA, BOOLEAN_TYPE, (short)XSConstants.DERIVATION_RESTRICTION))
                  {
                     XSSimpleTypeDefinition st = (XSSimpleTypeDefinition)typeDef;
                     StringList s = st.getLexicalPattern();

                     if (s.getLength() == 1)
                     {
                        String sPattern = s.item(0);

                        if ("true|false".equals(sPattern) || "false|true".equals(sPattern))
                        {
                           mapping.setFormat("true;false");
                        }
                     }
                  }

                  break;
  
               default:
                  primitivePart.setType(Primitive.STRING);
                  break;
            }
         }
      }
View Full Code Here

      verifyNotReadOnly();
      m_part = part;

      CompositeMessagePart parentPart = part.getParent();
      XMLMessagePartMapping parentMapping = (parentPart == null) ? null : (XMLMessagePartMapping)parentPart.getMapping();
      PrimitiveMessagePart primitivePart = null;
      CompositeMessagePart compositePart = null;

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

      if (part instanceof CompositeMessagePart)
      {
         compositePart = (CompositeMessagePart)part;
      }

      switch (m_nNodeType)
      {
         case ATTRIBUTE:
            if (parentPart == null)
            {
               throw new MetadataException("err.meta.integration.xml.rootNotElement",
                  new Object[]{part.getFullPath()});
            }

            if (compositePart != null)
            {
               throw new MetadataException("err.meta.integration.xml.compositeAttribute",
                  new Object[]{part.getFullPath()});
            }

            if (part.isCollection())
            {
               throw new MetadataException("err.meta.integration.xml.collectionAttribute",
                  new Object[]{part.getFullPath()});
            }

            if (m_bNillable)
            {
               throw new MetadataException("err.meta.integration.xml.misplacedNillable",
                  new Object[]{part.getFullPath()});
            }

            break;

         case VALUE:
            if (parentPart == null)
            {
               throw new MetadataException("err.meta.integration.xml.rootNotElement",
                  new Object[]{part.getFullPath()});
            }

            if (compositePart != null)
            {
               throw new MetadataException("err.meta.integration.xml.compositeValue",
                  new Object[]{part.getFullPath()});
            }

            if (part.isCollection() && primitivePart.getType() != Primitive.ANY)
            {
               throw new MetadataException("err.meta.integration.xml.collectionValue",
                  new Object[]{part.getFullPath()});
            }

            if (parentMapping.getValuePart() != null)
            {
               throw new MetadataException("err.meta.integration.xml.duplicateElementValueMapping",
                  new Object[]{part.getFullPath()});
            }

            parentMapping.m_valuePart = primitivePart;

            if (m_bNillable)
            {
               throw new MetadataException("err.meta.integration.xml.misplacedNillable",
                  new Object[]{part.getFullPath()});
            }

            break;

         case ELEMENT:
            if (m_bNillable && part.isRequired())
            {
               throw new MetadataException("err.meta.integration.xml.requiredNillable",
                  new Object[]{part.getFullPath()});
            }

            break;
      }

      if (m_nSubtype != SUBTYPE_DEFAULT && m_sFormat != null)
      {
         throw new MetadataException("err.meta.integration.xml.formatSubtype",
            new Object[]{part.getFullPath()});
      }

      boolean bSubtypeValid;

      if (primitivePart != null)
      {
         switch (primitivePart.getType().getOrdinal())
         {
            case Primitive.BINARY_ORDINAL:
               switch (m_nSubtype)
               {
                  case SUBTYPE_DEFAULT:
                     m_nSubtype = SUBTYPE_BASE64;

                  case SUBTYPE_BASE64:
                  case SUBTYPE_HEX:
                     bSubtypeValid = true;
                     break;

                  default:
                     bSubtypeValid = false;
                     break;
               }

               break;

            case Primitive.TIMESTAMP_ORDINAL:
               switch (m_nSubtype)
               {
                  case SUBTYPE_DEFAULT:
                     m_nSubtype = SUBTYPE_DATETIME;

                  case SUBTYPE_DATE:
                  case SUBTYPE_TIME:
                  case SUBTYPE_DATETIME:
                     bSubtypeValid = true;
                     break;

                  default:
                     bSubtypeValid = false;
                     break;
               }

               break;

            case Primitive.ANY_ORDINAL:
               bSubtypeValid = m_nSubtype == SUBTYPE_DEFAULT || m_nSubtype == SUBTYPE_XSI && m_nNodeType == ELEMENT;
               break;

            default:
               bSubtypeValid = m_nSubtype == SUBTYPE_DEFAULT;
               break;
         }
      }
      else
      {
         bSubtypeValid = m_nSubtype == SUBTYPE_DEFAULT;

         if (m_sFormat != null)
         {
            throw new MetadataException("err.meta.integration.formatComposite",
               new Object[]{part.getFullPath()});
         }
      }

      if (!bSubtypeValid)
      {
         throw new MetadataException("err.meta.integration.xml.inapplicableSubtype",
            new Object[]{SUBTYPE_NAMES[m_nSubtype], part.getFullPath()});
      }

      MessagePart rootPart = part.getRoot();
      RootXMLMessagePartMapping rootMapping = (RootXMLMessagePartMapping)rootPart.getMapping();

      // Ensure XSI namespace is used on message root if nillable elements are used
      if (m_bNillable && rootMapping != null)
      {
         rootMapping.addNamespace(XMLNamespace.XSI_NAME, XMLNamespace.XSI, null, false);
      }

      // ANY-typed part with polymorphic typing
      if (primitivePart != null && primitivePart.getType() == Primitive.ANY &&
         m_nSubtype == XMLMessagePartMapping.SUBTYPE_XSI)
      {
         rootMapping.addNamespace(XMLNamespace.XSI_NAME, XMLNamespace.XSI, null, false);
         rootMapping.addNamespace(XMLNamespace.XSD_NAME, XMLNamespace.XSD, null, false);
      }
View Full Code Here

                        loadCompositeMessagePart(element, part, message);
                     }
                  }
                  else if (element.getNodeName().equals("Value"))
                  {
                     final PrimitiveMessagePart part = new PrimitiveMessagePart(sName);

                     composite.addPart(part);
                     part.setType(Primitive.parse(XMLUtil.getReqStringAttr(element, "type")));
                     loadMessagePart(element, part, message);

                     XMLUtil.withFirstChildElement(element, "Enumerations", false, new ElementHandler()
                     {
                        public void handleElement(Element enumerationsElement)
                        {
                           XMLUtil.forEachChildElement(enumerationsElement, "Enumeration", new ElementHandler()
                           {
                              public void handleElement(Element enumerationElement)
                              {
                                 part.addEnumeration(XMLUtil.getReqStringAttr(enumerationElement, "value"));
                              }
                           });
                        }
                     });
                  }
View Full Code Here

      MessagePart previousPart = rowPart;
     
      //Format fields in ordinal order
      for (int nPartIndex=0; nPartIndex < partsInOrder.length; nPartIndex++)
      {
         PrimitiveMessagePart part = partsInOrder[nPartIndex];
        
         if (part == null)
         {
            nDelimiterAccumulator += 1;
            continue;
         }
        
         CSVMessagePartMapping partMapping = (CSVMessagePartMapping)part.getMapping();
        
         //Get the transfer object for this part's datum.
         String[] dataKeyPath = partMapping.getDataKeyPath();
         Object datum = rowTransferObj;

         for (int nKeyPathIndex=0; nKeyPathIndex < dataKeyPath.length; nKeyPathIndex++)
         {
            datum = ((TransferObject)datum).findValue(dataKeyPath[nKeyPathIndex], Undefined.VALUE);
           
            if (datum == Undefined.VALUE)
            {
               break;
            }
         }
        
         //Always write the absolute minimum number of delimiters: if there is no data
         //for the last fields on the line, then no delimiter is written.
         if (datum != Undefined.VALUE)
         {
            for (int nDelim = 0; nDelim < nDelimiterAccumulator; nDelim++)
            {
               m_writer.write(((CSVMessagePartMapping)previousPart.getMapping()).getDelimiter().charValue());
            }
           
            nDelimiterAccumulator = 1;
            formatField(datum, partMapping, part);
         }
         else
         {
            nDelimiterAccumulator++;
           
            if (part.isRequired())
            {
               throw new IntegrationException("err.integration.minPartCount",
                  new Object[]{part.getFullPath()});
            }
         }
        
         previousPart = part;
      }
View Full Code Here

      TransferObject result = new TransferObject(partsInOrder.length)//over-allocates
      boolean bGotData = false;

      for (int nDataIndex = 0; nDataIndex < partsInOrder.length; nDataIndex++)
      {
         PrimitiveMessagePart part = (PrimitiveMessagePart)partsInOrder[nDataIndex];

         //Check for missing required parts.
         if (nDataIndex >= rawRow.length || rawRow[nDataIndex] == Invalid.VALUE)
         {
            for (int nPartScanIndex = nDataIndex; nPartScanIndex < partsInOrder.length; nPartScanIndex++)
            {
               MessagePart scanPart = partsInOrder[nPartScanIndex];

               if (scanPart != null && scanPart.isRequired())
               {
                  throw new IntegrationException("err.integration.minPartCount",
                     new Object[]{scanPart.getFullPath()});
               }
            }

            continue;
         }

         //Skip data that are not mapped to a MessagePart
         if (part == null)
         {
            continue;
         }

         Object datum = rawRow[nDataIndex];

         //Traverse graph of TransferObjects to find the object to which this
         //datum should be attached, creating the graph as necessary.
         if ((datum != null && datum != Invalid.VALUE) || part.isRequired())
         {
            CSVMessagePartMapping mapping = (CSVMessagePartMapping)part.getMapping();

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

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

            TransferObject nestedResult = result;
            TransferObject nextNestedResult = null;
            String[] dataKeyPath = mapping.getDataKeyPath();

            for (int nKeyPathIndex=0; nKeyPathIndex < dataKeyPath.length - 1; nKeyPathIndex++)
            {
               nextNestedResult = (TransferObject)nestedResult.findValue(dataKeyPath[nKeyPathIndex]);

               if (nextNestedResult == null)
               {
                  nextNestedResult = new TransferObject();
                  nestedResult.setValue(dataKeyPath[nKeyPathIndex], nextNestedResult);
               }

               nestedResult = nextNestedResult;
            }

            nestedResult.setValue(part.getName(), datum);
            bGotData = true;
         }
      }

      return (bGotData) ? result : null;
View Full Code Here

TOP

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

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.