Package nexj.core.meta

Examples of nexj.core.meta.MetadataException


      if (StringUtil.isEmpty(sName))
      {
         if (m_defaultFragment != null)
         {
            throw new MetadataException("err.meta.persistence.fragmentDup",
               new Object[]{"", getName()});
         }

         m_defaultFragment = fragment;

         if (m_fragmentMap != null)
         {
            m_fragmentMap.put("", fragment);
         }
      }
      else
      {
         if (m_fragmentMap == null)
         {
            m_fragmentMap = new HashTab(4);

            if (m_defaultFragment != null)
            {
               m_fragmentMap.put("", m_defaultFragment);
            }
         }

         Object oldFragment = m_fragmentMap.put(sName, fragment);

         if (oldFragment != null)
         {
            m_fragmentMap.put(sName, oldFragment);

            throw new MetadataException("err.meta.persistence.fragmentDup",
               new Object[]{sName, getName()});
         }
      }

      fragment.setDataSource(this);
View Full Code Here


         m_mappingArray = new AttributeMapping[attribute.getMetaclass().getInstanceAttributeCount()];
      }

      if (m_mappingArray[attribute.getOrdinal()] != null)
      {
         throw new MetadataException("err.meta.attributeMappingDup",
            new Object[]{attribute.getName(), getMetaclass().getName()});
      }

      m_mappingArray[attribute.getOrdinal()] = mapping;
      mapping.setPersistenceMapping(this);
View Full Code Here

   {
      init(schema);

      if (schema.getVersionTable() == null)
      {
         throw new MetadataException("err.meta.upgrade.sql.versionTable",
            new Object[]{schema.getDataSource().getName()});
      }

      StringBuffer buf = new StringBuffer(256);
      SQLAppender outerAppender = m_appender;
View Full Code Here

      m_index = schema.getIndex(m_sAspectName);

      if (m_index.getType() != Index.ASPECT)
      {
         throw new MetadataException("err.meta.indexAspectUpgradeType", new Object[]{m_sAspectName});
      }

      new IndexAspectUpgradeManager(schema).removeAspects();
   }
View Full Code Here

      m_table = schema.getTable(m_sAspectName);

      if (m_table.getType() != Table.ASPECT)
      {
         throw new MetadataException("err.meta.tableAspectUpgradeType", new Object[]{m_sAspectName});
      }

      new TableAspectUpgradeManager(schema).removeAspects();
   }
View Full Code Here

                              attrMapping = primitiveMapping;

                              if (element.hasAttribute("attributes"))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"attributes", sName, metaclass.getName()});
                              }

                              if (XMLUtil.getBooleanAttr(element, "objectSourceKey", false))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"objectSourceKey", sName, metaclass.getName()});
                              }

                              if (element.hasAttribute("destinationKey"))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"destinationKey", sName, metaclass.getName()});
                              }

                              if (nMaxLength != 0)
                              {
                                 if (attribute.getType() != Primitive.BINARY && attribute.getType() != Primitive.STRING)
                                 {
                                    throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
                                       new Object[]{attribute.getName(), metaclass.getName()});
                                 }

                                 primitiveMapping.setMaxLength(nMaxLength);
                              }
                           }
                           else
                           {
                              final VirtualClassMapping classMapping = new VirtualClassMapping();

                              attrMapping = classMapping;

                              classMapping.setComposition((Pair)m_helper.parse(
                                 XMLUtil.getStringAttr(element, "attributes"),
                                 true, null, null, metadata.getGlobalEnvironment()
                              ));

                              final boolean bObjectSourceKey = XMLUtil.getBooleanAttr(element, "objectSourceKey", false);
                              final String sDestinationKeyName = XMLUtil.getStringAttr(element, "destinationKey");

                              if (nMaxLength != 0)
                              {
                                 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));
View Full Code Here

      {
         if (m_metaclass != null)
         {
            if (!(m_metaclass instanceof Aspect) || !((Aspect)m_metaclass).isAspect())
            {
               throw new MetadataException("err.meta.persistence.sql.noPrimaryTable",
                  new Object[]{m_metaclass.getName()});
            }
         }
      }
View Full Code Here

      }

      if (m_metaclass != null &&
         (m_metaclass instanceof Aspect && ((Aspect)m_metaclass).isAspect()) != table.isAspect())
      {
         throw new MetadataException(
            (table.isAspect()) ? "err.meta.persistence.sql.classAspectTableMismatch" :
               "err.meta.persistence.sql.aspectClassTableMismatch",
               new Object[]{m_metaclass.getName(), table.getName()});
      }

      if (m_nTableCount == m_tableArray.length)
      {
         Table[] tableArray = new Table[m_nTableCount << 1];
         System.arraycopy(m_tableArray, 0, tableArray, 0, m_nTableCount);
         m_tableArray = tableArray;
      }

      if (m_primaryTable != null && m_primaryTable.getPrimaryKey() != null && table.getPrimaryKey() != null &&
         !m_primaryTable.getPrimaryKey().isCompatible(table.getPrimaryKey()))
      {
         throw new MetadataException("err.meta.incompatibleTablePrimaryKeys",
            new Object[]{m_primaryTable.getName(), table.getName()});
      }

      m_tableArray[m_nTableCount] = table;
