Package nexj.core.meta

Examples of nexj.core.meta.Metaclass$ClassPointcutHelper


       *
       * @param classDoc The class to process
       */
      private void write(ClassDoc classDoc) throws IOException
      {
         Metaclass clazz;
         Tag[] tagArray;

         // Set up the current class
         clazz = new Metaclass(getAlias(classDoc.name()));
         tagArray = classDoc.tags(DESCRIPTION_TAG);

         // Class @description
         if (tagArray.length > 0)
         {
            clazz.setDescription(tagArray[0].text());

            if (tagArray.length != 1)
            {
               warning(classDoc, "Multiple description tags found for " + clazz.getName());
            }
         }

         if (classDoc.superclass() != null)
         {
            clazz.setBase(new Metaclass(getAlias(classDoc.superclass().name())));

            if (clazz.getName().equals(clazz.getBase().getName()))
            {
               error(classDoc, "Type aliases cause circular hierarchy");
               clazz.setBase(null);
            }
         }

         // Process the methods
         addMembers(clazz, classDoc);

         ClassDoc[] innerTypeArray = classDoc.innerClasses();

         for (int i = 0; i < innerTypeArray.length; i++)
         {
            addMembers(clazz, innerTypeArray[i]);
         }

         innerTypeArray = classDoc.interfaces();

         for (int i = 0; i < innerTypeArray.length; i++)
         {
            addMembers(clazz, innerTypeArray[i]);
         }

         // Export to file
         FileOutputStream fosStream = null;
         IndentingXMLWriter xmlWriter = null;

         try
         {
            fosStream = new FileOutputStream(new File(m_outputDir, clazz.getName() + ".meta"));
            xmlWriter = new IndentingXMLWriter(new OutputStreamWriter(new BufferedOutputStream(fosStream), XMLUtil.ENCODING));

            new XMLMetadataExporter(xmlWriter).exportMetaclass(clazz);
         }
         finally
View Full Code Here


   /**
    * @see nexj.core.persistence.OIDGenerator#generateOID(nexj.core.runtime.Instance, nexj.core.persistence.PersistenceAdapter)
    */
   public OID generateOID(Instance instance, PersistenceAdapter adapter)
   {
      Metaclass metaclass = instance.getMetaclass().getPersistenceRoot();

      return new OID(new Object[]{instance.getInvocationContext().getMetadata()
         .getMetaclass("SysCounter").invoke("next", new Object[]{"class." + metaclass.getName()})});
   }
View Full Code Here

                  bAdd = false;
               }
            }
         }

         Metaclass metaclass;

         if (bIdentity)
         {
            if (oid == null)
            {
               if (query.getRoot() == m_query)
               {
                  m_instanceArray[query.getOrdinal()] = null;
               }

               continue;
            }

            if (query.getRoot() != m_query && !query.isLazy())
            {
               if (!bSkipInstance)
               {
                  query.addParentInstance(container, oid);
               }

               continue;
            }

            Field field = query.getTypeCodeField();

            if (field != null)
            {
               metaclass = query.getPersistenceMapping().findMetaclassByTypeCode(getValue(field));

               if (metaclass == null)
               {
                  m_instanceArray[query.getOrdinal()] = null;

                  continue;
               }
            }
            else
            {
               metaclass = getMetaclass(query);
            }
         }
         else
         {
            metaclass = getMetaclass(query);
         }

         InstanceRef ref = m_query.getInvocationContext().findInstanceRef(metaclass, oid);
         Instance instance = (ref == null) ? null : ref.getInstance();

         // Check if the instance has already been retrieved
         if (instance != null)
         {
            // Already retrieved instance
            if (instance.isLazy())
            {
               if (query.isLazy())
               {
                  if (!metaclass.isUpcast(instance.getLazyMetaclass()))
                  {
                     instance.setLazyMetaclass(metaclass);
                  }
               }
               else
               {
                  instance.setMetaclass(metaclass);
               }
            }

            if (instanceList != null)
            {
               bAdd = !instanceList.contains(instance);

               if (bAdd &&
                  container == null &&
                  m_nMaxCount >= 0 &&
                  instanceList.getCount() == m_nOffset + m_nMaxCount)
               {
                  m_bEOF = bDiscardExtra;
                  m_bEOP = !bDiscardExtra;

                  return false;
               }
            }

            if (bAdd)
            {
               switch (instance.getState())
               {
                  case Instance.DELETED:
                     bAdd = false;
                     break;

                  case Instance.DIRTY:
                     if (reverse != null)
                     {
                        Object reverseValue = instance.getValueDirect(reverse.getOrdinal());

                        if (reverseValue != Undefined.VALUE && reverseValue != container)
                        {
                           bAdd = false;
                        }
                     }

                     break;
               }

               if (!bAdd && instanceList == null)
               {
                  if (container.getValueDirect(assoc.getOrdinal()) == Undefined.VALUE)
                  {
                     // Set the new value to null, old value to the retrieved instance
                     container.setValueDirect(assoc.getOrdinal(), null);
                  }

                  bAdd = true;
               }
            }

            if (m_instanceSet.get(query, instance) == null)
            {
               // Merge the not yet retrieved attribute values

               if (!bSkipInstance)
               {
                  // Overwrite only if the instance is clean
                  boolean bOverwrite = (instance.getUnitOfWork() == null);
                  Field lockingField = query.getLockingField();

                  if (lockingField != null)
                  {
                     Attribute lockingAttribute = lockingField.getAttribute();
                     Object oldValue = instance.getNewValueDirect(lockingAttribute.getOrdinal());

                     if (oldValue != Undefined.VALUE)
                     {
                        // Check the old lock value
                        Primitive primitive = (Primitive)lockingAttribute.getType();
                        Object value = getValue(lockingField);

                        if (((Boolean)primitive.findNEFunction(primitive).invoke(oldValue, value)).booleanValue())
                        {
                           // The lock values do not match
                           // If the instance is dirty/deleted or share-locked, throw an exception
                           if (!bOverwrite || ref.isLocked())
                           {
                              throw new OptimisticLockException(instance);
                           }

                           // Discard all the instance attributes
                           for (int i = 0, n = metaclass.getInstanceAttributeCount(); i != n; ++i)
                           {
                              discard(instance, metaclass.getInstanceAttribute(i));
                           }

                           instance.setOldValueDirect(lockingAttribute.getOrdinal(), value);
                        }
                        else
View Full Code Here

         whereMap = new HashTab(names.length);

         for (int i = 0; i < names.length; ++i)
         {
            Metaclass metaclass = m_context.getMetadata().findMetaclass(names[i]);

            if (metaclass != null)
            {
               whereMap.put(metaclass, Boolean.FALSE);
            }
View Full Code Here

    * @param primaryWork The work item for which to add the dependencies.
    */
   protected void addCreateDependencies(UnitOfWork uow, Instance instance, Work primaryWork)
   {
      boolean bOID = (instance.getOID() != null);
      Metaclass metaclass = instance.getMetaclass();
      PersistenceMapping mapping = instance.getPersistenceMapping();

      for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
      {
         Attribute attribute = metaclass.getInstanceAttribute(i);
         AttributeMapping attributeMapping = mapping.getAttributeMapping(attribute);

         if (attributeMapping == null)
         {
            continue;
View Full Code Here

    * @param instance The instance being updated.
    * @param primaryWork The work item for which to add the dependencies.
    */
   protected void addUpdateDependencies(UnitOfWork uow, Instance instance, Work primaryWork)
   {
      Metaclass metaclass = instance.getMetaclass();
      PersistenceMapping mapping = instance.getPersistenceMapping();

      for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
      {
         Attribute attribute = metaclass.getInstanceAttribute(i);
         AttributeMapping attributeMapping = mapping.getAttributeMapping(attribute);

         if (attributeMapping == null)
         {
            continue;
View Full Code Here

      metadata.addDataSource(m_database);
      ((RelationalSchema)m_database.getSchema()).generateMetaclasses(getProperty("meta.prefix"), properties, null);

      for (Iterator itr = metadata.getMetaclassIterator(); itr.hasNext();)
      {
         Metaclass metaclass = (Metaclass)itr.next();

         File file = new File(dir, metaclass.getName() + ".meta");
         Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), XMLUtil.ENCODING);

         try
         {
            StringWriter swriter = new StringWriter(0x2000);

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("Writing class \"" + metaclass.getName() +
                  "\" to file \"" + file.toString() + "\"");
            }

            new XMLMetadataExporter(swriter).exportMetaclass(metaclass);
            writer.write(XMLUtil.formatXML(swriter.toString()));
View Full Code Here

public class XMLUnmarshallerTest extends TestCase
{
   public void testTransferObject() throws MarshallerException, IOException
   {
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(Repository.getMetadata()));
      Metaclass metaclass = Repository.getMetadata().findMetaclass("User");
      StringReader reader = new StringReader(
         "<User xmlns=\"" + XML.NS_URI_TNS + "\">" +
         "<fullName>fullname</fullName>" +
         "<names>name1</names><names>name2</names><names>name3</names>" +
         "</User>");
View Full Code Here

   }

   public void testEvent() throws Exception
   {
      Metadata metadata = new XMLMetadata(null, null, null, null, null);
      Metaclass metaclass = new Metaclass("Test");
      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);
      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));
      assertTrue(argArray[3] instanceof List);
      assertEquals("ghi", ((List)argArray[4]).get(0));
      assertEquals("jkl", ((List)argArray[4]).get(1));
      assertEquals(metaclass.getName(), tobj.getClassName());
      assertNull(tobj.getEventName());
      assertNull(tobj.getOID());
      assertEquals(0, tobj.getValueCount());
   }
View Full Code Here

   public void testEvaluation()
   {
      InvocationContext context = new InvocationContext(Repository.getMetadata());
      MatchOperator op = new MatchOperator(context);
      Metaclass metaclass = context.getMetadata().getMetaclass("Contact");
      AttributeOperator attribOp = new AttributeOperator(
         new Field(new Query(metaclass, context), metaclass.getAttribute("firstName")));

      context.setLocale(Locale.ENGLISH);
      op.setAttribute(attribOp);
      attribOp.setConstant(true);
      attribOp.setValue("a abc def ghi");
View Full Code Here

TOP

Related Classes of nexj.core.meta.Metaclass$ClassPointcutHelper

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.