harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r596693 [7/9] - in /harmony/enhanced/classlib/branches/java6: ./ depends/jars/ depends/libs/build/ make/ modules/auth/src/main/java/common/org/apache/harmony/auth/jgss/kerberos/ modules/auth/src/main/java/common/org/apache/harmony/auth/jgss...
Date Tue, 20 Nov 2007 14:43:29 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/common/org/apache/harmony/x/print/Graphics2D2PS.java Tue Nov 20 06:42:33 2007
@@ -14,179 +14,130 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/** 
- * @author Igor A. Pyankov 
- * @version $Revision: 1.2 $ 
- */ 
 
 package org.apache.harmony.x.print;
 
 import java.awt.Color;
-import java.awt.Composite;
 import java.awt.Font;
-import java.awt.FontMetrics;
 import java.awt.Graphics;
-import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
 import java.awt.Image;
-import java.awt.Paint;
 import java.awt.Rectangle;
-import java.awt.RenderingHints;
 import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.RenderingHints.Key;
-import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.PathIterator;
 import java.awt.image.BufferedImage;
 import java.awt.image.BufferedImageOp;
 import java.awt.image.ImageObserver;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.RenderableImage;
+import java.awt.print.PageFormat;
 import java.io.PrintStream;
 import java.text.AttributedCharacterIterator;
 import java.text.CharacterIterator;
 import java.util.Date;
-import java.util.Map;
 