View Full Code Here

      {
         if (m_lockingAttribute != null)
         {
            if (((RelationalPrimitiveMapping)getAttributeMapping(m_lockingAttribute)).getColumn().getTable() != getPrimaryTable())
            {
               throw new MetadataException("err.meta.lockingAttributeNotInPrimaryTable",
                  new Object[]{m_lockingAttribute.getName(), m_metaclass.getName()});
            }
         }

         if (m_typeCodeAttribute != null)
View Full Code Here

               }
            }
         }
         catch (Throwable t)
         {
            throw new MetadataException("err.meta.handlerCreate", new Object[]{sURLHandlerName}, t);
         }
      }

      URL rootURL = XMLMetadataHelper.getURL(sURI, true, handler);

      if (s_logger.isInfoEnabled())
      {
         s_logger.info("Metadata URL: \"" + rootURL + '"');
      }

      URL baseURL = null;
      String sBaseURI = properties.getProperty(BASE_URL_PROPERTY);

      if (!StringUtil.isEmpty(sBaseURI) && handler == null)
      {
         baseURL = XMLMetadataHelper.getURL(sBaseURI, true, handler);

         if (s_logger.isInfoEnabled())
         {
            s_logger.info("Base metadata URL: \"" + baseURL + '"');
         }
      }

      String sCompatibleURI = properties.getProperty(COMPATIBLE_URL_PROPERTY);

      URL configURL = null;

      try
      {
         configURL = XMLMetadataHelper.getURL(properties.getProperty(
            SysUtil.CONFIG_PROPERTY, SysUtil.DEFAULT_CONFIG_URL), false, handler);
         m_sConfigURL = configURL.toString();
      }
      catch (MetadataException e)
      {
         throw new MetadataException("err.meta.configURL",
            new Object[]{properties.getProperty(SysUtil.CONFIG_PROPERTY)}, e);
      }

      if (s_logger.isInfoEnabled())
      {
         s_logger.info("Configuration URL: \"" + m_sConfigURL + '"');
      }

      if (!StringUtil.parseBoolean(properties.getProperty(METADATA_INTEGRATION_PROPERTY, "true")))
      {
         nFlags |= INTEGRATION_EXCLUDED;
      }

      if (StringUtil.parseBoolean(properties.getProperty(METADATA_DOCUMENTATION_PROPERTY, "false")))
      {
         nFlags |= DOCUMENTATION_INCLUDED;
      }

      if (StringUtil.parseBoolean(properties.getProperty(METADATA_WARNING_PROPERTY, "false")))
      {
         nFlags |= WARNING;
      }

      boolean bDataSourceOnly = (nFlags & DATASOURCE_ONLY) != 0;

      m_properties = new Properties(properties);

      // Initialize the member variables for loading

      m_bEnvironmentOnly = ((nFlags & ENVIRONMENT_ONLY) != 0);
      m_bRuntimeExcluded = ((nFlags & RUNTIME_EXCLUDED) != 0);
      m_bIntegrationExcluded = ((nFlags & INTEGRATION_EXCLUDED) != 0);
      m_bValidatedOnly = ((nFlags & VALIDATED_ONLY) != 0);
      m_bDocumented = ((nFlags & DOCUMENTATION_INCLUDED) != 0);
      m_bWritable = ((nFlags & WRITABLE) != 0);
      m_helper = new XMLMetadataHelper(rootURL, baseURL, m_properties, null, handler);
      m_metadata = createXMLMetadata(sURI, rootURL, baseURL, (m_bValidatedOnly) ? m_helper : null);
      m_metadata.setConfigurationURL(configURL);
      m_machine = new Machine(m_metadata.getGlobalEnvironment(),
         new InvocationContext(m_metadata, m_metadata.getGlobalEnvironment()));
      m_enumerationValueMap = new HashTab(16);
      m_inheritanceCheckList = new ArrayList();
      m_inheritanceFixupList = new ArrayList();
      m_inheritance1stPassFixupList = new ArrayList();
      m_inheritance2ndPassFixupList = new ArrayList(1);
      m_inheritance4thPassFixupList = new ArrayList(1);
      m_attributeGenerationList = new ArrayList();
      m_attributeFixupList = new ArrayList();
      m_attributeResolutionList = new ArrayList(1);
      m_actionFixupList = new ArrayList();
      m_persistenceMappingLoadList = new ArrayList();
      m_persistenceMappingFixupList = new ArrayList();
      m_persistenceMappingGenerationList = new ArrayList();
      m_attributeDependencyList = new ArrayList(1);
      m_attributeDependencySet = new HashHolder();
      m_class2ndPassList = new ArrayList(1);
      m_ioFixupList = new ArrayList();
      m_environmentFixupList = new ArrayList();
      m_privilegeFixupList = new ArrayList();
      m_preInheritanceMessageFixupList = new ArrayList();
      m_postInheritanceMessageFixupList = new ArrayList();
      m_transformationFixupList = new ArrayList();
      m_postInheritanceTransformationFixupList = new ArrayList();
      m_componentFixupList = new ArrayList();
      m_singletonFixupList = new ArrayList();
      m_tmpDocument = XMLUtil.parse(new StringReader("<TmpDocument/>"));

      m_metadata.setEncrypted((nFlags & ENCRYPTED) != 0);
      m_metadata.setEnvironmentOnly(m_bEnvironmentOnly);

      if ((nFlags & WARNING) != 0)
      {
         m_helper.setWarnings(new GenericException(null)
         {
            private final static long serialVersionUID = -2984934222963813773L;

            public void addException(Throwable e)
            {
               e.setStackTrace(ObjUtil.EMPTY_STACK_TRACE);
               super.addException(e);
            }
         });
      }

      // Prepare the progress listener
      ProgressProxy progressProxy = new ProgressProxy(progress);

      if (progress != null)
      {
         progress = progressProxy;
      }

      // Load the repository descriptors and process the elements in them

      if (progress != null)
      {
         progress.progress("info.meta.loadingDescriptors", null, 0);
      }

      Element baseDescElement = m_helper.getDescriptorElement(false);
      Element rootDescElement = m_helper.getDescriptorElement(true);

      progressProxy.setRange(0.01, 0.02);

      m_metadata.setListing(m_helper.getListing(new XMLMetadataHelper.MixinHandler()
         {
            /**
             * Metadata repository information, indexed by namespace.
             */
            private Lookup m_metadataMap = new HashTab();

            private String getMetadataName(String sNamespace)
            {
               MetadataInfo info = ((MetadataInfo)m_metadataMap.get(sNamespace));

               return (info == null || info.metadata == null) ? sNamespace : info.metadata.getName();
            }

            public void handleRepository(XMLMixin mixin)
            {
               String sNamespace = mixin.getNamespace();
               XMLMetadataHelper helper = mixin.getHelper();
               MetadataInfo info = (MetadataInfo)m_metadataMap.get(sNamespace);

               if (info == null)
               {
                  info = new MetadataInfo();
               }

               // get the metadata instance
               if (m_metadataMap.size() == 0)
               {
                  info.metadata = m_metadata;
               }
               else
               {
                  URL rootURL = helper.getRootURL();

                  info.metadata = createXMLMetadata(rootURL.getPath(), rootURL, helper.getBaseURL(), helper);
               }

               // load the version
               loadVersion(info.metadata, helper);
               m_metadataMap.put(sNamespace, info);

               // validate loaded mixin
               if (m_metadata != info.metadata)
               {
                  // Adopt the highest coreVersion available from any of the repositories.
                  if (m_metadata.getCoreVersion() == null || (info.metadata.getCoreVersion() != null &&
                     StringUtil.compareVersionRanges(m_metadata.getCoreVersion(), info.metadata.getCoreVersion()) < 0))
                  {
                     m_metadata.setCoreVersion(info.metadata.getCoreVersion());
                  }

                  if (info.ref == null)
                  {
                     throw new MetadataValidationException("err.meta.mixinNamespace", new Object[]{info.metadata.getName(), sNamespace});
                  }

                  String sVersion = info.ref.getVersion();
                  String sChecksum = info.ref.getChecksum();

                  // validate that repository matches mixin declaration
                  if ((sVersion != null && !sVersion.equals(info.metadata.getVersion()))
                     || (sChecksum != null && !sChecksum.equals(info.metadata.getChecksum())))
                  {
                     throw new MetadataValidationException("err.meta.mixinLinkVersion", new Object[]{
                        info.metadata.getName(),
                        info.metadata.getVersion(),
                        info.metadata.getChecksum(),
                        sVersion,
                        sChecksum,
                        getMetadataName(info.parentNamespace)
                     });
                  }
               }
            }

            public void handleMixinReference(XMLMixin ref, XMLMixin parent)
            {
               String sParentNamespace = parent.getNamespace();
               String sNamespace = ref.getNamespace();
               String sVersion = ref.getVersion();
               String sChecksum = ref.getChecksum();
               MetadataInfo info = (MetadataInfo)m_metadataMap.get(sNamespace);

               if (info == null)
               {
                  info = new MetadataInfo();
                  info.parentNamespace = sParentNamespace;
                  info.ref = (XMLMixin)ref.clone();
                  m_metadataMap.put(sNamespace, info);

                  // mixin declared at top-level is also base
                  if (sParentNamespace.equals(m_metadata.getNamespace()) && sNamespace.equals(m_metadata.getBaseNamespace()))
                  {
                     m_helper.addException(new MetadataValidationException("err.meta.mixinDup",
                        new Object[] {sNamespace, getMetadataName(sParentNamespace)}));
                  }

                  // mixin matches base, but has different version/checksum
                  if (sNamespace.equals(m_metadata.getBaseNamespace()) &&
                     (!sVersion.equals(m_metadata.getBaseVersion()) || !sChecksum.equals(m_metadata.getBaseChecksum())))
                  {
                     m_helper.addException(new MetadataValidationException("err.meta.mixinBaseVersion",
                        new Object[]{sNamespace, sVersion, sChecksum, m_metadata.getBaseVersion(), m_metadata.getBaseChecksum()}));
                  }
               }
               else if (info.ref != null)
               {
                  if (sParentNamespace.equals(info.parentNamespace))
                  {
                     // mixin declared twice in same repository
                     m_helper.addException(new MetadataValidationException("err.meta.mixinDup",
                        new Object[] {sNamespace, getMetadataName(sParentNamespace)}));
                  }

                  // mixin declared more than once with different version/checksum
                  if ((info.ref.getVersion() != null && !info.ref.getVersion().equals(sVersion)) ||
                     (info.ref.getChecksum() != null && !info.ref.getChecksum().equals(sChecksum)))
                  {
                     m_helper.addException(new MetadataValidationException("err.meta.mixinVersion", new Object[] {
                        sNamespace,
                        sVersion,
                        sChecksum,
                        getMetadataName(sParentNamespace),
                        info.ref.getVersion(),
                        info.ref.getChecksum(),
                        getMetadataName(info.parentNamespace)
                     }));
                  }
               }
            }

            public void handleMixinOverrideConflict(XMLMixin ref, XMLMixin mixin)
            {
               throw new MetadataValidationException("err.meta.mixinOverride", new Object[]{ref.getName(), mixin.getName()});
            }

            public void handleCircularReference(XMLMixin mixin)
            {
               throw new MetadataValidationException("err.meta.mixinCycle", new Object[]{mixin.getName()});
            }

            public void handleResourceConflict(XMLResource first, XMLResource second)
            {
               m_helper.addException(new MetadataValidationException("err.meta.mixinConflict",
                  new Object[]{
                     first.getName(),
                     getMetadataName(first.getNamespace()),
                     getMetadataName(second.getNamespace())
                  }));
            }

            public void handleLinkFailure(XMLMixin ref, Exception e)
            {
               if (e instanceof MetadataValidationException)
               {
                  m_helper.addException((MetadataValidationException)e);
               }
               else
               {
                  throw new MetadataException("err.meta.mixin", new Object[]{ref}, e);
               }
            }

            public void handleAlternateResource(XMLResource first, XMLResource second)
            {
            }

            public void handleResourceOverride(XMLResource source, XMLResource overridden)
            {
            }

            final class MetadataInfo
            {
               /**
                * The metadata instance of the repository.
                */
               private XMLMetadata metadata;

               /**
                * The namespace of the repository that linked this repository.
                */
               private String parentNamespace;

               /**
                * The reference that caused this repository to be linked.
                */
               private XMLMixin ref;
            }
         }));

      m_helper.setMetadataCoreVersion(
         m_metadata.getCoreVersion(), m_metadata.getUpgradeResources());

      progressProxy.shiftRange(0.05);

      if (!m_bEnvironmentOnly && !bDataSourceOnly)
      {
         Lookup localeMap = new HashTab();
         m_helper.addResources(localeMap, ".locale", "Locale", "locale");
         loadStrings(localeMap.iterator());

         Lookup stringResMap = new HashTab();
         m_helper.addResources(stringResMap, ".strings", "Strings", "strings");
         loadStrings(stringResMap.iterator());

         if (StringTable.getInstance() == null)
         {
            StringTable.setInstance(m_metadata.getStringTable(Metadata.DEFAULT_LOCALE));
            StringTable.setTimeZone(TZ.UTC);
         }
      }

      progressProxy.shiftRange(0.10);

      m_helper.loadEncryptedResourceURL(configURL, "Server", "server", new ResourceHandler()
      {
         public void handleResource(final Element element, final String sName)
         {
            if (element.getNodeName().equals("Environment"))
            {
               String sConnectionsURL = m_properties.getProperty(CONNECTIONS_URL_PROPERTY);

               if (StringUtil.isEmpty(sConnectionsURL))
               {
                  m_properties.setProperty(CONNECTIONS_URL_PROPERTY, m_sConfigURL);
               }
            }

            NamedNodeMap attrMap = element.getAttributes();

            for (int i = 0; i != attrMap.getLength(); ++i)
            {
               Node node = attrMap.item(i);
               String sOldValue = m_properties.getProperty(node.getNodeName());

               if (StringUtil.isEmpty(sOldValue))
               {
                  m_properties.setProperty(node.getNodeName(), node.getNodeValue());
               }
            }
         }
      }, m_properties);

      m_decryptionDispatcher = new CharacterStreamCipherDispatcher();
      m_decryptionDispatcher.init(m_properties);
      m_helper.setEncryptionSchemeSet(new HashHolder(4));

      loadServer(m_properties);

      String sConnectionsURL = m_properties.getProperty(CONNECTIONS_URL_PROPERTY);
      URL connectionsURL = null;

      if (!StringUtil.isEmpty(sConnectionsURL))
      {
         connectionsURL = XMLMetadataHelper.getURL(sConnectionsURL, false, handler);
         sConnectionsURL = connectionsURL.toString();

         if (s_logger.isInfoEnabled())
         {
            s_logger.info("Connections URL: \"" + sConnectionsURL + "\"");
         }
      }

      m_helper.loadSystemResource("system.dstypes",
         "DataSourceTypes", "dataSourceTypes", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadDataSourceTypes(element);
         }
      });

      m_helper.loadResources(".dstype", "DataSourceType", "dataSourceType", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadDataSourceType(element, sName);
         }
      }, progress);

      m_helper.loadResources(".datasource", "DataSource", "dataSource", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadDataSource(element, sName);
         }
      }, progress);

      if (!m_bIntegrationExcluded)
      {
         m_helper.loadSystemResource("system.chtypes",
            "ChannelTypes", "channelTypes", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadChannelTypes(element);
            }
         });

         m_helper.loadResources(".chtype", "ChannelType", "channelType", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadChannelType(element, sName);
            }
         }, progress);

         // Load the SOA definition XML metadata (which may include definitions of other XML metadata)
         m_soaLoader = new XMLSOAMetadataLoader(m_helper);
         m_helper.loadResources(".soadef", "SOADefinition", "soadef", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               m_soaLoader.loadDefinition(element, sName);
            }
         }, progress);
         m_soaLoader.resolveReferences();

         // dispatcher channel properties loaded from environment.
         ChannelType type = m_metadata.getChannelType("ObjectQueue");

         m_dispatcherChannel.setType(type);
         m_metadata.addChannel(m_dispatcherChannel);

         m_helper.loadResources(".channel", "Channel", "channel", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadChannel(element, sName);
            }
         }, progress);
      }

      final Set componentNameSet = new HashHolder();
     
      m_helper.loadResources(".comp", "Component", "component", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            if (m_bEnvironmentOnly)
            {
               XMLMetadataHelper.verifyRootElement(element, "Component");

               m_metadata.addComponent(new Component(sName));
            }
           
            componentNameSet.add(sName);
         }
      }, progress);
     
      if (componentNameSet.contains("System.ObjectQueueDispatcher") &&
         Boolean.parseBoolean(properties.getProperty("queueing.enabled", "true")))
      {
      // only enable the dispatcher if the metadata supports it.
         m_dispatcherChannel.setSendable(true);
         m_dispatcherChannel.setReceivable(true);
      }

      if (connectionsURL != null)
      {
         boolean bEnvironment = (sConnectionsURL.equals(m_sConfigURL) ||
            sConnectionsURL.toLowerCase(Locale.ENGLISH).endsWith(".environment"));

         m_helper.loadEncryptedResourceURL(connectionsURL,
            (bEnvironment) ? "Environment" : "Connections",
            (bEnvironment) ? "environment" : "connections",
            new ResourceHandler()
         {
            public void handleResource(final Element element, final String sName)
            {
               loadConnections(element, sName);
            }
         }, m_properties);
      }
      else
      {
         loadConnections(null, null);
      }

      // .server file overrides highest scheme used in the connections file
      m_metadata.setEncryptionScheme(m_properties.getProperty("cipher.scheme",
            CharacterStreamCipherDispatcher.computeMostSecure(m_helper.getEncryptionSchemeSet())));

      if (!bDataSourceOnly)
      {
         loadUIMetadata(baseDescElement, rootDescElement);
      }

      progressProxy.shiftRange(0.12);

      m_helper.fixup(m_ioFixupList.iterator());
      m_ioFixupList = null;

      m_helper.loadResources(".extlib", "ExternalLibrary", "externalLibrary", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadExternalLibrary(element, sName);
         }
      }, progress);

      m_nStage = STAGE_LOADED_ENVIRONMENT;
      progressProxy.progress(null, null, 1.0);

      if (m_bEnvironmentOnly || bDataSourceOnly)
      {
         m_nStage = STAGE_LOAD_ENVIRONMENT_FIXUPS;
         m_helper.fixup(m_environmentFixupList.iterator()); // safe to run since no J2EE container
         m_nStage = STAGE_FINISHED;

         return m_metadata;
      }

      progressProxy.shiftRange(0.13);

      m_helper.loadResources(".security", "SecurityDescriptor", "securityDescriptor", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadSecurityDescriptor(element);
         }
      }, progress);

      m_helper.fixup(m_privilegeFixupList.iterator());
      m_privilegeFixupList = null;
      PrivilegeGroup.resolve(m_metadata);

      if (progress != null)
      {
         progressProxy.shiftRange(0.15);
         progress.progress("info.meta.loadingSystemResources", null, 0);
      }

      Context contextSaved = ThreadContextHolder.getContext();

      try
      {
         ThreadContextHolder.setContext(m_machine.getContext());

         m_helper.loadSystemResource("scheme.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         // Load the Dynamic Object System
         m_helper.loadSystemResource("object.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         // Load the Services Oriented Architecture functionality
         m_helper.loadSystemResource("soa.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         m_helper.loadSystemResource("server.scm",
            "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, true);
            }
         });

         m_helper.loadSystemResource(Metadata.ROOT_CLASS_NAME + ".meta",
            "Class", "class", new ResourceHandler()
         {
            public void handleResource(Element rootElement, String sName)
            {
               loadClass(rootElement, sName);
            }
         });

         loadExtendedSystemMetadata();

         progressProxy.shiftRange(0.16);

         m_helper.loadResources(".scm", "Library", "library", new CharacterStreamHandler()
         {
            public void handleCharacterStream(Reader reader, String sName) throws IOException
            {
               loadLibrary(reader, sName, false);
            }
         }, progress);
      }
      finally
      {
         ThreadContextHolder.setContext(contextSaved);
      }

      progressProxy.shiftRange(0.23);

      m_helper.loadResources(".meta", "Class", "class", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            String sElement = element.getNodeName();

            if (sElement.equals("Class"))
            {
               loadClass(element, sName);
            }
            else if (sElement.equals("Aspect"))
            {
               loadClassAspect(element, sName);
            }
            else
            {
               throw new MetadataException("err.meta.metaDocRoot", new Object[]{sElement});
            }
         }
      }, progress);

      progressProxy.shiftRange(0.24);

      m_helper.loadResources(".enum", "Enumeration", "enum", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadEnumeration(element, sName);
         }
      }, progress);

      progressProxy.shiftRange(0.25);

      loadUIEventMetadata(baseDescElement, rootDescElement, progress);

      if (progress != null)
      {
         progressProxy.shiftRange(0.26);
         progress.progress("info.meta.resolvingResourceReferences", null, 0);
      }

      m_helper.fixup(m_inheritanceCheckList.iterator());
      m_inheritanceCheckList = null;
      m_helper.fixup(m_attributeGenerationList.iterator());
      m_attributeGenerationList = null;

      m_helper.fixup(Collections.singleton(new ClassFixup()
      {
         public void fixup()
         {
            m_classAspectArray = ClassAspect.resolveAspects(m_metadata);
         }
      }).iterator());

      m_helper.fixup(m_inheritanceFixupList.iterator());
      m_inheritanceFixupList = null;
      m_enumerationValueMap = null;
      m_helper.fixup(m_attributeFixupList.iterator());
      m_attributeFixupList = null;
      m_helper.fixup(m_actionFixupList.iterator());
      m_actionFixupList = null;

      if (m_classAspectArray != null)
      {
         ClassAspect.resolveMembers(m_classAspectArray);
      }

      m_helper.fixup(m_persistenceMappingLoadList.iterator());
      m_persistenceMappingLoadList = null;
      m_helper.fixup(m_attributeResolutionList.iterator());
      m_attributeResolutionList = null;
      m_helper.fixup(m_inheritance1stPassFixupList.iterator());
      m_inheritance1stPassFixupList = null;

      progressProxy.shiftRange(0.27);

      m_helper.loadResources(".action", "Action", "action", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadFlowMacro(element, sName);
         }
      }, progress);

      progressProxy.shiftRange(0.32);

      m_helper.loadResources(".workflow", "Workflow", "workflow", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadWorkflow(element, sName);
         }
      }, progress);

      progressProxy.shiftRange(0.33);

      if (!m_bIntegrationExcluded)
      {
         m_helper.loadSystemResource("system.formats",
            "Formats", "formats", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadFormats(element);
            }
         });

         m_helper.loadResources(".format", "Format", "format", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadFormat(element, sName);
            }
         }, progress);

         progressProxy.shiftRange(0.34);

         final Lookup importedMessageMap = new HashTab();

         m_helper.loadResources(".xsd", "XSD", "xsd", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sRelativePath)
            {
               loadXSD(m_helper.getResource(sRelativePath).getURL(), sName, importedMessageMap);
            }
         }, progress);

         m_helper.loadResources(".wsdl", "WSDL", "wsdl", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sRelativePath)
            {
               loadXSD(m_helper.getResource(sRelativePath).getURL(), sName, importedMessageMap);
            }
         }, progress);

         m_helper.loadResources(".soaimpl", "SOAImplementation", "soaimpl", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               m_soaLoader.loadImplementation(element, sName, m_metadata.getGlobalEnvironment());
            }
         }, progress);

         contextSaved = ThreadContextHolder.getContext();

         try
         {
            ThreadContextHolder.setContext(m_machine.getContext());
            m_soaLoader.initDefinitions(m_machine);
         }
         finally
         {
            ThreadContextHolder.setContext(contextSaved);
         }

         m_helper.loadResources(".message", "Message", "message", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadMessage(element, sName);
            }
         }, progress);

         // Explicitly-defined Message metadata shall override Message metadata from imported XSDs and WSDLs
         for (Lookup.Iterator itr = importedMessageMap.iterator(); itr.hasNext(); )
         {
            String sName = (String)itr.next();

            if (m_metadata.findMessage(sName) == null)
            {
               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Adding imported message \"" + sName + "\"");
               }

               m_metadata.addMessage((Message)itr.getValue());
            }
            else
            {
               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Skipping the overridden imported message \"" + sName + "\"");
               }
            }
         }

         // Resolve Inheritance
         m_helper.fixup(m_preInheritanceMessageFixupList.iterator());
         m_preInheritanceMessageFixupList = null;

         List sortedMessageList = new ArrayList(m_metadata.getMessageCount());

         Message.resolveInheritance(m_metadata.getMessageIterator(), sortedMessageList);

         m_helper.fixup(m_postInheritanceMessageFixupList.iterator());
         m_postInheritanceMessageFixupList = null;

         Message.resolveReferences(m_metadata.getMessageIterator());

         progressProxy.shiftRange(0.36);

         m_helper.loadResources(".transformation", "Transformation", "transformation", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadTransformation(element, sName);
            }
         }, progress);

         m_helper.fixup(m_transformationFixupList.iterator());
         m_transformationFixupList = null;

         Transformation.resolveInheritance(m_metadata.getTransformationIterator());

         m_helper.fixup(m_postInheritanceTransformationFixupList.iterator());
         m_postInheritanceTransformationFixupList = null;

         for (Iterator itr = m_metadata.getTransformationIterator(); itr.hasNext(); )
         {
            Transformation transformation = (Transformation)itr.next();

            try
            {
               transformation.finish(m_machine);
            }
            catch (UncheckedException ex)
            {
               m_helper.addException(ex);
            }
         }

         m_helper.checkForError();

         progressProxy.shiftRange(0.37);

         m_helper.loadResources(".interface", "Interface", "interface", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadInterface(element, sName);
            }
         }, progress);

         progressProxy.shiftRange(0.38);

         m_helper.loadResources(".service", "Service", "service", new ResourceHandler()
         {
            public void handleResource(Element element, String sName)
            {
               loadService(element, sName);
            }
         }, progress);

         finishMessagePartMappings(sortedMessageList.iterator());
      }

      if (progress != null)
      {
         progressProxy.shiftRange(0.39);
         progress.progress("info.meta.resolvingResourceReferences", null, 0);
      }

      m_helper.fixup(m_persistenceMappingFixupList.iterator());
      m_persistenceMappingFixupList = null;
      m_helper.fixup(m_persistenceMappingGenerationList.iterator());
      m_persistenceMappingGenerationList = null;
      m_helper.fixup(m_attributeDependencyList.iterator());
      m_attributeDependencyList = null;
      Attribute.resolveInverseDependency(m_attributeDependencySet.iterator());
      m_attributeDependencySet = null;

      if (m_classAspectArray != null)
      {
         m_helper.fixup(Collections.singleton(new ClassFixup()
         {
            public void fixup()
            {
               ClassAspect.resolvePersistence(m_classAspectArray);
            }
         }).iterator());
      }

      m_helper.fixup(m_inheritance2ndPassFixupList.iterator());
      m_inheritance2ndPassFixupList = null;
      m_helper.fixup(m_class2ndPassList.iterator());
      m_class2ndPassList = null;

      loadLocales();
      progressProxy.shiftRange(0.40);

      m_helper.loadResources(".comp", "Component", "component", new ResourceHandler()
      {
         public void handleResource(Element element, String sName)
         {
            loadComponent(element, sName);
         }
      }, progress);

      m_nStage = STAGE_LOADED_COMPONENTS;
      progressProxy.progress(null, null, 0);

      m_nStage = STAGE_LOAD_ENVIRONMENT_FIXUPS;
      progressProxy.shiftRange(0.405);

      m_helper.fixup(m_environmentFixupList.iterator());

      if (progress != null)
      {
         progressProxy.shiftRange(0.41);
         progress.progress("info.meta.instantiatingComponents", null, 0);
      }

      m_helper.fixup(m_componentFixupList.iterator());
      m_componentFixupList = null;
      m_helper.fixup(m_inheritance4thPassFixupList.iterator());
      m_inheritance4thPassFixupList = null;
      m_helper.fixup(m_singletonFixupList.iterator());
      m_singletonFixupList = null;

      m_helper.addResources(m_metadata.getDumpResourceMap(), ".dump", "Dump", "dump");
      m_helper.addResources(m_metadata.getUnitTestResourceMap(), ".utest", "UnitTest", "unittest");
      m_helper.addResources(m_metadata.getUpgradeResourceMap(), ".upgrade", "Upgrade", "upgrade");

      loadExtendedMetadata(baseDescElement, rootDescElement);

      if (m_bValidatedOnly)
      {
         progressProxy.setRange(0.42, 0.96);

         m_helper.validateResources(m_metadata.getUnitTestResourceMap(), "UnitTest", "unittest", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sFullName)
            {
               m_metadata.getUnitTest(sName);
            }
         }, null);

         progressProxy.shiftRange(0.98);

         m_helper.validateResources(m_metadata.getUpgradeResourceMap(), "Upgrade", "upgrade", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sFullName)
            {
               if (m_helper.findResource(sFullName, XMLMetadataHelper.SEARCH_ROOT_THEN_BASE) != null)
               {
                  m_metadata.getUpgrade(sName).validate(m_metadata, m_helper.getWarnings());
               }
            }
         }, null);

         validateExtendedMetadata(progressProxy);
      }

      try
      {
         m_metadata.validate(m_metadata, m_helper.getWarnings());

         if (!StringUtil.isEmpty(sCompatibleURI))
         {
            progressProxy.shiftRange(0.988);
            progressProxy.progress("info.meta.loadCompatibleModel", null, 0);

            Properties compatibleProperties = new Properties(properties);

            compatibleProperties.setProperty(BASE_URL_PROPERTY, "");
            compatibleProperties.setProperty(COMPATIBLE_URL_PROPERTY, "");

            Metadata compatible;

            try
            {
               compatible = new MetadataLoaderDispatcher().load(sCompatibleURI, compatibleProperties, nFlags, null);
            }
            catch (UncheckedException e)
            {
               throw new MetadataCompatibilityException("err.meta.compatibleMetadataLoadFailure", null, e);
            }

            progressProxy.progress("info.meta.verifyModelCompatibility", null, 1);
            m_metadata.checkCompatibility(compatible);
         }
      }
      catch (UncheckedException e)
      {
         m_helper.addException(e);
      }

      if (m_bValidatedOnly)
      {
         progressProxy.shiftRange(.989);

         m_helper.validateResources(m_metadata.getDumpResourceMap(), "Dump", "dump", new ResourceNameHandler()
         {
            public void handleResource(String sName, String sFullName)
            {
               if (m_helper.findResource(sFullName, XMLMetadataHelper.SEARCH_ROOT_THEN_BASE) == null)
               {
                  return;
               }

               InputStream is = null;
               Pair dumpVersion = null;

               try
               {
                  dumpVersion = new DataLoader(null).getDumpVersion(is = m_helper.getResourceAsStream(sFullName));
               }
               catch (Exception e)
               {
                  throw new MetadataException("err.meta.dumpLoad", new Object[]
                  {
                     sName
                  }, e);
               }
               finally
               {
                  IOUtil.close(is);
               }

               if (dumpVersion != null
                  && (!m_metadata.getNamespace().equals(dumpVersion.getHead()) || !m_metadata.getVersion().equals(
                     dumpVersion.getTail())))
               {
                  throw new MetadataException("err.meta.dumpVersion", new Object[]
                  {
                     dumpVersion.getHead(),
                     dumpVersion.getTail(),
                     m_metadata.getNamespace(),
                     m_metadata.getVersion()
View Full Code Here

TOP

Related Classes of nexj.core.meta.MetadataException

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.