<commit_before>package org.nakedobjects.object.defaults;

import org.nakedobjects.object.NakedClass;
import org.nakedobjects.object.NakedCollection;
import org.nakedobjects.object.NakedObject;
import org.nakedobjects.object.NakedObjectPersistor;
import org.nakedobjects.object.NakedObjectSpecification;
import org.nakedobjects.object.NakedObjects;
import org.nakedobjects.object.NotPersistableException;
import org.nakedobjects.object.control.AbstractConsent;
import org.nakedobjects.object.control.Allow;
import org.nakedobjects.object.control.Consent;
import org.nakedobjects.object.control.Hint;
import org.nakedobjects.object.control.Veto;
import org.nakedobjects.object.reflect.internal.about.InternalAbout;
import org.nakedobjects.utility.NakedObjectRuntimeException;

import org.apache.log4j.Logger;


public class NakedClassImpl implements NakedClass {
    private final static Logger LOG = Logger.getLogger(NakedClass.class);
    private final String className;
    private boolean createPersistentInstances;
    private NakedObjectSpecification specification;

    {
        createPersistentInstances = NakedObjects.getConfiguration().getBoolean("nakedclass.create-persistent", true);
    }

    public NakedClassImpl(String name) {
        specification = NakedObjects.getSpecificationLoader().loadSpecification(name);
        className = name;
    }

