<commit_before>package gov.nih.nci.codegen.transformer;

import gov.nih.nci.codegen.ArtifactHandler;
import gov.nih.nci.codegen.GenerationException;
import gov.nih.nci.codegen.GeneratorError;
import gov.nih.nci.codegen.GeneratorErrors;
import gov.nih.nci.codegen.Transformer;
import gov.nih.nci.codegen.artifact.BaseArtifact;
import gov.nih.nci.codegen.util.Constant;
import gov.nih.nci.codegen.util.TransformerUtils;
import gov.nih.nci.ncicb.xmiinout.domain.UMLAssociationEnd;
import gov.nih.nci.ncicb.xmiinout.domain.UMLAttribute;
import gov.nih.nci.ncicb.xmiinout.domain.UMLClass;
import gov.nih.nci.ncicb.xmiinout.domain.UMLModel;
import gov.nih.nci.ncicb.xmiinout.domain.UMLPackage;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.log4j.Logger;
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.mmbase.util.Encode;

/**
 *
 * @author caCORE SDK Team
 * @version 1.0
 */
public class XmlMappingTransformer implements Transformer { 


	private static Logger log = Logger.getLogger(XmlMappingTransformer.class);
	
	private GeneratorErrors generatorErrors = new GeneratorErrors();
	
	private ArtifactHandler artifactHandler;
	
	private Encode xmlEncoder = new Encode("ESCAPE_XML");	
	
	private String namespaceUriPrefix;
	
	private boolean useGMETags = false;

	private boolean includeAssociations = false;    
	private boolean includeFieldHandler = false;    

	private boolean enabled = true;
	
	private String name = XmlMappingTransformer.class.getName();
	
	protected TransformerUtils transformerUtils;
	
	public void setTransformerUtils(TransformerUtils transformerUtils) {
		this.transformerUtils = transformerUtils;
	}
	
	/* @param model The UMLModel containing the classes for which a 
	 * Castor Mapping file should be generated
	 * @see gov.nih.nci.codegen.Transformer#execute(gov.nih.nci.ncicb.xmiinout.domain.UMLModel)
	 */
	public GeneratorErrors execute(UMLModel model)
	{
		log.debug("Model name: " + model.getName());

		GeneratorErrors errors = new GeneratorErrors();
		Collection<UMLClass> classes = null;
		
		setModelNamespace(model,transformerUtils.getBasePkgLogicalModel());

		try {
			classes = transformerUtils.getAllClasses(model);
		} catch(GenerationException ge){
			errors.addError(new GeneratorError(getName() + ": Error while retrieving classes to process: ", ge));
		}
		
		log.debug("classes size: " + classes.size());		
		processClasses(classes);
		
		return generatorErrors;
	}

	/* @param model The UMLModel containing the classes for which a 
	 * Castor Mapping file should be generated.  This method will run any
	 * necessary validations.<commit_msg>Fix for [#20562] NAMESPACE_PREFIX value in deploy.properties is not honored in generated castor mapping files.<commit_after>package gov.nih.nci.codegen.transformer;

import gov.nih.nci.codegen.ArtifactHandler;
import gov.nih.nci.codegen.GenerationException;
import gov.nih.nci.codegen.GeneratorError;
import gov.nih.nci.codegen.GeneratorErrors;
import gov.nih.nci.codegen.Transformer;
import gov.nih.nci.codegen.artifact.BaseArtifact;
import gov.nih.nci.codegen.util.Constant;
import gov.nih.nci.codegen.util.TransformerUtils;
import gov.nih.nci.ncicb.xmiinout.domain.UMLAssociationEnd;
import gov.nih.nci.ncicb.xmiinout.domain.UMLAttribute;
import gov.nih.nci.ncicb.xmiinout.domain.UMLClass;
import gov.nih.nci.ncicb.xmiinout.domain.UMLModel;
import gov.nih.nci.ncicb.xmiinout.domain.UMLPackage;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.log4j.Logger;
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.Namespace;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.mmbase.util.Encode;

/**
 *
 * @author caCORE SDK Team
 * @version 1.0
 */
public class XmlMappingTransformer implements Transformer { 


	private static Logger log = Logger.getLogger(XmlMappingTransformer.class);
	
	private GeneratorErrors generatorErrors = new GeneratorErrors();
	
	private ArtifactHandler artifactHandler;
	
	private Encode xmlEncoder = new Encode("ESCAPE_XML");	
	
	private String namespaceUriPrefix;
	
	private boolean useGMETags = false;

	private boolean includeAssociations = false;    
	private boolean includeFieldHandler = false;    

	private boolean enabled = true;
	
	private String name = XmlMappingTransformer.class.getName();
	
	protected TransformerUtils transformerUtils;
	
	public void setTransformerUtils(TransformerUtils transformerUtils) {
		this.transformerUtils = transformerUtils;
	}
	
	/* @param model The UMLModel containing the classes for which a 
	 * Castor Mapping file should be generated
	 * @see gov.nih.nci.codegen.Transformer#execute(gov.nih.nci.ncicb.xmiinout.domain.UMLModel)
	 */
	public GeneratorErrors execute(UMLModel model)
	{
		log.debug("Model name: " + model.getName());

		GeneratorErrors errors = new GeneratorErrors();
		Collection<UMLClass> classes = null;

		try {
			if (useGMETags){
				setModelNamespace(model,transformerUtils.getBasePkgLogicalModel());
			}
			
			classes = transformerUtils.getAllClasses(model);
		} catch(GenerationException ge){
			errors.addError(new GeneratorError(getName() + ": Error while retrieving classes to process: ", ge));
		}
		
		log.debug("classes size: " + classes.size());		
		processClasses(classes);
		
		return generatorErrors;
	}

	/* @param model The UMLModel containing the classes for which a 
	 * Castor Mapping file should be generated.  This method will run any
	 * necessary validations.
{'fraction_non_alphanumeric': 0.09788672865595943, 'fraction_numerical': 0.0018596787827557058, 'mean_word_length': 4.993920972644377, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6992818', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1837, 'n_words': 405}