Package nexj.core.meta

Examples of nexj.core.meta.Attribute$InverseDependency


            continue;
         }

         for (int i = sortKey.getAttributeCount() - 1; i >= 0 ; i--)
         {
            Attribute attr = sortKey.getAttribute(i);

            if (attr == null)
            {
               keyAttrSet.clear();

               break;
            }
            else
            {
               AttributeMapping mapping = getAttributeMapping(attr);

               if (mapping instanceof VirtualPrimitiveMapping)
               {
                  if (((VirtualPrimitiveMapping)mapping).getObjectKeyPart() >= 0)
                  {
                     keyAttrSet.clear();

                     break;
                  }
               }

               keyAttrSet.set(attr.getOrdinal());
            }
         }

         if (!keyAttrSet.isEmpty() && keySet.add(keyAttrSet))
         {
View Full Code Here


   {
      verifyNotReadOnly();
     
      if (m_type == null)
      {
         Attribute attribute = null;

         for (Iterator itr = m_table.getMappingArrayIterator(); itr.hasNext();)
         {
            RelationalPrimitiveMapping[] mappings = (RelationalPrimitiveMapping[])itr.next();
            RelationalPrimitiveMapping mapping = mappings[m_nOrdinal];

            if (mapping != null)
            {
               Primitive type = (Primitive)mapping.getAttribute().getType();

               if (type != Primitive.ANY)
               {
                  if (attribute != null && m_type != type)
                  {
                     throw new MetadataException("err.meta.ambiguousColumnTypeMapping",
                        new Object[]{getName(), getTable().getName(),
                           mapping.getAttribute().getName(),
                           mapping.getAttribute().getMetaclass().getName(),
                           attribute.getName(),
                           attribute.getMetaclass().getName()});
                  }
  
                  m_type = type;
                  attribute = mapping.getAttribute();
               }
View Full Code Here

            {
               public void handleElement(Element attributeElement, String sAttributeName)
               {
                  XMLMetadataHelper.validateName(sAttributeName);

                  Attribute attribute = new Attribute(sAttributeName);

                  attribute.setMetaclass(metaclass);
                  attribute.setDeclarator(metaclass);
                  loadAttribute(attributeElement, attribute);
                  metaclass.addAttribute(attribute);
               }
            });
         }
View Full Code Here

            {
               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);
                           }
                        }
                     });
                  }
                  else
                  {
                     if (sParentEnumeration != null)
                     {
                        throw new MetadataException("err.meta.enumNoParentValue", new Object[]{sValue, sEnumerationName});
                     }
                  }

                  if (m_bValidatedOnly)
                  {
                     XMLUtil.withFirstChildElement(valueElement, "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.enumValueLocaleDup",
                                       new Object[]{sLocale, sValue, sEnumerationName});
                                 }

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

            if (behaveAsSet.size() != 0)
            {
               // Remove the values that have no behavior
               for (int i = 0, n = fixupList.size(); i != n; i += 3)
               {
                  if (!((Boolean)fixupList.get(i + 2)).booleanValue())
                  {
                     valueSet.remove(fixupList.get(i + 1));
                  }
               }

               for (Iterator itr = behaveAsSet.iterator(); itr.hasNext();)
               {
                  String sValue = (String)itr.next();

                  if (!valueSet.contains(sValue))
                  {
                     throw new MetadataLookupException("err.meta.enumBehaveAsValueLookup",
                        sValue, sEnumerationName);
                  }
               }
            }

            valueSet.clear();

            m_attributeGenerationList.add(new ContextFixup(m_helper)
            {
               public void fixup()
               {
                  Primitive type = null;

                  for (Metaclass base = ((metaclass == null) ?
                     m_metadata.getMetaclass(sEnumerationName) : metaclass).getBase();
                     base != null; base = base.getBase())
                  {
                     Attribute attribute = base.findAttribute("value");

                     if (attribute != null)
                     {
                        if (!attribute.getType().isPrimitive())
                        {
                           throw new MetadataException("err.meta.enumBaseValueType",
                              new Object[]{base.getName(), sEnumerationName});
                        }

                        if (attribute.isStatic())
                        {
                           throw new MetadataException("err.meta.enumBaseValueScope",
                              new Object[]{base.getName(), sEnumerationName});
                        }

                        type = (Primitive)attribute.getType();

                        break;
                     }
                  }

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

                  for (int i = 0, n = fixupList.size(); i != n; i += 3)
                  {
                     Object value = fixupList.get(i + 1);

                     if (type != Primitive.STRING)
                     {
                        value = type.convert(value);
                     }

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

                     if (metaclass != null && ((Boolean)fixupList.get(i + 2)).booleanValue())
                     {
                        Attribute attribute = new Attribute((String)fixupList.get(i));

                        attribute.setMetaclass(metaclass);
                        attribute.setDeclarator(metaclass);
                        attribute.setStatic(true);
                        attribute.setReadOnly(true);
                        attribute.setType(type);
                        attribute.setValue(value);

                        metaclass.addAttribute(attribute);
                     }
                  }
               }
View Full Code Here

            m_writer.openElement("KeyPart");
            m_writer.writeAttribute("type", type.getName());

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

               if (attributeMapping instanceof VirtualPrimitiveMapping)
               {
                  VirtualPrimitiveMapping primitiveMapping = (VirtualPrimitiveMapping)attributeMapping;

                  if (primitiveMapping.getObjectKeyPart() == i)
                  {
                     m_writer.writeAttribute("attribute", attribute.getName());

                     break;
                  }
               }
            }
View Full Code Here

      int nCount = metaclass.getInstanceAttributeCount();
      boolean bWroteMapping = false;

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

         if (attrMapping != null)
         {
            if (!bWroteMapping)
            {
               m_writer.startElement("AttributeMappings");
               bWroteMapping = true;
            }

            m_writer.openElement("AttributeMapping");
            m_writer.writeAttribute("name", attribute.getName());

            if (attrMapping instanceof VirtualClassMapping)
            {
               VirtualClassMapping classMapping = (VirtualClassMapping)attrMapping;
View Full Code Here

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

      if (!m_metadata.isLocaleSupported(Metadata.DEFAULT_LOCALE))
View Full Code Here

   {
      for (Lookup.Iterator itr = attrMap.iterator(); itr.hasNext();)
      {
         Symbol sym = (Symbol)itr.next();
         Object value = itr.getValue();
         Attribute attr = metaclass.findAttribute(sym);

         if (value instanceof Lookup)
         {
            if (attr == null || attr.getType().isPrimitive() ||
               !((metaclass = (Metaclass)attr.getType()).getPersistenceMapping() instanceof VirtualMapping))
            {
               throw new MetadataException("err.meta.persistence.virtual.invalidCompositeAttribute",
                  new Object[]{((Symbol)sym).getName(), m_attribute.getName(), m_attribute.getDeclarator().getName()});
            }
View Full Code Here

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

      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);
            }
View Full Code Here

TOP

Related Classes of nexj.core.meta.Attribute$InverseDependency

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.