tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/rules/AutoAddParameterRuleBase.java
changeset 56 aa2539c91954
parent 54 a151135b0cf9
child 60 e54443a6878c
child 62 1c2bb2fc7c87
equal deleted inserted replaced
54:a151135b0cf9 56:aa2539c91954
     1 /*
       
     2 * Copyright (c) 2007 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 * Base class for the auto-add parameter rules
       
    17 *
       
    18 */
       
    19 package com.nokia.tracecompiler.engine.rules;
       
    20 
       
    21 import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
       
    22 import com.nokia.tracecompiler.engine.utils.TraceMultiplierRule;
       
    23 import com.nokia.tracecompiler.model.Trace;
       
    24 import com.nokia.tracecompiler.model.TraceCompilerException;
       
    25 import com.nokia.tracecompiler.model.TraceModelExtension;
       
    26 import com.nokia.tracecompiler.model.TraceObjectRule;
       
    27 import com.nokia.tracecompiler.model.TraceObjectRuleCreateObject;
       
    28 import com.nokia.tracecompiler.model.TraceObjectRuleRemoveOnCreate;
       
    29 import com.nokia.tracecompiler.model.TraceObjectUtils;
       
    30 
       
    31 /**
       
    32  * Base class for the auto-add parameter rules
       
    33  * 
       
    34  */
       
    35 abstract class AutoAddParameterRuleBase extends RuleBase implements
       
    36 		TraceObjectRuleCreateObject, TraceObjectRuleRemoveOnCreate {
       
    37 
       
    38 	/*
       
    39 	 * (non-Javadoc)
       
    40 	 * 
       
    41 	 * @see com.nokia.tracecompiler.model.TraceObjectRuleCreateObject#createObject()
       
    42 	 */
       
    43 	public void createObject() throws TraceCompilerException {
       
    44 		TraceObjectRule rule = getRule();
       
    45 		TraceModelExtension[] extensions = null;
       
    46 		if (rule != null) {
       
    47 			extensions = new TraceModelExtension[] { rule };
       
    48 		}
       
    49 		Trace owner = (Trace) getOwner();
       
    50 		int id = owner.getNextParameterID();
       
    51 		String name = TraceObjectUtils.modifyDuplicateParameterName(owner,
       
    52 				getName()).getData();
       
    53 		String type = getType();
       
    54 		try {
       
    55 			owner.getModel().getVerifier().checkTraceParameterProperties(owner,
       
    56 					null, id, name, type);
       
    57 			owner.getModel().getFactory().createTraceParameter(owner, id, name,
       
    58 					type, extensions);
       
    59 		} catch (TraceCompilerException e) {
       
    60 			TraceCompilerEngineGlobals.getEvents().postError(e);
       
    61 				throw e;
       
    62 		}
       
    63 	}
       
    64 
       
    65 	/**
       
    66 	 * Gets the name for the new parameter
       
    67 	 * 
       
    68 	 * @return the parameter name
       
    69 	 */
       
    70 	protected abstract String getName();
       
    71 
       
    72 	/**
       
    73 	 * Gets the new parameter type
       
    74 	 * 
       
    75 	 * @return the type
       
    76 	 */
       
    77 	protected abstract String getType();
       
    78 
       
    79 	/**
       
    80 	 * Gets the rule for the parameter
       
    81 	 * 
       
    82 	 * @return the rule
       
    83 	 */
       
    84 	protected abstract TraceObjectRule getRule();
       
    85 
       
    86 	/*
       
    87 	 * (non-Javadoc)
       
    88 	 * 
       
    89 	 * @see com.nokia.tracecompiler.model.TraceObjectRuleRemoveOnCreate#canBeRemoved()
       
    90 	 */
       
    91 	public boolean canBeRemoved() {
       
    92 		// If the owner has a multiplier, this needs to be moved to it using the
       
    93 		// CopyAndRemoveExtensionRule
       
    94 		return getOwner().getExtension(TraceMultiplierRule.class) == null;
       
    95 	}
       
    96 
       
    97 }