<commit_before>/*******************************************************************************
 * Copyright (c) 1998, 2008 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
 * which accompanies this distribution. 
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
package org.eclipse.persistence.tools.workbench.mappingsmodel.meta;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import org.eclipse.persistence.tools.workbench.mappingsmodel.MWModel;
import org.eclipse.persistence.tools.workbench.mappingsmodel.ProjectSubFileComponentContainer;
import org.eclipse.persistence.tools.workbench.mappingsmodel.descriptor.MWDescriptor;
import org.eclipse.persistence.tools.workbench.mappingsmodel.mapping.MWMapping;
import org.eclipse.persistence.tools.workbench.mappingsmodel.project.MWProject;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ClassDescription;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClass;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassDescription;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassNotFoundException;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassRepository;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassRepositoryFactory;
import org.eclipse.persistence.tools.workbench.utility.ClassTools;
import org.eclipse.persistence.tools.workbench.utility.Classpath;
import org.eclipse.persistence.tools.workbench.utility.CollectionTools;
import org.eclipse.persistence.tools.workbench.utility.iterators.ArrayIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.CloneIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.CloneListIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.CompositeIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.FilteringIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.TransformationIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.TreeIterator;
import org.eclipse.persistence.tools.workbench.utility.node.Node;

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.eclipse.persistence.oxm.XMLDescriptor;
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
import org.eclipse.persistence.oxm.mappings.XMLTransformationMapping;
import org.eclipse.persistence.sessions.Record;
import org.eclipse.persistence.sessions.Session;

/**
 * This is the factory and repository for all the class "descriptions"
 * (MWClasses) that represent the user's object model.
 * 
 * This "internal" class repository manages all the MWClasses.
 * It uses an "external" class repository to build the MWClasses
 * from external metadata, which are typically derived from Java
 * Class objects or byte codes.
 * 
 * There are several varieties of MWClasses:
 * - "core" classes
 *     for performance reasons, a "core" class (i.e. a JDK or TopLink
 *     classes) is initially only partially populated with state related
 *     to its class declaration (superclass, interfaces, etc.); the
 *     remaining state is lazily populated on demand
 * - "stub" classes
 *     a user class that is only referenced by other user classes is not
 *     populated beyond its name (and whether it might be an interface)
 * - "fully populated" classes
 *     a user class that is mapped, or whose fields or methods are referenced
 *     by descriptors, is fully populated with all its state; this is the only type
 *     of class that is written out to an XML file
 * 
 * To avoid confusion between Java Classes and MWClasses,
 * we refer to MWClasses as "types" whenever possible and
 * to Java Classes as "classes".
 * 
 * NB: We synchronized 'types' whenever types are being added or removed.
 * This is because multiple threads can fault in new types. :-(  ~bjv
 */
