1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.Version; 19 import org.apache.axis.utils.Messages; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 25 108 public abstract class JavaClassWriter extends JavaWriter { 109 110 111 protected Namespaces namespaces; 112 113 114 protected String className; 115 116 117 protected String packageName; 118 119 127 protected JavaClassWriter(Emitter emitter, String fullClassName, 128 String type) { 129 130 super(emitter, type); 131 132 this.namespaces = emitter.getNamespaces(); 133 this.packageName = Utils.getJavaPackageName(fullClassName); 134 this.className = Utils.getJavaLocalName(fullClassName); 135 } 137 143 protected String getFileName() { 144 return namespaces.toDir(packageName) + className + ".java"; 145 } 147 156 protected void registerFile(String file) { 157 158 final String pkg = getPackage(); 159 String fqClass; 160 if (pkg != null && pkg.length() > 0) { 161 fqClass = pkg + '.' + getClassName(); 162 } else { 163 fqClass = getClassName(); 164 } 165 166 emitter.getGeneratedFileInfo().add(file, fqClass, type); 167 } 169 176 protected void writeFileHeader(PrintWriter pw) throws IOException { 177 178 writeHeaderComments(pw); 179 writePackage(pw); 180 181 pw.println(getClassModifiers() + getClassText() + getClassName() + ' ' 183 + getExtendsText() + getImplementsText() + "{"); 184 } 186 192 protected void writeHeaderComments(PrintWriter pw) throws IOException { 193 194 String localFile = getFileName(); 195 int lastSepChar = localFile.lastIndexOf(File.separatorChar); 196 197 if (lastSepChar >= 0) { 198 localFile = localFile.substring(lastSepChar + 1); 199 } 200 201 pw.println("/**"); 202 pw.println(" * " + localFile); 203 pw.println(" *"); 204 pw.println(" * " + Messages.getMessage("wsdlGenLine00")); 205 pw.println(" * " 206 + Messages.getMessage("wsdlGenLine01", 207 Version.getVersionText())); 208 pw.println(" */"); 209 pw.println(); 210 } 212 218 protected void writePackage(PrintWriter pw) throws IOException { 219 220 final String pkg = getPackage(); 221 if (pkg != null && pkg.length() > 0) { 222 pw.println("package " + pkg + ";"); 223 pw.println(); 224 } 225 } 227 233 protected String getClassModifiers() { 234 return "public "; 235 } 237 243 protected String getClassText() { 244 return "class "; 245 } 247 254 protected String getExtendsText() { 255 return ""; 256 } 258 265 protected String getImplementsText() { 266 return ""; 267 } 269 274 protected String getPackage() { 275 return packageName; 276 } 278 283 protected String getClassName() { 284 return className; 285 } 287 293 protected void writeFileFooter(PrintWriter pw) throws IOException { 294 super.writeFileFooter(pw); 295 pw.println('}'); 296 } } | Popular Tags |