trace/traceviewer/com.nokia.trace.dictionary/src/com/nokia/trace/dictionary/model/handlers/TypeMemberHandler.java
changeset 11 5b9d4d8641ce
equal deleted inserted replaced
10:ed1c9f64298a 11:5b9d4d8641ce
       
     1 /*
       
     2  * Copyright (c) 2007-2010 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  * TypeMember handler
       
    17  *
       
    18  */
       
    19 package com.nokia.trace.dictionary.model.handlers;
       
    20 
       
    21 import org.xml.sax.Attributes;
       
    22 
       
    23 import com.nokia.trace.dictionary.TraceDictionaryEngine;
       
    24 import com.nokia.trace.dictionary.model.DictionaryContentHandler;
       
    25 import com.nokia.trace.dictionary.model.DictionaryDecodeModel;
       
    26 import com.nokia.trace.dictionary.model.decodeparameters.CompoundParameter;
       
    27 import com.nokia.trace.dictionary.model.decodeparameters.DecodeParameter;
       
    28 import com.nokia.trace.dictionary.model.decodeparameters.EnumMember;
       
    29 import com.nokia.trace.dictionary.model.decodeparameters.EnumParameter;
       
    30 import com.nokia.trace.eventrouter.TraceEvent;
       
    31 
       
    32 /**
       
    33  * TypeMember handler
       
    34  */
       
    35 final class TypeMemberHandler extends BaseHandler {
       
    36 
       
    37 	/**
       
    38 	 * Tag name this handler handles
       
    39 	 */
       
    40 	private static final String TYPEMEMBER_TAG = "typemember"; //$NON-NLS-1$
       
    41 
       
    42 	/**
       
    43 	 * Constructor
       
    44 	 * 
       
    45 	 * @param model
       
    46 	 *            the model
       
    47 	 */
       
    48 	TypeMemberHandler(DictionaryDecodeModel model) {
       
    49 		super(model, TYPEMEMBER_TAG);
       
    50 	}
       
    51 
       
    52 	/*
       
    53 	 * (non-Javadoc)
       
    54 	 * 
       
    55 	 * @see
       
    56 	 * com.nokia.trace.dictionary.model.handlers.BaseHandler#processStartElement
       
    57 	 * (org.xml.sax.Attributes,
       
    58 	 * com.nokia.trace.dictionary.model.DictionaryContentHandler)
       
    59 	 */
       
    60 	@Override
       
    61 	public void processStartElement(Attributes atts,
       
    62 			DictionaryContentHandler handler) {
       
    63 		// Check are we doing enum or compound
       
    64 		if (atts.getValue(VALUE) != null) {
       
    65 			// Get the previous enum parameter
       
    66 			EnumParameter prevEnum = handler.getVariables()
       
    67 					.getPreviousEnumParameter();
       
    68 
       
    69 			// Create new enum member
       
    70 			EnumMember enumMember = new EnumMember(atts.getValue(NAME), Integer
       
    71 					.parseInt(atts.getValue(VALUE)));
       
    72 
       
    73 			// Add to enum parameter
       
    74 			prevEnum.addMember(enumMember);
       
    75 
       
    76 		} else if (atts.getValue(TYPE) != null) {
       
    77 			// Get the parameter from model
       
    78 			DecodeParameter parameter = model.getDecodeParameter(atts
       
    79 					.getValue(TYPE));
       
    80 
       
    81 			// Get the previous compoundParameter
       
    82 			CompoundParameter prevCompound = handler.getVariables()
       
    83 					.getPreviousCompoundParameter();
       
    84 
       
    85 			// Add parameter and it's name to compoundParameter
       
    86 			prevCompound.addParameter(parameter, atts.getValue(NAME));
       
    87 
       
    88 		} else {
       
    89 			TraceEvent event = new TraceEvent(TraceEvent.ERROR, Messages
       
    90 					.getString("TypeMemberHandler.WrongTypeMember")); //$NON-NLS-1$
       
    91 			event.setCategory(EVENT_CATEGORY);
       
    92 			event.setSource(Integer.valueOf(handler.getLocator()
       
    93 					.getLineNumber()));
       
    94 			TraceDictionaryEngine.postEvent(event);
       
    95 		}
       
    96 	}
       
    97 }