-/*
- * Graphics2D2PS
- *  
- */
-public class Graphics2D2PS extends Graphics2D {
-    
-    private Color color;
-    private Color bgcolor;
-    private Color XORcolor; 
-    private Paint paint; 
-    private Font font;    
-    private PrintStream out_stream;
-    
-    static double const1 = 842; // 11.7"
-    static double yscale = 1;
-    
-    private static int convY (int y){      
-        return (int)(const1*yscale)- y ;        
-    }
-   
-    public void setY(int y){
-        const1 = (double)y;
-    }
-           
-    private static String threebytes2Hex (int b){
-        
-        char [] hex = {'0', '1', '2', '3', '4', '5', '6', '7',
-                       '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
-        
-        char [] ret = new char[6];
-        
-            for (int i = 0; i < 6; i++){
-                ret[5-i] = hex[b & 0x0F];
-                b = b >> 4;
-        }
-        return new  String(ret);
-    }   
-            
-    public Graphics2D2PS(PrintStream stream, double height) {              
+import org.apache.harmony.awt.gl.CommonGraphics2D;
+
+public class Graphics2D2PS extends CommonGraphics2D {
+
+    private static final Font DEF_FONT = new Font("Courier", Font.PLAIN, 12); //$NON-NLS-1$
+
+    private final PrintStream out_stream;
+    private final PageFormat  format;
+    private final Rectangle   defaultClip;
+    private double            yscale   = 1;
+
+    public Graphics2D2PS(final PrintStream stream, final PageFormat format) {
         super();
         if (stream == null) {
-            throw new IllegalArgumentException("stream is null");
-        }          
+            throw new IllegalArgumentException("stream is null"); //$NON-NLS-1$
+        }
+
         out_stream = stream;
-        font = new Font("Courier", Font.PLAIN, 12);
-        color = Color.BLACK;
-        bgcolor = Color.WHITE;
-        yscale = 1;
-        const1 = height;
-        out_stream.println("%!PS-Adobe");
-        out_stream.println("%%Title: Java printJob");
-        out_stream.println("%%Creator: Intel(tm) java printing ");
-        out_stream.println("%%CreationDate: " + new Date());
-        out_stream.println("%%EndComments"); 
-    }
-    
-    public Graphics2D2PS(PrintStream stream) {    
-        this(stream, 842D);   
-    }   
+        this.format = format != null ? format : new PageFormat();
+        defaultClip = new Rectangle((int) this.format.getImageableX(),
+                        (int) this.format.getImageableY(), (int) this.format
+                                        .getImageableWidth(), (int) this.format
+                                        .getImageableHeight());
+        PS.printHeader(stream);
+        resetGraphics();
+        setColor(fgColor);
+        setFont(DEF_FONT);
+        setClip(defaultClip);
+        ps(PS.gsave);
+    }
+
+    public Graphics2D2PS(final PrintStream stream) {
+        this(stream, null);
+    }
 
-    public void finish(){       
-        out_stream.println("%%EOF");   
+    public void finish() {
+        PS.printFooter(out_stream);
         out_stream.close();
     }
 
-    public void startPage(int number){
-        out_stream.println("%%Page: " + number + " " + number);
+    public void startPage(final int number) {
+        ps(PS.comment, "Page: " + number + " " + number); //$NON-NLS-1$ //$NON-NLS-2$
+        ps(PS.grestore);
+        resetGraphics();
+    }
+
+    public void endOfPage(final int number) {
+        ps(PS.showpage);
+        ps(PS.comment, "EndPage: " + number + " " + number); //$NON-NLS-1$ //$NON-NLS-2$
     }
-    
-    public void endOfPage(int number){
-        out_stream.println("showpage");
-        out_stream.println("%%EndPage: " + number + " " + number);
-    }
-         
-    /* drawImage-s */    
-    public boolean drawImage(Image image, int x, int y,
-            ImageObserver imageObserver) {
+
+    public boolean drawImage(final Image image, final int x, final int y,
+                    final ImageObserver imageObserver) {
         drawImage(image, x, convY(y));
         return true;
-    }   
-  
-    public boolean drawImage(Image image, int x, int y, int width, int height,
-            ImageObserver imageObserver) {
-        float w;
-        float h;         
-        BufferedImage imageGIF = (BufferedImage) image;
-        w = (float)imageGIF.getWidth();
-        h = (float)imageGIF.getHeight();       
-        drawImage(image, x, convY(y), true, ((float)width)/w , ((float)height)/h);
+    }
+
+    public boolean drawImage(final Image image, final int x, final int y,
+                    final int width, final int height,
+                    final ImageObserver imageObserver) {
+        final BufferedImage imageGIF = (BufferedImage) image;
+        final float w = (float) imageGIF.getWidth();
+        final float h = (float) imageGIF.getHeight();
+
+        drawImage(image, x, convY(y), true, ((float) width) / w,
+                        ((float) height) / h);
         return true;
     }
-        
-    public boolean drawImage(Image image, int x, int y, Color bbgcolor,
-            ImageObserver imageObserver) {
-        int iw;
-        int ih;
-        Color cur_color;
-        
-        BufferedImage imageGIF = (BufferedImage) image;
-        cur_color = getColor();
+
+    public boolean drawImage(final Image image, final int x, final int y,
+                    final Color bbgcolor, final ImageObserver imageObserver) {
+        final BufferedImage imageGIF = (BufferedImage) image;
+        final int iw = imageGIF.getWidth();
+        final int ih = imageGIF.getHeight();
+        final Color cur_color = getColor();
+
         setColor(bbgcolor);
-        
-        iw = imageGIF.getWidth();
-        ih = imageGIF.getHeight();               
         fillRect(x, y, iw, ih);
         setColor(cur_color);
-        
         drawImage(image, x, convY(y));
         return true;
     }
-    
-    
-    public boolean drawImage(Image image, int x, int y, int width, int height,
-            Color bbgcolor, ImageObserver imageObserver) {
-        float w;
-        float h;
-        Color cur_color;
 
-        cur_color = getColor();
-        setColor(bbgcolor);        
+    public boolean drawImage(final Image image, final int x, final int y,
+                    final int width, final int height, final Color bbgcolor,
+                    final ImageObserver imageObserver) {
+        final BufferedImage imageGIF = (BufferedImage) image;
+        final float w = (float) imageGIF.getWidth();
+        final float h = (float) imageGIF.getHeight();
+        final Color cur_color = getColor();
+
+        setColor(bbgcolor);
         fillRect(x, y, width, height);
         setColor(cur_color);
-        
-        BufferedImage imageGIF = (BufferedImage) image;
-        w = (float)imageGIF.getWidth();
-        h = (float)imageGIF.getHeight();
-        
-        drawImage(image, x, convY(y), true, ((float)width)/w , ((float)height)/h);
+        drawImage(image, x, convY(y), true, ((float) width) / w,
+                        ((float) height) / h);
         return true;
     }
-     
-    
-    public boolean drawImage(Image image, 
-            int dx1, int dy1, int dx2, int dy2,
-            int sx1, int sy1, int sx2, int sy2, 
-            ImageObserver imageObserver) {
-        
+
+    public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2,
+                    int sx1, int sy1, int sx2, int sy2,
+                    ImageObserver imageObserver) {
         int sx;
         int sy;
         int width;
@@ -197,10 +148,9 @@
         int comp;
         BufferedImage newImage;
         BufferedImage imageGIF;
-        
-        /* this method have to be improved to flip image 
-         * if dx2 < dx1 or dy2 <dy1
-         */     
+
+        // TODO: this method have to be improved to flip image if dx2 < dx1 or
+        // dy2<dy1
         if (dx2 < dx1) {
             d = dx2;
             dx2 = dx1;
@@ -212,577 +162,542 @@
             dy1 = d;
         }
         dx = dx2 - dx1 + 1;
-        dy = dy2 - dy1 + 1;       
-        
+        dy = dy2 - dy1 + 1;
+
         imageGIF = (BufferedImage) image;
         width = imageGIF.getWidth();
-        height = imageGIF.getHeight();       
-        if (dx2 > width || dy2 > height){
+        height = imageGIF.getHeight();
+        if (dx2 > width || dy2 > height) {
             return false;
         }
-        newImage = new BufferedImage(dx, dy, BufferedImage.TYPE_INT_ARGB);  
-        
+        newImage = new BufferedImage(dx, dy, BufferedImage.TYPE_INT_ARGB);
+
         sy = 0;
         for (int iy = dy1; iy <= dy2; iy++) {
             sx = 0;
-            for (int ix = dx1; ix <= dx2; ix++) {   
+            for (int ix = dx1; ix <= dx2; ix++) {
                 comp = imageGIF.getRGB(ix, iy);
-                newImage.setRGB(sx++, sy, comp);              
-            } 
-            sy++;                
-        }        
+                newImage.setRGB(sx++, sy, comp);
+            }
+            sy++;
+        }
         drawImage(newImage, sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1, null);
-        
-        return true;         
+
+        return true;
     }
-    
-    public boolean drawImage(Image image, 
-            int dx1, int dy1, int dx2, int dy2,
-            int sx1, int sy1, int sx2, int sy2, 
-            Color bbgcolor, ImageObserver imageObserver) {
-        
-        Color cur_color;
-        cur_color = getColor();
-        setColor(bbgcolor);        
-        fillRect( sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1);
+
+    public boolean drawImage(final Image image, final int dx1, final int dy1,
+                    final int dx2, final int dy2, final int sx1, final int sy1,
+                    final int sx2, final int sy2, final Color bbgcolor,
+                    final ImageObserver imageObserver) {
+        final Color cur_color = getColor();
+
+        setColor(bbgcolor);
+        fillRect(sx1, sy1, sx2 - sx1 + 1, sy2 - sy1 + 1);
         setColor(cur_color);
-        
-        return drawImage(image, 
-                dx1, dy1, dx2, dy2,
-                sx1, sy1, sx2, sy2, 
-                imageObserver); 
-        
-    }
-
-    /* method have to be implemented*/
-    public boolean drawImage(Image image, AffineTransform transform,
-            ImageObserver imageObserver) {
-        return true;        
-    }    
-    
-    /* method have to be implemented*/     
-    public void drawImage(BufferedImage image, BufferedImageOp arg1, 
-            int arg2, int arg3) {       
-    }
-    
-    
-    /*
-     * common private methods for drawImage methods.  
-     */    
-    private void drawImage(Image image, int x, int y) {
-         drawImage(image, x, y, false, 0f, 0f);     
-    }       
-
-    private void drawImage(Image image, int x, int y, boolean scale,
-            float sx, float sy) {
-        int line = 0;
-        int comp;
-        int imageHeight;
-        int imageWidth;
-        BufferedImage imageGIF;
-        
-        if (image != null) {
-            imageHeight = image.getHeight(null);
-            imageWidth = image.getWidth(null);           
-            imageGIF = (BufferedImage) image;          
-           
-            out_stream.println("");
-            out_stream.println(x + " " + y + " translate");  
-            if (scale){
-                out_stream.println(sx + " " + sy + " scale");               
-            }
-            out_stream.print(imageWidth + " ");
-            out_stream.println(imageHeight + " 8");
-            
-            out_stream.println(" [1 0 0 -1 0 1]");   
-            out_stream.println("{ currentfile");
-            
-            out_stream.println(" 32 string readhexstring pop");
-            out_stream.println("}");
-            out_stream.println("false 3"); 
-            out_stream.println("colorimage");             
-            
-            for (int iy = 0; iy < imageHeight; iy++) {
-                for (int ix = 0; ix < imageWidth; ix++) {   
-                    comp = imageGIF.getRGB(ix, iy);
-                    out_stream.print(threebytes2Hex(comp));                                         
-                    if (line++ == 30) {
-                        out_stream.println();
-                        line = 0;
-                    }                      
-                }
-                if (line != 0){
-                    line = 0;
-                    out_stream.println();
-                }
-            }
-              
-            if (scale){
-                out_stream.println(1/sx + " " + 1/sy + " scale");                   
-            }
-            out_stream.println((-x) + " " + (-y) + " translate");
-            out_stream.println("stroke");
-        }
-        return;
-    }
-   
-    
-    
-    public void drawString(String text, float x, float y) {
+
+        return drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
+                        imageObserver);
+
+    }
+
+    public boolean drawImage(final Image image,
+                    final AffineTransform transform,
+                    final ImageObserver imageObserver) {
+        // TODO: Implement
+        return false;
+    }
+
+    public void drawImage(final BufferedImage image,
+                    final BufferedImageOp arg1, final int arg2, final int arg3) {
+        // TODO: Implement
+    }
+
+    public void drawString(final String text, final float x, final float y) {
         drawString(text, (int) x, (int) y);
     }
-    
-    public void drawString(String text, int x, int y) {
-        Font cur_font = getFont(); 
-        y = convY(y);
-        out_stream.println("/" + cur_font.getName() + " findfont");
-        out_stream.println(cur_font.getSize() + " scalefont setfont");
-        out_stream.println("  " + x + " " + y + " moveto");
-        out_stream.println("(" + text + ") show");       
-        out_stream.println("stroke");
-    }  
 
-    public void drawString(AttributedCharacterIterator iterator, 
-                           float x, float y) {
+    public void drawString(final String text, final int x, final int y) {
+        if (text != null) {
+            ps(PS.moveto, x, convY(y));
+            ps(PS.show, "(" + wrapString(text) + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }
+
+    public void drawString(final AttributedCharacterIterator iterator,
+                    final float x, final float y) {
         drawString(iterator, (int) x, (int) y);
     }
-    
-    public void drawString(AttributedCharacterIterator iterator, int x, int y) {
 
+    public void drawString(final AttributedCharacterIterator iterator,
+                    final int x, final int y) {
+        final int n = iterator.getEndIndex();
+        final char[] cc = new char[n];
         int i = 0;
-        int n = iterator.getEndIndex();
-        char [] cc = new char[n];
-        
-        for (char c = iterator.first(); c != CharacterIterator.DONE; 
-                c = iterator.next()) {
+
+        for (char c = iterator.first(); c != CharacterIterator.DONE; c = iterator
+                        .next()) {
             cc[i++] = c;
         }
-        drawChars(cc, 0, n, x, y);        
+        drawChars(cc, 0, n, x, y);
     }
 
-    
-    public void drawLine(int x1, int y1, int x2, int y2)  {
-        out_stream.println("newpath");  
-        out_stream.println("  " + x1 + " " + convY(y1) + " moveto");
-        out_stream.println("  " + x2 + " " + convY(y2) + " lineto");
-        out_stream.println("stroke");         
+    public void drawLine(final int x1, final int y1, final int x2, final int y2) {
+        ps(PS.newpath);
+        ps(PS.moveto, x1, convY(y1));
+        ps(PS.lineto, x2, convY(y2));
+        ps(PS.stroke);
     }
-    
-    
-    
-    public void drawOval(int x, int y, int width, int height) {    
-        drawArc(x, y, width, height, 0, 360, false);       
+
+    public void drawOval(final int x, final int y, final int width,
+                    final int height) {
+        drawArc(x, y, width, height, 0, 360, false);
     }
 
-    
-    public void fillOval(int x, int y, int width, int height) {
+    public void fillOval(final int x, final int y, final int width,
+                    final int height) {
         drawArc(x, y, width, height, 0, 360, true);
     }
 
-    
-    public void drawArc(int x, int y, int width, int height, int startAngle,
-            int arcAngle) {          
-        drawArc(x, y, width, height, startAngle, arcAngle, false);  
-    }
-    
-    public void fillArc(int x, int y, int width, int height, 
-            int startAngle, int arcAngle) {      
-        drawArc(x, y, width, height, startAngle, arcAngle, true);      
-    }
-      
-    /*
-     * common private method for drawOval, fillOval, 
-     * drawArc and fillArc methods.  
-     */
-    private void drawArc(int x, int y, int width, int height, int startAngle,
-            int arcAngle, boolean fill) {   
-        
-        int cx = x + width /2;
-        int cy = convY(y + height /2);
-        y = convY(y);
-        
-        float scale1 = (float)width/(float)height;
-        float scale2 = (float)height/(float)width;       
-        
-        out_stream.println("newpath");
-        out_stream.println(scale1 + " 1 scale");
-        out_stream.print("  " + (cx * scale2));
-        out_stream.print(" " + cy + " " + height /2); 
-        out_stream.println(" " + startAngle + " " + arcAngle + " arc");
-        if (fill) {      
-            out_stream.print("  " + (cx * scale2));
-            out_stream.println(" " + cy + " lineto");                
-            out_stream.println("fill");       
-        }
-        out_stream.println(scale2 + " 1 scale");
-        out_stream.println("stroke");       
-    } 
- 
-    public void drawRoundRect(int x, int y, int width, int height,
-            int arcWidth, int arcHeight) {
+    public void drawArc(final int x, final int y, final int width,
+                    final int height, final int startAngle, final int arcAngle) {
+        drawArc(x, y, width, height, startAngle, arcAngle, false);
+    }
+
+    public void fillArc(final int x, final int y, final int width,
+                    final int height, final int startAngle, final int arcAngle) {
+        drawArc(x, y, width, height, startAngle, arcAngle, true);
+    }
+
+    public void drawRoundRect(final int x, final int y, final int width,
+                    final int height, final int arcWidth, final int arcHeight) {
         drawRoundRect(x, y, width, height, arcWidth, arcHeight, false);
     }
-    
-    public void fillRoundRect(int x, int y, int width, int height,
-            int arcWidth, int arcHeight) {
+
+    public void fillRoundRect(final int x, final int y, final int width,
+                    final int height, final int arcWidth, final int arcHeight) {
         drawRoundRect(x, y, width, height, arcWidth, arcHeight, true);
     }
-    
-    /*
-     * common private method for drawRoundRect 
-     * and fillRoundRect methods.  
-     */        
-    private void drawRoundRect(int x, int y, int width, int height,
-            int arcWidth, int arcHeight, boolean fill) { 
-             
-        int x1 = x + arcWidth;
-        int x2 = x + width - arcWidth;
-       
-        int y1 = convY(y + arcHeight);
-        int y2 = convY(y + height - arcHeight);        
-        y = convY(y);   
-        
-        float scale1 = (float)arcWidth/(float)arcHeight;
-        float scale2 = (float)arcHeight/(float)arcWidth;  
-       
-        out_stream.println("newpath");
-        out_stream.println("  " + x + " " + y1 + " moveto");
-        out_stream.println(scale1 + " 1 scale");        
-        out_stream.print("  " + (x1 * scale2) + " " + y2 + " ");
-        out_stream.println(arcHeight + " 180 270 arc");
-        out_stream.print("  " + (x2 * scale2) + " " + y2 + " "); 
-        out_stream.println(arcHeight + " 270 0 arc");
-        out_stream.print("  " + (x2 * scale2) + " " + y1 + " ");
-        out_stream.println(arcHeight + " 0 90 arc");
-        out_stream.print("  " + (x1 * scale2) + " " + y1 + " ");
-        out_stream.println(arcHeight + " 90 180 arc");
-        out_stream.println(scale2 + " 1 scale");
-        if (fill) { 
-            out_stream.println("fill");       
-        }        
-        out_stream.println("stroke");        
-    }
-    
-    public void drawRect(int x, int y, int width, int height) {        
+
+    public void drawRect(final int x, final int y, final int width,
+                    final int height) {
         int x2 = x + width;
         int y1 = convY(y);
-        int y2 = convY(y + height);        
-        int [] xPoints = {x, x2, x2, x};
-        int [] yPoints = {y1, y1, y2, y2};
-        drawPolyline (xPoints, yPoints, 4, true, false);
+        int y2 = convY(y + height);
+        int[] xPoints = { x, x2, x2, x };
+        int[] yPoints = { y1, y1, y2, y2 };
+        drawPolyline(xPoints, yPoints, 4, true, false);
     }
 
-    public void fillRect(int x, int y, int width, int height) {
+    public void fillRect(final int x, final int y, final int width,
+                    final int height) {
         int x2 = x + width;
         int y1 = convY(y);
-        int y2 = convY(y + height);        
-        int [] xPoints = {x, x2, x2, x};
-        int [] yPoints = {y1, y1, y2, y2};
-        drawPolyline (xPoints, yPoints, 4, true, true);        
-    }       
-    
-    public void clearRect(int x, int y, int width, int height) {
-        Color savecolor = getColor();
-        setColor(bgcolor);      
+        int y2 = convY(y + height);
+        int[] xPoints = { x, x2, x2, x };
+        int[] yPoints = { y1, y1, y2, y2 };
+        drawPolyline(xPoints, yPoints, 4, true, true);
+    }
+
+    public void clearRect(final int x, final int y, final int width,
+                    final int height) {
+        final Color savecolor = getColor();
+        setColor(bgColor);
         fillRect(x, y, width, height);
         setColor(savecolor);
-    }   
-    
-    public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
-        for (int i = 0; i < nPoints; i++) {
-            yPoints[i]=convY(yPoints[i]);
-        } 
-        drawPolyline (xPoints, yPoints, nPoints, true, false); 
     }
 
-    
-    public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {          
+    public void drawPolygon(final int[] xPoints, final int[] yPoints,
+                    final int nPoints) {
         for (int i = 0; i < nPoints; i++) {
-            yPoints[i]=convY(yPoints[i]);
-        }        
-        drawPolyline (xPoints, yPoints, nPoints, false, false);       
+            yPoints[i] = convY(yPoints[i]);
+        }
+        drawPolyline(xPoints, yPoints, nPoints, true, false);
     }
 
-    public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
+    public void drawPolyline(final int[] xPoints, final int[] yPoints,
+                    final int nPoints) {
         for (int i = 0; i < nPoints; i++) {
-            yPoints[i]=convY(yPoints[i]);
-        } 
-        drawPolyline (xPoints, yPoints, nPoints, true, true);      
-    }
-    
-    /*
-     * common private method for drawPolyline, drawPolygon, drawRect,
-     * clearRect, fillPolyline, fillPolygon and  fillRect methods.  
-     */
-    private void drawPolyline(int[] xPoints, int[] yPoints, int nPoints,
-            boolean close, boolean fill) {
-
-        out_stream.println("newpath");
-        out_stream.print("  " + xPoints[0]); 
-        out_stream.println(" " + yPoints[0] + " moveto");
-        
-        for (int i = 1; i < nPoints; i++) {
-            out_stream.print("  " + xPoints[i]); 
-            out_stream.println(" " + yPoints[i] + " lineto");
+            yPoints[i] = convY(yPoints[i]);
         }
-        if (close) {
-            out_stream.println("closepath");            
-        }
-        if (fill) {
-            out_stream.println("fill");
+        drawPolyline(xPoints, yPoints, nPoints, false, false);
+    }
+
+    public void fillPolygon(final int[] xPoints, final int[] yPoints,
+                    final int nPoints) {
+        for (int i = 0; i < nPoints; i++) {
+            yPoints[i] = convY(yPoints[i]);
         }
-        out_stream.println("stroke");
-    }      
-   
-    
-    public void draw(Shape shape) {
-        drawShape(shape, false);
+        drawPolyline(xPoints, yPoints, nPoints, true, true);
+    }
+
+    public void draw(final Shape shape) {
+        drawShape(shape, false, true);
     }
 
-    public void fill(Shape shape) {
-        drawShape(shape, true);
+    public void fill(final Shape shape) {
+        drawShape(shape, true, true);
     }
 
-    private void drawShape(Shape shape, boolean fill) {
-        float[] coords = new float[6];
+    private void drawShape(final Shape shape, final boolean fill,
+                    final boolean stroke) {
+        final float[] coords = new float[6];
+        final PathIterator pathIterator = shape
+                        .getPathIterator((AffineTransform) null);
         int i;
-        PathIterator  pathIterator;    
-        pathIterator = shape.getPathIterator((AffineTransform)null);
-        
-        out_stream.println("newpath 3");
-        i = 0;
-        int j=0;
-        
-        while (!pathIterator.isDone()){
-            i=pathIterator.currentSegment(coords);
+
+        ps(PS.newpath);
+
+        while (!pathIterator.isDone()) {
+            i = pathIterator.currentSegment(coords);
             switch (i) {
-                case PathIterator.SEG_MOVETO: {
-                    out_stream.print("  " + (int) coords[0] + " ");
-                    out_stream.println(convY((int) coords[1]) + " moveto");
-                    break;
-                }
-                case PathIterator.SEG_LINETO: {
-                    out_stream.println("  " + (int) coords[0] + " ");
-                    out_stream.println(convY((int) coords[1]) + " lineto");
-                    break;
-                }
-                case PathIterator.SEG_QUADTO: {
-                    //fake - need to improved
-                    out_stream.print("  " + (int) coords[0] + " ");
-                    out_stream.println(convY((int) coords[1]) + " lineto");                     
-                    out_stream.print("  " + (int) coords[2] + " ");
-                    out_stream.println(convY((int) coords[3]) + " lineto");
-                    break;  
-                }
-                case PathIterator.SEG_CUBICTO: {
-                    out_stream.print("  " + (int) coords[0] + " ");
-                    out_stream.print(convY((int) coords[1]));
-                    out_stream.print("  " + (int) coords[2] + " ");
-                    out_stream.print(convY((int) coords[3]));
-                    out_stream.print("  " + (int) coords[4] + " ");
-                    out_stream.print(convY((int) coords[5]));
-                    out_stream.println(" curveto");
-                    break;
-                }
-                case PathIterator.SEG_CLOSE: {
-                    out_stream.println("closepath");
-                    break;
-                } 
+            case PathIterator.SEG_MOVETO: {
+                ps(PS.moveto, (int) coords[0], convY((int) coords[1]));
+                break;
+            }
+            case PathIterator.SEG_LINETO: {
+                ps(PS.lineto, (int) coords[0], convY((int) coords[1]));
+                break;
+            }
+            case PathIterator.SEG_QUADTO: {
+                // XXX: improvement required
+                ps(PS.lineto, (int) coords[0], convY((int) coords[1]));
+                ps(PS.lineto, (int) coords[2], convY((int) coords[3]));
+                break;
+            }
+            case PathIterator.SEG_CUBICTO: {
+                ps(PS.curveto, (int) coords[0], convY((int) coords[1]),
+                                (int) coords[2], convY((int) coords[3]),
+                                (int) coords[4], convY((int) coords[5]));
+                break;
+            }
+            case PathIterator.SEG_CLOSE: {
+                ps(PS.closepath);
+                break;
+            }
             }
             pathIterator.next();
         }
-        
+
         if (fill) {
-            out_stream.println("fill");
+            ps(PS.fill);
         }
-        out_stream.println("stroke");
-    }      
-           
-    public Color getColor() { 
-        return color;
-    }
 
-    public void setColor(Color arg_color) {
-        color = arg_color;        
-        float[] rgb = color.getRGBColorComponents((float[])null);
-        out_stream.print("  " + rgb[0] + " " + rgb[1]);
-        out_stream.println(" " + rgb[2] + " setrgbcolor");  
+        if (stroke) {
+            ps(PS.stroke);
+        }
     }
 
-    public Color getBackground() {
-        return bgcolor;
+    public void setColor(final Color color) {
+        super.setColor(color);
+        final float[] rgb = fgColor.getRGBColorComponents((float[]) null);
+        ps(PS.setcolor, rgb[0], rgb[1], rgb[2]);
     }
 
-    public void setBackground(Color arg_color) {
-        bgcolor = arg_color;
-    }
-        
-    public void setXORMode(Color arg_color) {        
-        XORcolor = arg_color;
+    public void setFont(final Font font) {
+        super.setFont(font);
+        ps(PS.setfnt, font.getName(), font.getSize());
     }
 
-    public Font getFont() {
-        return font;
+    public void translate(final int x, final int y) {
+        ps(PS.translate, x, -y);
     }
 
-    public void setFont(Font arg_font) {
-        font=arg_font;
+    public void translate(final double x, final double y) {
+        translate((int) x, (int) y);
     }
 
-    public FontMetrics getFontMetrics(Font arg_font) {
-        Font cur_font = getFont();
-        setFont(arg_font);
-        FontMetrics fontMetrics=getFontMetrics(); 
-        setFont(cur_font);
-        return fontMetrics;
+    public void rotate(final double theta) {
+        rotate(theta, 0d, 0d);
     }
 
-    public void translate(int x, int y) {
-          out_stream.println(x + " " + (-y) + " translate");
-    }
+    public void rotate(final double theta, final double x, final double y) {
+        final double alfa = -theta * 180 / java.lang.Math.PI;
+        final int x0 = (int) x;
+        final int y0 = convY((int) y);
 
-    public void translate(double x, double y) {
-        translate((int)x, (int)y);
-    }
-    
-    public void rotate(double theta) {
-        rotate(theta, 0d, 0d);
+        ps(PS.translate, x0, y0);
+        ps(PS.rotate, alfa);
+        ps(PS.translate, -x0, -y0);
     }
 
-    public void rotate(double theta, double x, double y) {
-        double alfa; //angle in degrees 
-        int y0;
-        int x0;
-        alfa = - theta * 180/java.lang.Math.PI;
-        x0 =(int)x;
-        y0 = convY((int)y);
-        out_stream.println(x0 + " " + y0 + " translate");       
-        out_stream.println(alfa + " rotate");
-        out_stream.println((-x0) + " " + (-y0) + " translate");
-    }
-       
-    public void scale(double sx, double sy) {
-        out_stream.println(sx + " " + sy + " scale");
-        yscale = yscale/sy;
-    }
-
-    public Paint getPaint() {      
-        return  paint; 
+    public void scale(final double sx, final double sy) {
+        ps(PS.scale, sx, sy);
+        yscale = yscale / sy;
     }
 
-    public void setPaint(Paint arg0) {
-        paint = arg0;
+    public void setClip(final int x, final int y, final int width,
+                    final int height) {
+        setClip(new Rectangle(x, y, width, height));
     }
-    
-    public void setClip(int x, int y, int width, int height) {
-        int x2 = x + width;
-        int y1 = convY(y);
-        int y2 = convY(y + height);
-        
-        out_stream.println("newpath");
-        out_stream.println("  " + x + " " + y1 + " moveto");
-        out_stream.println("  " + x2 + " " + y1 + " lineto");
-        out_stream.println("  " + x2 + " " + y2 + " lineto");
-        out_stream.println("  " + x + " " + y2 + " lineto");
-        out_stream.println("closepath clip");   
-    }      
-    
-    /* methods below this line must be implemented*/    
-    public Graphics create() {        
-        return null;
+
+    @Override
+    public void setClip(final Shape s) {
+        super.setClip(s);
+        drawShape(s, false, false);
+        ps(PS.clip);
     }
 
-    public Rectangle getClipBounds() {       
-        return null;
+    @Override
+    public void drawGlyphVector(GlyphVector g, float x, float y) {
+        // TODO Implement
     }
 
-    public Shape getClip() {
+    @Override
+    public GraphicsConfiguration getDeviceConfiguration() {
+        // TODO Implement
         return null;
     }
 
-    public void setClip(Shape arg0) {       
+    @Override
+    public void copyArea(int sx, int sy, int width, int height, int dx, int dy) {
+        // TODO Implement
     }
 
-    public void shear(double arg0, double arg1) {
-    }
-   
-    public Composite getComposite() {
-        return null;
+    @Override
+    public Graphics create() {
+        return this;
     }
 
-    public void setComposite(Composite arg0) {
+    @Override
+    public void setTransform(final AffineTransform transform) {
+        super.setTransform(transform);
+        ps(PS.concat, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4],
+                        matrix[5]);
     }
 
-    public GraphicsConfiguration getDeviceConfiguration() {
-        return null;
+    private static String wrapString(final String str) {
+        return str.replace("\\", "\\\\").replace("\n", "\\\n").replace("\r", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$
+                        "\\\r").replace("(", "\\(").replace(")", "\\)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
     }
 
-    public RenderingHints getRenderingHints() {
-        return null;
+    private void drawImage(final Image image, final int x, final int y) {
+        drawImage(image, x, y, false, 0f, 0f);
     }
 
-    public void clip(Shape arg0) {
-    }
-  
-   
-    public Stroke getStroke() {
-        return null;
-    }
+    /**
+     * common private method for image drawing
+     */
+    private void drawImage(final Image image, final int x, final int y,
+                    final boolean scale, final float sx, final float sy) {
+        if (image != null) {
+            final int imageHeight = image.getHeight(null);
+            final int imageWidth = image.getWidth(null);
+            final BufferedImage imageGIF = (BufferedImage) image;
+            int line = 0;
+            int comp;
 
-    public void setStroke(Stroke arg0) {
-    }
+            ps(PS.translate, x, y);
 
-    public FontRenderContext getFontRenderContext() {
-        return null;
-    }
+            if (scale) {
+                ps(PS.scale, sx, sy);
+            }
 
-    public void drawGlyphVector(GlyphVector arg0, float arg1, float arg2) {
-    }
+            out_stream.print(imageWidth);
+            out_stream.println(imageHeight + " 8"); //$NON-NLS-1$
 
-    public AffineTransform getTransform() {
-        return null;
-    }
+            out_stream.println(" [1 0 0 -1 0 1]"); //$NON-NLS-1$
+            out_stream.println("{ currentfile"); //$NON-NLS-1$
 
-    public void setTransform(AffineTransform arg0) {
-    }
+            out_stream.println(" 32 string readhexstring pop"); //$NON-NLS-1$
+            out_stream.println("}"); //$NON-NLS-1$
+            out_stream.println("false 3"); //$NON-NLS-1$
+            out_stream.println("colorimage"); //$NON-NLS-1$
 
-    public void transform(AffineTransform arg0) {
-    }
+            for (int iy = 0; iy < imageHeight; iy++) {
+                for (int ix = 0; ix < imageWidth; ix++) {
+                    comp = imageGIF.getRGB(ix, iy);
+                    out_stream.print(threebytes2Hex(comp));
+                    if (line++ == 30) {
+                        out_stream.println();
+                        line = 0;
+                    }
+                }
+                if (line != 0) {
+                    line = 0;
+                    out_stream.println();
+                }
+            }
 
-    public void addRenderingHints(Map hints) {
+            if (scale) {
+                ps(PS.scale, 1 / sx, 1 / sy);
+            }
+            ps(PS.translate, -x, -y);
+            ps(PS.stroke);
+        }
     }
 
-    public void setRenderingHints(Map hints) {
+    /**
+     * common private method for drawOval, fillOval, drawArc and fillArc
+     * methods.
+     */
+    private void drawArc(final int x, final int y, final int width,
+                    final int height, final int startAngle, final int arcAngle,
+                    final boolean fill) {
+        final int cx = x + width / 2;
+        final int cy = convY(y + height / 2);
+        final float scale1 = (float) width / (float) height;
+        final float scale2 = (float) height / (float) width;
+
+        ps(PS.newpath);
+        ps(PS.scale, scale1, 1);
+        ps(PS.arc, (cx * scale2), cy, (height / 2), startAngle, arcAngle);
+        if (fill) {
+            ps(PS.lineto, (cx * scale2), cy);
+            ps(PS.fill);
+        }
+        ps(PS.scale, scale2, 1);
+        ps(PS.stroke);
     }
 
-    public boolean hit(Rectangle arg0, Shape arg1, boolean arg2) {
-        return false;
-    }
+    /**
+     * common private method for drawRoundRect and fillRoundRect methods.
+     */
+    private void drawRoundRect(final int x, final int y, final int width,
+                    final int height, final int arcWidth, final int arcHeight,
+                    final boolean fill) {
+
+        final int x1 = x + arcWidth;
+        final int x2 = x + width - arcWidth;
+        final int y1 = convY(y + arcHeight);
+        final int y2 = convY(y + height - arcHeight);
+        final float scale1 = (float) arcWidth / (float) arcHeight;
+        final float scale2 = (float) arcHeight / (float) arcWidth;
+
+        ps(PS.newpath);
+        ps(PS.moveto, x, y1);
+        ps(PS.scale, scale1, 1);
+        ps(PS.arc, (x1 * scale2), y2, arcHeight, 180, 270);
+        ps(PS.arc, (x2 * scale2), y2, arcHeight, 270, 0);
+        ps(PS.arc, (x2 * scale2), y1, arcHeight, 0, 90);
+        ps(PS.arc, (x1 * scale2), y1, arcHeight, 90, 180);
+        ps(PS.scale, scale2, 1);
 
-    public void drawRenderedImage(RenderedImage arg0, AffineTransform arg1) {
+        if (fill) {
+            ps(PS.fill);
+        }
+        ps(PS.stroke);
     }
 
-    public void drawRenderableImage(RenderableImage arg0, 
-                                            AffineTransform arg1) {
-    }
+    /**
+     * common private method for drawPolyline, drawPolygon, drawRect, clearRect,
+     * fillPolyline, fillPolygon and fillRect methods.
+     */
+    private void drawPolyline(final int[] xPoints, final int[] yPoints,
+                    final int nPoints, final boolean close, final boolean fill) {
+        ps(PS.moveto, xPoints[0], yPoints[0]);
 
-    public Object getRenderingHint(Key hintKey) {
-        return null;
+        for (int i = 1; i < nPoints; i++) {
+            ps(PS.lineto, xPoints[i], yPoints[i]);
+        }
+        if (close) {
+            ps(PS.closepath);
+        }
+        if (fill) {
+            ps(PS.fill);
+        }
+        ps(PS.stroke);
     }
 
-    public void setRenderingHint(RenderingHints.Key hintKey, 
-                                            Object hintValue) {
+    private static String threebytes2Hex(int b) {
+        final char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+                        'A', 'B', 'C', 'D', 'E', 'F' };
+        final char[] ret = new char[6];
+
+        for (int i = 0; i < 6; i++) {
+            ret[5 - i] = hex[b & 0x0F];
+            b = b >> 4;
+        }
+        return new String(ret);
     }
 
-    public void dispose() {      
+    /**
+     * Generates PostScript procedure call with the specified arguments.
+     * 
+     * @param ps procedure name
+     * @param args procedure arguments
+     */
+    private void ps(final PS ps, final Object... args) {
+        ps.print(out_stream, args);
     }
 
-    public void setPaintMode() {        
+    private int convY(final int y) {
+        return (int) (format.getHeight() * yscale) - y;
     }
-  
-    public void clipRect(int x, int y, int width, int height) {
+
+    private void resetGraphics() {
+        super.setTransform(new AffineTransform());
+        super.setClip(defaultClip);
+        super.setFont(DEF_FONT);
+        super.setColor(Color.BLACK);
+        super.setBackground(Color.WHITE);
+    }
+
+    private enum PS {
+            arc,
+            clip,
+            closepath,
+            curveto,
+            def,
+            exch,
+            fill,
+            grestore,
+            gsave,
+            lineto,
+            moveto,
+            newpath,
+            rlineto,
+            rmoveto,
+            rotate,
+            scale,
+            scalefont,
+            setfont,
+            setlinewidth,
+            show,
+            showpage,
+            stroke,
+            translate,
+            comment(null, "%%%%%s"), //$NON-NLS-1$
+            concat(null, "[%s %s %s %s %s %s] concat"), //$NON-NLS-1$
+            setcolor("C", null), //$NON-NLS-1$
+            setfnt(null, "/%s %s F"); //$NON-NLS-1$
+
+        final String name;
+        final String format;
+
+        PS() {
+            this(null, null);
+        }
+
+        PS(final String name, final String format) {
+            this.name = (name != null) ? name : toString();
+            this.format = format;
+        }
+
+        static void printHeader(final PrintStream out) {
+            out.println("%!PS-Adobe-3"); //$NON-NLS-1$
+            out.println("%%Title: G2D generated document"); //$NON-NLS-1$
+            out.println("%%Creator: Apache Harmony"); //$NON-NLS-1$
+            out.println("%%CreationDate: " + new Date()); //$NON-NLS-1$
+            out.println("%%EndComments"); //$NON-NLS-1$
+            out.println("/F {exch findfont exch scalefont setfont} def"); //$NON-NLS-1$
+            out.println("/C {setrgbcolor} bind def"); //$NON-NLS-1$
+        }
+
+        static void printFooter(final PrintStream out) {
+            out.println("%%EOF"); //$NON-NLS-1$
+        }
+
+        void print(final PrintStream out, final Object... args) {
+            if (format != null) {
+                out.printf(format, args);
+                out.println();
+            } else {
+                for (Object arg : args) {
+                    out.print(arg + " "); //$NON-NLS-1$
+                }
+                out.println(name);
+            }
+        }
     }
-        
-    public void copyArea(int x, int y, int width, int height, int dx, int dy) {
-    }    
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/javax.print.PrintServiceLookup
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/javax.print.PrintServiceLookup?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/javax.print.PrintServiceLookup (original)
+++ harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/javax.print.PrintServiceLookup Tue Nov 20 06:42:33 2007
@@ -1,2 +1,3 @@
-org.apache.harmony.x.print.Win32PrintServiceProvider
-org.apache.harmony.x.print.cups.CUPSPrintServiceProvider
+org.apache.harmony.x.print.WinPrintServiceLookup
+#org.apache.harmony.x.print.Win32PrintServiceProvider
+#org.apache.harmony.x.print.cups.CUPSPrintServiceProvider

Modified: harmony/enhanced/classlib/branches/java6/modules/print/src/main/native/print/windows/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/print/src/main/native/print/windows/makefile?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/print/src/main/native/print/windows/makefile (original)
+++ harmony/enhanced/classlib/branches/java6/modules/print/src/main/native/print/windows/makefile Tue Nov 20 06:42:33 2007
@@ -30,7 +30,9 @@
   -I$(SHAREDSUB)\include
 
 BUILDFILES = print.obj \
-ui.obj
+ui.obj \
+win_printer_factory.obj \
+devmode_struct_wrapper.obj
 
 VIRTFILES = $(LIBBASE).res
 SYSLIBFILES = ws2_32.lib Iphlpapi.lib

Modified: harmony/enhanced/classlib/branches/java6/modules/security/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/META-INF/MANIFEST.MF?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/META-INF/MANIFEST.MF Tue Nov 20 06:42:33 2007
@@ -12,7 +12,8 @@
 Bundle-ClassPath: .
 Eclipse-JREBundle: true
 Eclipse-ExtensibleAPI: true
-Import-Package: java.io,
+Import-Package: com.ibm.icu.text,
+ java.io,
  java.lang,
  java.lang.reflect,
  java.math,

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/common/org/apache/harmony/security/asn1/BerInputStream.java Tue Nov 20 06:42:33 2007
@@ -25,7 +25,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Calendar;
 
 import org.apache.harmony.security.internal.nls.Messages;
 
@@ -132,8 +131,8 @@
         if (length != INDEFINIT_LENGTH) {
             // input stream has definite length encoding
             // check allocated length to avoid further reallocations
-            if (buffer.length < length) {
-                byte[] newBuffer = new byte[length];
+            if (buffer.length < (length + offset)) {
+                byte[] newBuffer = new byte[length + offset];
                 System.arraycopy(buffer, 0, newBuffer, 0, offset);
                 buffer = newBuffer;
             }
@@ -916,9 +915,22 @@
         if (in == null) {
             offset += length;
         } else {
-            if (in.read(buffer, offset, length) != length) {
-                throw new ASN1Exception(Messages.getString("security.13C")); //$NON-NLS-1$
+            int bytesRead = in.read(buffer, offset, length);
+
+            if (bytesRead != length) {
+                // if input stream didn't return all data at once
+                // try to read it in several blocks
+                int c = bytesRead;
+                do {
+                    if (c < 1 || bytesRead > length) {
+                        throw new ASN1Exception(Messages
+                                .getString("security.13C")); //$NON-NLS-1$
+                    }
+                    c = in.read(buffer, offset + bytesRead, length - bytesRead);
+                    bytesRead += c;
+                } while (bytesRead != length);
             }
+
             offset += length;
         }
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/test/impl/java/org/apache/harmony/security/tests/asn1/der/BerInputStreamTest.java Tue Nov 20 06:42:33 2007
@@ -25,9 +25,11 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.math.BigInteger;
+import java.util.Arrays;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.security.asn1.ASN1Constants;
 import org.apache.harmony.security.asn1.ASN1Exception;
 import org.apache.harmony.security.asn1.BerInputStream;
 
@@ -102,8 +104,29 @@
         } catch (ASN1Exception e) {
             assertTrue(e.getMessage().startsWith("Too long"));
         }
+
+        //
+        // Test for correct internal array reallocation
+        // Regression for HARMONY-5054
+        //
+
+        // must be greater then buffer initial size (16K)
+        int arrayLength = 17000;
+
+        // 1 byte for tag and 3 for length
+        byte[] encoding = new byte[arrayLength + 4];
+
+        // fill tag and length bytes
+        encoding[0] = ASN1Constants.TAG_OCTETSTRING;
+        encoding[1] = (byte) 0x82; // length is encoded in two bytes
+        encoding[2] = (byte) (arrayLength >> 8);
+        encoding[3] = (byte) (arrayLength & 0xFF);
+
+        BerInputStream in = new BerInputStream(new ByteArrayInputStream(
+                encoding));
+        assertEquals(encoding.length, in.getBuffer().length);
     }
-    
+
     /**
      * @tests org.apache.harmony.security.asn1.BerInputStream#BerInputStream(byte[],
      *        int,int)
@@ -146,4 +169,55 @@
             assertEquals("Wrong content length", e.getMessage());
         }
     }
-}
\ No newline at end of file
+
+    /**
+     * @tests org.apache.harmony.security.asn1.BerInputStream#readContent()
+     */
+    public void test_readContent() throws IOException {
+
+        byte[] encoding = { ASN1Constants.TAG_OCTETSTRING, 0x0F, 0x01, 0x02,
+                0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C,
+                0x0D, 0x0E, 0x0F };
+
+        // a custom input stream that doesn't return all data at once
+        ByteArrayInputStream in = new ByteArrayInputStream(encoding) {
+            public int read(byte[] b, int off, int len) {
+                if (len < 2) {
+                    return super.read(b, off, len);
+                } else {
+                    return super.read(b, off, 4);
+                }
+
+            }
+        };
+
+        BerInputStream berIn = new BerInputStream(in);
+        berIn.readContent();
+
+        assertTrue(Arrays.equals(encoding, berIn.getEncoded()));
+
+        //
+        // negative test case: the stream returns only 4 bytes of content
+        //
+        in = new ByteArrayInputStream(encoding) {
+
+            int i = 0;
+
+            public int read(byte[] b, int off, int len) {
+                if (i == 0) {
+                    i++;
+                    return super.read(b, off, 4);
+                } else {
+                    return 0;
+                }
+
+            }
+        };
+        berIn = new BerInputStream(in);
+        try {
+            berIn.readContent();
+            fail("No expected ASN1Exception");
+        } catch (ASN1Exception e) {
+        }
+    }
+}

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRow.java Tue Nov 20 06:42:33 2007
@@ -16,12 +16,10 @@
  */
 package org.apache.harmony.sql.internal.rowset;
 
-
-import java.sql.Blob;
 import java.sql.SQLException;
 import java.util.BitSet;
 
-public class CachedRow implements Cloneable{
+public class CachedRow implements Cloneable {
     private Object[] columnData;
 
     private Object[] originalColumnData;
@@ -30,13 +28,15 @@
 
     private boolean isDelete;
 
-    private boolean insert;
+    private boolean isInsert;
+
+    private boolean isUpdate;
 
     private boolean nonUpdateable = false;
 
     public CachedRow(Object[] columnData) {
-        this.columnData = columnData;
-        this.originalColumnData = columnData;
+        this.columnData = columnData.clone();
+        originalColumnData = columnData.clone();
         mask = new BitSet(columnData.length);
     }
 
@@ -47,12 +47,13 @@
     public void setUpdateMask(int i) {
         mask.set(i);
     }
-    
-    public void setUnavailable(){
+
+    public void setUnavailable() {
+        // FIXME: What is this method used for?
         setDelete();
         setInsert();
         mask.clear();
-        mask.flip(0,columnData.length);
+        mask.flip(0, columnData.length);
     }
 
     public void setNonUpdateable() {
@@ -68,71 +69,59 @@
     }
 
     public void setDelete() {
-        this.isDelete = true;
+        isDelete = true;
     }
-    
-    public void unDoDelete() {
-        this.isDelete = false;
+
+    public void undoDelete() {
+        isDelete = false;
     }
 
-    public boolean getDelete() {
+    public boolean isDelete() {
         return isDelete;
     }
 
     public void setInsert() {
-        this.insert = true;
+        isInsert = true;
     }
 
-    public boolean getInsert() {
-        return this.insert;
+    public boolean isInsert() {
+        return isInsert;
     }
 
-    public void updateString(int columnIndex, String x) throws SQLException {
-        if (nonUpdateable)
-            throw new SQLException("Not Updateable of the CurrentRow");
-        this.columnData[columnIndex - 1] = x;
-        setUpdateMask(columnIndex - 1);
+    public void setUpdate() {
+        isUpdate = true;
     }
 
-    public void updateInt(int columnIndex, int x) {
-        this.columnData[columnIndex - 1] = x;
-        setUpdateMask(columnIndex - 1);
-    }
-    
-    public CachedRow getOriginal() {
-        return new CachedRow(originalColumnData);
+    public void undoUpdate() {
+        isUpdate = false;
+        mask.flip(0, columnData.length);
+        columnData = originalColumnData.clone();
     }
 
-    public String getString(int columnIndex) {
-        return (String) this.columnData[columnIndex - 1];
-    }
-    
-    public Object getObject(int columnIndex) {
-        return this.columnData[columnIndex - 1];
-    }
-
-    public int getInt(int columnIndex) {
-        return (Integer) this.columnData[columnIndex - 1];
+    public boolean isUpdate() {
+        return isUpdate;
     }
 
-    public Blob getBLOb(int columnIndex) {
-        return (Blob) this.columnData[columnIndex - 1];
-    }
+    public void updateObject(int columnIndex, Object x) throws SQLException {
+        if (nonUpdateable) {
+            // TODO load message from resource file
+            throw new SQLException("Not Updateable of the CurrentRow");
+        }
 
-    public boolean getBoolean(int columnIndex) {
-        return (Boolean) this.columnData[columnIndex - 1];
+        columnData[columnIndex - 1] = x;
+        setUpdateMask(columnIndex - 1);
     }
 
-    public byte getByte(int columnIndex) {
-        return (Byte) this.columnData[columnIndex - 1];
+    public CachedRow getOriginal() {
+        return new CachedRow(originalColumnData);
     }
 
-    public byte[] getBytes(int columnIndex) {
-        return (byte[]) this.columnData[columnIndex - 1];
+    public Object getObject(int columnIndex) {
+        return columnData[columnIndex - 1];
     }
 
     // deep clone
-    public CachedRow createClone() throws CloneNotSupportedException {  
+    public CachedRow createClone() throws CloneNotSupportedException {
         CachedRow cr = (CachedRow) super.clone();
 
         Object[] cd = new Object[columnData.length];
@@ -140,8 +129,9 @@
             cd[i] = columnData[i];
         }
         cr.columnData = cd;
-        cr.insert = insert;
+        cr.isInsert = isInsert;
         cr.isDelete = isDelete;
+        cr.isUpdate = isUpdate;
         cr.mask = (BitSet) mask.clone();
         cr.nonUpdateable = nonUpdateable;
         // cr.originalColumnData

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetImpl.java Tue Nov 20 06:42:33 2007
@@ -87,12 +87,14 @@
 
     private CachedRow insertRow;
 
+    // TODO remember to evalute it in CachedRowSetReader
     private int[] keyCols;
 
     private int columnCount;
 
     private SyncProvider syncProvider;
 
+    // TODO where is it initialized
     private CachedRowSetImpl originalResultSet;
 
     private Object currentColumn;
@@ -108,23 +110,29 @@
     }
 
     public void setRows(ArrayList<CachedRow> data, int cloumnCount) {
-        this.rows = data;
+        rows = data;
         this.columnCount = cloumnCount;
     }
 
     public void acceptChanges() throws SyncProviderException {
-        if (currentRow == insertRow)
+        if (currentRow == insertRow) {
             throw new SyncProviderException();
+        }
+
         try {
-            acceptChanges(this.getConnection());
+            acceptChanges(getConnection());
         } catch (SQLException e) {
+            // FIXME deal with the exception, not just print it
             e.printStackTrace();
         }
     }
 
     public void acceptChanges(Connection con) throws SyncProviderException {
-        if (currentRow == insertRow)
+        if (currentRow == insertRow) {
+            // TODO add error messages
             throw new SyncProviderException();
+        }
+
         try {
             setUrl(con.getMetaData().getURL());
             RowSetWriter rowSetWriter = syncProvider.getRowSetWriter();
@@ -133,6 +141,7 @@
             // setOriginalRow();
             notifyRowSetChanged();
         } catch (SQLException e) {
+            // TODO deal with the exception
             e.printStackTrace();
             throw new SyncProviderException();
         }
@@ -171,10 +180,12 @@
             // restore "this"'s states
             int temp = currentRowIndex;
             CachedRow cr;
-            if (currentRow != null)
+            if (currentRow != null) {
                 cr = currentRow.createClone();
-            else
+            } else {
                 cr = null;
+            }
+
             first();
 
             // Deep Copy
@@ -188,14 +199,14 @@
             // inspect!
             ((CachedRowSetImpl) output).setRows(data, columnCount);
             output.setMetaData(((RowSetMetaDataImpl) getMetaData()));
-            output.originalResultSet = this.originalResultSet;
+            output.originalResultSet = originalResultSet;
             output.setUrl(getUrl());
             output.setTableName(getTableName());
 
             // Constraints
             output.setReadOnly(isReadOnly());
-            output.setConcurrency(this.getConcurrency());
-            output.setType(this.getType());
+            output.setConcurrency(getConcurrency());
+            output.setType(getType());
 
             // recovery this's state for the modification of the operation
             // first() and next();
@@ -204,6 +215,7 @@
 
             return output;
         } catch (CloneNotSupportedException e) {
+            // FIXME deal with the exception
             e.printStackTrace();
             return null;
         }
@@ -216,10 +228,12 @@
             // restore "this"'s states
             int temp = currentRowIndex;
             CachedRow cr;
-            if (currentRow != null)
+            if (currentRow != null) {
                 cr = currentRow.createClone();
-            else
+            } else {
                 cr = null;
+            }
+
             first();
 
             // Deep Copy
@@ -231,8 +245,8 @@
             // TODO: should be the same granularity with RI using Debug tool
             // inspect!
             ((CachedRowSetImpl) output).setRows(data, columnCount);
-            output.setMetaData((RowSetMetaData) (this.getMetaData()));
-            output.originalResultSet = this.originalResultSet;
+            output.setMetaData((RowSetMetaData) (getMetaData()));
+            output.originalResultSet = originalResultSet;
             output.setUrl(getUrl());
             output.setTableName(getTableName());
 
@@ -243,6 +257,7 @@
 
             return output;
         } catch (CloneNotSupportedException e) {
+            // FIXME deal with the exception
             e.printStackTrace();
             return null;
         }
@@ -252,27 +267,43 @@
         // For webRowSet: represent the table structure: Columns
         CachedRowSetImpl result;
         try {
+            // copy data from BaseRowSet
             result = (CachedRowSetImpl) super.clone();
-            result.meta = (RowSetMetaDataImpl) meta;
-            result.keyCols = this.keyCols == null ? null : this.keyCols.clone();
+            // deep copy meta data
+            result.meta = copyMetaData(meta);
+            result.columnCount = columnCount;
+            result.keyCols = keyCols == null ? null : keyCols.clone();
+            result.originalResultSet = new CachedRowSetImpl(syncProvider
+                    .getProviderID());
+            result.pageSize = pageSize;
+            result.setSyncProvider(syncProvider.getProviderID());
+            result.setTableName(getTableName());
+
+            // clean up rows data
+            result.currentColumn = null;
+            result.currentRowIndex = 0;
+            result.insertRow = null;
+            result.originalRow = null;
+            result.pageNumber = 1;
+            result.rememberedCursorPosition = 0;
+            result.rows = new ArrayList<CachedRow>();
+            result.sqlwarn = null;
             return result;
-        } catch (CloneNotSupportedException e1) {
-            return null;
+        } catch (CloneNotSupportedException e) {
+            // TODO add error message
+            throw new SQLException();
         }
     }
 
     public RowSet createShared() throws SQLException {
         // shallow copy
-        CachedRowSetImpl result = new CachedRowSetImpl();
-        result.rows = this.rows;
-
-        result.currentRowIndex = this.currentRowIndex;
-        result.currentRow = this.currentRow;
-        result.meta = this.meta;
-
-        result.setReadOnly(isReadOnly());
-        result.setConcurrency(super.getConcurrency());
-        result.setType(super.getType());
+        RowSet result = null;
+        try {
+            result = (RowSet) super.clone();
+        } catch (CloneNotSupportedException e) {
+            // TODO add error message
+            throw new SQLException();
+        }
 
         return result;
     }
@@ -280,8 +311,10 @@
     public void execute(Connection conn) throws SQLException {
         // ensure the getConnection can works!
         String localCommand = getCommand();
-        if (localCommand == null || getParams() == null)
+        if (localCommand == null || getParams() == null) {
+            // TODO add error messages
             throw new SQLException();
+        }
 
         PreparedStatement ps = conn.prepareStatement(localCommand);
         Object[] params = getParams();
@@ -294,7 +327,7 @@
     }
 
     public int[] getKeyColumns() throws SQLException {
-        return keyCols.clone();
+        return keyCols == null ? null : keyCols.clone();
     }
 
     public ResultSet getOriginal() throws SQLException {
@@ -302,12 +335,15 @@
     }
 
     public ResultSet getOriginalRow() throws SQLException {
-        if (currentRow == null)
+        if (currentRow == null) {
+            // TODO add error messages
             throw new SQLException();
+        }
+
         CachedRowSetImpl specialRset = new CachedRowSetImpl();
         ArrayList<CachedRow> data = new ArrayList<CachedRow>();
-        data.add(this.originalRow);
-        specialRset.setRows(data, this.columnCount);
+        data.add(originalRow);
+        specialRset.setRows(data, columnCount);
         return specialRset;
     }
 
@@ -320,7 +356,7 @@
     }
 
     public SyncProvider getSyncProvider() throws SQLException {
-        return this.syncProvider;
+        return syncProvider;
     }
 
     public String getTableName() throws SQLException {
@@ -328,7 +364,7 @@
     }
 
     /**
-     * refill the cachedrowset with pagesize, and the previous rowset was
+     * TODO refill the cachedrowset with pagesize, and the previous rowset was
      * replaced
      */
     public boolean nextPage() throws SQLException {
@@ -342,7 +378,7 @@
 
     public void populate(ResultSet rs, int startRow) throws SQLException {
         initParams();
-        composeMetaData(rs.getMetaData());
+        meta = copyMetaData(rs.getMetaData());
 
         new CachedRowSetReader(rs, startRow).readData(this);
 
@@ -350,7 +386,7 @@
 
         originalResultSet = new CachedRowSetImpl();
         new CachedRowSetReader(this, startRow).readData(originalResultSet);
-        originalResultSet.setMetaData((RowSetMetaData) (this.getMetaData()));
+        originalResultSet.setMetaData((RowSetMetaData) (getMetaData()));
 
         // recovery the states
         currentRow = null;
@@ -358,22 +394,35 @@
 
     }
 
-    private void composeMetaData(ResultSetMetaData metaData)
+    // deep copy of ResultSetMetaData
+    private RowSetMetaData copyMetaData(ResultSetMetaData metaData)
             throws SQLException {
         RowSetMetaDataImpl rowSetMetaData = new RowSetMetaDataImpl();
         rowSetMetaData.setColumnCount(metaData.getColumnCount());
-        for (int i = 1; i <= metaData.getColumnCount(); i++) {
-            rowSetMetaData.setColumnName(i, metaData.getColumnName(i));
-            rowSetMetaData.setTableName(i, metaData.getTableName(i));
-            rowSetMetaData.setSchemaName(i, metaData.getSchemaName(i));
-            rowSetMetaData.setCatalogName(i, metaData.getCatalogName(i));
+        for (int columnIndex = 1; columnIndex <= metaData.getColumnCount(); columnIndex++) {
+            rowSetMetaData.setAutoIncrement(columnIndex, metaData.isAutoIncrement(columnIndex));
+            rowSetMetaData.setCaseSensitive(columnIndex, metaData.isCaseSensitive(columnIndex));
+            rowSetMetaData.setCatalogName(columnIndex, metaData.getCatalogName(columnIndex));
+            rowSetMetaData.setColumnDisplaySize(columnIndex, metaData
+                    .getColumnDisplaySize(columnIndex));
+            rowSetMetaData.setColumnLabel(columnIndex, metaData.getColumnLabel(columnIndex));
+            rowSetMetaData.setColumnName(columnIndex, metaData.getColumnName(columnIndex));
+            rowSetMetaData.setColumnType(columnIndex, metaData.getColumnType(columnIndex));
+            rowSetMetaData.setColumnTypeName(columnIndex, metaData.getColumnTypeName(columnIndex));
+            rowSetMetaData.setCurrency(columnIndex, metaData.isCurrency(columnIndex));
+            rowSetMetaData.setNullable(columnIndex, metaData.isNullable(columnIndex));
+            rowSetMetaData.setPrecision(columnIndex, metaData.getPrecision(columnIndex));
+            rowSetMetaData.setScale(columnIndex, metaData.getScale(columnIndex));
+            rowSetMetaData.setSchemaName(columnIndex, metaData.getSchemaName(columnIndex));
+            rowSetMetaData.setSearchable(columnIndex, metaData.isSearchable(columnIndex));
+            rowSetMetaData.setSigned(columnIndex, metaData.isSigned(columnIndex));
+            rowSetMetaData.setTableName(columnIndex, metaData.getTableName(columnIndex));
         }
-        // TODO set other meta info when necessary
-        this.meta = rowSetMetaData;
+        return rowSetMetaData;
     }
 
     public boolean previousPage() throws SQLException {
-        // TODO
+        // TODO implement it
         return false;
     }
 
@@ -403,13 +452,15 @@
     }
 
     public void setMetaData(RowSetMetaData md) throws SQLException {
-        this.meta = md;
+        meta = md;
     }
 
     public void setOriginalRow() throws SQLException {
 
-        if (currentRow == null)
+        if (currentRow == null) {
+            // TODO add error messages
             throw new SQLException();
+        }
         originalRow = currentRow;
         currentRow.setNonUpdateable();
 
@@ -420,9 +471,11 @@
             // rowset.2=Negative page size
             throw new SQLException(Messages.getString("rowset.2"));
         }
-        if ((getMaxRows() != 0) && (getMaxRows() < size))
+        if ((getMaxRows() != 0) && (getMaxRows() < size)) {
+            // rowset.9=PageSize can not larger than MaxRows
             throw new SQLException(Messages.getString("rowset.9"));
-        this.pageSize = size;
+        }
+        pageSize = size;
     }
 
     public void setSyncProvider(String provider) throws SQLException {
@@ -434,7 +487,7 @@
             // rowset.3=Table name should not be null
             throw new SQLException("rowset.3");
         }
-        this.tableName = tabName;
+        tableName = tabName;
     }
 
     public int size() {
@@ -454,10 +507,13 @@
     }
 
     public void undoDelete() throws SQLException {
-        if (currentRow == null)
+        if (currentRow == null) {
+            // TODO add error messages
             throw new SQLException();
-        if (currentRow.getDelete())
-            currentRow.unDoDelete();
+        }
+        if (currentRow.isDelete()) {
+            currentRow.undoDelete();
+        }
     }
 
     public void undoInsert() throws SQLException {
@@ -509,33 +565,40 @@
     }
 
     public boolean absolute(int row) throws SQLException {
-        if (rows.size() == 0)
+        if (rows.size() == 0) {
             return false;
-        if (getType() == ResultSet.TYPE_FORWARD_ONLY)
+        }
+        if (getType() == ResultSet.TYPE_FORWARD_ONLY) {
+            // TODO add error messages
             throw new SQLException();
+        }
         if (row < 0) {
             row = rows.size() + row + 1;
         } else if (row == 0) {
-            this.currentRowIndex = row;
-            this.currentRow = null;
+            currentRowIndex = row;
+            currentRow = null;
             return true;
         }
 
-        this.currentRowIndex = row;
-        this.currentRow = (CachedRow) rows.get(currentRowIndex - 1);
+        currentRowIndex = row;
+        currentRow = (CachedRow) rows.get(currentRowIndex - 1);
         return true;
     }
 
     public void afterLast() throws SQLException {
-        if (getType() == TYPE_FORWARD_ONLY)
+        if (getType() == TYPE_FORWARD_ONLY) {
+            // rowset.8=The Result Set Type is TYPE_FORWARD_ONLY
             throw new SQLException(Messages.getString("rowset.8"));
+        }
         currentRowIndex = rows.size() + 1;
         currentRow = null;
     }
 
     public void beforeFirst() throws SQLException {
-        if (getType() == TYPE_FORWARD_ONLY)
+        if (getType() == TYPE_FORWARD_ONLY) {
+            // rowset.8=The Result Set Type is TYPE_FORWARD_ONLY
             throw new SQLException(Messages.getString("rowset.8"));
+        }
         currentRowIndex = 0;
         currentRow = null;
     }
@@ -621,35 +684,55 @@
     }
 
     public Blob getBlob(int columnIndex) throws SQLException {
-        return this.currentRow.getBLOb(columnIndex);
+        checkValidRow();
+        Object value = currentRow.getObject(columnIndex);
+        if (value == null) {
+            return null;
+        }
+        return (Blob) value;
     }
 
     public Blob getBlob(String columnName) throws SQLException {
-        return this.currentRow.getBLOb(getIndexByName(columnName));
+        return getBlob(getIndexByName(columnName));
     }
 
     public boolean getBoolean(int columnIndex) throws SQLException {
-        return this.currentRow.getBoolean(columnIndex);
+        checkValidRow();
+        Object value = currentRow.getObject(columnIndex);
+        if (value == null) {
+            return false;
+        }
+        return ((Boolean) value).booleanValue();
     }
 
     public boolean getBoolean(String columnName) throws SQLException {
-        return this.currentRow.getBoolean(getIndexByName(columnName));
+        return getBoolean(getIndexByName(columnName));
     }
 
     public byte getByte(int columnIndex) throws SQLException {
-        return this.currentRow.getByte(columnIndex);
+        checkValidRow();
+        Object value = currentRow.getObject(columnIndex);
+        if (value == null) {
+            return 0;
+        }
+        return ((Byte) value).byteValue();
     }
 
     public byte getByte(String columnName) throws SQLException {
-        return this.currentRow.getByte(getIndexByName(columnName));
+        return getByte(getIndexByName(columnName));
     }
 
     public byte[] getBytes(int columnIndex) throws SQLException {
-        return this.currentRow.getBytes(columnIndex);
+        checkValidRow();
+        Object value = currentRow.getObject(columnIndex);
+        if (value == null) {
+            return null;
+        }
+        return (byte[]) value;
     }
 
     public byte[] getBytes(String columnName) throws SQLException {
-        return this.currentRow.getBytes(getIndexByName(columnName));
+        return getBytes(getIndexByName(columnName));
     }
 
     public Reader getCharacterStream(int columnIndex) throws SQLException {
@@ -706,11 +789,16 @@
 
     public int getInt(int columnIndex) throws SQLException {
         checkCursorValid();
-        return this.currentRow.getInt(columnIndex);
+        checkValidRow();
+        Object value = currentRow.getObject(columnIndex);
+        if (value == null) {
+            return 0;
+        }
+        return ((Integer) value).intValue();
     }
 
     public int getInt(String columnName) throws SQLException {
-        return this.currentRow.getInt(getIndexByName(columnName));
+        return getInt(getIndexByName(columnName));
     }
 
     public long getLong(int columnIndex) throws SQLException {
@@ -722,11 +810,11 @@
     }
 
     public ResultSetMetaData getMetaData() throws SQLException {
-        return this.meta;
+        return meta;
     }
 
     public Object getObject(int columnIndex) throws SQLException {
-        return this.currentRow.getObject(columnIndex);
+        return currentRow.getObject(columnIndex);
     }
 
     public Object getObject(int columnIndex, Map<String, Class<?>> map)
@@ -735,7 +823,7 @@
     }
 
     public Object getObject(String columnName) throws SQLException {
-        return this.currentRow.getObject(getIndexByName(columnName));
+        return currentRow.getObject(getIndexByName(columnName));
     }
 
     public Object getObject(String columnName, Map<String, Class<?>> map)
@@ -769,18 +857,24 @@
 
     // columnIndex: from 1 rather than 0
     public String getString(int columnIndex) throws SQLException {
-        return currentRow.getString(columnIndex);
+        checkValidRow();
+        Object value = currentRow.getObject(columnIndex);
+        if (value == null) {
+            return null;
+        }
+        return (String) value;
     }
 
     private boolean checkCursorValid() throws SQLException {
-        if ((currentRowIndex <= 0) || (currentRowIndex > rows.size()))
-            throw new SQLException(Messages.getString("rowset.7"));
-        else
-            return false;
+        if ((currentRowIndex <= 0) || (currentRowIndex > rows.size())) {
+            // rowset.7=Not a valid cursor
+            throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
+        }
+        return false;
     }
 
     public String getString(String columnName) throws SQLException {
-        return currentRow.getString(getIndexByName(columnName));
+        return getString(getIndexByName(columnName));
     }
 
     public Time getTime(int columnIndex) throws SQLException {
@@ -872,18 +966,18 @@
 
     public void moveToCurrentRow() throws SQLException {
 
-        if (this.currentRow == this.insertRow) {
-            this.currentRowIndex = rememberedCursorPosition;
-            this.currentRow = rows.get(currentRowIndex - 1);
+        if (currentRow == insertRow) {
+            currentRowIndex = rememberedCursorPosition;
+            currentRow = rows.get(currentRowIndex - 1);
         }
 
     }
 
     public void moveToInsertRow() throws SQLException {
         insertRow = new CachedRow(new Object[columnCount]);
-        this.currentRow = insertRow;
-        this.rememberedCursorPosition = this.currentRowIndex;
-        this.currentRowIndex = rows.size();
+        currentRow = insertRow;
+        rememberedCursorPosition = currentRowIndex;
+        currentRowIndex = rows.size();
     }
 
     public boolean next() throws SQLException {
@@ -915,7 +1009,7 @@
     public boolean rowDeleted() throws SQLException {
         checkValidRow();
         checkCursorValid();
-        return currentRow.getDelete();
+        return currentRow.isDelete();
     }
 
     public boolean rowInserted() throws SQLException {
@@ -924,14 +1018,15 @@
          * FIXME: Determin the currentRow if have had a insertion 1. Need
          * traverse the rows and find if the data hava been added
          */
-        return this.currentRow.getInsert();
+        return currentRow.isInsert();
     }
 
     public boolean rowUpdated() throws SQLException {
 
         boolean sign = false;
-        for (int i = 0; i < meta.getColumnCount(); ++i)
-            sign = this.currentRow.getUpdateMask(i) | sign;
+        for (int i = 0; i < meta.getColumnCount(); ++i) {
+            sign = currentRow.getUpdateMask(i) | sign;
+        }
         return sign;
     }
 
@@ -1048,11 +1143,11 @@
     }
 
     public void updateInt(int columnIndex, int x) throws SQLException {
-        currentRow.updateInt(columnIndex, x);
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateInt(String columnName, int x) throws SQLException {
-        currentRow.updateInt(getIndexByName(columnName), x);
+        updateInt(getIndexByName(columnName), x);
     }
 
     public void updateLong(int columnIndex, long x) throws SQLException {
@@ -1099,8 +1194,10 @@
 
     public void updateRow() throws SQLException {
         if ((currentRow == insertRow)
-                || (this.getConcurrency() == (ResultSet.CONCUR_READ_ONLY)))
+                || (getConcurrency() == (ResultSet.CONCUR_READ_ONLY))) {
+            // TODO add error messages
             throw new SQLException();
+        }
         rows.set(currentRowIndex, currentRow);
         notifyRowChanged();
     }
@@ -1114,11 +1211,11 @@
     }
 
     public void updateString(int columnIndex, String x) throws SQLException {
-        currentRow.updateString(columnIndex, x);
+        currentRow.updateObject(columnIndex, x);
     }
 
     public void updateString(String columnName, String x) throws SQLException {
-        currentRow.updateString(getIndexByName(columnName), x);
+        updateString(getIndexByName(columnName), x);
     }
 
     public void updateTime(int columnIndex, Time x) throws SQLException {

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java?rev=596693&r1=596692&r2=596693&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/org/apache/harmony/sql/internal/rowset/CachedRowSetWriter.java Tue Nov 20 06:42:33 2007
@@ -32,7 +32,6 @@
 
 public class CachedRowSetWriter implements RowSetWriter {
 
-
     private ResultSet primaryKeys;
 
     private CachedRowSet originalRowSet;
@@ -56,7 +55,6 @@
     private String keyColumnName, whereStatementForOriginal,
             whereStatementForCurrent;
 
-
     public boolean writeData(RowSetInternal theRowSet) throws SQLException {
         // use an optimistic concurrency control mechanism
 
@@ -64,14 +62,16 @@
         // analyse every row and do responsible task.
         currentRowSet.first();
         originalRowSet.first();
-        do{
+        do {
             // rolling with currentRowSet
             if (originalRowSet.next()) {
                 // deal with updated or deleted row which need do conflict check
                 if (checkConflictNotExist(originalRowSet)) {
-                    //If all of the values in the data source are already the values to be persisted, 
-                    //the method acceptChanges does nothing. 
-                    if(!checkConflictNotExist(currentRowSet))  writeRowData();
+                    // If all of the values in the data source are already the
+                    // values to be persisted,
+                    // the method acceptChanges does nothing.
+                    if (!checkConflictNotExist(currentRowSet))
+                        writeRowData();
                 } else {
                     cleanEnvironment();
                     throw new SyncProviderException(Messages
@@ -84,14 +84,14 @@
                 // FIXME: need pre-check before insert into database?
                 writeRowData();
             }
-        }while (currentRowSet.next());
+        } while (currentRowSet.next());
 
         cleanEnvironment();
 
         return true;
     }
-    
-    private void initial(RowSetInternal theRowSet) throws SQLException {      
+
+    private void initial(RowSetInternal theRowSet) throws SQLException {
         currentRowSet = (CachedRowSetImpl) theRowSet;
         // initial environment
         originalRowSet = (CachedRowSet) currentRowSet.getOriginal();
@@ -104,7 +104,6 @@
         cachedKeySet.populate(primaryKeys);
     }
 
-
     private void writeRowData() throws SQLException {
         try {
             createScriptForWriteBack();
@@ -131,27 +130,26 @@
 
     }
 
-
     private void createScriptForWriteBack() throws SQLException {
         cachedKeySet.first();
         whereStatementForCurrent = "";
         String insertCollector = "", updateCollector = "";
         // FIXME:uses getUpdateMask()
 
-         do{
+        do {
             keyColumnName = cachedKeySet.getString("COLUMN_NAME");
             whereStatementForCurrent = whereStatementForCurrent + keyColumnName
                     + " = ? " + " and ";
-        }while (cachedKeySet.next());
+        } while (cachedKeySet.next());
 
         whereStatementForCurrent = subStringN(whereStatementForCurrent, 5);
 
         // insertCollector: all column
         for (int i = 1; i <= columnCount; i++) {
-            insertCollector = insertCollector + " ? "+" , ";            
+            insertCollector = insertCollector + " ? " + " , ";
         }
         insertCollector = subStringN(insertCollector, 3);
-        
+
         // update: all column
         ResultSetMetaData tempRSMD = currentRowSet.getMetaData();
         for (int i = 1; i <= columnCount; i++) {
@@ -160,12 +158,12 @@
         }
         updateCollector = subStringN(updateCollector, 3);
 
-        if (currentRowSet.getCurrentRow().getDelete()) {
+        if (currentRowSet.getCurrentRow().isDelete()) {
             // paras of where: pks
             sql = " delete from " + tableName + " where "
                     + whereStatementForCurrent;
             signal = 0;
-        } else if (currentRowSet.getCurrentRow().getInsert()) {
+        } else if (currentRowSet.getCurrentRow().isInsert()) {
             // paras of insert : all
             sql = " insert into " + tableName + " values " + " ( "
                     + insertCollector + " ) ";
@@ -206,18 +204,25 @@
     private void fillParasOfKeys(CachedRowSet inputRS, int from)
             throws SQLException {
         cachedKeySet.first();
-        int i = from+1;        
+        int i = from + 1;
         do {
             keyColumnName = cachedKeySet.getString("COLUMN_NAME");
             ((PreparedStatement) statement).setObject(i++, inputRS
                     .getObject(keyColumnName));
-        } while (cachedKeySet.next()); 
+        } while (cachedKeySet.next());
     }
 
     private void fillParasOfAllColumn() throws SQLException {
-        for (int i = 1; i <= columnCount; i++)
-            ((PreparedStatement) statement).setObject(i, currentRowSet
-                    .getObject(i));
+        for (int i = 1; i <= columnCount; i++) {
+            ResultSetMetaData rsmd = currentRowSet.getMetaData();
+            if (currentRowSet.getObject(i) == null) {
+                ((PreparedStatement) statement).setNull(i, rsmd
+                        .getColumnType(i));
+            } else {
+                ((PreparedStatement) statement).setObject(i, currentRowSet
+                        .getObject(i));
+            }
+        }
     }
 
     private boolean checkConflictNotExist(CachedRowSet crs) {
@@ -230,8 +235,12 @@
             // compare line by line, column by column
             if (dataInDB.next()) {
                 for (int i = 1; i <= dataInDB.getMetaData().getColumnCount(); i++) {
-                    if (!(dataInDB.getObject(i).equals(crs.getObject(i))))
+                    if (dataInDB.getObject(i) == crs.getObject(i)) {
+                        continue;
+                    }
+                    if (!(dataInDB.getObject(i).equals(crs.getObject(i)))) {
                         return false;
+                    }
                 }
             }
         } catch (Exception e) {
@@ -241,7 +250,7 @@
     }
 
     private void cleanEnvironment() {
-        try {           
+        try {
             originalRowSet.close();
             originalConnection.close();
             cachedKeySet.close();



Mime
View raw message