Package nexj.core.meta

Examples of nexj.core.meta.Event


       * @param methodDoc The Java method that defined this event. Used for
       *           initialization and error reporting.
       */
      public ScriptingEvent(MethodDoc methodDoc)
      {
         m_event = new Event(methodDoc.name());
         m_argList = new ArrayList();
         m_argList.add(null);
         m_methodDoc = methodDoc;
      }
View Full Code Here


      Attribute attr = new Attribute("attr");
      Argument untyped = new Argument("untyped");
      Argument anytyped = new Argument("anytyped");
      Argument inttyped = new Argument("inttyped");
      Argument listtyped = new Argument("listtyped");
      Event protectedEv = new Event("protected");
      Event publicEv = new Event("public");
      Event staticEv = new Event("static");
      MockServer server = new MockServer(new Object[]{null});
      Timestamp ts =
         SOAPUtil.parseDateTime("1234-05-06T07:08:09", true, true, TimeZone.getDefault());

      attr.setType(Primitive.ANY);
      anytyped.setType(Primitive.ANY);
      inttyped.setType(Primitive.INTEGER);
      listtyped.setType(Primitive.STRING);
      listtyped.setCollection(true);
      protectedEv.setVisibility(Metaclass.PROTECTED);
      publicEv.addArgument(untyped);
      publicEv.addArgument(anytyped);
      publicEv.addArgument(inttyped);
      publicEv.addArgument(listtyped);
      staticEv.addArgument(untyped);
      staticEv.addArgument(anytyped);
      staticEv.addArgument(inttyped);
      staticEv.addArgument(listtyped);
      staticEv.setStatic(true);
      staticEv.setVarArg(true);
      metaclass.addAttribute(attr);
      metaclass.addEvent(protectedEv);
      metaclass.addEvent(publicEv);
      metaclass.addEvent(staticEv);
      metadata.addMetaclass(metaclass);

      // test protected event
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(metadata));
      String sElement = XSDGenerator.computeElementName(protectedEv);
      StringReader reader = new StringReader(
         "<" + sElement + " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'/>");

      try
      {
         unmarshaller.deserialize(reader);
         fail(); // SOAPUnmarshallerException expected
      }
      catch (SOAPUnmarshallerException e)
      {
         assertEquals("err.rpc.soap.missingType", e.getErrorCode());
      }

      // test public non-static unbound event
      sElement = XSDGenerator.computeElementName(publicEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped>abc</listtyped><listtyped>def</listtyped>" +
         "</" + sElement + ">");

      try
      {
         unmarshaller.deserialize(reader);
         fail(); // SOAPUnmarshallerException expected
      }
      catch (SOAPUnmarshallerException e)
      {
         assertEquals("err.rpc.soap.unmshComplex", e.getErrorCode());
      }

      // test public non-static event
      sElement = XSDGenerator.computeElementName(publicEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns:tns='" + XML.NS_URI_TNS + "'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<_instance><tns:" + attr.getName() + ">test</tns:" + attr.getName() + "></_instance>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped>abc</listtyped><listtyped>def</listtyped>" +
         "</" + sElement + ">");

      ((XMLInvocationRequest)unmarshaller.deserialize(reader)).invoke(server);

      Request request = server.getRequest();

      assertNotNull(request);
      assertEquals(1, request.getInvocationCount());

      Request.Invocation action = request.getInvocation(0);
      TransferObject tobj = action.getObject();
      Object[] argArray = action.getArguments();

      assertEquals(publicEv.getName(), action.getEventName());
      assertEquals(publicEv.getArgumentCount(), argArray.length);
      assertTrue(argArray[0] instanceof BigDecimal);
      assertEquals(3.1415926535897932384626433832795, ((BigDecimal)argArray[0]).doubleValue(), 0);
      assertTrue(argArray[1] instanceof Timestamp);
      assertEquals(ts.getTime(), ((Timestamp)argArray[1]).getTime());
      assertEquals(Primitive.createInteger(42), argArray[2]);
      assertTrue(argArray[3] instanceof List);
      assertEquals(2, ((List)argArray[3]).size());
      assertEquals("abc", ((List)argArray[3]).get(0));
      assertEquals("def", ((List)argArray[3]).get(1));
      assertEquals(metaclass.getName(), tobj.getClassName());
      assertNull(tobj.getEventName());
      assertNull(tobj.getOID());
      assertEquals(1, tobj.getValueCount());
      assertEquals("test", tobj.findValue(attr.getName()));

      // test static bound event
      sElement = XSDGenerator.computeElementName(staticEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns:tns='" + XML.NS_URI_TNS + "'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<_instance><tns:" + attr.getName() + ">test</tns:" + attr.getName() + "></_instance>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped>abc</listtyped><listtyped>def</listtyped>" +
         "</" + sElement + ">");

      try
      {
         unmarshaller.deserialize(reader);
         fail(); // SOAPUnmarshallerException expected
      }
      catch (SOAPUnmarshallerException e)
      {
         assertEquals("err.rpc.soap.element", e.getErrorCode());
      }

      // test static event
      sElement = XSDGenerator.computeElementName(staticEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns:tns='" + XML.NS_URI_TNS + "'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped><tns:item>abc</tns:item><tns:item>def</tns:item></listtyped>" +
         "<listtyped><tns:item>ghi</tns:item><tns:item>jkl</tns:item></listtyped>" +
         "</" + sElement + ">");
      ((XMLInvocationRequest)unmarshaller.deserialize(reader)).invoke(server);
      request = server.getRequest();
      assertNotNull(request);
      assertEquals(1, request.getInvocationCount());
      action = request.getInvocation(0);
      tobj = action.getObject();
      assertEquals(staticEv.getName(), action.getEventName());
      argArray = action.getArguments();
      assertEquals(5, argArray.length); // untyped + anytyped + inttyped + 2*listtyped
      assertTrue(argArray[0] instanceof BigDecimal);
      assertEquals(3.1415926535897932384626433832795, ((BigDecimal)argArray[0]).doubleValue(), 0);
      assertTrue(argArray[1] instanceof Timestamp);
