|
Attribute |
|
1 /* 2 * Copyright (c) 1998-2001, The University of Sheffield. 3 * 4 * This file is part of GATE (see http://gate.ac.uk/), and is free 5 * software, licenced under the GNU Library General Public License, 6 * Version 2, June 1991 (in the distribution as file licence.html, 7 * and also available at http://gate.ac.uk/gate/licence.html). 8 * 9 * Valentin Tablan 19/11/2002 10 * 11 * $Id: Attribute.java,v 1.3 2003/05/08 15:42:33 valyt Exp $ 12 * 13 */ 14 package gate.creole.ml; 15 16 import java.util.*; 17 import java.io.*; 18 19 import org.jdom.*; 20 21 import gate.util.*; 22 23 /** 24 * Describes an attribute associated to a ML instance. 25 */ 26 27 public class Attribute implements Serializable{ 28 29 public Attribute(Element jdomElement) throws GateException { 30 //find the name 31 Element anElement = jdomElement.getChild("NAME"); 32 if(anElement == null) throw new GateException( 33 "Required element \"NAME\" not present in attribute:\n" + 34 jdomElement.toString() + "!"); 35 else name = anElement.getTextTrim(); 36 37 //find the type 38 anElement = jdomElement.getChild("TYPE"); 39 if(anElement == null) throw new GateException( 40 "Required element \"TYPE\" not present in attribute:\n" + 41 jdomElement.toString() + "!"); 42 else type = anElement.getTextTrim(); 43 44 //find the feature if present 45 anElement = jdomElement.getChild("FEATURE"); 46 if(anElement != null)feature = anElement.getTextTrim(); 47 48 //find the position if present 49 anElement = jdomElement.getChild("POSITION"); 50 if(anElement == null) position = 0; 51 else position = Integer.parseInt(anElement.getTextTrim()); 52 53 //find the class if present 54 isClass = jdomElement.getChild("CLASS") != null; 55 56 //find the allowed values if present 57 anElement = jdomElement.getChild("VALUES"); 58 if(anElement == null) values = null; 59 else{ 60 values = new ArrayList(); 61 Iterator valuesIter = anElement.getChildren("VALUE").iterator(); 62 while(valuesIter.hasNext()){ 63 values.add(((Element)valuesIter.next()).getTextTrim()); 64 } 65 } 66 } 67 68 public Attribute(){ 69 name = null; 70 type =null; 71 feature = null; 72 isClass = false; 73 position = 0; 74 values = null; 75 } 76 77 public String toString(){ 78 StringBuffer res = new StringBuffer(); 79 res.append("Name: " + name + "\n"); 80 res.append("Type: " + type + "\n"); 81 res.append("Feature: " + feature + "\n"); 82 Iterator valIter = values.iterator(); 83 while(valIter.hasNext()){ 84 res.append(" Value:" + valIter.next().toString() + "\n"); 85 } 86 return res.toString(); 87 } 88 89 public boolean isClass(){ 90 return isClass; 91 } 92 93 public void setName(String name) { 94 this.name = name; 95 } 96 97 public String getName() { 98 return name; 99 } 100 101 public void setType(String type) { 102 this.type = type; 103 } 104 105 public String getType() { 106 return type; 107 } 108 109 public void setFeature(String feature) { 110 this.feature = feature; 111 } 112 113 public String getFeature() { 114 return feature; 115 } 116 117 public java.util.List getValues() { 118 return values; 119 } 120 121 public int getPosition() { 122 return position; 123 } 124 125 public void setClass(boolean isClass) { 126 this.isClass = isClass; 127 } 128 129 public void setValues(java.util.List values) { 130 this.values = values; 131 } 132 133 public void setPosition(int position) { 134 this.position = position; 135 } 136 137 boolean isClass = false; 138 private String name; 139 private String type; 140 private String feature; 141 private java.util.List values; 142 private int position; 143 }
|
Attribute |
|