1 23 24 package org.objectweb.jorm.metainfo.lib; 25 26 import org.objectweb.jorm.metainfo.api.CompositeName; 27 import org.objectweb.jorm.metainfo.api.MetaObject; 28 import org.objectweb.jorm.metainfo.api.NameDef; 29 import org.objectweb.jorm.metainfo.api.NameRef; 30 import org.objectweb.jorm.util.api.Loggable; 31 import org.objectweb.util.monolog.api.Logger; 32 import org.objectweb.util.monolog.api.LoggerFactory; 33 34 import java.util.ArrayList ; 35 import java.util.Iterator ; 36 import java.util.Collection ; 37 import java.util.Collections ; 38 39 46 public class BasicNameDef extends BasicMetaObject implements NameDef { 47 48 53 private boolean isSystem = false; 54 55 59 private boolean isNameRef = false; 60 61 65 private boolean isFieldName = false; 66 67 70 private NameRef nameRef = null; 71 72 77 private String fieldName = null; 78 79 82 private String name = null; 83 84 91 public BasicNameDef(MetaObject parent) { 92 super(parent); 93 name = ""; 94 } 95 96 97 101 102 107 public int getFieldNumber() { 108 return (isNameRef() ? nameRef.getProjection().size() : 1); 109 } 110 111 119 public boolean isSystem() { 120 return isSystem; 121 } 122 123 131 public void setSystem(boolean system) { 132 isSystem = system; 133 } 134 135 139 public boolean isNameRef() { 140 return isNameRef; 141 } 142 143 147 public boolean isFieldName() { 148 return isFieldName; 149 } 150 151 157 public NameRef createNameRef(CompositeName cn_Class) { 158 isNameRef = true; 159 BasicNameRef bnr = new BasicNameRef(cn_Class, this); 160 this.nameRef = bnr; 161 return bnr; 162 } 163 164 168 public NameRef getNameRef() { 169 return this.nameRef; 170 } 171 172 173 178 public String getFieldName() { 179 return this.fieldName; 180 } 181 182 186 public void setFieldName(String fieldname) { 187 this.fieldName = fieldname; 188 this.isFieldName = true; 189 } 190 191 195 public String getName() { 196 return this.name; 197 } 198 199 203 public void setName(String name) { 204 this.name = name; 205 } 206 207 214 215 public Iterator iterateField() { 216 if (!(isNameRef())) { 217 ArrayList allInOne = new ArrayList (); 218 allInOne.add(fieldName); 219 return allInOne.iterator(); 220 } else 221 return nameRef.getProjection().values().iterator(); 222 } 223 224 protected Collection getChildren() { 225 if (isNameRef && nameRef != null) { 226 return Collections.singleton(nameRef); 227 } else { 228 return super.getChildren(); 229 } 230 } 231 } 232 | Popular Tags |