Package nexj.core.runtime

Examples of nexj.core.runtime.Instance


   protected Object transfer1(Object obj, MessagePart msg) throws IntegrationException
   {
      MessagePart processedPart = msg;
      String sMessageName = null;
      Metaclass metaclass;
      Instance instance = (obj instanceof Instance) ? (Instance)obj : null;
      TransferObject srcTobj = (obj instanceof TransferObject) ? (TransferObject)obj : null;
      Message message = null;

      if (instance != null || srcTobj != null)
      {
         if (msg instanceof CompositeMessagePartRef)
         {
            CompositeMessagePartRef ref = (CompositeMessagePartRef)msg;
            CompositeMessagePart referencedPart = ref.getRefPart();

            message = ((ObjectMessagePartMapping)referencedPart.getMapping()).getMessage();
         }
         else if (msg.getParent() == null)
         {
            message = ((ObjectMessagePartMapping)msg.getRoot().getMapping()).getMessage();
         }
      }

      // Process inheritance
      if (message != null)
      {
         metaclass = (instance != null) ? instance.getMetaclass() :
            m_context.getMetadata().getMetaclass(srcTobj.getClassName());

         Message derivedMessage = findDerivedMessage(message, metaclass);

         if (derivedMessage == null)
         {
            throw new IntegrationException("err.integration.object.missingMapping",
               new Object[]{metaclass.getName(), message.getName(), msg.getFullPath()});
         }

         Message.validatePolymorphism(message, derivedMessage, msg);
         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;

               case ObjectMessagePartMapping.ATTR_CLASS:
                  value = instance.getMetaclass().getName();
                  break;

               case ObjectMessagePartMapping.ATTR_EVENT:
                  value = sEvent;
                  break;
View Full Code Here


    * synchronization link is not null and the use of sync objects is not allowed.
    * @param syncLink The OIDHolder of the synchronization link - source of data used for this persist step to set.
    */
   public void initFormatterStrategy(Sync.Link syncLink)
   {
      Instance link = (syncLink == null || syncLink.getLink() == null) ? null : syncLink.getLink();

      if (m_formatterStrategy == null || link != m_link)
      {
         m_link = link;

         if (syncLink == null)
         {
            m_formatterStrategy = (ObjectMessageFormatterStrategy)new BasicFormatter();
         }
         else
         {
            Instance target = (link != null) ? (Instance)link.getValue("target") : null;

            boolean bUseSyncObjects = (target == null) ? false :
               ((Boolean)target.getValue("SYNC_OBJECTS_USED", "USE_SYNC_OBJECTS")).booleanValue();

            String sFormatterClassName = (bUseSyncObjects) ?
               "nexj.core.integration.format.object.StatefulSyncObjectFormatter" :
                  "nexj.core.integration.format.object.StatelessSyncObjectFormatter";

View Full Code Here

         GenericServer.auditRequest(m_instanceByTobjMap, null, m_context);

         for (int i = 0, n = m_invocationList.size(); i != n; ++i)
         {
            TransferObject nextTobj = (TransferObject)m_invocationList.get(i);
            Instance inst = (Instance)m_instanceByTobjMap.get(nextTobj);
            boolean bInvoke = true;

            if (inst.isEventPending())
            {
               // For a change from an external system, the event could be set to create. Additionally, the internal
               // instance may already exist. In such a case, the instance should simply be updated and not create
               // any duplicates in the internal system.
               bInvoke = (("create".equals(nextTobj.getEventName()) && inst.getState() == Instance.DIRTY) &&
                  "update".equals(inst.getPendingEventName()))
                  ? false
                  : !inst.getPendingEventName().equals(nextTobj.getEventName());

               inst.invokePendingEvent();
            }

            if (bInvoke && nextTobj.getEventName() != null
               // Ignore pending "update" events - they should only run if there has been an actual update.
               && (!nextTobj.getEventName().equals("update") || inst.getState() == Instance.DIRTY)
               // Instance update or insert was rejected (e.g. by sync engine)
               && inst.getState() != Instance.DELETED)
            {
               inst.invoke(nextTobj.getEventName());
            }
         }

         finalizeInstantiate();
         s_logger.debug("Completed formatting the object message");
View Full Code Here

         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();

               for (Iterator itr = allInstances.iterator(); itr.hasNext();)
               {
                  Instance instance = (Instance)itr.next();

                  if (!foundInstances.contains(instance))
                  {
                     addInstanceToDelete(instance, composite, parentTobj);
                  }
View Full Code Here

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

      adjustEventName(tobj, derivedClass);

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

      if (instance == null)
      {
         deleteInstanceState(tobj, derivedClass);
View Full Code Here

      {
         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())
               {
View Full Code Here

         }
      }

      CompositeMessagePart composite = (CompositeMessagePart)derivedPart;
      TransferObject tobj = (TransferObject)obj;
      Instance instance = (Instance)m_instanceByTobjMap.get(tobj);

      if (instance == null && "delete".equals(tobj.getEventName())) // Obsolete delete
      {
         if (part.isRequired())
         {
            throw new IntegrationException("err.integration.minPartCount", new Object[]{part.getFullPath()});
         }

         return null;
      }

      boolean bNew = (instance == null);

      if (bNew && derivedClass != null)
      {
         instance = new Instance(metaclass, m_context);
         instance.setNew();
         m_instanceByTobjMap.put(tobj, instance);
      }
      else
      {
         if (m_context.isSecure() && instance != null && !instance.isReadable())
         {
            throw new SecurityViolationException("err.rpc.instanceAccess",
               new Object[]{instance.getLazyCaption(), instance.getLazyClassName()});
         }
      }

      if (instance != null && ! m_invocationList.contains(tobj))
      {
         m_invocationList.add(tobj);
      }

      if ((bNew ||
         part.getParent() != null ||
         mapping.isUpdate() &&
         (mapping.getAccessAttribute() == null ||
          Intrinsic.isTrue(instance.getValue(mapping.getAccessAttribute().getOrdinal())))))
      {
         updateInstance(bNew, tobj, instance, composite, mapping);
      }

      return instance;
View Full Code Here

                     InstanceList list = (InstanceList)instance.getValue(attribute.getOrdinal());
                     InstanceList valueList = (InstanceList)value;

                     for (int l = 0; l < valueList.size(); ++l)
                     {
                        Instance newInst = valueList.getInstance(l);

                        if (!list.contains(newInst))
                        {
                           list.add(newInst);
                        }
View Full Code Here

      if (s_logger.isDebugEnabled())
      {
         s_logger.debug("Invoking " + service);
      }

      Instance instance = null;

      try
      {
         m_context.setSecure(false);
         instance = new Instance(metaclass, m_context);

         State state = new State(service, true);

         state.setReservedValue(0, instance);
         state.setReservedValue(1, state);
         state.setValue(Service.OUTPUT, sOutput);
         state.setToken(service, message);

         int i = 0;

         for (Pair pair = args; pair != null; pair = pair.getNext())
         {
            if (i >= service.getArgumentCount())
            {
               i = -1;
               break;
            }
           
            state.setValue(service.getArgument(i++), pair.getHead());
         }

         if (i != service.getArgumentCount())
         {
            throw new IntegrationException("err.integration.service.argCount",
               new Object[]{Primitive.createInteger(Pair.length(args)),
                  Primitive.createInteger(service.getArgumentCount())});
         }

         instance.setNew();
         instance.setValue("name", service.getName());
         instance.setValue("version", Primitive.createInteger(service.getVersion()));
         instance.setValue("oid", EMPTY_BINARY);
         instance.setValue("class", "");
         instance.setValue("local", GUIDUtil.generateGUID());
         instance.setValue("object", null);
         instance.setValue("state", state);
         instance.setValue("serializedState", null);
         instance.setValue("serializedVariables", null);
         instance.invoke("create");
         m_context.setSecure(bSecure);
         instance.invoke("run");
      }
      catch (Throwable e)
      {
         if (instance != null && instance.getState() != Instance.INIT)
         {
            m_context.setSecure(false);
            instance.invoke("delete");
         }

         ObjUtil.rethrow(e);
      }
      finally
View Full Code Here

      }
      else if (value instanceof Instance)
      {
         buf.append('<');

         Instance instance = (Instance)value;

         try
         {
            Attribute attr = instance.getMetaclass().getNameAttribute();

            if (attr != null)
            {
               appendValue(buf, instance.getValue(attr.getOrdinal()), true);
               buf.append(": ");
            }
         }
         catch (Exception e)
         {
         }

         if (bClassName)
         {
            try
            {
               buf.append(instance.getMetaclass().getName());
               buf.append(": ");
            }
            catch (Exception e)
            {
            }
         }

         if (instance.getOID() == null)
         {
            buf.append("OID");
         }
         else
         {
            buf.append(instance.getOID());
         }

         buf.append('>');
      }
      else if (value instanceof TransferObject)
View Full Code Here

TOP

Related Classes of nexj.core.runtime.Instance

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.