Package nexj.core.meta.integration.format.object

Examples of nexj.core.meta.integration.format.object.ObjectMessagePartMapping


         msg = derivedMessage.getRoot();
         message = derivedMessage;
         sMessageName = message.getName();
      }

      ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)msg.getMapping();

      if (m_context.isSecure())
      {
         if (mapping.getAttribute() != null)
         {
            mapping.getAttribute().checkReadAccess(m_context.getPrivilegeSet());
         }
         else
         {
            mapping.getMetaclass().checkReadAccess(m_context.getPrivilegeSet());
         }
      }

      if (obj == null)
      {
         if (msg.isRequired())
         {
            throw new IntegrationException("err.integration.minPartCount", new Object[]{msg.getFullPath()});
         }
        
         return null;
      }
     
      if (msg instanceof PrimitiveMessagePart)
      {
         return ((PrimitiveMessagePart)msg).convertValue(obj);
      }

      CompositeMessagePart composite = (CompositeMessagePart)msg;
      int nCount = composite.getPartCount();
     
      if (obj instanceof TransferObject)
      {
         if (isFetchInstance())
         {
            instance = (Instance)RPCUtil.instantiateClean(srcTobj, new HashTab(), m_context);
         }
         else
         {
            TransferObject tobj = new TransferObject(sMessageName, composite.getPartCount());

            tobj.setEventName(srcTobj.getEventName());
            tobj.setOID(srcTobj.getOID());
  
            for (int i = 0; i < nCount; ++i)
            {
               MessagePart part = composite.getPart(i);
               ObjectMessagePartMapping objectMessagePartMapping = (ObjectMessagePartMapping)part.getMapping();
               Attribute attribute = objectMessagePartMapping.getAttribute();
               Object value = null;

               if (attribute != null)
               {
                  value = transfer(srcTobj.findValue(attribute.getName()), part);
               }
               else
               {
                  switch (objectMessagePartMapping.getSystemAttribute())
                  {
                     case ObjectMessagePartMapping.ATTR_OID:
                        value = srcTobj.getOID().toBinary();
                        break;

                     case ObjectMessagePartMapping.ATTR_CLASS:
                        value = srcTobj.getClassName();
                        break;

                     case ObjectMessagePartMapping.ATTR_EVENT:
                        value = srcTobj.getEventName();
                        break;
                  }
               }

               tobj.setValue(part.getName(), value);
            }
  
            return tobj;
         }
      }

      if (m_context.isSecure() && !instance.isReadable())
      {
         return null;
      }

      metaclass = instance.getMetaclass();

      TransferObject tobj = new TransferObject(sMessageName, composite.getPartCount());
     
      if (!mapping.getMetaclass().isUpcast(metaclass))
      {
         throw new IntegrationException("err.integration.object.partClass",
            new Object[]{mapping.getMetaclass().getName(), composite.getFullPath()});
      }

      String sEvent = null;
      boolean bProcessed = m_processedSet.put(instance, processedPart, Boolean.TRUE) != null;
     
      m_instanceMap.put(instance, tobj);
      tobj.setOID(instance.getOID());

      if (srcTobj != null)
      {
         sEvent = srcTobj.getEventName();
      }
      else
      {
         switch (instance.getState())
         {
            case Instance.NEW:
               sEvent = "create";
               break;

            case Instance.DIRTY:
               sEvent = "update";
               break;

            case Instance.DELETED:
               sEvent = "delete";
               break;
         }
      }

      tobj.setEventName(sEvent);

      for (int i = 0; i < nCount; ++i)
      {
         MessagePart part = composite.getPart(i);
         ObjectMessagePartMapping objectMessagePartMapping = (ObjectMessagePartMapping)part.getMapping();
         Attribute attribute = objectMessagePartMapping.getAttribute();
         Object value = null;

         if (attribute != null)
         {
            if (bProcessed && objectMessagePartMapping.isKey() && !(part instanceof PrimitiveMessagePart))
            {
               throw new IntegrationException("err.integration.object.recursive", new Object[]{msg.getName()});
            }
           
            if (!bProcessed || objectMessagePartMapping.isKey())
            {
               value = transfer(instance.getValue(attribute.getOrdinal()), part);
               tobj.setValue(part.getName(), value);
            }
         }
         else
         {
            switch (objectMessagePartMapping.getSystemAttribute())
            {
               case ObjectMessagePartMapping.ATTR_OID:
                   value = (instance.getOID() == null) ? null : instance.getOID().toBinary();
                   break;
View Full Code Here


    */
   public static Message findDerivedMessage(Message message, Metaclass clazz)
   {
      if (clazz != null && message.getDerivation() != Message.DERIVATION_FINAL)
      {
         ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)message.getRoot().getMapping();
         Message result = mapping.findMessage(clazz);

         if (result == null)
         {
            return findDerivedMessage(message, clazz.getBase());
         }
View Full Code Here

      try
      {
         m_context.setAudited(false);

         ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();

         if (mapping != null)
         {
            String sDerivedMessageName = tobj.getClassName();
            Message message = mapping.getMessage();

            if (!StringUtil.isEmpty(sDerivedMessageName) && !sDerivedMessageName.equals(message.getName()))
            {
               Message derivedMessage = m_context.getMetadata().getMessage(sDerivedMessageName);
               Message.validatePolymorphism(message, derivedMessage, derivedMessage.getRoot());
View Full Code Here

   {
      if (composite.isCollection())
      {
         List list = getList(obj, composite);
         InstanceList foundInstances = new InstanceArrayList(list.size());
         ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();

         for (int i = 0, n = list.size(); i != n; ++i)
         {
            Instance instance = findInstance1((TransferObject)list.get(i), composite, parentTobj, parentComposite);

            if (instance != null)
            {
               foundInstances.add(instance, InstanceList.REPLACE | InstanceList.DIRECT);
            }
         }

         if (mapping.isDelete() && obj != null) // Delete all unmatched instances
         {
            Object where = mapping.getWhere();

            if (mapping.isLocal() && parentComposite.getMapping() != null)
            {
               Pair eq = Pair.list(Symbol.ATAT, ((ObjectMessagePartMapping)
                  parentComposite.getMapping()).getMetaclass().getSymbol(),
                  mapping.getAttribute().getSymbol()).eq(m_instanceByTobjMap.get(parentTobj));

               where = eq.and(where);
            }

            InstanceList allInstances = Query.createRead(mapping.getMetaclass(), getAttributes(composite),
               where, null, -1, 0, false, Query.SEC_NONE, m_context).read();

            if (!allInstances.isEmpty())
            {
               List instToKeepList = new ArrayList();
View Full Code Here

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

      ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();
      CompositeMessagePart derivedComposite = getPolymorphic(composite, tobj);
      ObjectMessagePartMapping derivedMapping = (ObjectMessagePartMapping)derivedComposite.getMapping();
      Metaclass derivedClass = (derivedMapping == null) ? null : derivedMapping.getMetaclass();

      // If any message part is mapped to special attributes ATTR_EVENT and ATTR_OID,
      // it overrides the event or oid set on message.
      String sEventName = (String)getSystemAttributeValue(derivedComposite, tobj, ObjectMessagePartMapping.ATTR_EVENT);
      OID oid = (OID)getSystemAttributeValue(derivedComposite, tobj, ObjectMessagePartMapping.ATTR_OID);

      if (sEventName != null)
      {
         setEventName(tobj, sEventName);
      }

      if (oid != null)
      {
         tobj.setOID(oid);
      }

      boolean bDelete = "delete".equals(tobj.getEventName());

      adjustEventName(tobj, derivedClass);

      Instance instance = (Instance)m_instanceByTobjMap.get(tobj);

      if (instance == null)
      {
         deleteInstanceState(tobj, derivedClass);

         if ("create".equals(tobj.getEventName())
            && (!derivedMapping.hasAlternativeSyncKey() || !isRootSynchronized(tobj)))
         {
            // The internal instance corresponding to the transfer object will be created during instantiation.
            m_instanceByTobjMap.put(tobj, null);
         }
         else
View Full Code Here

      {
         MessagePart part = derivedComposite.getPart(i);

         if (part instanceof CompositeMessagePart && !part.isCollection())
         {
            ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)part.getMapping();

            if (mapping != null && mapping.isKey())
            {
               Object childObj = tobj.findValue(part.getName());

               if (!(childObj instanceof TransferObject))
               {
View Full Code Here

    * @param composite The message part metadata.
    * @return a list of attribute to be read from the datasource
    */
   private Pair getAttributes(CompositeMessagePart composite)
   {
      ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();
      Pair attributes = null;

      for (int i = composite.getPartCount() - 1; i >= 0; --i)
      {
         ObjectMessagePartMapping partMapping = ((ObjectMessagePartMapping)composite.getPart(i).getMapping());
         Attribute attr = partMapping.getAttribute();
        
         if (attr != null && !attr.isCollection())
         {
            attributes = new Pair(attr.getSymbol(), attributes);

            if (partMapping.getAccessAttribute() != null)
            {
               attributes = new Pair(partMapping.getAccessAttribute().getSymbol(), attributes);
            }
         }
      }

      if (composite.getParent() == null && mapping.getAccessAttribute() != null)
View Full Code Here

    * @param bRoot True if this is the object to which the where clause applies.
    */
   protected Pair getWhere1(TransferObject tobj, CompositeMessagePart composite, TransferObject parent,
      CompositeMessagePart parentComposite, Pair assoc, boolean bRoot)
   {
      ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();
      CompositeMessagePart derivedComposite = getPolymorphic(composite, tobj);
      ObjectMessagePartMapping derivedMapping = ((ObjectMessagePartMapping)derivedComposite.getMapping());
      Metaclass derivedMetaclass = derivedMapping.getMetaclass();
      Pair where = null;

      if (!bRoot)
      {
         assoc = new Pair(mapping.getAttribute().getSymbol(), assoc);

         if (!mapping.isLocal())
         {
            Instance instance = (Instance)m_instanceByTobjMap.get(tobj);

            if (instance == null)
            {
               if (!m_instanceByTobjMap.contains(tobj) && !mapping.isSubKeyParent())
               {
                  instance = findInstance1(tobj, composite, parent, parentComposite);
               }

               if (instance == null && !mapping.isSubKeyParent())
               {
                  return EMPTY;
               }
            }

            if (instance != null && !mapping.isSubKeyParent())
            {
               return getComparison(assoc, instance);
            }
         }
      }

      if (tobj == null || isInstanceRead(tobj, derivedMapping))
      {
         return EMPTY;
      }

      if (tobj.getOID() != null)
      {
         where = new Pair(getComparison(assoc, tobj.getOID()), where);
      }
      else
      {
         for (int i = 0, n = derivedComposite.getPartCount(); i != n; ++i)
         {
            MessagePart part = derivedComposite.getPart(i);
            ObjectMessagePartMapping partMapping = (ObjectMessagePartMapping)part.getMapping();

            if (bRoot && partMapping.isKey() || !bRoot && partMapping.isSubKey())
            {
               if (!tobj.hasValue(part.getName()))
               {
                  return EMPTY;
               }

               Object obj = tobj.getValue(part.getName());
               Pair expr = null;

               if (part instanceof CompositeMessagePart)
               {
                  expr = getWhere(obj, (CompositeMessagePart)part, tobj, composite, assoc, false);

                  if (expr == EMPTY)
                  {
                     return EMPTY;
                  }
               }
               else if (partMapping.getSystemAttribute() == ObjectMessagePartMapping.ATTR_OID)
               {
                  expr = getComparison(assoc, obj);
               }
               else if (partMapping.getAttribute() != null)
               {
                  expr = getComparison(new Pair(partMapping.getAttribute().getSymbol(), assoc),
                     partMapping.getAttribute().getType().convert(obj));
               }

               if (expr != null)
               {
                  where = new Pair(expr, where);
View Full Code Here

    * @param obj The object to instantiate.
    * @param msg The message part metadata.
    */
   protected Object instantiate1(Object obj, MessagePart part)
   {
      ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)part.getMapping();
      Metaclass derivedClass = (mapping == null) ? null : mapping.getMetaclass();
      MessagePart derivedPart = part;

      if (part instanceof CompositeMessagePart)
      {
         derivedPart = getPolymorphic((CompositeMessagePart)part, (TransferObject)obj);

         if (derivedPart != part)
         {
            ObjectMessagePartMapping derivedMapping = (ObjectMessagePartMapping)derivedPart.getMapping();

            if (mapping == null)
            {
               mapping = derivedMapping;
            }

            derivedClass = derivedMapping.getMetaclass();
         }
      }

      Metaclass metaclass = null;

View Full Code Here

    * @param nAttr One of the ObjectMessagePartMapping.ATTR_* constants.
    * @return The system attribute value, or null if not found.
    */
   protected Object getSystemAttributeValue(CompositeMessagePart composite, TransferObject tobj, int nAttr)
   {
      ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();
      Object value = null;

      if (mapping != null)
      {
         MessagePart part = mapping.getSystemPart(nAttr);

         if (part != null)
         {
            value =  tobj.findValue(part.getName());
         }

         switch (nAttr)
         {
            case ObjectMessagePartMapping.ATTR_CLASS:
               String sClass = (String)value;

               if (StringUtil.isEmpty(sClass))
               {
                  return mapping.getMetaclass();
               }

               return m_context.getMetadata().getMetaclass(sClass);

            case ObjectMessagePartMapping.ATTR_OID:
View Full Code Here

TOP

Related Classes of nexj.core.meta.integration.format.object.ObjectMessagePartMapping

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.