Package nexj.core.meta

Examples of nexj.core.meta.Metaclass$ClassPointcutHelper


         return;
      }
     
      if (event.generateDeleteFlowAction())
      {
         Metaclass metaclass = event.getMetaclass();
        
         for (int i = 0, nCount = metaclass.getDerivedCount(); i < nCount; ++i)
         {
            generateDeleteFlowAction(metaclass.getDerived(i).findEvent(event.getName(), event.getArgumentCount()));
         }
      }
   }
View Full Code Here


    */
   public VirtualUpdate(Instance instance, VirtualAdapter adapter)
   {
      super(instance, adapter);

      Metaclass metaclass = instance.getMetaclass();
      int nCount = metaclass.getInstanceAttributeCount();

      m_attributeSet = new BitSet(nCount);

      for (int i = 0; i < nCount; i++)
      {
         if (instance.isDirty(i))
         {
            Attribute attribute = metaclass.getInstanceAttribute(i);
            AttributeMapping attributeMapping = m_mapping.getAttributeMapping(attribute);

            if (attributeMapping != null && (attribute.getType().isPrimitive() ||
               !((VirtualClassMapping)attributeMapping).getKey(false).isObjectKey()))
            {
View Full Code Here

   public void execute(Work[] workArray, int nStart, int nEnd)
   {
      // All items have the same attributes to update
      VirtualMapping mapping = (VirtualMapping)m_mapping;
      UpdateMapping updateMapping = mapping.getUpdateMapping();
      Metaclass metaclass = mapping.getMetaclass();
      List updateList = updateMapping.getUpdateCases(m_attributeSet);

      // Execute updates
      Attribute lockingAttribute = mapping.getLockingAttribute();
      int nLockingOrdinal = (lockingAttribute == null) ? -1 : lockingAttribute.getOrdinal();
      String sLockingAttributeName = (lockingAttribute == null) ? null : lockingAttribute.getName();
      VirtualDataSourceFragment fragment = (VirtualDataSourceFragment)getFragment();

      for (int i = 0, nSize = updateList.size(); i < nSize; i++)
      {
         UpdateMappingCase update = (UpdateMappingCase)updateList.get(i);
         BitSet updateAttrSet = update.getAttributeSet();
         ArrayList tobjList =  new ArrayList(nEnd - nStart);
         int nUpdateAttrCount = updateAttrSet.cardinality() + ((nLockingOrdinal >= 0) ? 1 : 0);
         boolean bIgnoreDirty = !update.isDirty();
         boolean bFull = update.isFull();

         for (int k = nStart; k < nEnd; k++)
         {
            VirtualUpdate work = (VirtualUpdate)workArray[k];
            Instance instance = work.getInstance();
            TransferObject tobj = new TransferObject(instance.getOID(), metaclass.getName(), EVENT, nUpdateAttrCount);

            if (bFull)
            {
               for (int m = 0, nCount = metaclass.getInstanceAttributeCount(); m < nCount; m++)
               {
                  Attribute attribute = metaclass.getInstanceAttribute(m);

                  if (bIgnoreDirty || instance.isDirty(m))
                  {
                     setValue(tobj, attribute, instance.getValue(m));
                  }
               }
            }
            else
            {
               for (int m = updateAttrSet.nextSetBit(0); m >= 0; m = updateAttrSet.nextSetBit(m + 1))
               {
                  Attribute attribute = metaclass.getInstanceAttribute(m);

                  if (bIgnoreDirty || instance.isDirty(m))
                  {
                     setValue(tobj, attribute, instance.getValue(m));
                  }
View Full Code Here

    * @param uow The unit of work.
    * @param instance The instance for which to add the work items.
    */
   protected void addCreate(UnitOfWork uow, Instance instance)
   {
      Metaclass metaclass = instance.getMetaclass();
      int nCount = metaclass.getInstanceAttributeCount();
      VirtualMapping mapping = (VirtualMapping)instance.getPersistenceMapping();
      OID oid = instance.getOID();
      VirtualWork work = getWork(uow, VirtualWork.CREATE, instance);

      if (oid == null)
      {
         Component keyGen = mapping.getKeyGenerator();

         if (keyGen != null)
         {
            oid = ((OIDGenerator)keyGen.getInstance(uow.getInvocationContext())).generateOID(instance, this);
         }
         else
         {
            // Compute OID from attribute values
            Object[] valueArray = null;

            for (int i = 0; i < nCount; i++)
            {
               Attribute attribute = metaclass.getInstanceAttribute(i);

               if (attribute.getType().isPrimitive())
               {
                  VirtualPrimitiveMapping attrMapping = (VirtualPrimitiveMapping)mapping.getAttributeMapping(attribute);

View Full Code Here

    */
   protected void loadClass(Element classElement, final String sClassName)
   {
      XMLMetadataHelper.verifyRootElement(classElement, "Class");

      final Metaclass metaclass = m_metadata.defineMetaclass(sClassName, null);

      if (!metaclass.isForward())
      {
         m_metadata.addMetaclass(metaclass);
      }

      loadMetaclass(classElement, metaclass);

      metaclass.setCaption(XMLUtil.getStringAttr(classElement, "caption", metaclass.getCaption()));
      metaclass.setVisibility(parseVisibility(XMLUtil.getStringAttr(classElement, "visibility"), Metaclass.PUBLIC));

      final String sNameAttribute = XMLUtil.getStringAttr(classElement, "nameAttribute");

      if (sNameAttribute != null)
      {
         m_attributeFixupList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               metaclass.setNameAttribute(sNameAttribute);
            }
         });
      }

      m_inheritanceCheckList.add(new ContextFixup(m_helper)
      {
         public void fixup()
         {
            metaclass.checkInheritance();
         }
      });

      final String sBaseName = XMLUtil.getStringAttr(classElement, "base",
         (sClassName.equals(Metadata.ROOT_CLASS_NAME)) ? null : Metadata.ROOT_CLASS_NAME);

      if (sBaseName != null)
      {
         metaclass.setPointcut(true);
         m_metadata.defineMetaclass(sBaseName, metaclass).addDerived(metaclass);
      }
      else
      {
         m_attributeResolutionList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               metaclass.resolveAttributes(m_machine);
            }
         });

         m_attributeDependencyList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               metaclass.computeInverseDependency(m_attributeDependencySet);
            }
         });

         m_inheritanceFixupList.add(new ClassFixup()
         {
            public void fixup()
            {
               metaclass.resolveInheritance();
            }
         });

         m_inheritance1stPassFixupList.add(new ClassFixup()
         {
            public void fixup()
            {
               metaclass.resolveInheritance1();
            }
         });

         m_inheritance2ndPassFixupList.add(new ClassFixup()
         {
            public void fixup()
            {
               metaclass.compile(m_machine);
            }
         });

         m_inheritance4thPassFixupList.add(new ClassFixup()
         {
            public void fixup()
            {
               metaclass.resolveInheritance4();
            }
         });

         m_class2ndPassList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               metaclass.resolveInitializers(m_machine);
            }
         });
      }

      // Queue for second pass only if a persistence mapping element is present

      XMLUtil.withFirstChildElement(classElement, "PersistenceMapping", false, new ElementHandler()
      {
         public void handleElement(Element element)
         {
            final String sResourceName = m_helper.getCurResourceName();
            final Element clone = (Element)m_tmpDocument.importNode(element, true);

            m_persistenceMappingLoadList.add(new ContextFixup(m_helper)
            {
               public void fixup()
               {
                  int nCookie = m_helper.pushMarker(MetadataValidationException.RESOURCE_NAME, sResourceName);

                  try
                  {
                     metaclass.setPersistenceMapping(loadPersistenceMapping(clone, metaclass));
                  }
                  finally
                  {
                     m_helper.restoreMarker(nCookie);
                  }
View Full Code Here

                              loader.addPersistenceMappingFixup(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    Metaclass type = (Metaclass)attribute.getType();
                                    PersistenceMapping assocClassMapping = type.getPersistenceMapping();

                                    if (assocClassMapping == null)
                                    {
                                       throw new MetadataException("err.meta.missingAssocPersistenceMapping",
                                          new Object[]{attribute.getName(), metaclass.getName(), type.getName()});
                                    }

                                    classMapping.setSourceKey((bObjectSourceKey) ? mapping.getObjectKey() : new VirtualKey(attribute));
                                    classMapping.setDestinationKey(assocClassMapping.addForeignKey(sDestinationKeyName, classMapping));
                                 }
View Full Code Here

    */
   public static void resolve(Metadata metadata)
   {
      for (Iterator itr = metadata.getMetaclassIterator(); itr.hasNext();)
      {
         final Metaclass metaclass = (Metaclass)itr.next();

         metaclass.visit(new PersistenceMapping.Visitor()
         {
            public void visit(PersistenceMapping mapping)
            {
               if (mapping instanceof RelationalMapping)
               {
                  RelationalMapping relMapping = (RelationalMapping)mapping;
                  BitSet[] bitSetArray = new BitSet[relMapping.getTableCount()];

                  for (int i = 0; i != relMapping.getTableCount(); ++i)
                  {
                     bitSetArray[i] = new BitSet(relMapping.getTable(i).getColumnCount());
                  }

                  for (int nAttr = 0; nAttr != metaclass.getInstanceAttributeCount(); ++nAttr)
                  {
                     AttributeMapping attrMapping = relMapping.getAttributeMapping(metaclass.getInstanceAttribute(nAttr));

                     if (attrMapping instanceof RelationalPrimitiveMapping)
                     {
                        RelationalPrimitiveMapping primitiveMapping = (RelationalPrimitiveMapping)attrMapping;

View Full Code Here

      XMLMetadataHelper.validateName(sEnumerationName);

      final String sBaseName = XMLUtil.getStringAttr(enumerationElement,
         "base", Metadata.ENUMERATION_CLASS_NAME);

      final Metaclass metaclass = (sEnumerationName.equals(sBaseName)) ? null :
         m_metadata.defineMetaclass(sEnumerationName, null);
      final String sParentEnumeration = XMLUtil.getStringAttr(enumerationElement, "parent");

      if (metaclass != null)
      {
         if (metaclass.isForward())
         {
            metaclass.setResourceName(m_helper.getCurResourceName());
            metaclass.setForward(false);
         }
         else
         {
            m_metadata.addMetaclass(metaclass);
         }

         loadDocumentation(enumerationElement, metaclass);
         m_metadata.defineMetaclass(sBaseName, metaclass).addDerived(metaclass);

         m_inheritanceCheckList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               metaclass.checkInheritance();
            }
         });

         if (sParentEnumeration != null)
         {
            final String sAssociation = XMLUtil.getStringAttr(enumerationElement, "association");

            if (sAssociation == null)
            {
               throw new MetadataException("err.meta.missingEnumAssoc", new Object[]{sEnumerationName});
            }

            final String sReverse = XMLUtil.getStringAttr(enumerationElement, "reverse");

            if (sReverse == null)
            {
               throw new MetadataException("err.meta.missingEnumReverse", new Object[]{sEnumerationName});
            }

            XMLMetadataHelper.validateName(sAssociation);

            m_attributeGenerationList.add(new ContextFixup(m_helper)
            {
               public void fixup()
               {
                  final Metaclass parentMetaclass = m_metadata.getMetaclass(sParentEnumeration);

                  final Attribute parentAttribute = new Attribute(sReverse);

                  parentAttribute.setMetaclass(metaclass);
                  parentAttribute.setDeclarator(metaclass);
                  parentAttribute.setType(parentMetaclass);
                  parentAttribute.setRequired(true);

                  metaclass.addAttribute(parentAttribute);

                  final Attribute childAttribute = new Attribute(sAssociation);

                  childAttribute.setMetaclass(parentMetaclass);
                  childAttribute.setDeclarator(parentMetaclass);
                  childAttribute.setType(metaclass);
                  childAttribute.setCollection(true);
                  childAttribute.setReverse(parentAttribute);

                  parentMetaclass.addAttribute(childAttribute);

                  m_persistenceMappingGenerationList.add(new ContextFixup(m_helper)
                  {
                     public void fixup()
                     {
                        copyAttributeMapping(parentAttribute, metaclass.getAttribute("parent"));
                        copyAttributeMapping(childAttribute, parentMetaclass.getAttribute("children"));
                     }

                     protected void copyAttributeMapping(Attribute dst, Attribute src)
                     {
                        PersistenceMapping mapping = src.getMetaclass().getPersistenceMapping();

                        if (mapping.getAttributeMapping(dst) != null)
                        {
                           return;
                        }

                        for (PersistenceMapping baseMapping = mapping;
                           baseMapping != null && baseMapping.isCompatible(mapping);
                           baseMapping = baseMapping.getBaseMapping())
                        {
                           Attribute attribute = baseMapping.getMetaclass().findAttribute(src.getName());

                           if (attribute != null)
                           {
                              AttributeMapping attributeMapping = baseMapping.getAttributeMapping(attribute);

                              if (attributeMapping != null)
                              {
                                 attributeMapping = (AttributeMapping)attributeMapping.clone();

                                 attributeMapping.setPersistenceMapping(mapping);
                                 attributeMapping.setAttribute(dst);

                                 ((ClassMapping)attributeMapping).setMapping(((Metaclass)dst.getType()).getPersistenceMapping());

                                 mapping.addAttributeMapping(attributeMapping);

                                 return;
                              }
                           }
                        }

                        throw new MetadataException("err.meta.enumAssociation",
                           new Object[]{src.getName(), src.getMetaclass().getName()});
                     }
                  });
               }
            });
         }

         final String sTypeCode = XMLUtil.getReqStringAttr(enumerationElement, "typeCode");

         m_inheritance1stPassFixupList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               Attribute attribute = null;

               for (PersistenceMapping mapping = metaclass.getPersistenceMapping();
                  mapping != null; mapping = mapping.getBaseMapping())
               {
                  attribute = mapping.getTypeCodeAttribute();

                  if (attribute != null)
                  {
                     attribute = metaclass.getDerivedAttribute(attribute);

                     break;
                  }
               }

               if (attribute == null)
               {
                  throw new MetadataException("err.meta.noTypeCodeAttribute",
                     new Object[]{metaclass.getName()});
               }

               attribute.setValue(attribute.getType().convert(sTypeCode));
            }
         });
      }

      if (m_bValidatedOnly)
      {
         XMLUtil.withFirstChildElement(enumerationElement, "Locales", false, new ElementHandler()
         {
            public void handleElement(Element localesElement)
            {
               final Set localeSet = new HashHolder();

               XMLUtil.forEachChildElement(localesElement, "Locale",
                  m_helper.new ElementHandler("locale")
               {
                  public void handleElement(Element localeElement, String sLocale)
                  {
                     if (!localeSet.add(sLocale))
                     {
                        throw new MetadataException("err.meta.enumLocaleDup",
                           new Object[]{sLocale, sEnumerationName});
                     }

                     XMLUtil.getReqStringAttr(localeElement, "caption");
                  }
               });
            }
         });
      }

      final Set valueSet = new HashHolder();
      m_enumerationValueMap.put(sEnumerationName, valueSet);

      XMLUtil.withFirstChildElement(enumerationElement, "Values", false, new ElementHandler()
      {
         public void handleElement(Element valuesElement)
         {
            final Set nameSet = new HashHolder();
            final Set behaveAsSet = new HashHolder();
            final Set externSet = new HashHolder();
            final List fixupList = new ArrayList();

            XMLUtil.forEachChildElement(valuesElement, "Value",
               m_helper.new ElementHandler("value")
            {
               public void handleElement(Element valueElement, String sName)
               {
                  XMLMetadataHelper.validateName(sName);

                  fixupList.add(sName);

                  if (!nameSet.add(sName))
                  {
                     throw new MetadataException("err.meta.enumValueNameDup",
                        new Object[]{sName, sEnumerationName});
                  }

                  final String sValue = XMLUtil.getReqStringAttr(valueElement, "value");

                  if (!valueSet.add(sValue))
                  {
                     throw new MetadataException("err.meta.enumValueDup",
                        new Object[]{sValue, sEnumerationName});
                  }

                  fixupList.add(sValue);

                  boolean bHasBehavior = XMLUtil.getBooleanAttr(valueElement, "hasBehavior", false);

                  fixupList.add(Boolean.valueOf(bHasBehavior));

                  String sBehaveAsValue = XMLUtil.getStringAttr(valueElement, "behaveAsValue");

                  if (sBehaveAsValue != null)
                  {
                     if (bHasBehavior)
                     {
                        if (!sBehaveAsValue.equals(sValue))
                        {
                           throw new MetadataException("err.meta.enumBehaveAsValueMismatch",
                              new Object[]{sBehaveAsValue, sValue, sEnumerationName});
                        }
                     }
                     else
                     {
                        if (sBehaveAsValue.equals(sValue))
                        {
                           throw new MetadataException("err.meta.enumInvalidSelfReference",
                              new Object[]{sValue, sEnumerationName});
                        }

                        behaveAsSet.add(sBehaveAsValue);
                     }
                  }

                  String sExternValue = XMLUtil.getStringAttr(valueElement, "externalValue");

                  if (sExternValue != null)
                  {
                     if (!externSet.add(sExternValue))
                     {
                        throw new MetadataException("err.meta.enumExternValueDup",
                           new Object[]{sExternValue, sEnumerationName});
                     }
                  }

                  final String sParentValue = XMLUtil.getStringAttr(valueElement, "parentValue");

                  if (sParentValue != null)
                  {
                     if (sParentEnumeration == null)
                     {
                        throw new MetadataException("err.meta.enumParentValue", new Object[]{sEnumerationName});
                     }

                     m_inheritanceFixupList.add(new ContextFixup(m_helper)
                     {
                        public void fixup()
                        {
                           Metaclass parent = m_metadata.getMetaclass(sParentEnumeration);

                           if (!((Set)m_enumerationValueMap.get(sParentEnumeration)).contains(parent.getAttribute("value").getType().convert(sParentValue)))
                           {
                              throw new MetadataLookupException("err.meta.enumParentValueLookup", sParentValue, sParentEnumeration);
                           }
                        }
                     });
View Full Code Here

      // Add primitive output attributes
      for (Field field = query.getFirstOutputField(); field != null; field = field.getNext())
      {
         Attribute attribute = field.getAttribute();
         Metaclass metaclass = attribute.getMetaclass();

         if (metaclass.isUpcast(query.getMetaclass()))
         {
            attributes = new Pair(attribute.getSymbol(), attributes);
         }
         else
         {
            // Attribute defined in subclass, add to polymorphic attribute list
            assert query.getMetaclass().isUpcast(metaclass);

            if (polymorphicAttrMap == null)
            {
               polymorphicAttrMap = new HashTab(2);
            }

            Pair subclassAttrs = (Pair)polymorphicAttrMap.get(metaclass);

            subclassAttrs = new Pair(attribute.getSymbol(), subclassAttrs);
            polymorphicAttrMap.put(metaclass, subclassAttrs);
         }
      }

      // Add non-primitive output attributes
      for (Iterator itr = query.getAssocIterator(Query.ASSOC_QUERY); itr.hasNext(); )
      {
         Query subQuery = (Query)itr.next();
         Attribute attribute = subQuery.getAttribute();
         Pair subQueryAttrs = getAttributes(subQuery);
         Metaclass metaclass = attribute.getMetaclass();
         Object itemToAdd = (subQueryAttrs == null) ? (Object)attribute.getSymbol() : new Pair(attribute.getSymbol(), subQueryAttrs);

         if (metaclass.isUpcast(query.getMetaclass()))
         {
            attributes = new Pair(itemToAdd, attributes);
         }
         else
         {
            // Attribute defined in subclass, add to polymorphic attribute list
            assert query.getMetaclass().isUpcast(metaclass);

            if (polymorphicAttrMap == null)
            {
               polymorphicAttrMap = new HashTab(2);
            }

            Pair subclassAttrs = (Pair)polymorphicAttrMap.get(metaclass);

            subclassAttrs = new Pair(itemToAdd, subclassAttrs);
            polymorphicAttrMap.put(metaclass, subclassAttrs);
         }
      }

      // Merge the polymorphic attributes
      if (polymorphicAttrMap != null)
      {
         for (Lookup.Iterator itr = (Lookup.Iterator)polymorphicAttrMap.iterator(); itr.hasNext(); )
         {
            Metaclass subClass = (Metaclass)itr.next();
            Pair subclassAttrs = (Pair)itr.getValue();

            attributes = new Pair(
               new Pair(Symbol.ATAT, new Pair(subClass.getSymbol(), subclassAttrs)),
               attributes
            );
         }
      }
View Full Code Here

   /**
    * Loads the supported locales.
    */
   protected void loadLocales()
   {
      Metaclass metaclass = m_metadata.findMetaclass(Metadata.LOCALE_CLASS_NAME);

      if (metaclass != null)
      {
         for (int i = 0, n = metaclass.getStaticAttributeCount(); i != n; ++i)
         {
            Attribute attribute = metaclass.getStaticAttribute(i);

            if (attribute.isStatic() && attribute.isReadOnly() &&
               attribute.getValue() instanceof String)
            {
               m_metadata.addLocale((String)attribute.getValue());
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.