Package nexj.core.util

Examples of nexj.core.util.Lookup


    * @param specItr Read specification iterator: (class attributes where)
    * @return List of transfer object.
    */
   public List exportData(Iterator specItr)
   {
      Lookup identityMap = new IdentityHashTab(128);

      while (specItr.hasNext())
      {
         Object spec = specItr.next();
         Metaclass metaclass;
         Pair attributes = null;
         Object where = null;
         Object obj;
         Pair pair;

         if (spec instanceof Pair)
         {
            pair = (Pair)spec;
            obj = pair.getHead();
            pair = pair.getNext();
         }
         else
         {
            obj = spec;
            pair = null;
         }

         if (obj instanceof Metaclass)
         {
            metaclass = (Metaclass)obj;
         }
         else if (obj instanceof Symbol || obj instanceof String)
         {
            metaclass = m_context.getMetadata().getMetaclass(obj.toString());
         }
         else
         {
            throw new IllegalArgumentException("Invalid class specification");
         }

         if (pair != null)
         {
            attributes = (Pair)pair.getHead();
            pair = pair.getNext();
         }

         if (pair != null)
         {
            where = pair.getHead();

            if (pair.getTail() != null)
            {
               throw new IllegalArgumentException("Invalid query specification");
            }
         }

         RPCUtil.transfer(read(metaclass, attributes, where), attributes,
            identityMap, RPCUtil.TF_ALL | RPCUtil.TF_LAZY);
      }

      Lookup whereMap = new HashTab();

      for (Iterator itr = identityMap.iterator(); itr.hasNext();)
      {
         Object obj = itr.next();

         if (obj instanceof Instance)
         {
            Instance instance = (Instance)obj;
            OID oid = instance.getOID();

            if (oid != null)
            {
               Metaclass metaclass = instance.getLazyMetaclass().getPersistenceRoot();
               Set oidSet = (Set)whereMap.get(metaclass);

               if (oidSet == null)
               {
                  oidSet = new HashHolder();
                  whereMap.put(metaclass, oidSet);
               }

               oidSet.add(oid);
            }
         }
View Full Code Here


         {
            // if resource references are not supplied, process resources in directory listing order
            List resourceList = new ArrayList();
            Set resourceSet = new HashHolder();
            XMLMetadataListing listing = getListing();
            Lookup baseMap = listing.getBaseResourceMap();

            if (bRoot)
            {
               Lookup rootMap = listing.getRootResourceMap();

               for (Iterator itr = rootMap.iterator(); itr.hasNext(); )
               {
                  Object resource = itr.next();

                  resourceList.add(resource);
                  resourceSet.add(resource);
View Full Code Here

      {
         throw new IllegalStateException("Unavailable persistent storage version");
      }

      VersionUpgrade lastUpgrade = upgrade.getVersion(version.getVersion());
      Lookup/*<Object, UpgradeState>*/ stateMap = Upgrade.getInitialState(lastUpgrade);

      version.setUpgradable(true);
      lastUpgrade.apply(Upgrade.getState(stateMap, lastUpgrade)); // advance to finished current ver

      for (VersionUpgrade u = lastUpgrade.getNext(); u != null; u = u.getNext())
      {
         DataSource dataSource = null;
         version.setVersion(u.getName());
         version.setStep(0);

         if (u.getName() == null)
         {
            u.apply(Upgrade.getState(stateMap, u));

            continue;
         }

         if (u instanceof SchemaUpgrade)
         {
            SchemaUpgrade su = (SchemaUpgrade)u;

            dataSource = su.getDataSource();

            if (dataSourceSet.contains(dataSource))
            {
               PersistenceAdapter adapter = (PersistenceAdapter)dataSource.getComponent().getInstance(m_context);

               adapter.upgrade(su, Upgrade.getState(stateMap, su), version);
            }
            else
            {
               su.apply(Upgrade.getState(stateMap, su));
            }
         }
         else if (u instanceof ScriptUpgrade)
         {
            Function fun = ((ScriptUpgrade)u).getFunction();

            if (fun != null)
            {
               if (u.getNext() == null)
               {
                  // Script upgrade must be run with metadata matching the final or previous data version
                  m_context.getMachine().invoke(fun, (Pair)null);
                  m_context.getUnitOfWork().commit(false); // precommit the UOW
               }
               else
               {
                  throw new UnsupportedOperationException(
                     "Unable to run script upgrade for version " + u.getName() +
                     ", temporarily revert metadata used by the upgrade to version "
                     + u.getName() + " before retrying upgrade.");
               }
            }
         }

         version.setStep(-1);

         for (Iterator itr = dataSourceSet.iterator(); itr.hasNext();)
         {
            DataSource ds = (DataSource)itr.next();

            if (ds != dataSource)
            {
               ((PersistenceAdapter)ds.getComponent().getInstance(m_context))
                  .setVersion(ds.getSchema(), version);
            }
         }
      }

      for (Lookup.Iterator itr = stateMap.valueIterator(); itr.hasNext();)
      {
         ((UpgradeState)itr.next()).end();
      }

      m_context.complete(true);
View Full Code Here

    * @param sourceMap Map of resource names to maps of XMLMixins to XMLResources.
    * @return The XMLMetadataListing.
    **/
   public XMLMetadataListing getListing(MixinHandler handler, Lookup sourceMap)
   {
      Lookup resourceMap = new HashTab();

      m_listing = linkMixinResources(null, sourceMap, new HashTab(), handler);

      // record full map of resources, check for conflicts
      for (Lookup.Iterator resItr = sourceMap.valueIterator(); resItr.hasNext(); )
      {
         Lookup srcMap = (Lookup)resItr.next();
         Iterator srcItr = srcMap.valueIterator();
         XMLResource mostDerivedSource = (XMLResource)srcItr.next();
         List identicalSourcesList = new ArrayList(srcMap.size());

         if (handler != null)
         {
            while (srcItr.hasNext())
            {
View Full Code Here

         {
            handler.handleRepository(mixin);
         }
      }

      Lookup refMap = new HashTab(); // XMLMixin[sNamespace]

      if (baseDescriptorElement != null)
      {
         loadMixinReferences(baseDescriptorElement, refMap, (XMLMixin)mixinMap.get(sBaseNamespace), handler);
      }

      loadMixinReferences(rootDescriptorElement, refMap, mixin, handler);

      // Process dynamic mix-ins
      if (bTop)
      {
         String sMixins = getProperty(MetadataLoader.METADATA_MIXINS_PROPERTY);

         if (!StringUtil.isEmpty(sMixins))
         {
            String[] sMixinArray = StringUtil.split(sMixins, ' ');

            for (int i = 0; i < sMixinArray.length; i++)
            {
               String sMixinNamespace = sMixinArray[i];

               if (!mixinMap.contains(sMixinNamespace))
               {
                  XMLMixin ref = new XMLMixin(sMixinNamespace);

                  if (handler != null)
                  {
                     handler.handleMixinReference(ref, mixin);
                  }

                  refMap.put(sMixinNamespace, ref);
               }
            }
         }
      }

      // set of XMLMixins having resources that can be overridden by the current mixin
      Set overridableSet = new HashHolder(1);

      for (Iterator itr = refMap.valueIterator(); itr.hasNext();)
      {
         XMLMixin ref = (XMLMixin)itr.next();
         boolean bOverride = ref.isOverridable();
         boolean bDynamic = (ref.getVersion() == null);
         String sRefNamespace = ref.getNamespace();
         XMLMixin old = (XMLMixin)mixinMap.get(sRefNamespace);

         try
         {
            if (old != null)
            {
               if (!ref.isRoot())
               {
                  old.setRoot(false);
               }

               ref = old;
            }
            else
            {
               String sMixinDefaultPath = getRepositoryPath(sRefNamespace);
               URL rootURL = null;

               if (m_handler == null)
               {
                  rootURL = getURL(getProperty(getRepositoryProperty(sRefNamespace), sMixinDefaultPath), true);
               }
               else
               {
                  String sURI = getProperty(getRepositoryProperty(sRefNamespace));

                  if (!StringUtil.isEmpty(sURI))
                  {
                     rootURL = findURL(sURI, true, null);
                  }

                  if (rootURL == null && m_handler instanceof MetadataURLHandler)
                  {
                     rootURL = ((MetadataURLHandler)m_handler).getMixinURL(m_rootURL, sRefNamespace);
                  }
               }

               ref.setHelper(new XMLMetadataHelper(rootURL, null, m_properties, null));
            }

            ref.getHelper().linkMixinResources(ref, sourceMap, mixinMap, handler);

            if (bDynamic)
            {
               bOverride = ref.isOverridable();
            }

            if (bOverride)
            {
               if (!ref.isOverridable() && handler != null)
               {
                  handler.handleMixinOverrideConflict(ref, mixin);
               }

               overridableSet.add(ref);
            }
         }
         catch (Exception e)
         {
            if (handler != null)
            {
               // if mix-in cannot be linked, keep building listing, but notify handler
               handler.handleLinkFailure(ref, e);
            }
         }
      }

      Lookup baseMap = listing.getBaseResourceMap();

      if (baseMap != null)
      {
         linkMixinResources(mixin, sourceMap, baseMap, sBaseNamespace, overridableSet, handler);
      }
View Full Code Here

      String sNamespace, Set overrideSet, MixinHandler handler)
   {
      for (Lookup.Iterator itr = resourceMap.valueIterator(); itr.hasNext(); )
      {
         XMLResource resource = (XMLResource)itr.next();
         Lookup map = (Lookup)sourceMap.get(resource.getName());

         if (map == null)
         {
            map = new HashTab(1);
            sourceMap.put(resource.getName(), map);
         }
         else
         {
            for (Iterator overrideItr = overrideSet.iterator(); overrideItr.hasNext(); )
            {
               XMLResource base = (XMLResource)map.remove(overrideItr.next()); // if override is permitted, replace overridden source

               if (base != null && base != resource)
               {
                  resource.addBase(base);

                  if (handler != null)
                  {
                     handler.handleResourceOverride(resource, base);
                  }
               }
            }
         }

         map.put(mixin, resource);
      }
   }
View Full Code Here

    * ResourceMap is initialized, but does not include resources from any mix-ins.
    */
   private XMLMetadataListing getListing(boolean bRoot, boolean bBase, Lookup mixinMap)
   {
      XMLMetadataListing listing = new XMLMetadataListing();
      Lookup resourceMap = new HashTab();

      if (bBase)
      {
         Lookup map = findResources(false, mixinMap);

         if (map != null)
         {
            for (Lookup.Iterator itr = map.valueIterator(); itr.hasNext();)
            {
               XMLResource resource = (XMLResource)itr.next();

               resourceMap.put(resource.getName(), resource);
            }
         }

         listing.setBaseResourceMap(map);
      }

      if (bRoot)
      {
         Lookup map = findResources(true, mixinMap);

         if (map != null)
         {
            for (Lookup.Iterator itr = map.valueIterator(); itr.hasNext();)
            {
               XMLResource resource = (XMLResource)itr.next();

               resourceMap.put(resource.getName(), resource);
            }
View Full Code Here

      {
         mixin.setHelper(this);
         mixin.setRoot(bRoot);
      }

      final Lookup map;

      try
      {
         List nameList = new ArrayList();
         URL url = (bRoot) ? m_rootURL : m_baseURL;

         URLUtil.addResourceNames(nameList, url, null, true);
         map = new HashTab(nameList.size());

         for (int i = 0, n = nameList.size(); i < n; ++i)
         {
            String sResource = (String)nameList.get(i);

            if (!sResource.equals(m_sMetadataFileName))
            {
               String sName = (sModule == null) ? sResource : sModule + Metadata.SCOPE_SEP + sResource;
               XMLResource resource = new XMLResource(sName, new URL(url, sResource), bRoot);

               resource.setMixin(mixin);
               map.put(sName, resource);
            }
         }
      }
      catch (Throwable t)
      {
         throw ObjUtil.rethrow(t);
      }

      XMLUtil.withFirstChildElement(element, "Resources", false, new XMLUtil.ElementHandler()
      {
         public void handleElement(Element parent)
         {
            XMLUtil.forEachChildElement(parent, "ResourceRef", new XMLUtil.ElementHandler()
            {
               public void handleElement(Element element)
               {
                  XMLResource resource = (XMLResource)map.get(XMLUtil.getReqStringAttr(element, "resource"));

                  if (resource != null)
                  {
                     resource.setEnabled(isElementEnabled(element));
                  }
View Full Code Here

   public Element mergeDescriptorElements(List baseList, List rootList) throws MetadataException
   {
      Document doc = XMLUtil.parse(new StringReader("<Metadata/>"));
      Element descriptorElement = doc.getDocumentElement();
      Lookup2D resourceMap = new HashTab2D();
      Lookup refNameMap = new LinkedHashTab();
      Lookup mixinMap = new LinkedHashTab();
      String sBaseNamespace = null;
      String sBaseVersion = null;
      String sBaseChecksum = null;
      String sBaseName = null;
      String sBaseRevision = null;
      String sBaseDescription = null;
      String sBaseCoreVersion = null;
      String sBaseModule = null;
      String sBaseOverride = null;
      String sRootNamespace = null;
      String sRootVersion = null;
      String sRootDescription = null;
      String sRootName = null;
      String sRootRevision = null;
      String sRootCoreVersion = null;
      String sRootModule = null;
      String sRootOverride = null;
      Element baseElement = getDescriptorElement(false);
      Element rootElement = getDescriptorElement(true);

      if (baseElement != null)
      {
         sBaseNamespace = XMLUtil.getReqStringAttr(baseElement, "namespace");
         sBaseVersion = XMLUtil.getReqStringAttr(baseElement, "version");
         sBaseName = XMLUtil.getReqStringAttr(baseElement, "name");
         sBaseRevision = XMLUtil.getReqStringAttr(baseElement, "revision");
         sBaseCoreVersion = XMLUtil.getStringAttr(baseElement, "coreVersion");
         sBaseModule = normalizeScope(XMLUtil.getStringAttr(baseElement, "module"));
         sBaseOverride = XMLUtil.getStringAttr(baseElement, "override");
         sBaseDescription = XMLUtil.getStringAttr(baseElement, "description");
         sBaseChecksum = getChecksum(false);
         addMixinElements(mixinMap, baseElement);
         addResourceElements(resourceMap, refNameMap, baseElement);
      }

      if (rootElement != null)
      {
         sRootNamespace = XMLUtil.getReqStringAttr(rootElement, "namespace");
         sRootVersion = XMLUtil.getReqStringAttr(rootElement, "version");
         sRootName = XMLUtil.getReqStringAttr(rootElement, "name");
         sRootRevision = XMLUtil.getReqStringAttr(rootElement, "revision");
         sRootCoreVersion = XMLUtil.getStringAttr(rootElement, "coreVersion");
         sRootModule = normalizeScope(XMLUtil.getStringAttr(rootElement, "module"));
         sRootOverride = XMLUtil.getStringAttr(rootElement, "override");
         sRootDescription = XMLUtil.getStringAttr(rootElement, "description");
         addMixinElements(mixinMap, rootElement);
         addResourceElements(resourceMap, refNameMap, rootElement);

         if (baseElement == null)
         {
            sBaseNamespace = XMLUtil.getStringAttr(rootElement, "baseNamespace");
            sBaseVersion = XMLUtil.getStringAttr(rootElement, "baseVersion");
            sBaseChecksum = XMLUtil.getStringAttr(rootElement, "baseChecksum");
         }
      }
      else
      {
         sRootNamespace = sBaseNamespace;
         sRootVersion = sBaseVersion;
         sRootName = sBaseName;
         sRootRevision = sBaseRevision;
         sRootModule = sBaseModule;
         sRootOverride = sBaseOverride;
         sRootDescription = sBaseDescription;
         sBaseNamespace = null;
         sBaseVersion = null;
         sBaseChecksum = null;
         sBaseModule = null;
         sBaseOverride = null;
         sBaseDescription = null;
      }

      if (sRootCoreVersion == null)
      {
         sRootCoreVersion = sBaseCoreVersion;
      }

      if (sRootNamespace != null)
      {
         descriptorElement.setAttribute("name", sRootName);
         descriptorElement.setAttribute("revision", sRootRevision);
         descriptorElement.setAttribute("namespace", sRootNamespace);
         descriptorElement.setAttribute("version", sRootVersion);

         if (sRootCoreVersion != null)
         {
            descriptorElement.setAttribute("coreVersion", sRootCoreVersion);
         }

         if (sRootModule != null)
         {
            descriptorElement.setAttribute("module", sRootModule);
         }

         if (sRootOverride != null)
         {
            descriptorElement.setAttribute("override", sRootOverride);
         }

         if (sRootDescription != null)
         {
            descriptorElement.setAttribute("description", sRootDescription);
         }
      }

      if (sBaseNamespace != null)
      {
         descriptorElement.setAttribute("baseNamespace", sBaseNamespace);
         descriptorElement.setAttribute("baseVersion", sBaseVersion);
         descriptorElement.setAttribute("baseChecksum", sBaseChecksum);
      }

      // Insert the mixin elements
      Element mixinsElement = doc.createElement("Mixins");

      descriptorElement.appendChild(mixinsElement);

      for (Iterator itr = mixinMap.valueIterator(); itr.hasNext(); )
      {
         Element mixinElement = XMLUtil.addChildElement(mixinsElement, null, "Mixin");
         NamedNodeMap map = ((Element)itr.next()).getAttributes();

         for (int i = 0, n = map.getLength(); i < n; ++i)
         {
            Attr attr = (Attr)map.item(i);

            mixinElement.setAttribute(attr.getName(), attr.getValue());
         }
      }

      // Instantiate all the container elements and place them in a map by name
      Lookup refMap = new HashTab(refNameMap.size());

      for (Lookup.Iterator itr = refNameMap.iterator(); itr.hasNext();)
      {
         Element element = doc.createElement((String)itr.next());

         descriptorElement.appendChild(element);
         refMap.put(itr.getKey(), element);
      }

      // Insert the reference elements
      for (Lookup2D.Iterator itr = resourceMap.valueIterator(); itr.hasNext();)
      {
         Element element = (Element)itr.next();
         Element refElement = doc.createElement((String)refNameMap.get(itr.getKey1()));

         ((Element)refMap.get(itr.getKey1())).appendChild(refElement);

         NamedNodeMap map = element.getAttributes();

         for (int i = 0, n = map.getLength(); i < n; ++i)
         {
            Attr attr = (Attr)map.item(i);

            refElement.setAttribute(attr.getName(), attr.getValue());
         }
      }

      XMLMetadataListing listing = getListing();

      if (rootList != null || baseList != null)
      {
         Set rootSet = new HashHolder();
         Lookup rootMap = listing.getRootResourceMap();

         if (rootMap != null)
         {
            for (Iterator iter = rootMap.iterator(); iter.hasNext(); )
            {
               String sName = (String)iter.next();

               sName = sName.substring(sName.lastIndexOf(Metadata.SCOPE_SEP) + 1);
               rootSet.add(sName);

               if (rootList != null)
               {
                  rootList.add(sName);
               }
            }
         }

         Lookup baseMap = listing.getBaseResourceMap();

         if (baseMap != null && baseList != null)
         {
            for (Iterator iter = baseMap.iterator(); iter.hasNext(); )
            {
               String sName = (String)iter.next();

               sName = sName.substring(sName.lastIndexOf(Metadata.SCOPE_SEP) + 1);
View Full Code Here

    */
   public void addString(String sLocale, String sPath)
   {
      verifyNotReadOnly();

      Lookup map = (Lookup)m_stringMap.get(sLocale);

      if (map == null)
      {
         map = new HashTab();
         m_stringMap.put(sLocale, map);
      }

      Object oldPath = map.put(sPath, sPath);

      if (oldPath != null)
      {
         throw new MetadataException("err.meta.stringDup", new Object[] {sLocale, getName()});
      }
View Full Code Here

TOP

Related Classes of nexj.core.util.Lookup

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.