[Jiemamy-notify] commit [2255] ModelIdManager廃止。 /

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 12月 12日 (金) 19:17:17 JST


Revision: 2255
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2255
Author:   daisuke_m
Date:     2008-12-12 19:17:17 +0900 (Fri, 12 Dec 2008)

Log Message:
-----------
ModelIdManager廃止。 /
Serializerのインターフェイスを直感的に変更。 /
StAXによるシリアライザ実装の検討開始。

Modified Paths:
--------------
    artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/RootModelImpl.java
    artemis/trunk/org.jiemamy.serializer/.classpath
    artemis/trunk/org.jiemamy.serializer/pom.xml
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/JiemamyModelCommand.java
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/ModelInfo.java
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyDefaultSerializer.java
    artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/SerializationTest.java
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/wizard/NewDiagramWizard.java
    zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/serializer/JiemamySerializer.java

Added Paths:
-----------
    artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyStaxSerializer.java

Removed Paths:
-------------
    artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/ModelIdManager.java
    artemis/trunk/org.jiemamy.core/src/test/java/org/jiemamy/model/ModelIdManagerTest.java


-------------- next part --------------
Deleted: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/ModelIdManager.java
===================================================================
--- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/ModelIdManager.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/ModelIdManager.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -1,100 +0,0 @@
-/*
- * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others.
- * Created on 2008/06/27
- *
- * This file is part of Jiemamy.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-package org.jiemamy.model;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * モデルIDを管理するマネージャクラス。
- * @author j5ik2o
- */
-public final class ModelIdManager {
-	
-	/** シングルトンインスタンス */
-	private static ModelIdManager singleton;
-	
-
-	/**
-	 * シングルトンのインスタンスを取得する。
-	 * <p>THINK パフォーマンスを改善する余地があるなら,instanceのnullチェック以降にsynchronizedを設けてみる。</p>
-	 * @return ModelManagerのインスタンス
-	 */
-	public static synchronized ModelIdManager getInstance() {
-		if (singleton == null) {
-			singleton = new ModelIdManager();
-		}
-		return singleton;
-	}
-	
-
-	/** モデル管理マップ */
-	private Map<UUID, Object> modelMap = new HashMap<UUID, Object>();
-	
-
-	/**
-	 * privateコンストラクタ。
-	 * @category instance creation
-	 */
-	private ModelIdManager() {
-	}
-	
-	/**
-	 * モデルIDからモデルを検索する。
-	 * 
-	 * <p>該当するモデルが見つからなかった時は、{@code null}を返す。</p>
-	 * 
-	 * @param <T> モデルの型
-	 * @param id モデルID
-	 * @return AbstractModel モデル
-	 */
-	@SuppressWarnings("unchecked")
-	public <T>T findModel(UUID id) {
-		T result = (T) modelMap.get(id);
-		return result;
-	}
-	
-	/**
-	 * モデルIDを生成して返す。
-	 * @return モデルID
-	 */
-	synchronized UUID generateModelId() {
-		UUID id = UUID.randomUUID();
-		return id;
-	}
-	
-	/**
-	 * モデルに新しいモデルIDを設定し,モデル管理マップに登録する。
-	 * @param model モデル
-	 */
-	synchronized void register(Identifiable model) {
-		modelMap.put(model.getId(), model);
-	}
-	
-	/**
-	 * モデルIDを消去する。
-	 * <p>モデルIDに関連づくオブジェクトも破棄されます</p>
-	 * @param model モデル
-	 */
-	synchronized void unregister(Identifiable model) {
-		modelMap.remove(model.getId());
-	}
-	
-}

Modified: artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/RootModelImpl.java
===================================================================
--- artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/RootModelImpl.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.core/src/main/java/org/jiemamy/model/RootModelImpl.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -104,11 +104,6 @@
 		Validate.notNull(connection);
 		((NodeModelAccessor) connection.getSource()).getModifiableSourceConnections().add(connection);
 		((NodeModelAccessor) connection.getTarget()).getModifiableTargetConnections().add(connection);
