<commit_before>/*
 * citygml4j - The Open Source Java API for CityGML
 * https://github.com/citygml4j
 * 
 * Copyright 2013-2017 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.citygml4j;

import java.util.ArrayList;
import java.util.List;

import org.citygml4j.builder.CityGMLBuilder;
import org.citygml4j.builder.CityGMLBuilderException;
import org.citygml4j.builder.jaxb.JAXBBuilder;
import org.citygml4j.builder.jaxb.JAXBBuilderFactory;
import org.citygml4j.model.citygml.ade.ADEException;
import org.citygml4j.model.citygml.ade.binding.ADEContext;
import org.citygml4j.model.module.Modules;
import org.citygml4j.model.module.ade.ADEModule;

public class CityGMLContext {
	private JAXBBuilder builder;
	private List<ADEContext> adeContexts;

	public CityGMLContext() {
		adeContexts = new ArrayList<>();
	}

	public void registerADEContext(ADEContext adeContext) throws ADEException {
		if (adeContext == null)
			throw new ADEException("The ADE context must not be null.");

		if (adeContexts.contains(adeContext))
			return;

		if (builder != null)
			throw new ADEException("An ADE context cannot be registered after the CityGML builder has been created.");

		if (adeContext.getModelPackageNames() == null || adeContext.getModelPackageNames().isEmpty())
			throw new ADEException("No model package names defined for the ADE context.");

		if (adeContext.getADEModules() == null || adeContext.getADEModules().isEmpty())
			throw new ADEException("No ADE module defined for the ADE context.");

		if (adeContext.getJAXBPackageNames() == null || adeContext.getJAXBPackageNames().isEmpty())
			throw new ADEException("No JAXB package names defined for the ADE context.");

		if (adeContext.getADEMarshaller() == null)
			throw new ADEException("No marshaller defined for the ADE context.");

		if (adeContext.getADEUnmarshaller() == null)
			throw new ADEException("No unmarshaller defined for the ADE context.");

		for (ADEModule module : adeContext.getADEModules()) {		
			if (module.getNamespaceURI() == null || module.getNamespaceURI().isEmpty())
				throw new ADEException("The namespace URI of the ADE module must not be null.");		

			for (ADEContext registeredContext : adeContexts) {
				for (ADEModule registeredModule : registeredContext.getADEModules()) {
					if (registeredModule.getNamespaceURI().equals(module.getNamespaceURI()))
						throw new ADEException("An ADE module has already been registered for the namespace '" + module.getNamespaceURI() + "'.");

					for (String packageName : adeContext.getModelPackageNames()) {
						if (registeredModule.getCityGMLVersion() == module.getCityGMLVersion() && registeredContext.getModelPackageNames().contains(packageName))
							throw new ADEException("An ADE module has already been registered for the package '" + packageName + "' and CityGML version " + module.getCityGMLVersion() + ".");					
					}
				}
			}
		}

		for (ADEModule module : adeContext.getADEModules())
			Modules.registerADEModule(module);

		adeContexts.add(adeContext);
	}

	public void unregisterADEContext(ADEContext adeContext) {
		for (ADEModule module : adeContext.getADEModules())
			Modules.unregisterADEModule(module);

		adeContexts.remove(adeContext);
	}

	public boolean isSetADEContexts() {
		return !adeContexts.isEmpty();
	}

	public List<ADEContext> getADEContexts() {
		return new ArrayList<>(adeContexts);
	}

	public ADEContext getADEContext(String namespaceURI) {
		for (ADEContext adeContext : adeContexts) {
			for (ADEModule module : adeContext.getADEModules()) {
				if (module.getNamespaceURI().equals(namespaceURI))
					return adeContext;
			}
		}

		return null;
	}

	public CityGMLBuilder createCityGMLBuilder() throws CityGMLBuilderException {
		return createJAXBBuilder();
	}

	public CityGMLBuilder createCityGMLBuilder(ClassLoader classLoader) throws CityGMLBuilderException {
		return createJAXBBuilder(classLoader);
	}

	public synchronized JAXBBuilder createJAXBBuilder() throws CityGMLBuilderException {
		if (builder == null)
			builder = JAXBBuilderFactory.defaults().withADEContexts(adeContexts).build();

		return builder;
	}

	public synchronized JAXBBuilder createJAXBBuilder(ClassLoader classLoader) throws CityGMLBuilderException {
		if (builder == null)
			builder = JAXBBuilderFactory.defaults().withADEContexts(adeContexts).withClassLoader(classLoader).build();

		return builder;
	}

}
<commit_msg>minor change to CityGMLContext<commit_after>/*
 * citygml4j - The Open Source Java API for CityGML
 * https://github.com/citygml4j
 * 
 * Copyright 2013-2017 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.citygml4j;

import java.util.ArrayList;
import java.util.List;

import org.citygml4j.builder.CityGMLBuilder;
import org.citygml4j.builder.CityGMLBuilderException;
import org.citygml4j.builder.jaxb.JAXBBuilder;
import org.citygml4j.builder.jaxb.JAXBBuilderFactory;
import org.citygml4j.model.citygml.ade.ADEException;
import org.citygml4j.model.citygml.ade.binding.ADEContext;
import org.citygml4j.model.module.Modules;
import org.citygml4j.model.module.ade.ADEModule;

public class CityGMLContext {
	private JAXBBuilder builder;
	private List<ADEContext> adeContexts;

	public CityGMLContext() {
		adeContexts = new ArrayList<>();
	}

	public void registerADEContext(ADEContext adeContext) throws ADEException {
		if (adeContext == null)
			throw new ADEException("The ADE context must not be null.");

		if (adeContexts.contains(adeContext))
			return;

		if (builder != null)
			throw new ADEException("An ADE context cannot be registered after the CityGML builder has been created.");

		if (adeContext.getModelPackageNames() == null || adeContext.getModelPackageNames().isEmpty())
			throw new ADEException("No model package names defined for the ADE context.");

		if (adeContext.getADEModules() == null || adeContext.getADEModules().isEmpty())
			throw new ADEException("No ADE module defined for the ADE context.");

		if (adeContext.getJAXBPackageNames() == null || adeContext.getJAXBPackageNames().isEmpty())
			throw new ADEException("No JAXB package names defined for the ADE context.");

		if (adeContext.getADEMarshaller() == null)
			throw new ADEException("No marshaller defined for the ADE context.");

		if (adeContext.getADEUnmarshaller() == null)
			throw new ADEException("No unmarshaller defined for the ADE context.");

		for (ADEModule module : adeContext.getADEModules()) {		
			if (module.getNamespaceURI() == null || module.getNamespaceURI().isEmpty())
				throw new ADEException("The namespace URI of the ADE module must not be null.");		

			for (ADEContext registeredContext : adeContexts) {
				for (ADEModule registeredModule : registeredContext.getADEModules()) {
					if (registeredModule.getNamespaceURI().equals(module.getNamespaceURI()))
						throw new ADEException("An ADE module has already been registered for the namespace '" + module.getNamespaceURI() + "'.");

					for (String packageName : adeContext.getModelPackageNames()) {
						if (registeredModule.getCityGMLVersion() == module.getCityGMLVersion() && registeredContext.getModelPackageNames().contains(packageName))
							throw new ADEException("An ADE module has already been registered for the package '" + packageName + "' and CityGML version " + module.getCityGMLVersion() + ".");					
					}
				}
			}
		}

		for (ADEModule module : adeContext.getADEModules())
			Modules.registerADEModule(module);

		adeContexts.add(adeContext);
	}

	public void unregisterADEContext(ADEContext adeContext) {
		for (ADEModule module : adeContext.getADEModules())
			Modules.unregisterADEModule(module);

		adeContexts.remove(adeContext);
	}

	public boolean isSetADEContexts() {
		return !adeContexts.isEmpty();
	}

	public List<ADEContext> getADEContexts() {
		return new ArrayList<>(adeContexts);
	}

	public ADEContext getADEContext(String namespaceURI) {
		for (ADEContext adeContext : adeContexts) {
			for (ADEModule module : adeContext.getADEModules()) {
				if (module.getNamespaceURI().equals(namespaceURI))
					return adeContext;
			}
		}

		return null;
	}

	public CityGMLBuilder createCityGMLBuilder() throws CityGMLBuilderException {
		return createJAXBBuilder();
	}

	public CityGMLBuilder createCityGMLBuilder(ClassLoader classLoader) throws CityGMLBuilderException {
		return createJAXBBuilder(classLoader);
	}

	public synchronized JAXBBuilder createJAXBBuilder() throws CityGMLBuilderException {
		if (builder == null)
			builder = JAXBBuilderFactory.defaults()
			.withADEContexts(adeContexts).build();

		return builder;
	}

	public synchronized JAXBBuilder createJAXBBuilder(ClassLoader classLoader) throws CityGMLBuilderException {
		if (builder == null)
			builder = JAXBBuilderFactory.defaults()
			.withADEContexts(adeContexts)
			.withClassLoader(classLoader).build();

		return builder;
	}
	
	public synchronized JAXBBuilder createJAXBBuilder(ClassLoader classLoader, String... packageNames) throws CityGMLBuilderException {
		if (builder == null)
			builder = JAXBBuilderFactory.defaults()
			.withADEContexts(adeContexts)
			.withClassLoader(classLoader)
			.withPackageNames(packageNames).build();

		return builder;
	}

}

{'fraction_non_alphanumeric': 0.09939464948252294, 'fraction_numerical': 0.004491310290958797, 'mean_word_length': 4.8464611872146115, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '351422', 'n_tokens_mistral': 3290, 'n_tokens_neox': 3016, 'n_words': 809}