// $LastChangedRevision: 4748 $ DO NOT EDIT.  Make changes to WiwoNameSpaceDefinition.java instead.
package mildo.wiwo.data;

import com.webobjects.eoaccess.*;
import com.webobjects.eocontrol.*;
import com.webobjects.foundation.*;
import java.math.*;
import java.util.*;

public abstract class _WiwoNameSpaceDefinition extends  EOGenericRecord {
	public static final String ENTITY_NAME = "WiwoNameSpaceDefinition";

	// Attributes
	public static final String DESCRIPTION_KEY = "description";
	public static final String NAME_KEY = "name";

	// Relationships
	public static final String WIWO_PAGES_KEY = "wiwoPages";

  public WiwoNameSpaceDefinition localInstanceOfWiwoNameSpaceDefinitionIn(EOEditingContext editingContext) {
    WiwoNameSpaceDefinition localInstance = (WiwoNameSpaceDefinition)EOUtilities.localInstanceOfObject(editingContext, this);
    if (localInstance == null) {
      throw new IllegalStateException("You attempted to localInstance " + this + ", which has not yet committed.");
    }
    return localInstance;
  }

  public String description() {
    return (String) storedValueForKey("description");
  }

  public void setDescription(String value) {
    takeStoredValueForKey(value, "description");
  }

  public String name() {
    return (String) storedValueForKey("name");
  }

  public void setName(String value) {
    takeStoredValueForKey(value, "name");
  }

  public NSArray wiwoPages() {
    return (NSArray)storedValueForKey("wiwoPages");
  }

  public NSArray wiwoPages(EOQualifier qualifier) {
    return wiwoPages(qualifier, null);
  }

  public NSArray wiwoPages(EOQualifier qualifier, NSArray sortOrderings) {
    NSArray results;
      results = wiwoPages();
      if (qualifier != null) {
        results = (NSArray)EOQualifier.filteredArrayWithQualifier(results, qualifier);
      }
      if (sortOrderings != null) {
        results = (NSArray)EOSortOrdering.sortedArrayUsingKeyOrderArray(results, sortOrderings);
      }
    return results;
  }
  
  public void addToWiwoPagesRelationship(mildo.wiwo.data.WiwoPage object) {
    addObjectToBothSidesOfRelationshipWithKey(object, "wiwoPages");
  }

  public void removeFromWiwoPagesRelationship(mildo.wiwo.data.WiwoPage object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "wiwoPages");
  }

  public mildo.wiwo.data.WiwoPage createWiwoPagesRelationship() {
    EOClassDescription eoClassDesc = EOClassDescription.classDescriptionForEntityName("WiwoPage");
    EOEnterpriseObject eo = eoClassDesc.createInstanceWithEditingContext(editingContext(), null);
    editingContext().insertObject(eo);
    addObjectToBothSidesOfRelationshipWithKey(eo, "wiwoPages");
    return (mildo.wiwo.data.WiwoPage) eo;
  }

  public void deleteWiwoPagesRelationship(mildo.wiwo.data.WiwoPage object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "wiwoPages");
    editingContext().deleteObject(object);
  }

  public void deleteAllWiwoPagesRelationships() {
    Enumeration objects = wiwoPages().immutableClone().objectEnumerator();
    while (objects.hasMoreElements()) {
      deleteWiwoPagesRelationship((mildo.wiwo.data.WiwoPage)objects.nextElement());
    }
  }


  public static WiwoNameSpaceDefinition createWiwoNameSpaceDefinition(EOEditingContext editingContext, String description
, String name
) {
    WiwoNameSpaceDefinition eo = (WiwoNameSpaceDefinition) EOUtilities.createAndInsertInstance(editingContext, _WiwoNameSpaceDefinition.ENTITY_NAME);    
		eo.setDescription(description);
		eo.setName(name);
    return eo;
  }

  public static NSArray fetchAllWiwoNameSpaceDefinitions(EOEditingContext editingContext) {
    return _WiwoNameSpaceDefinition.fetchAllWiwoNameSpaceDefinitions(editingContext, null);
  }

  public static NSArray fetchAllWiwoNameSpaceDefinitions(EOEditingContext editingContext, NSArray sortOrderings) {
    return _WiwoNameSpaceDefinition.fetchWiwoNameSpaceDefinitions(editingContext, null, sortOrderings);
  }

  public static NSArray fetchWiwoNameSpaceDefinitions(EOEditingContext editingContext, EOQualifier qualifier, NSArray sortOrderings) {
    EOFetchSpecification fetchSpec = new EOFetchSpecification(_WiwoNameSpaceDefinition.ENTITY_NAME, qualifier, sortOrderings);
    fetchSpec.setIsDeep(true);
    NSArray eoObjects = (NSArray)editingContext.objectsWithFetchSpecification(fetchSpec);
    return eoObjects;
  }

  public static WiwoNameSpaceDefinition fetchWiwoNameSpaceDefinition(EOEditingContext editingContext, String keyName, Object value) {
    return _WiwoNameSpaceDefinition.fetchWiwoNameSpaceDefinition(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
  }

  public static WiwoNameSpaceDefinition fetchWiwoNameSpaceDefinition(EOEditingContext editingContext, EOQualifier qualifier) {
    NSArray eoObjects = _WiwoNameSpaceDefinition.fetchWiwoNameSpaceDefinitions(editingContext, qualifier, null);
    WiwoNameSpaceDefinition eoObject;
    int count = eoObjects.count();
    if (count == 0) {
      eoObject = null;
    }
    else if (count == 1) {
      eoObject = (WiwoNameSpaceDefinition)eoObjects.objectAtIndex(0);
    }
    else {
      throw new IllegalStateException("There was more than one WiwoNameSpaceDefinition that matched the qualifier '" + qualifier + "'.");
    }
    return eoObject;
  }

  public static WiwoNameSpaceDefinition fetchRequiredWiwoNameSpaceDefinition(EOEditingContext editingContext, String keyName, Object value) {
    return _WiwoNameSpaceDefinition.fetchRequiredWiwoNameSpaceDefinition(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
  }

  public static WiwoNameSpaceDefinition fetchRequiredWiwoNameSpaceDefinition(EOEditingContext editingContext, EOQualifier qualifier) {
    WiwoNameSpaceDefinition eoObject = _WiwoNameSpaceDefinition.fetchWiwoNameSpaceDefinition(editingContext, qualifier);
    if (eoObject == null) {
      throw new NoSuchElementException("There was no WiwoNameSpaceDefinition that matched the qualifier '" + qualifier + "'.");
    }
    return eoObject;
  }

  public static WiwoNameSpaceDefinition localInstanceOfWiwoNameSpaceDefinitionIn(EOEditingContext editingContext, WiwoNameSpaceDefinition eo) {
    WiwoNameSpaceDefinition localInstance = (eo == null) ? null : (WiwoNameSpaceDefinition)EOUtilities.localInstanceOfObject(editingContext, eo);
    if (localInstance == null && eo != null) {
      throw new IllegalStateException("You attempted to localInstance " + eo + ", which has not yet committed.");
    }
    return localInstance;
  }
}