-		if (connection instanceof Identifiable) {
-			ModelIdManager modelIdManager = ModelIdManager.getInstance();
-			modelIdManager.register((Identifiable) connection);
-		}
-		
 	}
 	
 	/**
@@ -118,10 +113,6 @@
 		assert nodes != null;
 		Validate.notNull(node);
 		nodes.add(node);
-		if (node instanceof Identifiable) {
-			ModelIdManager modelIdManager = ModelIdManager.getInstance();
-			modelIdManager.register((Identifiable) node);
-		}
 	}
 	
 	/**
@@ -131,8 +122,6 @@
 		assert domains != null;
 		Validate.notNull(domain);
 		domains.add(domain);
-		ModelIdManager modelIdManager = ModelIdManager.getInstance();
-		modelIdManager.register(domain);
 	}
 	
 	/**
@@ -325,10 +314,6 @@
 	 */
 	public void removeModel(AbstractConnectionModel connection) {
 		Validate.notNull(connection);
-		if (connection instanceof Identifiable) {
-			ModelIdManager modelIdManager = ModelIdManager.getInstance();
-			modelIdManager.unregister((Identifiable) connection);
-		}
 		((NodeModelAccessor) connection.getSource()).getModifiableSourceConnections().remove(connection);
 		((NodeModelAccessor) connection.getTarget()).getModifiableTargetConnections().remove(connection);
 	}
@@ -339,10 +324,6 @@
 	public void removeModel(AbstractNodeModel node) {
 		assert nodes != null;
 		Validate.notNull(node);
-		if (node instanceof Identifiable) {
-			ModelIdManager modelIdManager = ModelIdManager.getInstance();
-			modelIdManager.unregister((Identifiable) node);
-		}
 		nodes.remove(node);
 	}
 	
@@ -352,8 +333,6 @@
 	public void removeModel(DomainModel domain) {
 		assert domain != null;
 		Validate.notNull(domain);
-		ModelIdManager modelIdManager = ModelIdManager.getInstance();
-		modelIdManager.unregister(domain);
 		domains.remove(domain);
 	}
 	

Deleted: artemis/trunk/org.jiemamy.core/src/test/java/org/jiemamy/model/ModelIdManagerTest.java
===================================================================
--- artemis/trunk/org.jiemamy.core/src/test/java/org/jiemamy/model/ModelIdManagerTest.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.core/src/test/java/org/jiemamy/model/ModelIdManagerTest.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -1,106 +0,0 @@
-/*
- * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others.
- * Created on 2008/06/28
- *
- * This file is part of Jiemamy.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-package org.jiemamy.model;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.jiemamy.model.node.TableModel;
-
-/**
- * {@link ModelIdManager}のテストクラス。
- * @author j5ik2o
- */
-public class ModelIdManagerTest {
-	
-	private RootModel rootModel;
-	
-
-	/**
-	 * setup
-	 */
-	@Before
-	public void setUp() {
-		Jiemamy.init(Artemis.CORE);
-		rootModel = Jiemamy.newRootModel();
-	}
-	
-	/**
-	 * teardown
-	 */
-	@After
-	public void tearDown() {
-		rootModel = null;
-		Jiemamy.dispose();
-	}
-	
-	/**
-	 * {@link org.jiemamy.model.ModelIdManager#findModel(java.util.UUID)} のためのテスト・メソッド。
-	 */
-	@Test
-	public void test01_findModelが正しく動作するか確認する() {
-		TableModel tableModel = rootModel.newModel(TableModel.class);
-		tableModel.autoDenominate(rootModel);
-		assertNotNull(tableModel);
-		ModelIdManager modelIdManager = ModelIdManager.getInstance();
-		assertNotNull(modelIdManager);
-		TableModel tableModel2 = modelIdManager.findModel(tableModel.getId());
-		assertThat(tableModel2, is(nullValue()));
-		
-		rootModel.appendModel(tableModel);
-		tableModel2 = modelIdManager.findModel(tableModel.getId());
-		assertThat(tableModel2, is(notNullValue()));
-		assertEquals(tableModel, tableModel2);
-	}
-	
-	/**
-	 * {@link org.jiemamy.model.ModelIdManager#register(org.jiemamy.model.Identifiable)} のためのテスト・メソッド。
-	 */
-	@Test
-	public void test02_newModelIdが正しく動作するか確認する() {
-		TableModel tableModel = rootModel.newModel(TableModel.class);
-		tableModel.autoDenominate(rootModel);
-		assertNotNull(tableModel);
-		assertNotNull(tableModel.getId());
-	}
-	
-	/**
-	 * {@link org.jiemamy.model.ModelIdManager#unregister(org.jiemamy.model.Identifiable)} のためのテスト・メソッド。
-	 */
-	@Test
-	public void test03_removeModelIdが正しく動作するか確認する() {
-		TableModel tableModel = rootModel.newModel(TableModel.class);
-		tableModel.autoDenominate(rootModel);
-		assertNotNull(tableModel);
-		ModelIdManager modelIdManager = ModelIdManager.getInstance();
-		assertNotNull(modelIdManager);
-		modelIdManager.unregister(tableModel);
-		TableModel tableModel2 = modelIdManager.findModel(tableModel.getId());
-		assertNull(tableModel2);
-	}
-}

Modified: artemis/trunk/org.jiemamy.serializer/.classpath
===================================================================
--- artemis/trunk/org.jiemamy.serializer/.classpath	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.serializer/.classpath	2008-12-12 10:17:17 UTC (rev 2255)
@@ -16,5 +16,7 @@
 	<classpathentry combineaccessrules="false" kind="src" path="/org.jiemamy.irenka"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/org.jiemamy.core"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/org.jiemamy.view"/>
+	<classpathentry kind="lib" path="lib/stax-1.2.0.jar" sourcepath="lib/sources/stax-1.2.0-sources.jar"/>
+	<classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/>
 	<classpathentry kind="output" path="target/classes"/>
 </classpath>

Modified: artemis/trunk/org.jiemamy.serializer/pom.xml
===================================================================
--- artemis/trunk/org.jiemamy.serializer/pom.xml	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.serializer/pom.xml	2008-12-12 10:17:17 UTC (rev 2255)
@@ -200,6 +200,11 @@
       <version>2.3</version>
     </dependency>
     <dependency>
+      <groupId>stax</groupId>
+      <artifactId>stax</artifactId>
+      <version>1.2.0</version>
+    </dependency>
+    <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>org.jiemamy.spec.core</artifactId>
       <version>${project.version}</version>

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/JiemamyModelCommand.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/JiemamyModelCommand.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/JiemamyModelCommand.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -77,7 +77,8 @@
 		String ref = attributes.getValue("ref");
 		UUID refId = UUID.fromString(ref);
 		// FIXME 実装に依存しないように(ModelIdManagerは仕様ではなく実装)
-		return (T) ModelIdManager.getInstance().findModel(refId);
+//		return (T) ModelIdManager.getInstance().findModel(refId);
+		return (T) ModelInfo.map.get(refId);
 	}
 	
 	/**

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/ModelInfo.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/ModelInfo.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/model/ModelInfo.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -19,7 +19,10 @@
 package org.jiemamy.model;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 
 import org.jiemamy.model.attribute.ColumnModel;
 import org.jiemamy.model.connection.ForeignKeyModel;
@@ -34,6 +37,9 @@
  */
 class ModelInfo {
 	
+	/** FIXME ModelIdManagerの代わり。ダサいので要修正。 */
+	static Map<UUID, Identifiable> map = new HashMap<UUID, Identifiable>();
+	
 	/** RootModel */
 	private RootModel rootModel;
 	
@@ -129,6 +135,7 @@
 	 */
 	public void setColumnModel(ColumnModel columnModel) {
 		this.columnModel = columnModel;
+		map.put(columnModel.getId(), columnModel);
 	}
 	
 	/**
@@ -138,6 +145,7 @@
 	 */
 	public void setDomainModel(DomainModel domainModel) {
 		this.domainModel = domainModel;
+		map.put(domainModel.getId(), domainModel);
 	}
 	
 	/**
@@ -147,6 +155,7 @@
 	 */
 	public void setForeignKeyModel(ForeignKeyModel foreignKeyModel) {
 		this.foreignKeyModel = foreignKeyModel;
+		map.put(foreignKeyModel.getId(), foreignKeyModel);
 	}
 	
 	/**
@@ -156,6 +165,8 @@
 	 */
 	public void setRootModel(RootModel rootModel) {
 		this.rootModel = rootModel;
+		map.clear();
+		map.put(rootModel.getId(), rootModel);
 	}
 	
 	/**
@@ -165,6 +176,7 @@
 	 */
 	public void setTableModel(TableModel tableModel) {
 		this.tableModel = tableModel;
+		map.put(tableModel.getId(), tableModel);
 	}
 	
 }

Modified: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyDefaultSerializer.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyDefaultSerializer.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyDefaultSerializer.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
@@ -74,9 +75,16 @@
 	/**
 	 * {@inheritDoc}
 	 */
-	public InputStream serialize(RootModel rootModel) {
+	public void serialize(RootModel rootModel, OutputStream out) {
 		try {
-			return new ModelInputStream(rootModel);
+//			new ModelInputStream(rootModel);
+			out.write(new byte[] {
+				'h',
+				'o',
+				'g',
+				'e'
+			});
+			// UNDONE
 		} catch (Exception e) {
 			throw new SerializationException(e);
 		}

Added: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyStaxSerializer.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyStaxSerializer.java	                        (rev 0)
+++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyStaxSerializer.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others.
+ * Created on 2008/10/13
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.serializer;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.XMLEvent;
+
+import org.jiemamy.exception.SerializationException;
+import org.jiemamy.model.Jiemamy;
+import org.jiemamy.model.RootModel;
+
+/**
+ * シリアライザのStAXによる実装。
+ * @author daisuke
+ */
+public class JiemamyStaxSerializer implements JiemamySerializer {
+	
+	private static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+	
+	private static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+	
+	private static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
+	
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public RootModel deserialize(InputStream in) throws SerializationException {
+		XMLInputFactory factory = XMLInputFactory.newInstance();
+		XMLEventReader reader = null;
+		RootModel rootModel = Jiemamy.newRootModel();
+		
+		try {
+			reader = factory.createXMLEventReader(in);
+			while (reader.hasNext()) {
+				XMLEvent event = reader.nextEvent();
+				handle(event, rootModel);
+			}
+		} catch (XMLStreamException e) {
+			throw new SerializationException(e);
+		} finally {
+			if (reader != null) {
+				try {
+					reader.close();
+				} catch (XMLStreamException e) {
+					// ignore
+				}
+			}
+		}
+		
+		return rootModel;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public void serialize(RootModel rootModel, OutputStream out) throws SerializationException {
+		XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
+		try {
+//			new ModelInputStream(rootModel);
+			XMLStreamWriter xmlw = xmlof.createXMLStreamWriter(out);
+			xmlw.writeStartDocument();
+			xmlw.writeComment("comment");
+			xmlw.writeStartElement("hoge");
+			xmlw.writeEndElement();
+			xmlw.writeEndDocument();
+			xmlw.close();
+			// UNDONE
+		} catch (Exception e) {
+			throw new SerializationException(e);
+		}
+	}
+	
+	private void handle(XMLEvent event, RootModel rootModel) {
+		// TODO Auto-generated method stub
+	}
+	
+}


Property changes on: artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/JiemamyStaxSerializer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/SerializationTest.java
===================================================================
--- artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/SerializationTest.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/SerializationTest.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -24,6 +24,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 import java.util.List;
 
 import org.apache.commons.io.IOUtils;
@@ -69,7 +71,8 @@
 	public void setUp() throws Exception {
 		Jiemamy.init(Artemis.VIEW);
 		rootModel = new ApplicationModelCreator().createModel();
-		jiemamySerializer = new JiemamyDefaultSerializer();
+//		jiemamySerializer = new JiemamyDefaultSerializer();
+		jiemamySerializer = new JiemamyStaxSerializer();
 	}
 	
 	/**
@@ -89,14 +92,18 @@
 	 */
 	@Test
 	public void test01_シリアライザの動作チェック() throws Exception {
-		InputStream serializeIs1 = null;
-		InputStream serializeIs2 = null;
+		PipedInputStream serializeIs1 = null;
+		PipedInputStream serializeIs2 = null;
 		InputStream referenceIs1 = null;
 		InputStream referenceIs2 = null;
 		InputStream referenceIs3 = null;
+		PipedOutputStream out = null;
 		try {
 			// とりあえず表示
-			serializeIs1 = jiemamySerializer.serialize(rootModel);
+			serializeIs1 = new PipedInputStream();
+			out = new PipedOutputStream(serializeIs1);
+			jiemamySerializer.serialize(rootModel, out);
+			out.close();
 			
 			logger.info("serialized=");// + IOUtils.toString(serializeIs1));
 			print(serializeIs1);
@@ -105,8 +112,11 @@
 			print(referenceIs1);
 			
 			// シリアライズ結果と参照ファイルの同一性試験
+			serializeIs2 = new PipedInputStream();
+			out = new PipedOutputStream(serializeIs2);
 			referenceIs2 = SerializationTest.class.getResourceAsStream("/sample.xml");
-			serializeIs2 = jiemamySerializer.serialize(rootModel);
+			jiemamySerializer.serialize(rootModel, out);
+			out.close();
 //			assertTrue(IOUtils.contentEquals(serializeIs2, referenceIs2));
 			
 			// this.rootModel と deserialized の同一性試験

Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -18,7 +18,8 @@
  */
 package org.jiemamy.eclipse.editor;
 
-import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.EventObject;
@@ -178,11 +179,19 @@
 	@Override
 	public void doSave(IProgressMonitor monitor) {
 		try {
+			PipedInputStream in = new PipedInputStream();
+			PipedOutputStream out = new PipedOutputStream(in);
+			
 			IFile file = ((IFileEditorInput) getEditorInput()).getFile();
 			JiemamySerializer serializer = new JiemamyDefaultSerializer();
-			InputStream stream = serializer.serialize(rootModel);
-			file.setContents(stream, true, true, monitor);
+			serializer.serialize(rootModel, out);
+			
+			out.close();
+			
+			file.setContents(in, true, true, monitor);
 			getCommandStack().markSaveLocation();
+			
+			in.close();
 		} catch (Exception e) {
 			ExceptionHandler.handleException(e);
 		}
@@ -210,9 +219,17 @@
 							@Override
 							public void execute(IProgressMonitor monitor) {
 								try {
+									PipedInputStream in = new PipedInputStream();
+									PipedOutputStream out = new PipedOutputStream(in);
+									
 									JiemamySerializer serializer = new JiemamyDefaultSerializer();
-									InputStream stream = serializer.serialize(rootModel);
-									file.create(stream, true, monitor);
+									serializer.serialize(rootModel, out);
+									
+									out.close();
+									
+									file.create(in, true, monitor);
+									
+									in.close();
 								} catch (Exception e) {
 									ExceptionHandler.handleException(e);
 								}

Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -18,7 +18,8 @@
  */
 package org.jiemamy.eclipse.editor;
 
-import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 
@@ -89,10 +90,19 @@
 	@Override
 	public void doSave(IProgressMonitor monitor) {
 		try {
+			PipedInputStream in = new PipedInputStream();
+			PipedOutputStream out = new PipedOutputStream(in);
+			
+			JiemamySerializer serializer = new JiemamyDefaultSerializer();
+			serializer.serialize(rootModel, out);
+			
+			out.close();
+			
 			IFile file = ((IFileEditorInput) getEditorInput()).getFile();
-			JiemamySerializer serializer = new JiemamyDefaultSerializer();
-			InputStream stream = serializer.serialize(rootModel);
-			file.setContents(stream, true, true, monitor);
+			file.setContents(in, true, true, monitor);
+			
+			in.close();
+			
 			for (DiagramEditor2 editor : editors) {
 				editor.doSave(monitor);
 			}
@@ -123,9 +133,17 @@
 							@Override
 							public void execute(IProgressMonitor monitor) {
 								try {
+									PipedInputStream in = new PipedInputStream();
+									PipedOutputStream out = new PipedOutputStream(in);
+									
 									JiemamySerializer serializer = new JiemamyDefaultSerializer();
-									InputStream stream = serializer.serialize(rootModel);
-									file.create(stream, true, monitor);
+									serializer.serialize(rootModel, out);
+									
+									out.close();
+									
+									file.create(in, true, monitor);
+									
+									in.close();
 								} catch (Exception e) {
 									ExceptionHandler.handleException(e);
 								}

Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/wizard/NewDiagramWizard.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/wizard/NewDiagramWizard.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/wizard/NewDiagramWizard.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -19,6 +19,8 @@
 package org.jiemamy.eclipse.wizard;
 
 import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.jface.viewers.ISelection;
@@ -142,7 +144,14 @@
 			RootModel rootModel = Jiemamy.newRootModel();
 			
 			try {
-				return serializer.serialize(rootModel);
+				PipedInputStream in = new PipedInputStream();
+				PipedOutputStream out = new PipedOutputStream(in);
+				
+				serializer.serialize(rootModel, out);
+				
+				out.close();
+				
+				return in;
 			} catch (Exception e) {
 				ExceptionHandler.handleException(e);
 				return null;

Modified: zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/serializer/JiemamySerializer.java
===================================================================
--- zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/serializer/JiemamySerializer.java	2008-12-12 04:16:26 UTC (rev 2254)
+++ zeus/trunk/org.jiemamy.spec.core/src/main/java/org/jiemamy/serializer/JiemamySerializer.java	2008-12-12 10:17:17 UTC (rev 2255)
@@ -19,6 +19,7 @@
 package org.jiemamy.serializer;
 
 import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.jiemamy.exception.SerializationException;
 import org.jiemamy.model.RootModel;
@@ -40,9 +41,9 @@
 	/**
 	 * RootModelをInputStreamにシリアライズする。
 	 * @param rootModel シリアライズするRootModel
-	 * @return シリアライズしたInputStream
+	 * @param out シリアライズ結果を出力するstream
 	 * @throws SerializationException シリアライズに失敗した時
 	 */
-	InputStream serialize(RootModel rootModel) throws SerializationException;
+	void serialize(RootModel rootModel, OutputStream out) throws SerializationException;
 	
 }


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