|
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.1 2002/11/26 14:41:05 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 69 public String toString(){ 70 StringBuffer res = new StringBuffer(); 71 res.append("Name: " + name + "\n"); 72 res.append("Type: " + type + "\n"); 73 res.append("Feature: " + feature + "\n"); 74 Iterator valIter = values.iterator(); 75 while(valIter.hasNext()){ 76 res.append(" Value:" + valIter.next().toString() + "\n"); 77 } 78 return res.toString(); 79 } 80 81 public boolean isClass(){ 82 return isClass; 83 } 84 85 public void setName(String name) { 86 this.name = name; 87 } 88 89 public String getName() { 90 return name; 91 } 92 93 public void setType(String type) { 94 this.type = type; 95 } 96 97 public String getType() { 98 return type; 99 } 100 101 public void setFeature(String feature) { 102 this.feature = feature; 103 } 104 105 public String getFeature() { 106 return feature; 107 } 108 109 public java.util.List getValues() { 110 return values; 111 } 112 public int getPosition() { 113 return position; 114 } 115 116 boolean isClass = false; 117 private String name; 118 private String type; 119 private String feature; 120 private java.util.List values; 121 private int position; 122 }
|
Attribute |
|