tracesrv/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDefStore.java
changeset 56 aa2539c91954
parent 41 838cdffd57ce
equal deleted inserted replaced
54:a151135b0cf9 56:aa2539c91954
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 * Writes type definition objects
       
    17 *
       
    18 */
       
    19 package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
       
    20 
       
    21 /**
       
    22  * Writes type definition objects
       
    23  * 
       
    24  */
       
    25 public class TypeDefStore {
       
    26 
       
    27 	/**
       
    28 	 * Writes <typedef>
       
    29 	 */
       
    30 	public static void startTypeDefs() {
       
    31 		TagWriter.write(TagWriter.TYPEDEFS_START, TagWriter.INDENT_1);
       
    32 	}
       
    33 
       
    34 	/**
       
    35 	 * Writes <external-def>path</external-def> structure
       
    36 	 * 
       
    37 	 * @param path
       
    38 	 *            path to external dictionary file
       
    39 	 */
       
    40 	public static void writeExternalDefFile(String path) {
       
    41 		StringBuffer sb = new StringBuffer();
       
    42 		sb.append(TagWriter.EXTERNAL_DEF_START);
       
    43 		sb.append(XMLDataFilter.changeData(path));
       
    44 		sb.append(TagWriter.EXTERNAL_DEF_END);
       
    45 		TagWriter.write(sb.toString(), TagWriter.INDENT_2);
       
    46 	}
       
    47 
       
    48 	/**
       
    49 	 * Starts <object type="" size="" formatChar="" dataType=""> structure
       
    50 	 * 
       
    51 	 * @param type
       
    52 	 *            original type name
       
    53 	 * @param size
       
    54 	 *            size of typical object, it’s optional because dictionary user
       
    55 	 *            can calculate size for compound types by sum size of each
       
    56 	 *            member. Give -1 if not used.
       
    57 	 * @param formatChar
       
    58 	 *            used for formatting
       
    59 	 * @param dataType
       
    60 	 *            one value form <datatype> enumeration
       
    61 	 */
       
    62 	public static void startTypeDef(String type, int size, String formatChar,
       
    63 			DataType dataType) {
       
    64 		StringBuffer sb = new StringBuffer();
       
    65 		sb.append(TagWriter.OBJECT_START_OPEN);
       
    66 		TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, false);
       
    67 		if (size >= 0) { // optional attribute
       
    68 			TagWriter.appendAttribute(sb, TagWriter.SIZE_ATTR, String
       
    69 					.valueOf(size), true);
       
    70 		}
       
    71 		if (formatChar != null) { // optional attribute
       
    72 			TagWriter.appendAttribute(sb, TagWriter.FORMATCHAR_ATTR,
       
    73 					formatChar, true);
       
    74 		}
       
    75 		TagWriter.appendAttribute(sb, TagWriter.CLASSIFICATION_ATTR, dataType
       
    76 				.getType(), true);
       
    77 		sb.append(TagWriter.TAG_CLOSE);
       
    78 		TagWriter.write(sb.toString(), TagWriter.INDENT_2);
       
    79 	}
       
    80 
       
    81 	/**
       
    82 	 * Writes <object type="" size="" formatChar="" dataType=""/>
       
    83 	 * structure
       
    84 	 * 
       
    85 	 * @param type
       
    86 	 *            original type name
       
    87 	 * @param size
       
    88 	 *            size of typical object, it’s optional because dictionary user
       
    89 	 *            can calculate size for compound types by sum size of each
       
    90 	 *            member. Give -1 if not used.
       
    91 	 * @param formatChar
       
    92 	 *            used for formatting
       
    93 	 * @param dataType
       
    94 	 *            one value form <datatype> enumeration
       
    95 	 */
       
    96 	public static void writeTypeDef(String type, int size, String formatChar,
       
    97 			DataType dataType) {
       
    98 		StringBuffer sb = new StringBuffer();
       
    99 		sb.append(TagWriter.OBJECT_START_OPEN);
       
   100 		TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, false);
       
   101 		if (size >= 0) {
       
   102 			TagWriter.appendAttribute(sb, TagWriter.SIZE_ATTR, String
       
   103 					.valueOf(size), true);
       
   104 		}
       
   105 		if (formatChar != null) {
       
   106 			TagWriter.appendAttribute(sb, TagWriter.FORMATCHAR_ATTR,
       
   107 					formatChar, true);
       
   108 		}
       
   109 		TagWriter.appendAttribute(sb, TagWriter.CLASSIFICATION_ATTR, dataType
       
   110 				.getType(), true);
       
   111 		sb.append(TagWriter.TAG_END);
       
   112 		TagWriter.write(sb.toString(), TagWriter.INDENT_2);
       
   113 	}
       
   114 
       
   115 	/**
       
   116 	 * Writes </object>
       
   117 	 */
       
   118 	public static void endTypeDef() {
       
   119 		TagWriter.write(TagWriter.OBJECT_END, TagWriter.INDENT_2);
       
   120 	}
       
   121 
       
   122 	/**
       
   123 	 * Writes </typedef>
       
   124 	 */
       
   125 	public static void endTypeDefs() {
       
   126 		TagWriter.write(TagWriter.TYPEDEFS_END, TagWriter.INDENT_1);
       
   127 	}
       
   128 }