Package nexj.core.meta.xml.XMLMetadataHelper

Examples of nexj.core.meta.xml.XMLMetadataHelper.ContextFixup


               {
                  final String sKeyGeneratorName = XMLUtil.getReqStringAttr(mappingElement, MAPPING_KEY_GENERATOR_ATTRIBUTE);

                  if (sKeyGeneratorName != null)
                  {
                     loader.addComponentFixup(new ContextFixup(getHelper())
                     {
                        public void fixup()
                        {
                           mapping.setKeyGenerator(
                              metaclass.getMetadata().getComponent(sKeyGeneratorName)
View Full Code Here


               if (sBases != null)
               {
                  final String[] sBaseArray = SPACE_PATTERN.split(sBases);

                  m_resolutionFixupList.add(new ContextFixup(m_helper)
                  {
                     public void fixup()
                     {
                        for (int i = 0; i < sBaseArray.length; i++)
                        {
                           String sBaseTypeName = definition.resolveTypeRef(sBaseArray[i]);
                           ModelType baseType = (ModelType)m_globalMap.get(sBaseTypeName);

                           if (baseType == null)
                           {
                              throw new MetadataException("err.meta.soa.unknownType",
                                 new Object[] {sBaseTypeName, type.getGlobalName(), definition.getNamePrefix()});
                           }

                           type.addBase(baseType);
                        }
                     }
                  });
               }

               Element attributesElement = XMLUtil.findChildElement(typeElement, "Attributes");

               if (attributesElement != null)
               {
                  XMLUtil.forEachChildElement(attributesElement, "Attribute", new XMLUtil.ElementHandler()
                  {
                     public void handleElement(Element attributeElement)
                     {
                        Attribute attribute = new Attribute();

                        loadPart(attributeElement, attribute);
                        attribute.setType(XMLUtil.getReqStringAttr(attributeElement, "type"))// TODO: Resolve later
                        attribute.setCollection(XMLUtil.getBooleanAttr(attributeElement, "collection", attribute.isCollection()));
                        attribute.setRequired(XMLUtil.getBooleanAttr(attributeElement, "required", attribute.isRequired()));

                        if (!type.addAttribute(attribute))
                        {
                           throw new MetadataException("err.meta.soa.attributeDup",
                              new Object[] {attribute.getName(), type.getName(), definition.getNamePrefix()});
                        }
                     }
                  });
               }
            }
         });
      }

      child = XMLUtil.findChildElement(element, "Interfaces");

      if (child != null)
      {
         XMLUtil.forEachChildElement(child, "Interface", new XMLUtil.ElementHandler()
         {
            public void handleElement(Element interfaceElement)
            {
               final Interface iface = new Interface(definition);

               loadPart(interfaceElement, iface);

               if (!definition.addInterface(iface))
               {
                  throw new MetadataException("err.meta.soa.interfaceDup",
                     new Object[] {iface.getName(), definition.getNamePrefix()});
               }

               m_globalMap.put(iface.getGlobalName(), iface);

               XMLUtil.forEachChildElement(interfaceElement, "Method", new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element methodElement)
                  {
                     final Method method = new Method();

                     loadPart(methodElement, method);

                     Element argumentsElement = XMLUtil.findChildElement(methodElement, "Arguments");

                     if (argumentsElement != null)
                     {
                        XMLUtil.forEachChildElement(argumentsElement, "Argument", new XMLUtil.ElementHandler()
                        {
                           public void handleElement(Element argumentElement)
                           {
                              Argument argument = new Argument();

                              loadPart(argumentElement, argument);

                              if (!method.addArgument(argument))
                              {
                                 throw new MetadataException("err.meta.soa.argumentDup",
                                    new Object[] {argument.getName(), method.getName(), iface.getName(), definition.getNamePrefix()});
                              }

                              argument.setType(XMLUtil.getReqStringAttr(argumentElement, "type"))// TODO: Resolve later
                              argument.setCollection(XMLUtil.getBooleanAttr(argumentElement, "collection", argument.isCollection()));
                           }
                        });
                     }

                     if (!iface.addMethod(method))
                     {
                        throw new MetadataException("err.meta.soa.methodDup",
                           new Object[] {method.getName(), method.getArgString(), iface.getName(), definition.getNamePrefix()});
                     }

                     Element resultElement = XMLUtil.findChildElement(methodElement, "Result");

                     if (resultElement != null)
                     {
                        Result result = new Result();

                        method.setResult(result);
                        result.setType(XMLUtil.getReqStringAttr(resultElement, "type"))// TODO: Resolve later
                        result.setCollection(XMLUtil.getBooleanAttr(resultElement, "collection", result.isCollection()));
                        result.setDescription(XMLUtil.getStringAttr(resultElement, "description", result.getDescription()));
                     }

                     Element faultsElement = XMLUtil.findChildElement(methodElement, "Faults");

                     if (faultsElement != null)
                     {
                        XMLUtil.forEachChildElement(faultsElement, "Fault", new XMLUtil.ElementHandler()
                        {
                           public void handleElement(Element faultElement)
                           {
                              Fault fault = new Fault();

                              fault.m_sRef = XMLUtil.getReqStringAttr(faultElement, "type")// TODO: Resolve later
                              method.addFault(fault);
                           }
                        });
                     }
                  }
               });
            }
         });
      }

      child = XMLUtil.findChildElement(element, "Services");

      if (child != null)
      {
         XMLUtil.forEachChildElement(child, "Service", new XMLUtil.ElementHandler()
         {
            public void handleElement(Element serviceElement)
            {
               final Service service = new Service(definition);

               loadPart(serviceElement, service);

               if (!definition.addService(service))
               {
                  throw new MetadataException("err.meta.soa.serviceDup",
                     new Object[] {service.getName(), definition.getNamePrefix()});
               }

               m_globalMap.put(service.getGlobalName(), service);

               Element interfacesElement = XMLUtil.findChildElement(serviceElement, "Interfaces");
               final int nCounter[] = {0};

               XMLUtil.forEachChildElement(interfacesElement, "Interface", new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element interfaceElement)
                  {
                     final String sInterfaceName = definition.resolveInterfaceRef(XMLUtil.getReqStringAttr(interfaceElement, "ref"));
                     final InterfaceRef ref = new InterfaceRef();

                     ref.setDefault(XMLUtil.getBooleanAttr(interfaceElement, "default", ref.isDefault()));
                     service.addInterfaceRef(ref);

                     if (ref.isDefault())
                     {
                        nCounter[0]++;
                     }

                     m_resolutionFixupList.add(new ContextFixup(m_helper)
                     {
                        public void fixup()
                        {
                           Interface iface = (Interface)m_globalMap.get(sInterfaceName);
View Full Code Here

                              {
                                 throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
                                    new Object[]{attribute.getName(), metaclass.getName()});
                              }

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

                              loader.addComponentFixup(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    classMapping.validate(metadata, m_helper.getWarnings());
                                 }
                              });
                           }

                           attrMapping.setAttribute(attribute);
                           mapping.addAttributeMapping(attrMapping);
                        }
                     });
                  }
               });

               XMLUtil.withFirstChildElement(element, "SortKeys", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     XMLUtil.forEachChildElement(element, "SortKey", new XMLUtil.ElementHandler()
                     {
                        public void handleElement(Element element)
                        {
                           mapping.addSortKey(
                              (Pair)m_helper.parse(XMLUtil.getReqStringAttr(element, "attributes"), true,
                                 mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()),
                              XMLUtil.getBooleanAttr(element, "unique", false)
                           );
                        }
                     });
                  }
               });

               XMLUtil.withFirstChildElement(element, "ReadMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final ReadMapping readMapping = mapping.getReadMapping();

                     XMLUtil.forEachChildElement(element, "Case", new XMLUtil.ElementHandler()
                     {
                        private int m_nOrdinal = 0;

                        public void handleElement(Element element)
                        {
                           final String sReadPrefix = sURLPrefix + ".read." + m_nOrdinal;
                           Object whereExpr = m_helper.parse(
                              XMLUtil.getStringAttr(element, "where"),
                              false, sReadPrefix + "$where", mapping.getTextPositionMap(), Symbol.ELSE, metadata.getGlobalEnvironment()
                           );
                           Pair variables = (Pair)m_helper.parse(
                              XMLUtil.getStringAttr(element, "variables"),
                              true, mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()
                           );
                           final ReadMappingCase readMappingCase = new ReadMappingCase();

                           readMappingCase.setWhere(whereExpr);
                           readMappingCase.setVariables(variables);

                           XMLUtil.withFirstChildElement(element, "Read", true, new XMLUtil.ElementHandler()
                           {
                              public void handleElement(Element element)
                              {
                                 readMappingCase.setReadScript(loadScript(element, sReadPrefix + "$read", mapping.getTextPositionMap()));
                              }
                           });

                           XMLUtil.withFirstChildElement(element, "Close", false, new XMLUtil.ElementHandler()
                           {
                              public void handleElement(Element element)
                              {
                                 readMappingCase.setCloseScript(loadScript(element, sReadPrefix + "$close", mapping.getTextPositionMap()));
                              }
                           });

                           readMapping.addCase(readMappingCase);
                           m_nOrdinal += 1;
                        }
                     });
                  }
               });

               XMLUtil.withFirstChildElement(element, "CreateMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final WorkMapping operation = new WorkMapping(metaclass);

                     operation.setBatch(XMLUtil.getBooleanAttr(element, "batch", operation.isBatch()));
                     operation.setScript(loadScript(element, sURLPrefix + ".create", mapping.getTextPositionMap()));
                     mapping.setCreateMapping(operation);
                  }
               });

               XMLUtil.withFirstChildElement(element, "UpdateMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final UpdateMapping updateMapping = new UpdateMapping(mapping);

                     XMLUtil.forEachChildElement(element, "Case", new XMLUtil.ElementHandler()
                     {
                        private int m_nOrdinal = 0;

                        public void handleElement(Element element)
                        {
                           final UpdateMappingCase update = new UpdateMappingCase(metaclass);

                           update.setBatch(XMLUtil.getBooleanAttr(element, "batch", update.isBatch()));
                           update.setDirty(XMLUtil.getBooleanAttr(element, "dirty", update.isDirty()));
                           update.setFull(XMLUtil.getBooleanAttr(element, "full", update.isFull()));

                           Pair attributes = (Pair)m_helper.parse(
                              XMLUtil.getStringAttr(element, "attributes"),
                              true, mapping.getTextPositionMap(), null, metadata.getGlobalEnvironment()
                           );

                           update.setScript(loadScript(element, sURLPrefix + ".update." + m_nOrdinal, mapping.getTextPositionMap()));
                           updateMapping.addCase(update, attributes);
                           m_nOrdinal += 1;
                        }
                     });

                     mapping.setUpdateMapping(updateMapping);
                  }
               });

               XMLUtil.withFirstChildElement(element, "DeleteMapping", false,
                  new XMLUtil.ElementHandler()
               {
                  public void handleElement(Element element)
                  {
                     final WorkMapping operation = new WorkMapping(metaclass);

                     operation.setBatch(XMLUtil.getBooleanAttr(element, "batch", operation.isBatch()));
                     operation.setScript(loadScript(element, sURLPrefix + ".delete", mapping.getTextPositionMap()));
                     mapping.setDeleteMapping(operation);
                  }
               });

               // Key Generator
               final String sKeyGeneratorName = XMLUtil.getStringAttr(element, "keyGenerator");

               if (sKeyGeneratorName != null)
               {
                  loader.addComponentFixup(new ContextFixup(m_helper)
                  {
                     public void fixup()
                     {
                        mapping.setKeyGenerator(metadata.getComponent(sKeyGeneratorName));
                     }
                  });
               }

               mapping.setDerived(XMLUtil.getBooleanAttr(element, "derived", mapping.isDerived()));
            }
         });

         loader.addSingletonFixup(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               mapping.compile(loader.getMachine());
            }
