Project: bml_lib License: BSD Dependencies: Used by: |
bml_lib/src/edu/wpi/hri/bml/behavior/HeadBehavior.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.bml.behavior; 00035 00036 import org.w3c.dom.Document; 00037 import org.w3c.dom.Element; 00038 00039 import edu.wpi.hri.bml.behavior.BehaviorEnums.BehaviorType; 00040 import edu.wpi.hri.bml.behavior.BehaviorEnums.HeadMovementType; 00041 import edu.wpi.hri.log.Logger; 00042 import edu.wpi.hri.log.Logger.LoggerLevel; 00043 00050 public class HeadBehavior extends Behavior { 00051 00052 private static final String TYPE_ATTR = "type"; 00053 private static final String REPEAT_ATTR = "repeats"; 00054 private static final String AMOUNT_ATTR = "amount"; 00055 00056 private final HeadMovementType type; 00057 private final int repeats; 00058 private final float amount; 00059 00068 public HeadBehavior(Logger logger, Element elem) { 00069 super(logger, elem); 00070 00071 // get the type first 00072 if (elem.hasAttribute(TYPE_ATTR)) 00073 this.type = HeadMovementType.valueOf(elem.getAttribute(TYPE_ATTR)); 00074 else 00075 this.type = HeadMovementType.NOD; 00076 00077 // get the number of repeats 00078 if (elem.hasAttribute(REPEAT_ATTR)) 00079 this.repeats = Integer.parseInt(elem.getAttribute(REPEAT_ATTR)); 00080 else 00081 this.repeats = 1; 00082 00083 // get the amount last 00084 if (elem.hasAttribute(AMOUNT_ATTR)) 00085 this.amount = Float.parseFloat(elem.getAttribute(AMOUNT_ATTR)); 00086 else 00087 this.amount = 0.0f; 00088 00089 this.logger.debug(LoggerLevel.BEHAVIOR, "Created ..."); 00090 } 00091 00108 public HeadBehavior(Logger logger, String id, HeadMovementType type, 00109 int repeats, float amount, boolean required) { 00110 super(logger, id, required); 00111 this.type = type; 00112 this.repeats = repeats; 00113 this.amount = amount; 00114 this.logger.debug(LoggerLevel.BEHAVIOR, "Created ..."); 00115 } 00116 00120 public HeadMovementType getType() { 00121 return type; 00122 } 00123 00127 public int getRepeats() { 00128 return repeats; 00129 } 00130 00134 public float getAmount() { 00135 return amount; 00136 } 00137 00138 @Override 00139 protected void appendAttributes(Document doc, Element elem) { 00140 // first add the type 00141 if (this.type != null) 00142 elem.setAttribute(TYPE_ATTR, this.type.toString()); 00143 00144 // then the number of repeats 00145 if (this.repeats > 1) 00146 elem.setAttribute(REPEAT_ATTR, String.valueOf(this.repeats)); 00147 00148 // finally the amount of the motion 00149 if (this.amount != 0.0f) 00150 elem.setAttribute(AMOUNT_ATTR, String.valueOf(this.amount)); 00151 } 00152 00153 @Override 00154 protected String getElementName() { 00155 return BehaviorType.HEAD.elementName; 00156 } 00157 } |