View Full Code Here

    */
   public Object invoke(String sName, Object[] args)
   {
      load();

      Event event = (Event)m_metaclass.getSelector(sName).getMember((args != null) ? args.length : 0);

      return event.invoke((event.isStatic()) ? (Accessor)m_metaclass : this, args, m_context.getMachine());
   }
View Full Code Here

    */
   public Object invoke(String sName, Pair args)
   {
      load();

      Event event = (Event)m_metaclass.getSelector(sName).getMember(Pair.length(args));

      return event.invoke((event.isStatic()) ? (Accessor)m_metaclass : this, args, m_context.getMachine());
   }
View Full Code Here

      // Compile the flow functions
      for (Lookup2D.Iterator itr = m_functionMap.valueIterator(); itr.hasNext();)
      {
         itr.next();

         Event event = (Event)itr.getKey1();
         Pair body = (Pair)machine.invoke((Function)machine.getGlobalEnvironment()
            .getVariable(Symbol.SYS_GENERATE_FLOW_FUNCTION), itr.getValue(), (Object[])null);

         itr.setValue(new Pair(new Compiler().compile(m_variables,
            event.getArguments(true), body, m_posMap, m_urlMap, machine)));
         map.put(event.getRoot(), itr.getKey2(), null);
      }

      for (Lookup2D.Iterator itr = map.valueIterator(); itr.hasNext();)
      {
         itr.next();
View Full Code Here

   {
      Metaclass metaclass = event.getMetaclass();
     
      for (int i = 0, nCount = metaclass.getDerivedCount(); i < nCount; ++i)
      {
         Event derived = metaclass.getDerived(i).findEvent(event.getName(), event.getArgumentCount());
         Pair dpair = (Pair)m_functionMap.get(derived, assoc);
        
         if (pair != null)
         {
            dpair = Pair.append(pair, dpair);
View Full Code Here

            {
               public void handleElement(Element eventElement, String sEventName)
               {
                  XMLMetadataHelper.validateName(sEventName);

                  Event event = new Event(sEventName);

                  event.setMetaclass(metaclass);
                  event.setDeclarator(metaclass);
                  loadEvent(eventElement, event);
                  metaclass.addEvent(event);
               }
            });
         }
View Full Code Here

         Symbol symbol = (Symbol)args.getHead();

         args = args.getNext();

         Event event = (Event)m_context.getMetadata()
            .getMetaclass(((Symbol)reader.getValue("class")).getName())
            .getSelector(symbol).getMember(Pair.length(args));

         reader.setValue("attributes", findValue(event, "attributes", args));
         reader.setValue("where", findValue(event, "where", args));
View Full Code Here

         Boolean inclusive = (Boolean)reader.getValue("inclusive");
         List parentList = (List)reader.getValue("parents");
         Object args = reader.getValue("event");
         Metaclass metaclass = m_context.getMetadata().getMetaclass(classSym.getName());
         Object[] argArray = null;
         Event event = null;

         if (args instanceof Pair)
         {
            argArray = Pair.toArray((Pair)args);
            event = (Event)metaclass.getSelector((Symbol)argArray[0]).getMember(argArray.length - 1);
            argArray[0] = metaclass;

            Argument result = event.getResult();

            if (result != null && !result.getType().isPrimitive())
            {
               metaclass = (Metaclass)result.getType();
            }
         }
         else if (args instanceof String)
         {
            event = (Event)metaclass.getSelector((String)args).getMember(6);
            argArray = new Object[]{metaclass, attributes, where, orderBy, count, offset, xlock};
         }

         metaclass.checkReadAccess(m_context.getPrivilegeSet());

         Pair security = metaclass.checkReadAccess(attributes, m_context.getPrivilegeSet());

         metaclass.checkExpressionAccess(where,  m_context.getPrivilegeSet());

         if (parentList != null)
         {
            List assocList = (List)reader.getValue("associations");
            boolean bConj = false;

            for (int i = parentList.size() - 1; i >= 0; --i)
            {
               Accessor parent = (Accessor)parentList.get(i);
               InstanceList resultList = (InstanceList)parent.getValue("results");

               if (resultList == null || resultList.size() == 0)
               {
                  return setEmptyResult(reader);
               }

               Object assoc = assocList.get(i);

               if (assoc !=  null && !(assoc instanceof Pair))
               {
                  assoc = new Pair(assoc);
               }

               Instance parentInstance = resultList.getInstance(0);
               Metaclass parentMetaclass = parentInstance.getMetaclass();

               // Check for attributes without persistence mappings
               if (i == 0)
               {
                  Metaclass containerMetaclass = parentMetaclass;

                  for (Pair pair = (Pair)assoc; pair != null; pair = pair.getNext())
                  {
                     Attribute attribute = containerMetaclass.findAttribute((Symbol)pair.getHead());

                     if (attribute == null)
                     {
                        break;
                     }

                     attribute.checkReadAccess(m_context.getPrivilegeSet());

                     if (!attribute.isPersistent() &&
                        !attribute.getType().isPrimitive() &&
                        event == null &&
                        ((Metaclass)attribute.getType()).findEvent("read", 6)
                           .findAction("main").getDeclarator().getBase() == null)
                     {
                        if (parentList.size() > 1)
                        {
                           throw new InvalidQueryException("err.persistence.multipleParentsWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        if (where != null || bookmark != null || orderBy != null)
                        {
                           throw new InvalidQueryException("err.persistence.whereWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        resultList = new InstanceArrayList();
                        collectAssociatedInstances((Pair)assoc, parentInstance, resultList);

                        int nOffset = (offset == null) ? 0 : offset.intValue();
                        int nCount = (count == null) ? -1 : count.intValue();

                        if (nOffset < 0)
                        {
                           nOffset = 0;
                        }

                        if (nCount < 0 || nCount > resultList.size() - nOffset)
                        {
                           nCount = resultList.size() - nOffset;

                           if (nCount < 0)
                           {
                              nCount = 0;
                           }
                        }

                        if (nOffset > 0 || resultList.size() > nCount)
                        {
                           InstanceList list = new InstanceArrayList(nCount);

                           for (int k = 0; k < nCount; ++k)
                           {
                              list.add(resultList.getInstance(k + nOffset), InstanceList.REPLACE | InstanceList.DIRECT);
                           }

                           resultList = list;
                        }

                        if (next != null && !next.booleanValue())
                        {
                           resultList.reverse();
                        }

                        for (int k = 0; k < nCount; ++k)
                        {
                           resultList.getInstance(k).invoke("load", attributes);
                        }

                        reader.setValue("results", resultList);

                        return resultList;
                     }

                     if (attribute.getType().isPrimitive())
                     {
                        break;
                     }

                     containerMetaclass = (Metaclass)attribute.getType();
                  }
               }

               assoc = new Pair(Symbol.ATAT, new Pair(parentMetaclass.getSymbol(), assoc));

               Pair cond = Pair.binary(Symbol.EQ, assoc, parentInstance.getOID());

               if (bConj)
               {
                  where = new Pair(cond, where);
               }
               else if (where != null)
               {
                  where = new Pair(cond, new Pair(where));
                  bConj = true;
               }
               else
               {
                  where = cond;
               }
            }

            if (bConj)
            {
               where = new Pair(Symbol.AND, where);
            }
         }

         // Handle the bookmark
         boolean bNext = true;

         if (next != null && orderBy != null)
         {
            bNext = next.booleanValue();

            if (!bNext)
            {
               // Flip sort order
               Pair pair = orderBy;
               Pair last = orderBy = null;

               for (; pair != null; pair = pair.getNext())
               {
                  Pair head = (Pair)pair.getHead();
                  Pair item = new Pair(new Pair(head.getHead(),
                     Boolean.valueOf(!((Boolean)head.getTail()).booleanValue())));

                  if (last == null)
                  {
                     orderBy = item;
                  }
                  else
                  {
                     last.setTail(item);
                  }

                  last = item;
               }
            }

            // The bookmark has the following format: (value1 ... valueN)
            // If values are missing, then the start or the end of the recordset is
            // retrieved, depending on the value of next (inclusive is ignored in this case)

            if (bookmark != null)
            {
               where = addBookmarkToWhere(where, orderBy, bookmark, inclusive);
            }
         }

         // This takes care of the bookmark attributes access rights
         metaclass.checkOrderByAccess(orderBy, m_context.getPrivilegeSet());
         attributes = Pair.nconc(security, attributes);

         InstanceList resultList;
        
         if (event != null)
         {
            setValue(event, "attributes", argArray, attributes);
            setValue(event, "where", argArray, where);
            setValue(event, "orderBy", argArray, orderBy);

            resultList = (InstanceList)event.invoke(argArray, m_context.getMachine());
         }
         else
         {
            resultList = (InstanceList)metaclass.invoke("read",
               new Object[]{attributes, where, orderBy, count, offset, xlock});
View Full Code Here

      m_writer.startElement("Events");

      for (Iterator itr = metaclass.getEventIterator(); itr.hasNext();)
      {
         Event event = (Event)itr.next();

         if (event.getDeclarator() == metaclass)
         {
            exportEvent(event);
         }
      }
View Full Code Here

TOP

Related Classes of nexj.core.meta.Event

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.