//
// https://www.ramecera.it/myscrewdriver.html
// e-mail: screwdriver@ramecera.it
//
/* This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html */
package it.ramecera.screwdriver.outfits;

import java.io.FileNotFoundException;
import java.io.IOException;

import it.ramecera.salad.analysis.Flute;
import it.ramecera.salad.analysis.JavaAnnotation;
import it.ramecera.salad.everyday.Candies;
import it.ramecera.salad.everyday.ExactException;
import it.ramecera.salad.everyday.Mix;
import it.ramecera.screwdriver.CandyScrew;
import it.ramecera.screwdriver.Cst;

/**
 * <p>
 * Elements forming a JSP.
 * </p>
 * <p>
 * Company: Ramecera™<br>
 * Creation date: 2020-04-09<br>
 * Last updated: 2020-04-09
 * </p>
 * <p>
 * Modifications:<br>
 * </p>
 * 
 * @author M. Maglioni */
final public class TableOutfit {

	/** the real name of the table */
	public String tableName;
	/** the real name of the table, first character uppercase */
	public String tableNameU;
	/** the name of the table in JPA project */
	public String entityName;
	/** the name of the table in JPA project, first character
	 * uppercase */
	public String entityNameU;
	/** the path of the entity bean, expressed with points */
	public String pathDots;
	/** the path of the entity bean, expressed with slashes */
	public String pathSlash;
	/** Java analysis of the entity bean */
	public Flute flute;
	/** the DB scheme */
	public String dbSchema;
	/** the JNDI */
	public String jndi;
	/** the abbreviation rail0, rail1, rail2, etc. which sums up the
	 * DB-place jndi-dbschema, all in lowercase */
	public String railLowercase;
	/** the abbreviation rail0, rail1, rail2, etc. which sums up the
	 * place-DB jndi-dbschema, capital inial */
	public String railUppercase;

	/** default constructor */
	public TableOutfit() {

	}

	/**
	 * <p>
	 * Standard constructor.
	 * </p>
	 * <p>
	 * Creation date: 2020-04-09<br>
	 * Last updated: 2020-06-20
	 * </p>
	 * <p>
	 * Modifications:<br>
	 * </p>
	 * 
	 * @param entityName the name of the table
	 * @param pathDots the path of the entity bean
	 * @param dbSchema DB schema of the DB table
	 * @param candies external properties
	 * @param jndi the JNDI
	 * @param stub stub of the "rail" markup, then simply the string
	 *        "hdefrail"
	 * @param text «rail» markup text
	 * @throws IOException a standard exception
	 * @throws ExactException a standard exception
	 * @throws FileNotFoundException a standard exception */

	public TableOutfit(final String entityName, final String pathDots,
			final String dbSchema, CandyScrew candies,
			final String jndi, final String stub, final String text)

			throws FileNotFoundException, ExactException, IOException {

		super();
		this.entityName = entityName;
		this.entityNameU = Mix.uppercaseFirstChar(entityName);
		this.pathDots = pathDots;
		this.pathSlash = pathDots.replaceAll("\\x2e", "/");
		this.dbSchema = dbSchema.toLowerCase();
		this.jndi = jndi;
		String s = Cst.RAIL + text;
		railLowercase = s.toLowerCase();
		railUppercase = Mix.uppercaseFirstChar(railLowercase
				.toLowerCase());
		this.flute = new Flute(candies.outputYS + this.jndi
				.toLowerCase() + "-" + this.dbSchema + "/src/"
				+ pathSlash + "/" + entityName + ".java");
		this.flute.analyze();
		for (JavaAnnotation ja : this.flute.fannotationE) {
			if (ja.fnome.equals("Table")) {
				this.tableName = ja.paramE.get("name");
				this.tableNameU = Mix.uppercaseFirstChar(ja.paramE.get(
						"name"));
			}
		}
	}

	/**
	 * <p>
	 * Classic toString() method.
	 * </p>
	 * <p>
	 * Company: Ramecera™<br>
	 * Creation date: 2020-04-09<br>
	 * Last updated: 2020-04-09<br>
	 * </p>
	 * <p >
	 * Modifications:<br>
	 * </p>
	 * 
	 * @return the compound string */
	public String toString() {
		String s = "";
		s += Candies.LF + "********************" + Candies.LF;
		s += "Entity «" + entityName + "»" + Candies.LF;
		s += "Table «" + tableName + "»" + Candies.LF + Candies.LF;
		s += "PathP = " + pathDots + Candies.LF;
		s += "PathS = " + pathSlash + Candies.LF;
		s += "DB schema = " + dbSchema + Candies.LF;
		s += "JNDI = " + jndi + Candies.LF;
		s += "Rail = " + railLowercase + Candies.LF;
		s += "********************" + Candies.LF;
		return s;

	}

}
