Examples of EOClassDescription


Examples of com.webobjects.eocontrol.EOClassDescription

      // classDescription = entity.classDescriptionForInstances();
    }
  }

  public static EOArrayDataSource dataSourceForObjects(EOEditingContext ec, NSArray list) {
    EOClassDescription cd = null;
    NSMutableArray objects = new NSMutableArray();
    for (Enumeration iter = list.objectEnumerator(); iter.hasMoreElements();) {
      Object o = iter.nextElement();

      EOEnterpriseObject eo = recordForObject(ec, o);
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

                }
                               
                for (Enumeration ee = model.entities().objectEnumerator(); ee.hasMoreElements();) {
                    EOEntity entity = (EOEntity)ee.nextElement();
                    checkForeignKeys(entity);
                    EOClassDescription cd = EOClassDescription.classDescriptionForEntityName(entity.name());
                    defaultLog.debug("Reading defaults for: " + entity.name());
                    if(cd instanceof ERXEntityClassDescription) {
                        ((ERXEntityClassDescription)cd).readDefaultValues();

                        if(isRapidTurnaroundEnabled() && modelPath != null) {
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

            Object defaultValue = stringValue;
            EOEditingContext ec = eo.editingContext();

            if(stringValue.charAt(0) == '@') { // computed key
                if(stringValue.equals("@new")) {
                    EOClassDescription cd = EOClassDescription.classDescriptionForEntityName(relationshipEntityName);
                    EOEnterpriseObject newObject = cd.createInstanceWithEditingContext(eo.editingContext(), null);
                    ec.insertObject(newObject);
                    eo.addObjectToBothSidesOfRelationshipWithKey(newObject,key);
                } else if(stringValue.startsWith("@threadStorage.")) {
                    String keyPath = stringValue.substring("@threadStorage.".length());
                    Object o = ERXThreadStorage.valueForKey(keyPath);
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

    NSMutableDictionary row = null;
    if (hasMoreRowsToReturn()) {
      try {
        int docId = _fetchedDocs.scoreDocs[_fetchIndex++].doc;
        Document doc = searcher().doc(docId);
        EOClassDescription cd = EOClassDescription.classDescriptionForEntityName(_entity.name());
        NSMutableDictionary dict = cd._newDictionaryForProperties();
        for (IndexAttribute attr : _indexAttributes) {
          String name = attr.attribute().name();
          String columnName = attr.attribute().columnName();
          Field field = doc.getField(columnName);
          Object value = null;
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

      }
      obj = objs;
    }
    else {
      String finalEntityName = entityName(entityName);
      EOClassDescription classDescription = ERXRestClassDescriptionFactory.classDescriptionForEntityName(entityName);
      if (classDescription == null) {
        throw new IllegalArgumentException("There is no registered entity with the name '" + finalEntityName + "'.");
      }
      obj = IERXRestDelegate.Factory.delegateForClassDescription(classDescription).objectOfEntityWithID(classDescription, id(), context);
      if (keyFilter != null) {
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

    // MS: if there is no type, just return the value of this object
    if (finalEntityName == null) {
      return value();
    }
   
    EOClassDescription classDescription = ERXRestClassDescriptionFactory.classDescriptionForEntityName(finalEntityName);
    if (classDescription == null) {
      throw new IllegalArgumentException("There is no registered entity with the name '" + finalEntityName + "'.");
    }
    Object obj = IERXRestDelegate.Factory.delegateForClassDescription(classDescription).createObjectOfEntityWithID(classDescription, id(), context);
    if (keyFilter != null) {
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

      if (!remainingKeys.isEmpty()) {
        // this is sort of expensive, but we want to support non-eomodel to-many relationships on EO's, so
        // we fallback and lookup the class entity ...
        if (classDescription instanceof EOEntityClassDescription) {
          // EOEntityClassDescription.classDescriptionForEntityName(obj.getClass().getName());
          EOClassDescription nonModelClassDescription = ERXRestClassDescriptionFactory.classDescriptionForObject(obj, true);
          for (ERXKey<?> remainingKey : remainingKeys) {
            String keyName = remainingKey.key();
            if (nonModelClassDescription.attributeKeys().containsObject(keyName)) {
              _addAttributeNodeForKeyInObject(remainingKey, obj, keyFilter);
            }
            else if (nonModelClassDescription.toManyRelationshipKeys().containsObject(keyName)) {
              _addToManyRelationshipNodeForKeyOfEntityInObject(remainingKey, nonModelClassDescription.classDescriptionForDestinationKey(keyName), obj, keyFilter, context, visitedObjects);
            }
            else if (nonModelClassDescription.toOneRelationshipKeys().containsObject(keyName)) {
              _addToOneRelationshipNodeForKeyInObject(remainingKey, obj, nonModelClassDescription.classDescriptionForDestinationKey(keyName), keyFilter, context, visitedObjects);
            }
            else if (nonModelClassDescription instanceof BeanInfoClassDescription && ((BeanInfoClassDescription) nonModelClassDescription).isAttributeMethod(keyName)) {
              _addAttributeNodeForKeyInObject(remainingKey, obj, keyFilter);
            }
            else if (nonModelClassDescription instanceof BeanInfoClassDescription && ((BeanInfoClassDescription) nonModelClassDescription).isToManyMethod(keyName)) {
              _addToManyRelationshipNodeForKeyOfEntityInObject(remainingKey, nonModelClassDescription.classDescriptionForDestinationKey(keyName), obj, keyFilter, context, visitedObjects);
            }
            else if (nonModelClassDescription instanceof BeanInfoClassDescription && ((BeanInfoClassDescription) nonModelClassDescription).isToOneMethod(keyName)) {
              _addToOneRelationshipNodeForKeyInObject(remainingKey, obj, nonModelClassDescription.classDescriptionForDestinationKey(keyName), keyFilter, context, visitedObjects);
            }
            else if (!keyFilter.isUnknownKeyIgnored()) {
              throw new IllegalArgumentException("This key filter specified that the key '" + keyName + "' should be included on '" + nonModelClassDescription.entityName() + "', but it does not exist.");
            }
          }
        }
        else if (classDescription instanceof BeanInfoClassDescription) {
          BeanInfoClassDescription beanInfoClassDescription = (BeanInfoClassDescription) classDescription;
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

  public void updateObjectWithFilter(Object obj, ERXKeyFilter keyFilter, ERXRestContext context) {
    if (obj == null) {
      return;
    }

    EOClassDescription classDescription = ERXRestClassDescriptionFactory.classDescriptionForObject(obj, false);
    for (Map.Entry<String, Object> attribute : _attributes.entrySet()) {
      ERXKey<Object> key = keyFilter.keyMap(new ERXKey<Object>(attribute.getKey()));
      String keyName = key.key();
      if (keyFilter.matches(key, ERXKey.Type.Attribute) && isClassProperty(classDescription, keyName)) {
        Object value = ERXRestUtils.coerceValueToAttributeType(attribute.getValue(), null, obj, keyName, context);
        if (value instanceof NSKeyValueCoding.Null) {
          value = null;
        }
        _safeWillTakeValueForKey(keyFilter, obj, value, keyName);
        key.takeValueInObject(value, obj);
        _safeDidTakeValueForKey(keyFilter, obj, value, keyName);
      }
      else {
        _safeDidSkipValueForKey(keyFilter, obj, attribute.getValue(), keyName); // MS: we didn't coerce the
        // value .. i think that's ok
      }
    }

    for (ERXRestRequestNode childNode : _children) {
      ERXKey<Object> key = keyFilter.keyMap(new ERXKey<Object>(childNode.name()));
      String keyName = key.key();
      if (isClassProperty(classDescription, keyName)) {
        NSKeyValueCoding._KeyBinding binding = NSKeyValueCoding.DefaultImplementation._keyGetBindingForKey(obj, keyName);
        Class<?> valueType = binding.valueType();
        if (valueType == Object.class) {
          if (childNode.isArray()) {
            valueType = NSArray.class;
          }
          else {
            Object childValue = childNode.value();
            if (childValue != null) {
              valueType = childValue.getClass();
            }
          }
        }

        if (List.class.isAssignableFrom(valueType) && keyFilter.matches(key, ERXKey.Type.ToManyRelationship)) {
          EOClassDescription destinationClassDescription;
          // this is sort of expensive, but we want to support non-eomodel to-many relationships on EO's, so
          // we fallback and lookup the class entity ...
          if (!classDescription.toManyRelationshipKeys().containsObject(keyName) && classDescription instanceof EOEntityClassDescription) {
            EOClassDescription nonModelClassDescription = ERXRestClassDescriptionFactory.classDescriptionForObject(obj, true);
            if (!nonModelClassDescription.toManyRelationshipKeys().containsObject(keyName)) {
              throw new IllegalArgumentException("There is no to-many relationship named '" + key.key() + "' on '" + classDescription.entityName() + "'.");
            }
            destinationClassDescription = classDescription.classDescriptionForDestinationKey(keyName);
          }
          else {
            destinationClassDescription = classDescription.classDescriptionForDestinationKey(keyName);
          }
          if (destinationClassDescription == null) {
            if (keyFilter.isUnknownKeyIgnored()) {
              continue;
            }
            else {
              throw new NSKeyValueCoding.UnknownKeyException("There is no key '" + keyName + "' on this object.", obj, keyName);
            }
          }
          boolean lockedRelationship = keyFilter.lockedRelationship(key);

          @SuppressWarnings("unchecked")
          List<Object> existingValues = (List<Object>) NSKeyValueCoding.DefaultImplementation.valueForKey(obj, keyName);

          Set<Object> removedValues;
          if (existingValues == null) {
            removedValues = new HashSet<Object>();
          }
          else {
            removedValues = new HashSet<Object>(existingValues);
          }
          List<Object> newValues = new LinkedList<Object>();
          List<Object> allValues = new LinkedList<Object>();
          for (ERXRestRequestNode toManyNode : childNode.children()) {
            Object id = toManyNode.id();

            if (toManyNode.type() != null) {
              destinationClassDescription = ERXRestClassDescriptionFactory.classDescriptionForEntityName(toManyNode.type());
            }

            Object childObj;
            if (toManyNode.children().count() == 0 && ERXRestUtils.isPrimitive(toManyNode.value())) {
              if (lockedRelationship) {
                childObj = null;
              }
              else {
                if (toManyNode.value() != null) {
                  childObj = toManyNode.value();
                } else {
                  childObj = IERXRestDelegate.Factory.delegateForClassDescription(destinationClassDescription).objectOfEntityWithID(destinationClassDescription, id, context);
                }
              }
            }
            else if (id == null) {
              if (lockedRelationship) {
                childObj = null;
              }
              else {
                childObj = IERXRestDelegate.Factory.delegateForClassDescription(destinationClassDescription).createObjectOfEntityWithID(destinationClassDescription, id, context);
              }
            }
            else {
              childObj = IERXRestDelegate.Factory.delegateForClassDescription(destinationClassDescription).objectOfEntityWithID(destinationClassDescription, id, context);
            }

            if (childObj != null) {
              boolean newMemberOfRelationship = existingValues == null || !existingValues.contains(childObj);
              if (newMemberOfRelationship) {
                if (!lockedRelationship) {
                  toManyNode.updateObjectWithFilter(childObj, keyFilter._filterForKey(key), context);
                  newValues.add(childObj);
                  allValues.add(childObj);
                }
              }
              else {
                toManyNode.updateObjectWithFilter(childObj, keyFilter._filterForKey(key), context);
                allValues.add(childObj);
              }
              removedValues.remove(childObj);
            }
          }

          if (!lockedRelationship) {
            _safeWillTakeValueForKey(keyFilter, obj, allValues, keyName);
            if (obj instanceof EOEnterpriseObject) {
              for (Object removedValue : removedValues) {
                ((EOEnterpriseObject) obj).removeObjectFromBothSidesOfRelationshipWithKey((EOEnterpriseObject) removedValue, keyName);
              }
              for (Object newValue : newValues) {
                ((EOEnterpriseObject) obj).addObjectToBothSidesOfRelationshipWithKey((EOEnterpriseObject) newValue, keyName);
              }
            }
            else {
              key.takeValueInObject(allValues, obj);
            }
            _safeDidTakeValueForKey(keyFilter, obj, allValues, keyName);
          }
          else {
            _safeDidSkipValueForKey(keyFilter, obj, allValues, keyName);
          }
        }
        else if (!ERXRestUtils.isPrimitive(valueType) && keyFilter.matches(key, ERXKey.Type.ToOneRelationship)) {
          EOClassDescription destinationClassDescription;
          // this is sort of expensive, but we want to support non-eomodel to-one relationships on EO's, so
          // we fallback and lookup the class entity ...
          if (!classDescription.toOneRelationshipKeys().containsObject(keyName) && classDescription instanceof EOEntityClassDescription) {
            EOClassDescription nonModelClassDescription = ERXRestClassDescriptionFactory.classDescriptionForObject(obj, true);
            if (!nonModelClassDescription.toOneRelationshipKeys().containsObject(keyName)) {
              throw new IllegalArgumentException("There is no to-one relationship named '" + key.key() + "' on '" + classDescription.entityName() + "'.");
            }
            destinationClassDescription = nonModelClassDescription.classDescriptionForDestinationKey(keyName);
          }
          else {
            destinationClassDescription = classDescription.classDescriptionForDestinationKey(keyName);
          }
          if (destinationClassDescription == null) {
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

   *            the filter to use
   * @return the root ERXRestRequestNode
   */
  public static ERXRestRequestNode requestNodeWithObjectAndFilter(Object obj, ERXKeyFilter keyFilter, ERXRestContext context) {
    String shortName = null;
    EOClassDescription classDescription = null;
    if (obj != null) {
      classDescription = ERXRestClassDescriptionFactory.classDescriptionForObject(obj, false);
      shortName = classDescription.entityName();
    }
    ERXRestRequestNode requestNode = new ERXRestRequestNode(shortName, true);
    if (ERXRestUtils.isPrimitive(obj)) {
      requestNode.setValue(obj);
    }
View Full Code Here

Examples of com.webobjects.eocontrol.EOClassDescription

   *            the controller class
   */
  public void addDefaultRoutes(String entityName, Class<? extends ERXRouteController> controllerClass) {
    // MS: We should probably remove all of the "boolean numericPKs" attributes for registration, but I don't
    // want to do that so soon after the initial screencast of using the APIs.
    EOClassDescription classDescription = ERXRestClassDescriptionFactory.classDescriptionForEntityName(entityName);
    boolean numericPKs = IERXRestDelegate.Factory.delegateForClassDescription(classDescription).__hasNumericPrimaryKeys(classDescription);
    addDefaultRoutes(entityName, numericPKs, controllerClass);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.