    public void aboutExplorationActionFind(InternalAbout about) {
        about.setDescription("Get a simple finder object to start searches within the " + getSingularName() + " instances");
        about.setName("Find " + getPluralName());
        about.unusableOnCondition(!getObjectManager().hasInstances(forObjectType(), false), "No instances available to find");
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canAccess().isVetoed()) {
            about.invisible();
        }
    }

    public Consent useAllInstance() {
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canAccess().isVetoed()) {
            return Veto.DEFAULT;
        } else {
            return AbstractConsent.create(getObjectManager().hasInstances(forObjectType(), false), "", "No instances available");
        }
    }
    
 /*   public void aboutExplorationActionInstances(InternalAbout about) {
        about.setDescription("Get the " + getSingularName() + " instances");
        about.setName(getPluralName());
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canAccess().isVetoed()) {
            about.invisible();
        } else {
            about.unusableOnCondition(!getObjectManager().hasInstances(forObjectType()), "No instances available");
        }
    }
*/
    
    public Consent useCreate() {
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canUse().isVetoed()) {
            return Veto.DEFAULT;
        }
        if(specification.isAbstract()) {
           return new Veto("Cannot create an instance of an abstract class");
        }
        
        return Allow.DEFAULT;
    }
    
    public void aboutExplorationActionNewInstance(InternalAbout about) {
        about.setDescription("Create a new " + getSingularName() + " instance");
        about.setName("New " + getSingularName());
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canUse().isVetoed()) {
            about.invisible();
        }
        if(specification.isAbstract()) {
            about.unusable("Cannot create an instance of an abstract class");
        }
    }

    public FastFinder explorationActionFind() {
        FastFinder find = new FastFinder();
        find.setFromClass(forObjectType());
        return find;
    }

    public NakedCollection allInstances() {
        return getObjectManager().allInstances(forObjectType(), specification.isAbstract());
    }

    public NakedCollection explorationActionInstances() {
        return allInstances();
    }

    public NakedObject explorationActionNewInstance() {
        return newInstance();
    }

    public NakedObjectSpecification forObjectType() {
        if (specification == null) {
            if (getName().length() == 0) {
                throw new NakedObjectRuntimeException();
            }
            specification = NakedObjects.getSpecificationLoader().loadSpecification(getName());
        }
        return specification;
    }

    public String getFullName() {<commit_msg>Added exploration action to create transient objects, complementing the create object action, that is also made available if the system is configured to make new objects persistent.<commit_after>package org.nakedobjects.object.defaults;

import org.nakedobjects.object.NakedClass;
import org.nakedobjects.object.NakedCollection;
import org.nakedobjects.object.NakedObject;
import org.nakedobjects.object.NakedObjectPersistor;
import org.nakedobjects.object.NakedObjectSpecification;
import org.nakedobjects.object.NakedObjects;
import org.nakedobjects.object.NotPersistableException;
import org.nakedobjects.object.control.AbstractConsent;
import org.nakedobjects.object.control.Allow;
import org.nakedobjects.object.control.Consent;
import org.nakedobjects.object.control.Hint;
import org.nakedobjects.object.control.Veto;
import org.nakedobjects.object.reflect.internal.about.InternalAbout;
import org.nakedobjects.utility.NakedObjectRuntimeException;

import org.apache.log4j.Logger;


public class NakedClassImpl implements NakedClass {
    private final static Logger LOG = Logger.getLogger(NakedClass.class);
    private final String className;
    private boolean createPersistentInstances;
    private NakedObjectSpecification specification;

    {
        createPersistentInstances = NakedObjects.getConfiguration().getBoolean("nakedclass.create-persistent", true);
    }

    public NakedClassImpl(String name) {
        specification = NakedObjects.getSpecificationLoader().loadSpecification(name);
        className = name;
    }

    public void aboutExplorationActionFind(InternalAbout about) {
        about.setDescription("Get a simple finder object to start searches within the " + getSingularName() + " instances");
        about.setName("Find " + getPluralName());
        about.unusableOnCondition(!getObjectManager().hasInstances(forObjectType(), false), "No instances available to find");
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canAccess().isVetoed()) {
            about.invisible();
        }
    }

    public Consent useAllInstance() {
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canAccess().isVetoed()) {
            return Veto.DEFAULT;
        } else {
            return AbstractConsent.create(getObjectManager().hasInstances(forObjectType(), false), "", "No instances available");
        }
    }
    
 /*   public void aboutExplorationActionInstances(InternalAbout about) {
        about.setDescription("Get the " + getSingularName() + " instances");
        about.setName(getPluralName());
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canAccess().isVetoed()) {
            about.invisible();
        } else {
            about.unusableOnCondition(!getObjectManager().hasInstances(forObjectType()), "No instances available");
        }
    }
*/
    
    public Consent useCreate() {
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canUse().isVetoed()) {
            return Veto.DEFAULT;
        }
        if(specification.isAbstract()) {
           return new Veto("Cannot create an instance of an abstract class");
        }
        
        return Allow.DEFAULT;
    }
    
    public void aboutExplorationActionNewInstance(InternalAbout about) {
        about.setDescription("Create a new " + getSingularName() + " instance");
        about.setName("New " + getSingularName());
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canUse().isVetoed()) {
            about.invisible();
        }
        if(specification.isAbstract()) {
            about.unusable("Cannot create an instance of an abstract class");
        }
    }


    public void aboutExplorationActionNewTransientInstance(InternalAbout about) {
        about.setDescription("Create a new " + getSingularName() + " instance");
        about.setName("New " + getSingularName());
        Hint ca = specification.getClassHint();
        if (ca != null && ca.canUse().isVetoed() && !createPersistentInstances) {
            about.invisible();
        }
        if(specification.isAbstract()) {
            about.unusable("Cannot create an instance of an abstract class");
        }
    }
    
    public FastFinder explorationActionFind() {
        FastFinder find = new FastFinder();
        find.setFromClass(forObjectType());
        return find;
    }

    public NakedCollection allInstances() {
        return getObjectManager().allInstances(forObjectType(), specification.isAbstract());
    }

    public NakedCollection explorationActionInstances() {
        return allInstances();
    }

    public NakedObject explorationActionNewInstance() {
        return newInstance();
    }

    public NakedObject explorationActionNewTransientInstance() {
        NakedObjectPersistor objectManager = getObjectManager();
        NakedObject object = objectManager.createTransientInstance(forObjectType());
        return object;
    }

    public NakedObjectSpecification forObjectType() {
        if (specification == null) {
            if (getName().length() == 0) {
                throw new NakedObjectRuntimeException();
            }
            specification = NakedObjects.getSpecificationLoader().loadSpecification(getName());
        }
        return specification;
    }

    public String getFullName() {
{'fraction_non_alphanumeric': 0.10476384780169336, 'fraction_numerical': 0.0004080383556054269, 'mean_word_length': 3.1402027027027026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1791866', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2535, 'n_words': 536}