Package com.webobjects.foundation

Examples of com.webobjects.foundation.NSMutableSet$Itr


       }
       if (allGIDs) {
         result = new NSSet(ERXEOGlobalIDUtilities.fetchObjectsWithGlobalIDs(editingContext, gidful.allObjects()));
       }
       else {
         NSMutableSet eoful = new NSMutableSet();
         objEnum = gidful.objectEnumerator();
         while (objEnum.hasMoreElements()) {
           eoful.addObject(ERXEOControlUtilities.convertGIDtoEO(editingContext, objEnum.nextElement()));
         }
         result = eoful;
       }
     }
     else if (obj instanceof NSDictionary) {
       NSDictionary gidful = (NSDictionary)obj;
       NSMutableDictionary eoful = new NSMutableDictionary();
       Enumeration keyEnum = gidful.keyEnumerator();
       while (keyEnum.hasMoreElements()) {
         Object gidfulKey = keyEnum.nextElement();
         Object eofulKey = ERXEOControlUtilities.convertGIDtoEO(editingContext, gidfulKey);
         Object eofulValue = ERXEOControlUtilities.convertGIDtoEO(editingContext, gidful.objectForKey(gidfulKey));
         eoful.setObjectForKey(eofulValue, eofulKey);
       }
       result = eoful;
     }
     else {
       result = obj;
View Full Code Here


     * @param template to check for keys
     * @param delimiter for finding keys
     * @return array of keys
     */
    public NSArray keysInTemplate(String template, String delimiter) {
        NSMutableSet keys = new NSMutableSet();
        if (delimiter == null) {
            delimiter = DEFAULT_DELIMITER;
        }
        NSArray components = NSArray.componentsSeparatedByString(template, delimiter);
        if (! isLoggingDisabled  &&  log.isDebugEnabled()) {
            log.debug("Components: " + components);
        }
        boolean deriveElement = false; // if the template starts with delim, the first component will be a zero-length string
        for (Enumeration e = components.objectEnumerator(); e.hasMoreElements();) {
            String element = (String)e.nextElement();
            if (deriveElement) {
                if (element.length() == 0) {
                    throw new IllegalArgumentException("\"\" is not a valid keypath");
                }
                keys.addObject(element);
                deriveElement = false;
            } else {
                deriveElement = true;
            }
        }
        return keys.allObjects();
    }   
View Full Code Here

    String name = eomodel.name();
    if (_modelsByName.objectForKey(name) != null) {
      log.warn("The model '" + name + "' (path: " + eomodel.pathURL() + ") cannot be added to model group " + this + " because it already contains a model with that name.");
      return;
    }
    NSMutableSet nsmutableset = new NSMutableSet(128);
    NSSet<String> nsset = new NSSet<String>(eomodel.entityNames());
    while (enumeration.hasMoreElements()) {
      EOModel eomodel1 = (EOModel) enumeration.nextElement();
      nsmutableset.addObjectsFromArray(eomodel1.entityNames());
    }
    NSSet intersection = nsmutableset.setByIntersectingSet(nsset);
    if (intersection.count() != 0) {
      log.warn("The model '" + name + "' (path: " + eomodel.pathURL() + ") has an entity name conflict with the entities " + intersection + " already in the model group " + this);
      Enumeration e = intersection.objectEnumerator();
      while (e.hasMoreElements()) {
        String entityName = (String) e.nextElement();
View Full Code Here

        EOAdaptorOperation adaptorOp = (EOAdaptorOperation) e.userInfo().objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey);
        NSDictionary changedValues = adaptorOp.changedValues();
        EOEntity entity = ERXEOAccessUtilities.entityForEo(eo);
        EOEditingContext ec = eo.editingContext();
        NSArray keys = changedValues.allKeys();
        NSMutableSet relationships = new NSMutableSet();
       
        for (int i=0; i<keys.count(); i++) {
            String key = (String)keys.objectAtIndex(i);
            EOAttribute attrib = entity.attributeNamed(key);
            if (attrib != null) {
                Object val = changedValues.objectForKey(key);
                if(ERXValueUtilities.isNull(val)) {
                  val = null;
                }
                if (entity.classProperties().containsObject(attrib)) {
                    eo.takeValueForKey(val, key);
                }
                NSArray relsUsingAttrib = ERXEOAccessUtilities.relationshipsForAttribute(entity, attrib);
                relationships.addObjectsFromArray(relsUsingAttrib);
            } else {
                log.error("Changed value found that isn't an attribute: " + key + "->" + changedValues.objectForKey(key));
            }
        }

        for (Enumeration enumerator = relationships.objectEnumerator(); enumerator.hasMoreElements();) {
            EORelationship relationship = (EORelationship) enumerator.nextElement();
            NSMutableDictionary pk = EOUtilities.destinationKeyForSourceObject(ec, eo, relationship.name()).mutableClone();
            for (int i=0; i<keys.count(); i++) {
                String key = (String)keys.objectAtIndex(i);
                if(pk.objectForKey(key) != null) {
View Full Code Here

    * test cases.
    *
    * @return a set of strings that describe the mismatches that occurred
    */
   public static NSSet verifyAllSnapshots() {
     NSMutableSet mismatches = new NSMutableSet();
     NSMutableSet verifiedDatabases = new NSMutableSet();
     EOEditingContext editingContext = ERXEC.newEditingContext();
     EOModelGroup modelGroup = EOModelGroup.defaultGroup();
     Enumeration modelsEnum = modelGroup.models().objectEnumerator();
     while (modelsEnum.hasMoreElements()) {
       EOModel model = (EOModel) modelsEnum.nextElement();
       EODatabaseContext databaseContext = null;
       try {
         databaseContext = EODatabaseContext.registeredDatabaseContextForModel(model, editingContext);
       }
       catch (IllegalStateException e) {
         log.warn("Model " + model.name() + " failed: " + e.getMessage());
       }
       if (databaseContext != null) {
         databaseContext.lock();
         try {
           EODatabase database = databaseContext.database();
           if (!verifiedDatabases.containsObject(database)) {
             Enumeration gidEnum = database.snapshots().keyEnumerator();
             while (gidEnum.hasMoreElements()) {
               EOGlobalID gid = (EOGlobalID) gidEnum.nextElement();
               if (gid instanceof EOKeyGlobalID) {
                 EOEnterpriseObject eo = null;
                 EOKeyGlobalID keyGID = (EOKeyGlobalID) gid;
                 String entityName = keyGID.entityName();
                 EOEntity entity = modelGroup.entityNamed(entityName);
                 NSDictionary snapshot = database.snapshotForGlobalID(gid);
                 if (snapshot != null) {
                   EOQualifier gidQualifier = entity.qualifierForPrimaryKey(entity.primaryKeyForGlobalID(gid));
                   EOFetchSpecification gidFetchSpec = new EOFetchSpecification(entityName, gidQualifier, null);

                   NSMutableDictionary databaseSnapshotClone;
                   NSMutableDictionary memorySnapshotClone = snapshot.mutableClone();
                   EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
                   channel.openChannel();
                   channel.selectAttributes(entity.attributesToFetch(), gidFetchSpec, false, entity);
                   try {
                     databaseSnapshotClone = channel.fetchRow().mutableClone();
                   }
                   finally {
                     channel.cancelFetch();
                   }
                   // gidFetchSpec.setRefreshesRefetchedObjects(true);
                   // NSArray databaseEOs = editingContext.objectsWithFetchSpecification(gidFetchSpec);
                   if (databaseSnapshotClone == null) {
                     mismatches.addObject(gid + " was deleted in the database, but the snapshot still exists: " + memorySnapshotClone);
                   }
                   else {
                     // NSMutableDictionary refreshedSnapshotClone =
                     // database.snapshotForGlobalID(gid).mutableClone();
                     ERXDictionaryUtilities.removeMatchingEntries(memorySnapshotClone, databaseSnapshotClone);
                     if (databaseSnapshotClone.count() > 0 || memorySnapshotClone.count() > 0) {
                       mismatches.addObject(gid + " doesn't match the database: original = " + memorySnapshotClone + "; database = " + databaseSnapshotClone);
                     }
                     eo = (EOEnterpriseObject) editingContext.objectsWithFetchSpecification(gidFetchSpec).objectAtIndex(0);
                   }
                 }

                 if (eo != null) {
                   Enumeration relationshipsEnum = entity.relationships().objectEnumerator();
                   while (relationshipsEnum.hasMoreElements()) {
                     EORelationship relationship = (EORelationship) relationshipsEnum.nextElement();
                     String relationshipName = relationship.name();
                     NSArray originalDestinationGIDs = database.snapshotForSourceGlobalID(keyGID, relationshipName);
                     if (originalDestinationGIDs != null) {
                       NSMutableArray newDestinationGIDs = new NSMutableArray();
                       EOQualifier qualifier = relationship.qualifierWithSourceRow(database.snapshotForGlobalID(keyGID));
                       EOFetchSpecification relationshipFetchSpec = new EOFetchSpecification(entityName, qualifier, null);
                       EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
                       channel.openChannel();
                       try {
                         channel.selectAttributes(relationship.destinationEntity().attributesToFetch(), relationshipFetchSpec, false, relationship.destinationEntity());
                         NSDictionary destinationSnapshot = null;
                         do {
                           destinationSnapshot = channel.fetchRow();
                           if (destinationSnapshot != null) {
                             EOGlobalID destinationGID = relationship.destinationEntity().globalIDForRow(destinationSnapshot);
                             newDestinationGIDs.addObject(destinationGID);
                           }
                         }
                         while (destinationSnapshot != null);
                       }
                       finally {
                         channel.cancelFetch();
                       }

                       NSArray objectsNotInDatabase = ERXArrayUtilities.arrayMinusArray(originalDestinationGIDs, newDestinationGIDs);
                       if (objectsNotInDatabase.count() > 0) {
                         mismatches.addObject(gid + "." + relationshipName + " has entries not in the database: " + objectsNotInDatabase);
                       }
                       NSArray objectsNotInMemory = ERXArrayUtilities.arrayMinusArray(newDestinationGIDs, originalDestinationGIDs);
                       if (objectsNotInMemory.count() > 0) {
                         mismatches.addObject(gid + "." + relationshipName + " is missing entries in the database: " + objectsNotInMemory);
                       }
                     }
                   }
                 }
               }
             }
             verifiedDatabases.addObject(database);
           }
         }
         finally {
           databaseContext.unlock();
         }
View Full Code Here

     *            EOEntity to return list of referencing entities for
     * @return list of names of entities previously recorded as referencing this
     *         entity
     */
    protected NSMutableSet entitiesDependentOn(NSMutableDictionary dependencies, EOEntity entity) {
        NSMutableSet referencingEntities = (NSMutableSet) dependencies.objectForKey(dependencyKeyFor(entity));
        if (referencingEntities == null) {
            referencingEntities = new NSMutableSet();
            dependencies.setObjectForKey(referencingEntities, dependencyKeyFor(entity));
        }
        return referencingEntities;
    }
View Full Code Here

        if (log.isDebugEnabled())
            log.debug("Registering Observer for file at path: " + filePath);
        // Register last modified date.
        registerLastModifiedDateForFile(file);
        // FIXME: This retains the observer.  This is not ideal.  With the 1.3 JDK we can use a ReferenceQueue to maintain weak references.
        NSMutableSet observerSet = (NSMutableSet)_observersByFilePath.objectForKey(filePath);
        if (observerSet == null) {
            observerSet = new NSMutableSet();
            _observersByFilePath.setObjectForKey(observerSet, filePath);
        }
        observerSet.addObject(new _ObserverSelectorHolder(observer, selector));
    }
View Full Code Here

     * Only used internally. Notifies all of the observers who have been registered for the
     * given file.
     * @param file file that has changed
     */
    protected void fileHasChanged(File file) {
        NSMutableSet observers = (NSMutableSet)_observersByFilePath.objectForKey(cacheKeyForFile(file));
        if (observers == null)
            log.warn("Unable to find observers for file: " + file);
        else {
            NSNotification notification = new NSNotification(FileDidChange, file);
            for (Enumeration e = observers.objectEnumerator(); e.hasMoreElements();) {
                _ObserverSelectorHolder holder = (_ObserverSelectorHolder)e.nextElement();
                try {
                    holder.selector.invoke(holder.observer, notification);
                } catch (Exception ex) {
                    log.error("Catching exception when invoking method on observer: " + ex.toString()+" - "+ERXUtilities.stackTrace(ex));
View Full Code Here

    }

    public NSArray allTests() {
        if(allTests == null) {
            String thisBundleName = NSBundle.bundleForClass(getClass()).name();
            NSMutableSet theClassNames = new NSMutableSet();
            Enumeration bundleEnum = bundles().objectEnumerator();
            while (bundleEnum.hasMoreElements()) {
                NSBundle bundle = (NSBundle)bundleEnum.nextElement();
                if (!bundle.name().equals(thisBundleName)) {
                    Enumeration classNameEnum = bundle.bundleClassNames().objectEnumerator();
                    while (classNameEnum.hasMoreElements()) {
                        String className = (String)classNameEnum.nextElement();
                        if (className != null
                            && ( className.endsWith( "Test" ) || className.endsWith( "TestCase" ) || className.indexOf("tests.") == 0 || className.indexOf(".tests.") > 0)
                            && !className.startsWith( "junit." )
                            && className.indexOf( "$" ) < 0) {
                          try {
                            Class c = ERXPatcher.classForName(className);
                            //if(c != null && c.isAssignableFrom(TestCase.class))
                              theClassNames.addObject(munge(className));
                          } catch(Exception ex) {
                            // ignored
                            log.warn("Skipping test " + className + ": " + ex);
                          }
                        }
                    }
                }
            }
            allTests = theClassNames.allObjects();
            try {
                allTests = allTests.sortedArrayUsingComparator(NSComparator.AscendingStringComparator);
            } catch (Exception ex) {
                log.warn(ex);
                // so we won't get sorted, oh well :)
View Full Code Here

    boolean should = true;

    NSArray deletedObjects = (NSArray) notification.userInfo().objectForKey("deleted");
    int deletedCount = deletedObjects != null ? deletedObjects.count() : 0;
    if ((deletedObjects != null) && (deletedCount != 0)) {
      NSMutableSet allHash = new NSMutableSet(_allObjects);
      NSMutableSet displayedHash = null;
      NSMutableSet selectedHash = null;
      boolean rebuildAll = false;
      boolean rebuildDisplayed = false;
      boolean rebuildSelected = false;
      for (int i = 0; i < deletedCount; i++) {
        Object deletedObject = deletedObjects.objectAtIndex(i);
        if (allHash.containsObject(deletedObject)) {
          allHash.removeObject(deletedObject);
          rebuildAll = true;
          if (displayedHash == null) {
            displayedHash = new NSMutableSet(_displayedObjects);
          }
          if (displayedHash.containsObject(deletedObject)) {
            displayedHash.removeObject(deletedObject);
            rebuildDisplayed = true;
            if (selectedHash == null) {
              /*
               * Updated to use lazy loading accessor method since
               * _selectedObjects is null after deserialization,
               * resulting in a NullPointerException in the
               * NSMutableSet constructor
               */
              selectedHash = new NSMutableSet(selectedObjects());
            }
            if (selectedHash.containsObject(deletedObject)) {
              selectedHash.removeObject(deletedObject);
              rebuildSelected = true;
            }
          }
        }
      }

      if (rebuildAll) {
        _allObjects = new NSMutableArray(allHash.allObjects());
        if (rebuildDisplayed) {
          for (int i = _displayedObjects.count() - 1; i >= 0; i--) {
            Object displayedObject = _displayedObjects.objectAtIndex(i);
            if ((displayedHash == null) || (!displayedHash.containsObject(displayedObject))) {
              _displayedObjects.removeObjectAtIndex(i);
            }
          }
          if ((selectedHash != null) && (rebuildSelected)) {
            _selectedObjects = new NSMutableArray(selectedHash.allObjects());
          }
          _selection = _NSArrayUtilities.indexesForObjectsIndenticalTo(_displayedObjects, _selectedObjects);
        }

      }
View Full Code Here

TOP

Related Classes of com.webobjects.foundation.NSMutableSet$Itr

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.