[Jiemamy-notify] commit [2063] カトさんトラップ回避w /

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 10月 30日 (木) 00:12:21 JST


Revision: 2063
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=2063
Author:   daisuke_m
Date:     2008-10-30 00:12:21 +0900 (Thu, 30 Oct 2008)

Log Message:
-----------
カトさんトラップ回避w /
javadocトカ追加。 /
typo修正など。

Modified Paths:
--------------
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelInputStream.java
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelWriter.java
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/XmlElement.java
    artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/ModelInputStreamTest.java


-------------- next part --------------
Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelInputStream.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelInputStream.java	2008-10-28 18:03:13 UTC (rev 2062)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelInputStream.java	2008-10-29 15:12:21 UTC (rev 2063)
@@ -75,5 +75,4 @@
 		}
 		return resourceQueue.poll().intValue();
 	}
-	
 }

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelWriter.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelWriter.java	2008-10-28 18:03:13 UTC (rev 2062)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelWriter.java	2008-10-29 15:12:21 UTC (rev 2063)
@@ -36,9 +36,33 @@
  */
 public class ModelWriter {
 	
-	private static final String NAMESPACE = "http://jiemamy.org/ns/model/v1";
+	private static final String CORE_NAMESPACE = "http://jiemamy.org/ns/core/v1";
 	
-	/** 処理中のモデル構造スタック */
+	private static final String EVENT_NAMESPACE = "http://jiemamy.org/ns/event/v1";
+	
+	private static final String VIEW_NAMESPACE = "http://jiemamy.org/ns/view/v1";
+	
+	/** 
+	 * 処理中のモデル構造スタック
+	 * 
+	 * <pre>
+	 * &lt;foo>
+	 *   &lt;bar/> 
+	 *   &lt;baz/>
+	 * &lt;/foo>
+	 * </pre>
+	 * 
+	 * 上記のようなXML構造の場合、下記の順にスタック操作が行われる。
+	 * 
+	 * <ul>
+	 *   <li>push foo</li>
+	 *   <li>push bar</li>
+	 *   <li>pop bar</li>
+	 *   <li>push baz</li>
+	 *   <li>pop baz</li>
+	 *   <li>pop foo</li>
+	 * </ul>
+	 */
 	private Stack<XmlElement> xmlStack = new Stack<XmlElement>();
 	
 	private DataWriter dataWriter = new DataWriter();
@@ -54,7 +78,9 @@
 	 */
 	public ModelWriter(RootModel rootModel, Queue<Byte> resourceQueue) {
 		this.resourceQueue = resourceQueue;
-		dataWriter.setPrefix(NAMESPACE, "");
+		dataWriter.setPrefix(CORE_NAMESPACE, "");
+		dataWriter.setPrefix(EVENT_NAMESPACE, "event");
+		dataWriter.setPrefix(VIEW_NAMESPACE, "view");
 		dataWriter.setIndentStep(2);
 		
 		StringWriter sw = new StringWriter();
@@ -116,21 +142,24 @@
 	 */
 	private void addToQueue(byte[] bytes) {
 		for (byte b : bytes) {
-			resourceQueue.add(b);
+			if (b != 0) {
+				resourceQueue.add(b);
+			}
 		}
 	}
 	
 	private void write(XmlElement element) throws SAXException {
 		if (element.getState() == ElementState.INIT) {
 			if (element.hasNext()) {
-				dataWriter.startElement(NAMESPACE, element.getName(), element.getName(), element.getAttributes());
+				dataWriter.startElement(CORE_NAMESPACE, element.getName(), element.getName(), element.getAttributes());
 				element.setState(ElementState.PROGRESS);
 				xmlStack.push(element.next());
 			} else {
 				if (element.getContent() == null || element.isEmptyCollection()) {
-					dataWriter.emptyElement(NAMESPACE, element.getName(), "", element.getAttributes());
+					dataWriter.emptyElement(CORE_NAMESPACE, element.getName(), element.getName(), element
+						.getAttributes());
 				} else {
-					dataWriter.dataElement(NAMESPACE, element.getName(), element.getContent().toString());
+					dataWriter.dataElement(CORE_NAMESPACE, element.getName(), element.getContent().toString());
 				}
 				element.setState(ElementState.FINISHED);
 				xmlStack.pop();
@@ -139,7 +168,7 @@
 			if (element.hasNext()) {
 				xmlStack.push(element.next());
 			} else {
-				dataWriter.endElement(NAMESPACE, element.getName(), element.getName());
+				dataWriter.endElement(CORE_NAMESPACE, element.getName(), element.getName());
 				element.setState(ElementState.FINISHED);
 				xmlStack.pop();
 			}

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/XmlElement.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/XmlElement.java	2008-10-28 18:03:13 UTC (rev 2062)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/XmlElement.java	2008-10-29 15:12:21 UTC (rev 2063)
@@ -50,7 +50,18 @@
 	
 	private ElementState state = ElementState.INIT;
 	
-	/** 未出力エレメントのキュー */
+	/** 
+	 * 未出力エレメントのキュー
+	 * 
+	 * <pre>
+	 * &lt;foo>
+	 *   &lt;bar/> 
+	 *   &lt;baz/>
+	 * &lt;/foo>
+	 * </pre>
+	 * 
+	 * 上記のようなXML構造の場合、foo要素のXmlElementでは、コンストラクト時に bar, baz がenqueueされる。
+	 */
 	private Queue<XmlElement> queue = new LinkedList<XmlElement>();
 	
 
@@ -122,7 +133,7 @@
 			queue.add(new XmlElement("beginScript", tableModel.getBeginScript()));
 			queue.add(new XmlElement("endScript", tableModel.getEndScript()));
 			queue.add(new XmlElement("description", tableModel.getDescription()));
-			queue.add(new XmlElement("columnns", tableModel.getColumns()));
+			queue.add(new XmlElement("columns", tableModel.getColumns()));
 		} else if (content instanceof ColumnModel) {
 			ColumnModel columnModel = (ColumnModel) content;
 			queue.add(new XmlElement("name", columnModel.getName()));

Modified: artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/ModelInputStreamTest.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/ModelInputStreamTest.java	2008-10-28 18:03:13 UTC (rev 2062)
+++ artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/ModelInputStreamTest.java	2008-10-29 15:12:21 UTC (rev 2063)
@@ -20,7 +20,10 @@
 
 import static org.junit.Assert.assertEquals;
 
-import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.InputStreamReader;
 
 import org.apache.commons.lang.text.StrBuilder;
 import org.junit.Test;
@@ -67,23 +70,21 @@
 		rootModel.appendModel(t);
 		
 		StrBuilder sbActual = new StrBuilder();
-		InputStream mis = null;
+		BufferedReader reader = null;
 		try {
-			mis = new ModelInputStream(rootModel);
-			byte[] buffer = new byte[50];
-			while (-1 != mis.read(buffer)) {
-				System.out.print(new String(buffer));
-				sbActual.append(new String(buffer));
-				buffer = new byte[255];
+			reader = new BufferedReader(new InputStreamReader(new ModelInputStream(rootModel)));
+			String buf;
+			while ((buf = reader.readLine()) != null) {
+				sbActual.appendln(buf);
 			}
 		} finally {
-			mis.close();
+			reader.close();
 		}
 		
 		StrBuilder sbExpected = new StrBuilder();
 		sbExpected.appendln("<?xml version=\"1.0\" standalone=\"yes\"?>");
 		sbExpected.append("<rootModel id=\"").append(rootModel.getId().toString()).appendln(
-				"\" xmlns=\"http://jiemamy.org/ns/model/v1\">");
+				"\" xmlns=\"http://jiemamy.org/ns/core/v1\">");
 		sbExpected.appendln("  <rdbmsName>org.jiemamy.dialect.mysql.MySqlDialect</rdbmsName>");
 		sbExpected.appendln("  <beginScript>BEGIN;</beginScript>");
 		sbExpected.appendln("  <endScript>COMMIT;</endScript>");
@@ -150,6 +151,7 @@
 		sbExpected.appendln("</rootModel>");
 		sbExpected.appendln("");
 		
+		System.out.println(sbActual.toString());
 //		System.out.println(sbExpected.toString());
 		assertEquals(sbExpected.toString(), sbActual.toString());
 	}


Jiemamy-notify メーリングリストの案内
Back to archive index