trace/tracebuilder/com.nokia.tracebuilder/src/com/nokia/tracebuilder/engine/propertyfile/PropertyElementParser.java
changeset 10 ed1c9f64298a
equal deleted inserted replaced
9:14dc2103a631 10:ed1c9f64298a
       
     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 * Parser for property element
       
    17 *
       
    18 */
       
    19 package com.nokia.tracebuilder.engine.propertyfile;
       
    20 
       
    21 import org.w3c.dom.Element;
       
    22 
       
    23 import com.nokia.tracebuilder.engine.TraceBuilderErrorCodes.StringErrorParameters;
       
    24 import com.nokia.tracebuilder.engine.TraceBuilderErrorCodes.TraceBuilderErrorCode;
       
    25 import com.nokia.tracebuilder.model.TraceBuilderException;
       
    26 
       
    27 /**
       
    28  * Parser for property element
       
    29  * 
       
    30  */
       
    31 final class PropertyElementParser implements PropertyFileElementParser {
       
    32 
       
    33 	/*
       
    34 	 * (non-Javadoc)
       
    35 	 * 
       
    36 	 * @see com.nokia.tracebuilder.engine.propertyfile.PropertyFileElementParser#
       
    37 	 *      parse(java.lang.Object, org.w3c.dom.Element)
       
    38 	 */
       
    39 	public void parse(Object owner, Element element)
       
    40 			throws TraceBuilderException {
       
    41 		// Property must be parsed within context of property list
       
    42 		if (owner instanceof TraceObjectPropertyListImpl) {
       
    43 			String name = element
       
    44 					.getAttribute(PropertyFileConstants.NAME_ATTRIBUTE);
       
    45 			if (name != null && name.length() > 0) {
       
    46 				String value = element.getTextContent();
       
    47 				TraceObjectPropertyImpl property = new TraceObjectPropertyImpl(
       
    48 						name, value);
       
    49 				((TraceObjectPropertyListImpl) owner).addProperty(property);
       
    50 			} else {
       
    51 				StringErrorParameters parameter = new StringErrorParameters();
       
    52 				parameter.string = PropertyFileConstants.NAME_ATTRIBUTE;
       
    53 				throw new TraceBuilderException(
       
    54 						TraceBuilderErrorCode.PROPERTY_FILE_ATTRIBUTE_INVALID,
       
    55 						parameter, null);
       
    56 			}
       
    57 		} else {
       
    58 			StringErrorParameters parameter = new StringErrorParameters();
       
    59 			parameter.string = PropertyFileConstants.PROPERTY_ELEMENT;
       
    60 			throw new TraceBuilderException(
       
    61 					TraceBuilderErrorCode.PROPERTY_FILE_ELEMENT_MISPLACED,
       
    62 					parameter, null);
       
    63 		}
       
    64 	}
       
    65 
       
    66 }