// $LastChangedRevision: 4748 $ DO NOT EDIT.  Make changes to WiwoPage.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 _WiwoPage extends  EOGenericRecord {
	public static final String ENTITY_NAME = "WiwoPage";

	// Attributes
	public static final String NAME_KEY = "name";
	public static final String VERSION_DATE_KEY = "versionDate";
	public static final String VERSION_TAG_KEY = "versionTag";
	public static final String WIKI_MARKUP_KEY = "wikiMarkup";

	// Relationships
	public static final String NAME_SPACE_DEFINITIONS_KEY = "nameSpaceDefinitions";
	public static final String PREVIOUS_VERSION_KEY = "previousVersion";
	public static final String USER_KEY = "user";

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

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

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

  public NSTimestamp versionDate() {
    return (NSTimestamp) storedValueForKey("versionDate");
  }

  public void setVersionDate(NSTimestamp value) {
    takeStoredValueForKey(value, "versionDate");
  }

  public Integer versionTag() {
    return (Integer) storedValueForKey("versionTag");
  }

  public void setVersionTag(Integer value) {
    takeStoredValueForKey(value, "versionTag");
  }

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

  public void setWikiMarkup(String value) {
    takeStoredValueForKey(value, "wikiMarkup");
  }

  public mildo.wiwo.data.WiwoPage previousVersion() {
    return (mildo.wiwo.data.WiwoPage)storedValueForKey("previousVersion");
  }

  public void setPreviousVersionRelationship(mildo.wiwo.data.WiwoPage value) {
    if (value == null) {
    	mildo.wiwo.data.WiwoPage oldValue = previousVersion();
    	if (oldValue != null) {
    		removeObjectFromBothSidesOfRelationshipWithKey(oldValue, "previousVersion");
      }
    } else {
    	addObjectToBothSidesOfRelationshipWithKey(value, "previousVersion");
    }
  }
  
  public mildo.wiwo.data.WiwoUser user() {
    return (mildo.wiwo.data.WiwoUser)storedValueForKey("user");
  }

  public void setUserRelationship(mildo.wiwo.data.WiwoUser value) {
    if (value == null) {
    	mildo.wiwo.data.WiwoUser oldValue = user();
    	if (oldValue != null) {
    		removeObjectFromBothSidesOfRelationshipWithKey(oldValue, "user");
      }
    } else {
    	addObjectToBothSidesOfRelationshipWithKey(value, "user");
    }
  }
  
  public NSArray nameSpaceDefinitions() {
    return (NSArray)storedValueForKey("nameSpaceDefinitions");
  }

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

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

  public void removeFromNameSpaceDefinitionsRelationship(mildo.wiwo.data.WiwoNameSpaceDefinition object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "nameSpaceDefinitions");
  }

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

  public void deleteNameSpaceDefinitionsRelationship(mildo.wiwo.data.WiwoNameSpaceDefinition object) {
    removeObjectFromBothSidesOfRelationshipWithKey(object, "nameSpaceDefinitions");
    editingContext().deleteObject(object);
  }

  public void deleteAllNameSpaceDefinitionsRelationships() {
    Enumeration objects = nameSpaceDefinitions().immutableClone().objectEnumerator();
    while (objects.hasMoreElements()) {
      deleteNameSpaceDefinitionsRelationship((mildo.wiwo.data.WiwoNameSpaceDefinition)objects.nextElement());
    }
  }


  public static WiwoPage createWiwoPage(EOEditingContext editingContext, String name
, NSTimestamp versionDate
, Integer versionTag
, String wikiMarkup
, mildo.wiwo.data.WiwoUser user) {
    WiwoPage eo = (WiwoPage) EOUtilities.createAndInsertInstance(editingContext, _WiwoPage.ENTITY_NAME);    
		eo.setName(name);
		eo.setVersionDate(versionDate);
		eo.setVersionTag(versionTag);
		eo.setWikiMarkup(wikiMarkup);
    eo.setUserRelationship(user);
    return eo;
  }

  public static NSArray fetchAllWiwoPages(EOEditingContext editingContext) {
    return _WiwoPage.fetchAllWiwoPages(editingContext, null);
  }

  public static NSArray fetchAllWiwoPages(EOEditingContext editingContext, NSArray sortOrderings) {
    return _WiwoPage.fetchWiwoPages(editingContext, null, sortOrderings);
  }

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

  public static WiwoPage fetchWiwoPage(EOEditingContext editingContext, String keyName, Object value) {
    return _WiwoPage.fetchWiwoPage(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
  }

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

  public static WiwoPage fetchRequiredWiwoPage(EOEditingContext editingContext, String keyName, Object value) {
    return _WiwoPage.fetchRequiredWiwoPage(editingContext, new EOKeyValueQualifier(keyName, EOQualifier.QualifierOperatorEqual, value));
  }

  public static WiwoPage fetchRequiredWiwoPage(EOEditingContext editingContext, EOQualifier qualifier) {
    WiwoPage eoObject = _WiwoPage.fetchWiwoPage(editingContext, qualifier);
    if (eoObject == null) {
      throw new NoSuchElementException("There was no WiwoPage that matched the qualifier '" + qualifier + "'.");
    }
    return eoObject;
  }

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