testdev/ite/src/com.nokia.testfw.stf.scripteditor/src/com/nokia/testfw/stf/scripteditor/utils/SelectiveArgument.java
author Johnson Ma <johnson.ma@nokia.com>
Tue, 30 Mar 2010 14:39:29 +0800
changeset 1 96906a986c3b
permissions -rw-r--r--
contribute ITE to symbian foundation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     1
/*
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     8
*
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    11
*
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    12
* Contributors:
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    13
*
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    14
* Description:
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    15
*
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    16
*/
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    17
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    18
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    19
package com.nokia.testfw.stf.scripteditor.utils;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    20
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    21
import static org.w3c.dom.Node.ELEMENT_NODE;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    22
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    23
import java.util.ArrayList;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    24
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    25
import org.w3c.dom.Node;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    26
import org.w3c.dom.NodeList;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    27
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    28
public class SelectiveArgument implements Arguments {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    29
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    30
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    31
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    32
	public SelectiveArgument(Node selectionNode) {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    33
		
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    34
		this.arglist = new ArrayList<Arguments>();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    35
		
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    36
		NodeList selectionList = selectionNode.getChildNodes();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    37
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    38
		for (int i = 0; i < selectionList.getLength(); i++) {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    39
			short typeC = selectionList.item(i).getNodeType();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    40
			if (typeC == ELEMENT_NODE) {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    41
				String value = selectionList.item(i).getAttributes()
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    42
				.getNamedItem("value").getNodeValue();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    43
				String textForNode = selectionList.item(i).getTextContent();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    44
				String binding = selectionList.item(i).getAttributes()
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    45
						.getNamedItem("binding").getNodeValue();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    46
				String nextvalue = selectionList.item(i).getAttributes()
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    47
						.getNamedItem("nextvalue").getNodeValue();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    48
			
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    49
				Argument normal = new Argument(value,textForNode.trim(), binding,nextvalue);
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    50
				arglist.add(normal);
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    51
				
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    52
			}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    53
		}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    54
	}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    55
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    56
	public String getNextValue() {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    57
		return null;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    58
	}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    59
	
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    60
	public String getArgumentBinding(){
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    61
		return "none";
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    62
	}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    63
	public String getArgumentName() {		
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    64
		return this.arglist.get(0).getArgumentName();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    65
	}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    66
	
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    67
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    68
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    69
	
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    70
	
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    71
	private ArrayList<Arguments> arglist;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    72
	
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    73
	
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    74
	public ArrayList<String> validate(ArrayList<String> tokenizedLine) {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    75
		int size = tokenizedLine.size();
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    76
		for(int i = 0 ; i < arglist.size() ; i++){
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    77
			
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    78
			tokenizedLine = this.arglist.get(i).validate(tokenizedLine);
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    79
			if(tokenizedLine.size() < size){
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    80
				return tokenizedLine;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    81
			}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    82
		}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    83
		
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    84
		return tokenizedLine;
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    85
	}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    86
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    87
	public String getArgumenType() {
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    88
		// TODO Auto-generated method stub
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    89
		return "value";
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    90
		
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    91
	}
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    92
96906a986c3b contribute ITE to symbian foundation
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    93
}