001 package com.mockrunner.mock.jdbc; 002 003 import java.sql.SQLException; 004 import java.sql.Struct; 005 import java.util.ArrayList; 006 import java.util.List; 007 import java.util.Map; 008 009 /** 010 * Mock implementation of <code>Struct</code>. 011 */ 012 public class MockStruct implements Struct, Cloneable 013 { 014 private String sqlTypeName; 015 private List attributes; 016 017 public MockStruct(String sqlTypeName) 018 { 019 this.sqlTypeName = sqlTypeName; 020 attributes = new ArrayList(); 021 } 022 023 public String getSQLTypeName() throws SQLException 024 { 025 return sqlTypeName; 026 } 027 028 public Object[] getAttributes() throws SQLException 029 { 030 return attributes.toArray(); 031 } 032 033 public Object[] getAttributes(Map map) throws SQLException 034 { 035 return getAttributes(); 036 } 037 038 public void addAttribute(Object attribute) 039 { 040 attributes.add(attribute); 041 } 042 043 public void addAttributes(Object[] attributes) 044 { 045 for(int ii = 0; ii < attributes.length; ii++) 046 { 047 addAttribute(attributes[ii]); 048 } 049 } 050 051 public void addAttributes(List attributes) 052 { 053 addAttributes(attributes.toArray()); 054 } 055 056 public void clearAttributes() 057 { 058 attributes.clear(); 059 } 060 061 public String toString() 062 { 063 StringBuffer buffer = new StringBuffer("Struct data:\n"); 064 buffer.append("SQLTypeName: " + sqlTypeName + "\n"); 065 for(int ii = 0; ii < attributes.size(); ii++) 066 { 067 buffer.append("Attribute " + ii + ": " + attributes.get(ii)+ "\n"); 068 } 069 buffer.append("\n"); 070 return buffer.toString(); 071 } 072 073 public Object clone() 074 { 075 MockStruct struct = new MockStruct(sqlTypeName); 076 struct.addAttributes(attributes.toArray()); 077 return struct; 078 } 079 }