1 18 package org.apache.geronimo.interop.generator; 19 20 import java.lang.reflect.Modifier ; 21 import java.util.Vector ; 22 23 public class JClass extends JEntity { 24 private JPackage pkg; 25 private Vector imports; 26 private Vector impls; 27 private String baseClassName; 28 private Vector constructors; 29 private Vector methods; 30 private Vector fields; 31 private Vector classes = new Vector (); 32 private JClass parent; 33 34 protected JClass(String name) { 35 super(name, Modifier.PUBLIC); 36 37 imports = new Vector (); 38 impls = new Vector (); 39 baseClassName = ""; 40 41 constructors = new Vector (); 42 methods = new Vector (); 43 fields = new Vector (); 44 } 45 46 protected JClass(String name, JPackage pkg) { 47 this(name); 48 49 if (pkg == null) { 50 pkg = new JPackage(""); 51 } 52 53 this.pkg = pkg; 54 } 55 56 protected JClass(String name, JClass parent) { 57 this(name); 58 59 this.parent = parent; 60 } 61 62 public JConstructor newConstructor(JParameter parms[], Class thrown[]) { 63 JConstructor c = new JConstructor(parms, thrown); 64 c.setParent(this); 65 constructors.add(c); 66 return c; 67 } 68 69 public void deleteConstructor(JConstructor m) { 70 constructors.removeElement(m); 71 } 72 73 public Vector getConstructors() { 74 return constructors; 75 } 76 77 public JMethod newMethod(JReturnType rt, String name, JParameter parms[], Class thrown[]) { 78 JMethod m = new JMethod(rt, name, parms, thrown); 79 m.setParent(this); 80 methods.add(m); 81 return m; 82 } 83 84 public void deleteMethod(JMethod m) { 85 methods.removeElement(m); 86 } 87 88 public Vector getMethods() { 89 return methods; 90 } 91 92 protected void setFieldParentAndModifier(JField f) { 93 f.setParent(this); 94 95 if (Modifier.isPublic(this.getModifiers())) { 96 f.setModifiers(f.getModifiers() | Modifier.PUBLIC); 97 } 98 99 if (Modifier.isProtected(this.getModifiers())) { 100 f.setModifiers(f.getModifiers() | Modifier.PROTECTED); 101 } 102 103 if (Modifier.isPrivate(this.getModifiers())) { 104 f.setModifiers(f.getModifiers() | Modifier.PRIVATE); 105 } 106 } 107 108 public JField newField(Class type, String name) { 109 return newField(type, name, null); 110 } 111 112 public JField newField(Class type, String name, JExpression initExpr) { 113 return newField(type, name, initExpr, false); 114 } 115 116 public JField newField(Class type, String name, JExpression initExpr, boolean isArray) { 117 JField f = new JField(type, name); 118 119 setFieldParentAndModifier(f); 120 f.setInitExpression(initExpr); 121 122 fields.add(f); 123 124 return f; 125 } 126 127 public void deleteField(JField f) { 128 fields.remove(f); 129 } 130 131 public Vector getFields() { 132 return fields; 133 } 134 135 public JClass newClass(String name) { 136 JClass c = new JClass(name, this); 137 classes.add(c); 138 return c; 139 } 140 141 public JPackage getPackage() { 142 if (parent != null) { 143 return parent.getPackage(); 144 } else { 145 return pkg; 146 } 147 } 148 149 public String getName() { 150 if (parent != null) { 151 return parent.getName() + "$" + super.getName(); 152 } else { 153 return super.getName(); 154 } 155 } 156 157 public void setExtends(String bcl) { 158 setBaseClassName(bcl); 159 } 160 161 public String getExtends() { 162 return getBaseClassName(); 163 } 164 165 public void setBaseClassName(String bcl) { 166 baseClassName = bcl; 167 } 168 169 public String getBaseClassName() { 170 return baseClassName; 171 } 172 173 public void addImplements(String className) { 174 impls.add(className); 175 } 176 177 public void removeImplements(String className) { 178 impls.remove(className); 179 } 180 181 public Vector getImplements() { 182 return impls; 183 } 184 185 188 public void addImport(Package pkg, String itemName) { 189 if (pkg != null) { 190 addImport(pkg.getName(), itemName); 191 } 192 } 193 194 public void addImport(Package pkg) { 195 if (pkg != null) { 196 addImport(pkg.getName(), "*"); 197 } 198 } 199 200 public void addImport(String name, String itemName) { 201 addImport(name + "." + itemName); 202 } 203 204 public void addImport(String fqName) { 205 imports.add(fqName); 206 } 207 208 public void removeImport(Package pkg, String itemName) { 209 if (pkg != null) { 210 removeImport(pkg.getName(), itemName); 211 } 212 } 213 214 public void removeImport(Package pkg) { 215 if (pkg != null) { 216 removeImport(pkg.getName()); 217 } 218 } 219 220 public void removeImport(String name, String itemName) { 221 removeImport(name + "." + itemName); 222 } 223 224 public void removeImport(String name) { 225 imports.remove(name); 226 } 227 228 public Vector getImports() { 229 return imports; 230 } 231 } 232 | Popular Tags |