svnno****@sourc*****
svnno****@sourc*****
2008年 10月 29日 (水) 02:44:57 JST
Revision: 2061 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=2061 Author: daisuke_m Date: 2008-10-29 02:44:57 +0900 (Wed, 29 Oct 2008) Log Message: ----------- XMLタグにid属性を出力。 Modified Paths: -------------- 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/ModelWriter.java =================================================================== --- artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelWriter.java 2008-10-28 16:41:15 UTC (rev 2060) +++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/ModelWriter.java 2008-10-28 17:44:57 UTC (rev 2061) @@ -44,7 +44,7 @@ private DataWriter dataWriter = new DataWriter(); - private Queue<Byte> resourceQueue; + private final Queue<Byte> resourceQueue; /** @@ -124,7 +124,7 @@ private void write(XmlElement element) throws SAXException { if (element.getState() == ElementState.INIT) { if (element.hasNext()) { - dataWriter.startElement(element.getName()); + dataWriter.startElement(NAMESPACE, element.getName(), element.getName(), element.getAttributes()); element.setState(ElementState.PROGRESS); xmlStack.push(element.next()); } else { @@ -133,9 +133,9 @@ if (element.getContent() == null || (element.getContent() instanceof Collection && ((Collection<?>) element.getContent()) .isEmpty())) { - dataWriter.emptyElement(element.getName()); + dataWriter.emptyElement(NAMESPACE, element.getName(), "", element.getAttributes()); } else { - dataWriter.dataElement(element.getName(), element.getContent().toString()); + dataWriter.dataElement(NAMESPACE, element.getName(), element.getContent().toString()); } element.setState(ElementState.FINISHED); xmlStack.pop(); @@ -144,7 +144,7 @@ if (element.hasNext()) { xmlStack.push(element.next()); } else { - dataWriter.endElement(element.getName()); + dataWriter.endElement(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 16:41:15 UTC (rev 2060) +++ artemis/trunk/org.jiemamy.serializer/src/main/java/org/jiemamy/serializer/XmlElement.java 2008-10-28 17:44:57 UTC (rev 2061) @@ -26,15 +26,26 @@ import java.util.Queue; import org.apache.commons.lang.ClassUtils; +import org.xml.sax.Attributes; +import org.xml.sax.helpers.AttributesImpl; +import org.jiemamy.core.model.datatype.adapter.PrecisionedDataTypeAdapter; +import org.jiemamy.core.model.datatype.adapter.SizedDataTypeAdapter; +import org.jiemamy.core.model.datatype.adapter.TimezonedDataTypeAdapter; import org.jiemamy.spec.model.ColumnModel; +import org.jiemamy.spec.model.JiemamyModel; import org.jiemamy.spec.model.RootModel; +import org.jiemamy.spec.model.datatype.DataType; import org.jiemamy.spec.model.node.TableModel; class XmlElement implements Iterator<XmlElement> { + private static final String NAMESPACE = "http://jiemamy.org/ns/model/v1"; + private String name; + private AttributesImpl attributes = new AttributesImpl(); + private Object content; private ElementState state = ElementState.INIT; @@ -59,8 +70,6 @@ * @category instance creation */ XmlElement(String name, Object content) { - this.content = content; - if (name == null) { if (content instanceof RootModel) { this.name = "rootModel"; @@ -68,6 +77,8 @@ this.name = "table"; } else if (content instanceof ColumnModel) { this.name = "column"; + } else if (content instanceof DataType) { + this.name = "dataType"; } else { this.name = ClassUtils.getShortClassName(content, "null"); } @@ -75,6 +86,13 @@ this.name = name; } + this.content = content; + + if (content instanceof JiemamyModel) { + JiemamyModel jiemamyModel = (JiemamyModel) content; + addAttribute("id", jiemamyModel.getId().toString()); + } + if (content instanceof Collection) { Collection<?> collection = (Collection<?>) content; Iterator<?> ite = collection.iterator(); @@ -117,9 +135,44 @@ queue.add(new XmlElement("description", columnModel.getDescription())); queue.add(new XmlElement("options", null)); // FIXME queue.add(new XmlElement("representation", columnModel.isRepresentation())); + } else if (content instanceof DataType) { + DataType dataType = (DataType) content; + if (dataType.hasAdapter(SizedDataTypeAdapter.class)) { + queue.add(new XmlElement("size", dataType.getAdapter(SizedDataTypeAdapter.class).getSize())); + } + if (dataType.hasAdapter(TimezonedDataTypeAdapter.class)) { + queue.add(new XmlElement("timezone", dataType.getAdapter(TimezonedDataTypeAdapter.class) + .isWithTimezone())); + } + if (dataType.hasAdapter(PrecisionedDataTypeAdapter.class)) { + queue.add(new XmlElement("precision", dataType.getAdapter(PrecisionedDataTypeAdapter.class) + .getPrecision())); + queue.add(new XmlElement("scale", dataType.getAdapter(PrecisionedDataTypeAdapter.class).getScale())); + } } } + public void addAttribute(String key, String value) { + // DOCME 引数、よく分からずに使ってます>< + attributes.addAttribute("", key, key, "", value); + } + + public Attributes getAttributes() { + return attributes; + } + + public Object getContent() { + return content; + } + + public String getName() { + return name; + } + + public ElementState getState() { + return state; + } + /** * {@inheritDoc} */ @@ -144,56 +197,26 @@ throw new UnsupportedOperationException(); } - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return name + ":" + content; - } - - Object getContent() { - return content; - } - -// Queue<XmlElement> getContentAsQueue() { -// Queue<XmlElement> result = new LinkedList<XmlElement>(); -// if (content instanceof Collection) { -// Collection<?> items = (Collection<?>) content; -// for (Object item : items) { -// result.offer(new XmlElement("collectionItem", item)); -// } -// } else if (content instanceof Map) { -// Map<?, ?> items = (Map<?, ?>) content; -// for (Map.Entry<?, ?> item : items.entrySet()) { -// result.offer(new XmlElement("mapItem", item.getKey() + ":" + item.getValue())); -// } -// } else if (content instanceof JiemamyModel) { -// result.add(new XmlElement(content.getClass().getName(), content.toString())); -// } -// return result; -// } - - String getName() { - return name; - } - - ElementState getState() { - return state; - } - - void setContent(Object content) { + public void setContent(Object content) { this.content = content; } - void setName(String name) { + public void setName(String name) { this.name = name; } - void setState(ElementState state) { + public void setState(ElementState state) { this.state = state; } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return name + ":" + content; + } + enum ElementState { INIT, PROGRESS, FINISHED 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 16:41:15 UTC (rev 2060) +++ artemis/trunk/org.jiemamy.serializer/src/test/java/org/jiemamy/serializer/ModelInputStreamTest.java 2008-10-28 17:44:57 UTC (rev 2061) @@ -82,12 +82,13 @@ StrBuilder sbExpected = new StrBuilder(); sbExpected.appendln("<?xml version=\"1.0\" standalone=\"yes\"?>"); - sbExpected.append("<rootModel id=\"").append(rootModel.getId().toString()).appendln("\">"); - sbExpected.appendln(" <rdbmsName>org.jiemamy.dialect.MySQLDialect</rdbmsName>"); + sbExpected.append("<rootModel id=\"").append(rootModel.getId().toString()).appendln( + "\" xmlns=\"http://jiemamy.org/ns/model/v1\">"); + sbExpected.appendln(" <rdbmsName>org.jiemamy.dialect.mysql.MySqlDialect</rdbmsName>"); sbExpected.appendln(" <beginScript>BEGIN;</beginScript>"); sbExpected.appendln(" <endScript>COMMIT;</endScript>"); sbExpected.appendln(" <description>シリアライゼーションイメージ</description>"); - sbExpected.appendln(" <schemaName/>"); + sbExpected.appendln(" <schemaName>FOO</schemaName>"); sbExpected.appendln(" <domains/>"); sbExpected.appendln(" <nodes>"); sbExpected.append(" <table id=\"").append(t.getId().toString()).appendln("\">"); @@ -97,7 +98,7 @@ sbExpected.appendln(" <targetConnections/>"); sbExpected.appendln(" <beginScript/>"); sbExpected.appendln(" <endScript/>"); - sbExpected.appendln(" <description>部署マスタです。</description>"); + sbExpected.appendln(" <description>HOGEHOGE</description>"); sbExpected.appendln(" <columns>"); sbExpected.append(" <column id=\"").append(t.getColumns().get(0).getId().toString()).appendln("\">"); sbExpected.appendln(" <name>col1</name>");