1 17 package org.apache.ws.jaxme.js; 18 19 import java.io.IOException ; 20 21 22 26 public class JavaField extends JavaSourceObject implements DirectAccessible { 27 private class MyTarget implements IndentationTarget { 28 private StringBuffer sb = new StringBuffer (); 29 private IndentationTarget actualTarget; 30 private MyTarget(IndentationTarget pActualTarget) { 31 actualTarget = pActualTarget; 32 } 33 public boolean isInterface() { 34 return actualTarget.isInterface(); 35 } 36 public String asString(JavaQName pQName) { 37 return actualTarget.asString(pQName); 38 } 39 public void write(String pValue) { 40 sb.append(pValue); 41 } 42 public void write() { 43 sb.append("\n"); 44 } 45 public void indent(int i) { 46 } 47 public String getResult() { return sb.toString(); } 48 } 49 50 private boolean isTransient; 51 private boolean isNullable = true; 52 53 56 JavaField(String pName, JavaQName pType, JavaSource.Protection pProtection) { 57 super(pName, pType, pProtection); 58 } 59 60 62 public void setTransient(boolean pTransient) { 63 isTransient = pTransient; 64 } 65 66 68 public boolean isTransient() { 69 return isTransient; 70 } 71 72 73 75 public void write(IndentationTarget pTarget) throws IOException { 76 pTarget.indent(0); 77 writeNoEol(pTarget); 78 pTarget.write(); 79 } 80 81 protected void writeNoEol(IndentationTarget pTarget) throws IOException { 82 if (pTarget.isInterface()) { 83 return; 84 } 85 JavaComment jcon = getComment(); 86 if (jcon != null) { 87 jcon.write(pTarget); 88 pTarget.indent(0); 89 } 90 JavaSource.Protection protection = getProtection(); 91 if (protection != null && !protection.equals(JavaSource.DEFAULT_PROTECTION)) { 92 pTarget.write(protection.toString()); 93 pTarget.write(" "); 94 } 95 if (isFinal()) { 96 pTarget.write("final "); 97 } 98 if (isStatic()) { 99 pTarget.write("static "); 100 } 101 if (isTransient()) { 102 pTarget.write("transient "); 103 } 104 pTarget.write(pTarget.asString(getType())); 105 pTarget.write(" "); 106 pTarget.write(getName()); 107 if (isEmpty()) { 108 pTarget.write(";"); 109 } else { 110 pTarget.write(" = "); 111 MyTarget mt = new MyTarget(pTarget); 112 super.write(mt); 113 String result = mt.getResult(); 114 if (result.endsWith("\r\n")) { 115 result = result.substring(0, result.length()-2); 116 } else if (result.endsWith("\n")) { 117 result = result.substring(0, result.length()-1); 118 } 119 pTarget.write(result); 120 if (!result.endsWith(";")) { 121 pTarget.write(";"); 122 } 123 } 124 } 125 126 public void setValue(Object pValue) { 127 clear(); 128 addLine(pValue); 129 } 130 131 public boolean isNullable() { return isNullable; } 132 public void setNullable(boolean pNullable) { isNullable = pNullable; } 133 } 134
| Popular Tags
|