public final class MWClassRepository
	extends MWModel
	implements ProjectSubFileComponentContainer
{

	/**
	 * The MWClasses, which includes "user" types, "stub" types,
	 * and "core" types, keyed by name. We need to carefully
	 * synchronize access to this map since we will fault in types
	 * whenever they are referenced. This means any number of
	 * methods can cause an addition to this map.
	 */
	private Map types;
		// 'types' is NOT a public property, but 'userTypes' is

	/**
	 * The names of the types contained in 'types', above,
	 * keyed by the name converted to lower-case.
	 * This must be kept in synch with 'types'.
	 * @see #addType(String, MWClass)
	 * @see #removeTypeNamed(String)
	 */
	private Map typeNames;

	/**
	 * this holds only the current set of "user" types and must
	 * be maintained by tracking changes to the types themselves (yuck);
	 * @see #typeChanged(MWClass)
	 * @see MWClass#aspectChanged(String)
	 */
	private Set userTypes;
		public static final String USER_TYPES_COLLECTION = "userTypes";

	/**
	 * these user type names are read in by TopLink and are then
	 * used and managed by the IOManager;
	 * DO NOT use them for anything else  ~bjv
	 */
	private Collection userTypeNames;
		private static final String USER_TYPE_NAMES_COLLECTION = "userTypeNames";

	/**
	 * the "external" class repository that supplies the
	 * "external" types/classes used to build MWClasses
	 */
	private volatile ExternalClassRepository externalClassRepository;

	/**
	 * classpath used by the "external" class repository, if necessary, to
	 * search for the "external" classes used to build MWClasses;
	 * it is a list of strings
	 */
	private List classpathEntries;
		public static final String CLASSPATH_ENTRIES_LIST = "classpathEntries";

	/** these are the keys used to find the classpath entries for the "core" classes */
	private static final Class[] CORE_KEYS =
		new Class[] {
			java.lang.Object.class,		// rt.jar
			//some custom jvms have the classes divided between more than one jar which can cause problems
			//associated with bug #6789722
			java.util.List.class,
			java.util.Map.class,
			java.util.Collection.class,
			java.util.Set.class,
			org.eclipse.persistence.indirection.ValueHolderInterface.class		// toplink.jar
		};

	/** the "core" classes: the names of the MWClasses that are never written out */
	private static Set coreClassNames;

	/**
	 * the "core" classes: the names of the MWClasses that are never written out,
	 * keyed by the name converted to lowercase
	 */
	private static Map coreClassNamesLowerCase;

	// queried reflectively by I/O Manager
	private static final String SUB_DIRECTORY_NAME = "classes";


	// ********** constructors **********
	
	/**
	 * default constructor - for TopLink use only
	 */
	private MWClassRepository() {
		super();
	}
	<commit_msg>fix for bug #222471, this was a problem with a custom IBM JDK.<commit_after>/*******************************************************************************
 * Copyright (c) 1998, 2008 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the 
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
 * which accompanies this distribution. 
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
package org.eclipse.persistence.tools.workbench.mappingsmodel.meta;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import org.eclipse.persistence.tools.workbench.mappingsmodel.MWModel;
import org.eclipse.persistence.tools.workbench.mappingsmodel.ProjectSubFileComponentContainer;
import org.eclipse.persistence.tools.workbench.mappingsmodel.descriptor.MWDescriptor;
import org.eclipse.persistence.tools.workbench.mappingsmodel.mapping.MWMapping;
import org.eclipse.persistence.tools.workbench.mappingsmodel.project.MWProject;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ClassDescription;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClass;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassDescription;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassNotFoundException;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassRepository;
import org.eclipse.persistence.tools.workbench.mappingsmodel.spi.meta.ExternalClassRepositoryFactory;
import org.eclipse.persistence.tools.workbench.utility.ClassTools;
import org.eclipse.persistence.tools.workbench.utility.Classpath;
import org.eclipse.persistence.tools.workbench.utility.CollectionTools;
import org.eclipse.persistence.tools.workbench.utility.iterators.ArrayIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.CloneIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.CloneListIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.CompositeIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.FilteringIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.TransformationIterator;
import org.eclipse.persistence.tools.workbench.utility.iterators.TreeIterator;
import org.eclipse.persistence.tools.workbench.utility.node.Node;

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.DescriptorEvent;
import org.eclipse.persistence.oxm.XMLDescriptor;
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
import org.eclipse.persistence.oxm.mappings.XMLTransformationMapping;
import org.eclipse.persistence.sessions.Record;
import org.eclipse.persistence.sessions.Session;

/**
 * This is the factory and repository for all the class "descriptions"
 * (MWClasses) that represent the user's object model.
 * 
 * This "internal" class repository manages all the MWClasses.
 * It uses an "external" class repository to build the MWClasses
 * from external metadata, which are typically derived from Java
 * Class objects or byte codes.
 * 
 * There are several varieties of MWClasses:
 * - "core" classes
 *     for performance reasons, a "core" class (i.e. a JDK or TopLink
 *     classes) is initially only partially populated with state related
 *     to its class declaration (superclass, interfaces, etc.); the
 *     remaining state is lazily populated on demand
 * - "stub" classes
 *     a user class that is only referenced by other user classes is not
 *     populated beyond its name (and whether it might be an interface)
 * - "fully populated" classes
 *     a user class that is mapped, or whose fields or methods are referenced
 *     by descriptors, is fully populated with all its state; this is the only type
 *     of class that is written out to an XML file
 * 
 * To avoid confusion between Java Classes and MWClasses,
 * we refer to MWClasses as "types" whenever possible and
 * to Java Classes as "classes".
 * 
 * NB: We synchronized 'types' whenever types are being added or removed.
 * This is because multiple threads can fault in new types. :-(  ~bjv
 */
public final class MWClassRepository
	extends MWModel
	implements ProjectSubFileComponentContainer
{

	/**
	 * The MWClasses, which includes "user" types, "stub" types,
	 * and "core" types, keyed by name. We need to carefully
	 * synchronize access to this map since we will fault in types
	 * whenever they are referenced. This means any number of
	 * methods can cause an addition to this map.
	 */
	private Map types;
		// 'types' is NOT a public property, but 'userTypes' is

	/**
	 * The names of the types contained in 'types', above,
	 * keyed by the name converted to lower-case.
	 * This must be kept in synch with 'types'.
	 * @see #addType(String, MWClass)
	 * @see #removeTypeNamed(String)
	 */
	private Map typeNames;

	/**
	 * this holds only the current set of "user" types and must
	 * be maintained by tracking changes to the types themselves (yuck);
	 * @see #typeChanged(MWClass)
	 * @see MWClass#aspectChanged(String)
	 */
	private Set userTypes;
		public static final String USER_TYPES_COLLECTION = "userTypes";

	/**
	 * these user type names are read in by TopLink and are then
	 * used and managed by the IOManager;
	 * DO NOT use them for anything else  ~bjv
	 */
	private Collection userTypeNames;
		private static final String USER_TYPE_NAMES_COLLECTION = "userTypeNames";

	/**
	 * the "external" class repository that supplies the
	 * "external" types/classes used to build MWClasses
	 */
	private volatile ExternalClassRepository externalClassRepository;

	/**
	 * classpath used by the "external" class repository, if necessary, to
	 * search for the "external" classes used to build MWClasses;
	 * it is a list of strings
	 */
	private List classpathEntries;
		public static final String CLASSPATH_ENTRIES_LIST = "classpathEntries";

	/** these are the keys used to find the classpath entries for the "core" classes */
	private static final Class[] CORE_KEYS =
		new Class[] {
			java.lang.Object.class,		// rt.jar
			//some custom jvms have the classes divided between more than one jar which can cause problems
			//associated with bug #222471
			java.util.List.class,
			java.util.Map.class,
			java.util.Collection.class,
			java.util.Set.class,
			org.eclipse.persistence.indirection.ValueHolderInterface.class		// eclipselink.jar
		};

	/** the "core" classes: the names of the MWClasses that are never written out */
	private static Set coreClassNames;

	/**
	 * the "core" classes: the names of the MWClasses that are never written out,
	 * keyed by the name converted to lowercase
	 */
	private static Map coreClassNamesLowerCase;

	// queried reflectively by I/O Manager
	private static final String SUB_DIRECTORY_NAME = "classes";


	// ********** constructors **********
	
	/**
	 * default constructor - for TopLink use only
	 */
	private MWClassRepository() {
		super();
	}
	
{'fraction_non_alphanumeric': 0.1053619997409662, 'fraction_numerical': 0.003302680999870483, 'mean_word_length': 4.6238164603059, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3963301', 'n_tokens_mistral': 4364, 'n_tokens_neox': 4157, 'n_words': 1386}