trace/traceviewer/com.nokia.trace.dictionary/src/com/nokia/trace/dictionary/model/handlers/DictionaryHandlerCreator.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  * Handler creator
       
    17  *
       
    18  */
       
    19 package com.nokia.trace.dictionary.model.handlers;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 import java.util.Collections;
       
    23 import java.util.Comparator;
       
    24 
       
    25 import com.nokia.trace.dictionary.model.DictionaryDecodeModel;
       
    26 
       
    27 /**
       
    28  * Creates Dictionary handlers
       
    29  * 
       
    30  */
       
    31 public class DictionaryHandlerCreator {
       
    32 
       
    33 	/**
       
    34 	 * Model
       
    35 	 */
       
    36 	private DictionaryDecodeModel model;
       
    37 
       
    38 	/**
       
    39 	 * Constructor
       
    40 	 * 
       
    41 	 * @param model
       
    42 	 *            the model
       
    43 	 */
       
    44 	public DictionaryHandlerCreator(DictionaryDecodeModel model) {
       
    45 		this.model = model;
       
    46 	}
       
    47 
       
    48 	/**
       
    49 	 * Creates start handlers and puts them into this array
       
    50 	 * 
       
    51 	 * @return arrayList of start handlers
       
    52 	 */
       
    53 	public ArrayList<DictionaryHandler> createStartHandlers() {
       
    54 		ArrayList<DictionaryHandler> handlers = new ArrayList<DictionaryHandler>();
       
    55 
       
    56 		// Add start handlers. Handlers that are commented out have no use in
       
    57 		// this time. In the future, they can be commented in and implemented
       
    58 
       
    59 		handlers.add(new ComponentHandler(model));
       
    60 		// handlers.add(new DataHandler(model));
       
    61 		handlers.add(new DefHandler(model));
       
    62 		// handlers.add(new ExternalDefHandler(model));
       
    63 		handlers.add(new FileHandler(model));
       
    64 		handlers.add(new GroupHandler(model));
       
    65 		handlers.add(new InstanceHandler(model));
       
    66 		// handlers.add(new LocationsHandler(model));
       
    67 		// handlers.add(new MetaDataHandler(model));
       
    68 		handlers.add(new ObjectHandler(model));
       
    69 		handlers.add(new OptionsHandler(model));
       
    70 		handlers.add(new PathHandler(model));
       
    71 		handlers.add(new TraceHandler(model));
       
    72 		// handlers.add(new TraceDictionaryHandler(model));
       
    73 		// handlers.add(new TypeDefHandler(model));
       
    74 		handlers.add(new TypeMemberHandler(model));
       
    75 
       
    76 		// Sort and return the handlers
       
    77 		sortHandlers(handlers);
       
    78 		return handlers;
       
    79 	}
       
    80 
       
    81 	/**
       
    82 	 * Creates end handlers and puts them into this array
       
    83 	 * 
       
    84 	 * @return arrayList of end handlers
       
    85 	 */
       
    86 	public ArrayList<DictionaryHandler> createEndHandlers() {
       
    87 		ArrayList<DictionaryHandler> handlers = new ArrayList<DictionaryHandler>();
       
    88 
       
    89 		// Add end handlers. Handlers that are commented out have no use in this
       
    90 		// time. In the future, they can be commented in if they need to
       
    91 		// implement processEndElement function.
       
    92 
       
    93 		handlers.add(new ComponentHandler(model));
       
    94 		// handlers.add(new DataHandler(model));
       
    95 		handlers.add(new DefHandler(model));
       
    96 		// handlers.add(new ExternalDefHandler(model));
       
    97 		handlers.add(new FileHandler(model));
       
    98 		handlers.add(new GroupHandler(model));
       
    99 		handlers.add(new InstanceHandler(model));
       
   100 		// handlers.add(new LocationsHandler(model));
       
   101 		// handlers.add(new MetaDataHandler(model));
       
   102 		// handlers.add(new ObjectHandler(model));
       
   103 		handlers.add(new OptionsHandler(model));
       
   104 		// handlers.add(new PathHandler(model));
       
   105 		handlers.add(new TraceHandler(model));
       
   106 		// handlers.add(new TraceDictionaryHandler(model));
       
   107 		// handlers.add(new TypeDefHandler(model));
       
   108 		// handlers.add(new TypeMemberHandler(model));
       
   109 
       
   110 		// Sort and return the handlers
       
   111 		sortHandlers(handlers);
       
   112 		return handlers;
       
   113 	}
       
   114 
       
   115 	/**
       
   116 	 * Sorts the handlers by the name attribute
       
   117 	 * 
       
   118 	 * @param handlers
       
   119 	 *            the dictionary handlers
       
   120 	 */
       
   121 	public void sortHandlers(ArrayList<DictionaryHandler> handlers) {
       
   122 		Collections.sort(handlers, new Comparator<DictionaryHandler>() {
       
   123 
       
   124 			/**
       
   125 			 * Compares two handler names
       
   126 			 * 
       
   127 			 * @param o1
       
   128 			 *            first handler
       
   129 			 * @param o2
       
   130 			 *            second handler
       
   131 			 * @return less than zero if first one is first in alphabetic order.
       
   132 			 *         More than zero if second is first.
       
   133 			 */
       
   134 			public int compare(DictionaryHandler o1, DictionaryHandler o2) {
       
   135 				int val = o1.getName().compareTo(o2.getName());
       
   136 				return val;
       
   137 			}
       
   138 		});
       
   139 	}
       
   140 }