All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dmd.dms.doc.web.AttributeFormatter Maven / Gradle / Ivy

Go to download

The dark-matter project provides mechanism to define concepts associated with Domain Specific Languages (DSLs) and generate code that can be extended with business logic that supports the given DSL purpose.

There is a newer version: 3.1.15
Show newest version
package org.dmd.dms.doc.web;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.TreeMap;

import org.dmd.dmc.DmcObject;
import org.dmd.dmc.types.DefinitionName;
import org.dmd.dms.ActionDefinition;
import org.dmd.dms.AttributeDefinition;
import org.dmd.dms.ClassDefinition;
import org.dmd.dms.RuleDefinition;
import org.dmd.dms.generated.dmo.RuleDataDMO;
import org.dmd.dmw.DmwWrapper;
import org.dmd.util.exceptions.DebugInfo;

public class AttributeFormatter {
	
	static public void dumpDetails(BufferedWriter out, AttributeDefinition ad) throws IOException {
		out.write("\n");
		attributeName(out, ad);
		attributeType(out, ad);
		description(out, ad);
		usage(out, ad);
	}
	
	static void attributeName(BufferedWriter out, AttributeDefinition ad) throws IOException{
		out.write("       " + ad.getName() + "  \n");
	}
	
	/**
	 * @param ad The attribute definition.
	 * @return The abbreviated form of the value type.
	 */
	static public String getValueType(AttributeDefinition ad){
		StringBuffer vt = new StringBuffer();
		
		switch(ad.getDataType()){
		case UNKNOWN:
			vt.append("U ");
			break;
		case PERSISTENT:
			vt.append("P ");
			break;
		case NONPERSISTENT:
			vt.append("N ");
			break;
		case TRANSIENT:
			vt.append("T ");
			break;
		}
		
		switch(ad.getValueType()){
		case SINGLE:
			vt.append("SV");
			break;
		case MULTI:
			if (ad.getIndexSize() == null)
				vt.append("MV");
			else
				vt.append("MV[" + ad.getIndexSize() + "]");
			break;
		case TREEMAPPED:
			vt.append("TM");
			break;
		case HASHMAPPED:
			vt.append("HM");
			break;
		case TREESET:
			vt.append("TS");
			break;
		case HASHSET:
			vt.append("HS");
			break;
		}
		
		return(vt.toString());
	}

	static void attributeType(BufferedWriter out, AttributeDefinition ad) throws IOException{
//		String vt 			= "";
		String vt 			= getValueType(ad);
		String schema 		= ad.getType().getDefinedIn().getName().getNameString();
		String type 		= TypeFormatter.getTypeName(ad.getType());
		String designated	= "";
		
		if (ad.getDesignatedNameAttribute()){
			designated = "(designated naming attribute)";
		}
		
//		switch(ad.getValueType()){
//		case SINGLE:
//			vt = "SV";
//			break;
//		case MULTI:
//			vt = "MV";
//			break;
//		case TREEMAPPED:
//			vt = "TM";
//			break;
//		case HASHMAPPED:
//			vt = "HM";
//			break;
//		case TREESET:
//			vt = "TS";
//			break;
//		case HASHSET:
//			vt = "HS";
//			break;
//		}
		out.write("    \n");
		out.write("       \n");
		out.write("       
" + vt + "
"); out.write(" " + designated + "\n"); out.write(" \n"); out.write(" \n\n"); } static void description(BufferedWriter out, AttributeDefinition ad) throws IOException{ // if (ad.getDescription() != null){ if (ad.getDescriptionSize() > 0){ // ArrayList referring = ad.getReferringObjects(); ArrayList referring = ad.getDMO().getReferringObjects(); out.write(" \n"); out.write(" \n"); out.write(" Description\n"); out.write(" \n"); if (ad.getDescription() != null){ out.write(" " + Converter.convert(ad.getDescriptionWithNewlines()) + "\n"); } out.write(" \n"); out.write(" \n\n"); // Iterator descr = ad.getDescription(); // while(descr.hasNext()){ // out.write(descr.next() + "\n"); // if (descr.hasNext()) // out.write("

\n"); // } // if (referring != null){ // out.write("

\n"); // for(DmcObject obj: referring){ // if (obj instanceof RuleDataDMO){ // RuleDataDMO rd = (RuleDataDMO) obj; // out.write(rd.getRuleTitle() + "\n

"); // } // // } // // } if (referring != null){ StringBuilder sb = new StringBuilder(); for(DmcObject obj: referring){ if (obj instanceof RuleDataDMO){ RuleDataDMO rd = (RuleDataDMO) obj; sb.append(" \n"); sb.append(" " + rd.getRuleTitle() + " "); sb.append(" \n\n"); } } if (sb.length() > 0) out.write(sb.toString()); } } } static void usage(BufferedWriter out, AttributeDefinition ad) throws IOException { ArrayList referring = ad.getReferringObjects(); // There's always one reference because the schema refers to its attributes if ( (referring != null) && (referring.size() > 1) ){ TreeMap classes = new TreeMap(); TreeMap rules = new TreeMap(); TreeMap actions = new TreeMap(); out.write(" \n"); out.write(" \n"); out.write(" Used in:\n"); out.write(" \n"); for(DmwWrapper wrapper: referring){ if (wrapper instanceof ClassDefinition){ ClassDefinition cd = (ClassDefinition) wrapper; classes.put(cd.getName(), cd); } // else if (wrapper instanceof RuleDefinition){ // RuleDefinition rd = (RuleDefinition) wrapper; // rules.put(rd.getName(), rd); // } else if (wrapper instanceof ActionDefinition){ ActionDefinition actd = (ActionDefinition) wrapper; actions.put(actd.getName(), actd); } } out.write(formatUsage(classes,rules,actions)); out.write(" \n"); out.write(" \n\n"); } } static String formatUsage(TreeMap cds, TreeMap rds, TreeMap ads){ StringBuffer sb = new StringBuffer(); sb.append("

\n"); int count = 0; if (cds.size() > 0){ count = 0; for(ClassDefinition ad: cds.values()){ if ((count % 3) == 0){ if (count > 3){ sb.append(" \n"); } sb.append(" \n"); } String ref = "" + ad.getDefinedIn().getName() + ""; sb.append(" \n" ); count++; } sb.append(" \n"); } if (rds.size() > 0){ count = 0; for(RuleDefinition ad: rds.values()){ if ((count % 3) == 0){ if (count > 3){ sb.append(" \n"); } sb.append(" \n"); } String ref = "" + ad.getDefinedIn().getName() + ""; sb.append(" \n" ); count++; } sb.append(" \n"); } if (ads.size() > 0){ count = 0; for(ActionDefinition ad: ads.values()){ if ((count % 3) == 0){ if (count > 3){ sb.append(" \n"); } sb.append(" \n"); } String ref = "" + ad.getDefinedIn().getName() + ""; sb.append(" \n" ); count++; } sb.append(" \n"); } sb.append("
" + ad.getName().getNameString() + " (" + ref + ")
" + ad.getName().getNameString() + " (" + ref + ")
" + ad.getName().getNameString() + " (" + ref + ")
\n"); return(sb.toString()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy