diff -r 07b41fa8d1dd -r ca8a1b6995f6 tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDefStore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDefStore.java Tue Aug 31 16:45:49 2010 +0300 @@ -0,0 +1,128 @@ +/* +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +* Writes type definition objects +* +*/ +package com.nokia.tracecompiler.decodeplugins.dictionary.encoder; + +/** + * Writes type definition objects + * + */ +public class TypeDefStore { + + /** + * Writes <typedef> + */ + public static void startTypeDefs() { + TagWriter.write(TagWriter.TYPEDEFS_START, TagWriter.INDENT_1); + } + + /** + * Writes <external-def>path</external-def> structure + * + * @param path + * path to external dictionary file + */ + public static void writeExternalDefFile(String path) { + StringBuffer sb = new StringBuffer(); + sb.append(TagWriter.EXTERNAL_DEF_START); + sb.append(XMLDataFilter.changeData(path)); + sb.append(TagWriter.EXTERNAL_DEF_END); + TagWriter.write(sb.toString(), TagWriter.INDENT_2); + } + + /** + * Starts <object type="" size="" formatChar="" dataType=""> structure + * + * @param type + * original type name + * @param size + * size of typical object, it’s optional because dictionary user + * can calculate size for compound types by sum size of each + * member. Give -1 if not used. + * @param formatChar + * used for formatting + * @param dataType + * one value form <datatype> enumeration + */ + public static void startTypeDef(String type, int size, String formatChar, + DataType dataType) { + StringBuffer sb = new StringBuffer(); + sb.append(TagWriter.OBJECT_START_OPEN); + TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, false); + if (size >= 0) { // optional attribute + TagWriter.appendAttribute(sb, TagWriter.SIZE_ATTR, String + .valueOf(size), true); + } + if (formatChar != null) { // optional attribute + TagWriter.appendAttribute(sb, TagWriter.FORMATCHAR_ATTR, + formatChar, true); + } + TagWriter.appendAttribute(sb, TagWriter.CLASSIFICATION_ATTR, dataType + .getType(), true); + sb.append(TagWriter.TAG_CLOSE); + TagWriter.write(sb.toString(), TagWriter.INDENT_2); + } + + /** + * Writes <object type="" size="" formatChar="" dataType=""/> + * structure + * + * @param type + * original type name + * @param size + * size of typical object, it’s optional because dictionary user + * can calculate size for compound types by sum size of each + * member. Give -1 if not used. + * @param formatChar + * used for formatting + * @param dataType + * one value form <datatype> enumeration + */ + public static void writeTypeDef(String type, int size, String formatChar, + DataType dataType) { + StringBuffer sb = new StringBuffer(); + sb.append(TagWriter.OBJECT_START_OPEN); + TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, false); + if (size >= 0) { + TagWriter.appendAttribute(sb, TagWriter.SIZE_ATTR, String + .valueOf(size), true); + } + if (formatChar != null) { + TagWriter.appendAttribute(sb, TagWriter.FORMATCHAR_ATTR, + formatChar, true); + } + TagWriter.appendAttribute(sb, TagWriter.CLASSIFICATION_ATTR, dataType + .getType(), true); + sb.append(TagWriter.TAG_END); + TagWriter.write(sb.toString(), TagWriter.INDENT_2); + } + + /** + * Writes </object> + */ + public static void endTypeDef() { + TagWriter.write(TagWriter.OBJECT_END, TagWriter.INDENT_2); + } + + /** + * Writes </typedef> + */ + public static void endTypeDefs() { + TagWriter.write(TagWriter.TYPEDEFS_END, TagWriter.INDENT_1); + } +}