View Full Code Here

      XMLUtil.withFirstChildElement(element, "Properties", false, new ElementHandler()
      {
         public void handleElement(final Element propertiesElement)
         {
            addIOFixup(new ContextFixup(m_helper)
            {
               public void fixup()
               {
                  loadComponentProperties(propertiesElement, dataSource.getComponent());
               }
View Full Code Here

      XMLUtil.withFirstChildElement(element, "SenderProperties", false, new ElementHandler()
      {
         public void handleElement(final Element propertiesElement)
         {
            addIOFixup(new ContextFixup(m_helper)
            {
               public void fixup()
               {
                  if (channel.getSender() != null)
                  {
                     loadComponentProperties(propertiesElement, channel.getSender());
                  }
               }
            });
         }
      });

      XMLUtil.withFirstChildElement(element, "ReceiverProperties", false, new ElementHandler()
      {
         public void handleElement(final Element propertiesElement)
         {
            addIOFixup(new ContextFixup(m_helper)
            {
               public void fixup()
               {
                  if (channel.getReceiver() != null)
                  {
                     loadComponentProperties(propertiesElement, channel.getReceiver());
                  }
               }
            });
         }
      });

      if (!m_bIntegrationExcluded)
      {
         XMLUtil.withFirstChildElement(element, "ServiceBindings", false, new ElementHandler()
         {
            public void handleElement(final Element bindingsElement)
            {
               addPersistenceMappingFixup(new ContextFixup(m_helper)
               {
                  public void fixup()
                  {
                     XMLUtil.forEachChildElement(bindingsElement, "ServiceBinding", m_helper.new ElementHandler("service")
                     {
                        protected String getName(Element element)
                        {
                           return XMLUtil.getReqStringAttr(element, "service");
                        }

                        public void handleElement(Element bindingElement, String sService)
                        {
                           final Binding binding = new Binding(m_metadata.getService(sService), channel);
                           String sOutput = XMLUtil.getStringAttr(bindingElement, "output");

                           if (sOutput != null)
                           {
                              binding.setOutput(m_metadata.getChannel(sOutput));
                           }

                           XMLUtil.withFirstChildElement(bindingElement, "Arguments", false, new ElementHandler()
                           {
                              public void handleElement(Element argumentsElement)
                              {
                                 XMLUtil.forEachChildElement(argumentsElement, "Argument", m_helper.new ElementHandler("argument")
                                 {
                                    public void handleElement(Element argumentElement, String sArgument)
                                    {
                                       String sChannel = XMLUtil.getStringAttr(argumentElement, "channel");

                                       if (sChannel != null)
                                       {
                                          binding.setArgumentChannel(sArgument, m_metadata.getChannel(sChannel));
                                       }

                                       String sValue = XMLUtil.getStringAttr(argumentElement, "value");

                                       if (sValue != null)
                                       {
                                          binding.setArgumentValue(sArgument,
                                             m_helper.parse(sValue, false, null, null, m_metadata.getGlobalEnvironment()));
                                       }
                                    }
                                 });
                              }
                           });

                           binding.compile(m_machine);
                           channel.addBinding(binding);
                        }
                     });
                  }
               });

               addSingletonFixup(new ContextFixup(m_helper)
               {
                  public void fixup()
                  {
                     MessageTable table = channel.getMessageTable();
View Full Code Here

                        XMLUtil.forEachChildElement(privilegesElement, "Privilege",
                           m_helper.new ElementHandler("privilege")
                        {
                           public void handleElement(Element privilegeElement, final String sPrivilegeName)
                           {
                              m_privilegeFixupList.add(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    privilegeGroup.addPrivilege(m_metadata.getPrivilege(sPrivilegeName));
                                 }
View Full Code Here

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

               public void handleElement(Element persistenceMappingElement)
               {
                  final String sResourceName = m_helper.getCurResourceName();
                  final Element clone = (Element)m_tmpDocument.importNode(persistenceMappingElement, true);

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

      final String sReverseName = XMLUtil.getStringAttr(attributeElement, "reverse");

      if (sReverseName != null)
      {
         m_attributeFixupList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               if (attribute.getType().isPrimitive())
               {
                  throw new MetadataException("err.meta.primitiveReverseAttrib",
                     new Object[]{sReverseName, attribute.getName(),
                        attribute.getMetaclass().getName()});
               }

               attribute.setReverse(((Metaclass)attribute.getType()).getAttribute(sReverseName));
            }
         });
      }

      final String sEnumeration = XMLUtil.getStringAttr(attributeElement, "enumeration");

      if (sEnumeration != null)
      {
         attribute.setEnumeration(m_metadata.defineMetaclass(sEnumeration, attribute));
      }

      attribute.setConstrained(XMLUtil.getBooleanAttr(attributeElement, "constrained", false));

      if (sEnumeration != null || attribute.isConstrained())
      {
         m_attributeFixupList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               attribute.validateEnumeration(m_metadata);
            }
         });
      }

      final String sAccessAttributeName = XMLUtil.getStringAttr(attributeElement, "access");

      if (sAccessAttributeName != null)
      {
         m_attributeFixupList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               attribute.setAccessAttribute(attribute.getMetaclass().getAttribute(sAccessAttributeName));
            }
View Full Code Here

      final String sAccessAttributeName = XMLUtil.getStringAttr(eventElement, "access");

      if (sAccessAttributeName != null)
      {
         m_attributeFixupList.add(new ContextFixup(m_helper)
         {
            public void fixup()
            {
               event.setAccessAttribute(event.getMetaclass().getAttribute(sAccessAttributeName));
            }
View Full Code Here

TOP

Related Classes of nexj.core.meta.xml.XMLMetadataHelper.ContextFixup

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.