1 package org.objectweb.modfact.jmi.reflect; 2 3 import javax.jmi.reflect.*; 4 import java.util.*; 5 6 public class EnumType implements java.io.Serializable { 7 8 String [] typeName; 9 String [] labels; 10 RefEnum_impl[] enums; 11 12 public EnumType() { 13 } 14 15 EnumType(List typeName, List labels) { 16 this.typeName = (String [])typeName.toArray(new String [0]); 17 this.labels = (String [])labels.toArray(new String [0]); 18 enums = new RefEnum_impl[this.labels.length]; 19 for(int i=0; i<this.labels.length; i++) { 20 enums[i] = new RefEnum_impl(i); 21 } 22 } 23 24 public RefEnum getEnum(String label) { 25 for(int i=0; i<labels.length; i++) { 26 if(label.equals(labels[i])) 27 return enums[i]; 28 } 29 throw new RuntimeException ( typeName[typeName.length-1] 30 +": invalide label '" +label +"'"); 31 } 32 33 private class RefEnum_impl implements javax.jmi.reflect.RefEnum, java.io.Serializable { 34 35 private int index; 36 37 public RefEnum_impl() { 38 } 39 40 RefEnum_impl(int index) { 41 this.index = index; 42 } 43 44 public java.util.List refTypeName() { 45 return RefBaseObjectImpl.arrayToList(typeName); 46 } 47 48 public int hashCode() { 49 return labels[index].hashCode(); 50 } 51 52 public boolean equals(Object o) { 53 if(!(o instanceof RefEnum_impl)) return false; 54 RefEnum_impl other = (RefEnum_impl) o; 55 if(index != other.index) return false; 56 return refTypeName().equals(other.refTypeName()); 57 } 58 59 public String toString() { 60 return labels[index]; 61 } 62 } } 64 | Popular Tags |