[Jiemamy-notify:1511] commit [2730] refactor

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 25日 (水) 00:10:13 JST


Revision: 2730
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2730
Author:   daisuke_m
Date:     2009-02-25 00:10:12 +0900 (Wed, 25 Feb 2009)

Log Message:
-----------
refactor

Modified Paths:
--------------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/JiemamyDomParser.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java
    artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/JiemamyDomParser.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/JiemamyDomParser.java	2009-02-24 14:31:54 UTC (rev 2729)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/serializer/JiemamyDomParser.java	2009-02-24 15:10:12 UTC (rev 2730)
@@ -249,7 +249,7 @@
 	
 	private void parseColumn(Element columnElement, TableModel tableModel) {
 		ColumnModel columnModel = factory.newModel(ColumnModel.class, DomUtil.getUUID(columnElement, CoreQName.ID));
-		columnModel.setName(XpathUtil.getText(columnElement, "core:name/text()"));
+		columnModel.setName(XpathUtil.getTextContent(columnElement, "core:name"));
 		columnModel.setLogicalName(XpathUtil.getTextContent(columnElement, "core:logicalName"));
 		columnModel.setDataType(getDataType((Element) XpathUtil.getNode(columnElement, "core:dataType")));
 		columnModel.setDefaultValue(XpathUtil.getTextContent(columnElement, "core:defaultValue"));
@@ -258,7 +258,7 @@
 		if (nnElement != null) {
 			NotNullConstraintModel nnModel =
 					factory.newModel(NotNullConstraintModel.class, DomUtil.getUUID(nnElement, CoreQName.ID));
-			nnModel.setName(XpathUtil.getText(nnElement, "core:name/text()"));
+			nnModel.setName(XpathUtil.getTextContent(nnElement, "core:name"));
 			readAdapter(nnElement, nnModel);
 			columnModel.setNotNull(nnModel);
 		}
@@ -266,7 +266,7 @@
 		Element ukElement = (Element) XpathUtil.getNode(columnElement, "core:columnUniqueKey");
 		if (ukElement != null) {
 			UniqueKeyModel ukModel = factory.newModel(UniqueKeyModel.class, DomUtil.getUUID(ukElement, CoreQName.ID));
-			ukModel.setName(XpathUtil.getText(ukElement, "core:name/text()"));
+			ukModel.setName(XpathUtil.getTextContent(ukElement, "core:name"));
 			ukModel.getKeyColumns().add(factory.newReference(columnModel));
 			readAdapter(ukElement, ukModel);
 			columnModel.setUniqueKey(ukModel);
@@ -275,7 +275,7 @@
 		Element pkElement = (Element) XpathUtil.getNode(columnElement, "core:columnPrimaryKey");
 		if (pkElement != null) {
 			PrimaryKeyModel pkModel = factory.newModel(PrimaryKeyModel.class, DomUtil.getUUID(pkElement, CoreQName.ID));
-			pkModel.setName(XpathUtil.getText(pkElement, "core:name/text()"));
+			pkModel.setName(XpathUtil.getTextContent(pkElement, "core:name"));
 			pkModel.getKeyColumns().add(factory.newReference(columnModel));
 			readAdapter(pkElement, pkModel);
 			columnModel.setPrimaryKey(pkModel);
@@ -285,8 +285,8 @@
 		if (checkElement != null) {
 			ColumnCheckModel checkModel =
 					factory.newModel(ColumnCheckModel.class, DomUtil.getUUID(checkElement, CoreQName.ID));
-			checkModel.setName(XpathUtil.getText(checkElement, "core:name/text()"));
-			checkModel.setExpression(XpathUtil.getText(checkElement, "core:expression/text()"));
+			checkModel.setName(XpathUtil.getTextContent(checkElement, "core:name"));
+			checkModel.setExpression(XpathUtil.getTextContent(checkElement, "core:expression"));
 			readAdapter(checkElement, checkModel);
 			columnModel.setCheck(checkModel);
 		}
@@ -303,7 +303,7 @@
 			
 			DataSetModel dataSetModel =
 					factory.newModel(DataSetModel.class, DomUtil.getUUID(dataSetNode, CoreQName.ID));
-			dataSetModel.setName(XpathUtil.getText(dataSetNode, "core:name/text()"));
+			dataSetModel.setName(XpathUtil.getTextContent(dataSetNode, "core:name"));
 			
 			NodeList tableRefNodeList = XpathUtil.getNodes(dataSetNode, "core:tableRef");
 			Iterable<Node> tableRefIterableNodeList = new IterableNodeList(tableRefNodeList);
@@ -380,7 +380,7 @@
 				Element checkElement = (Element) checkNode;
 				ColumnCheckModel checkModel =
 						factory.newModel(ColumnCheckModel.class, DomUtil.getUUID(checkNode, CoreQName.ID));
-				checkModel.setExpression(XpathUtil.getText(checkElement, "core:expression/text()"));
+				checkModel.setExpression(XpathUtil.getTextContent(checkElement, "core:expression"));
 				readAdapter(checkElement, checkModel);
 				checkModel.setName(XpathUtil.getTextContent(checkElement, "core:name"));
 				domainModel.setCheck(checkModel);
@@ -472,7 +472,7 @@
 		Element rootElement = document.getDocumentElement();
 		
 		RootModel rootModel = factory.getRootModel(DomUtil.getUUID(rootElement, CoreQName.ID));
-		rootModel.setDialectClassName(XpathUtil.getText(document, "/core:rootModel/core:dialect/text()"));
+		rootModel.setDialectClassName(XpathUtil.getTextContent(document, "/core:rootModel/core:dialect"));
 		rootModel.setSchemaName(XpathUtil.getTextContent(document, "/core:rootModel/core:schemaName"));
 		rootModel.setBeginScript(XpathUtil.getTextContent(document, "/core:rootModel/core:beginScript"));
 		rootModel.setEndScript(XpathUtil.getTextContent(document, "/core:rootModel/core:endScript"));
@@ -483,7 +483,7 @@
 	
 	private TableModel parseTable(Element tableElement) {
 		TableModel tableModel = factory.newModel(TableModel.class, DomUtil.getUUID(tableElement, CoreQName.ID));
-		tableModel.setName(XpathUtil.getText(tableElement, "core:name/text()"));
+		tableModel.setName(XpathUtil.getTextContent(tableElement, "core:name"));
 		tableModel.setLogicalName(XpathUtil.getTextContent(tableElement, "core:logicalName"));
 		tableModel.setBeginScript(XpathUtil.getTextContent(tableElement, "core:beginScript"));
 		tableModel.setEndScript(XpathUtil.getTextContent(tableElement, "core:endScript"));
@@ -500,7 +500,7 @@
 				factory.newModel(TableCheckModel.class, DomUtil.getUUID(checkElement, CoreQName.ID));
 		checkModel.setName(XpathUtil.getTextContent(checkElement, "core:name"));
 		checkModel.setLogicalName(XpathUtil.getTextContent(checkElement, "core:logicalName"));
-		checkModel.setExpression(XpathUtil.getText(checkElement, "core:expression/text()"));
+		checkModel.setExpression(XpathUtil.getTextContent(checkElement, "core:expression"));
 		readAdapter(checkElement, checkModel);
 		tableModel.getAttributes().add(checkModel);
 	}
@@ -524,12 +524,12 @@
 	
 	private ViewModel parseView(Element viewElement) {
 		ViewModel viewModel = factory.newModel(ViewModel.class, DomUtil.getUUID(viewElement, CoreQName.ID));
-		viewModel.setName(XpathUtil.getText(viewElement, "core:name/text()"));
+		viewModel.setName(XpathUtil.getTextContent(viewElement, "core:name"));
 		viewModel.setLogicalName(XpathUtil.getTextContent(viewElement, "core:logicalName"));
 		viewModel.setBeginScript(XpathUtil.getTextContent(viewElement, "core:beginScript"));
 		viewModel.setEndScript(XpathUtil.getTextContent(viewElement, "core:endScript"));
 		viewModel.setDescription(XpathUtil.getTextContent(viewElement, "core:description"));
-		viewModel.setDefinition(XpathUtil.getText(viewElement, "core:definition/text()"));
+		viewModel.setDefinition(XpathUtil.getTextContent(viewElement, "core:definition"));
 		readAdapter(viewElement, viewModel);
 		return viewModel;
 	}

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java	2009-02-24 14:31:54 UTC (rev 2729)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/XpathUtil.java	2009-02-24 15:10:12 UTC (rev 2730)
@@ -23,7 +23,6 @@
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 
-import org.apache.commons.lang.StringUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -92,26 +91,10 @@
 	}
 	
 	/**
-	 * XPath式で特定される文字列を取得する。
-	 * 
-	 * @param root 対象ノード
-	 * @param strExpr XPath式
-	 * @return 取得した文字列
-	 * @deprecated use {@link #getTextContent(Node, String)}
-	 */
-	@Deprecated
-	public static String getText(Node root, String strExpr) {
-		try {
-			String str = (String) XPATH.evaluate(strExpr, root, XPathConstants.STRING);
-			return StringUtils.defaultIfEmpty(str, null);
-		} catch (XPathExpressionException e) {
-			throw new UnexpectedConditionError("XPath expression error: " + strExpr, e);
-		}
-	}
-	
-	/**
 	 * XPath式で特定されるノードの内容文字列を取得する。
 	 * 
+	 *<p> ノードが見つからなかった場合は{@code null}を返す。ノードはあるが空だった場合は空文字列を返す。</p>
+	 * 
 	 * @param root 対象ノード
 	 * @param strExpr XPath式
 	 * @return 取得した文字列

Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java
===================================================================
--- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java	2009-02-24 14:31:54 UTC (rev 2729)
+++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/utils/XpathUtilTest.java	2009-02-24 15:10:12 UTC (rev 2730)
@@ -91,9 +91,6 @@
 		assertThat(XpathUtil.getNode(document, "/core:root/core:foobar[1]"), is(notNullValue()));
 		assertThat(XpathUtil.getNode(document, "/core:root/core:foobar[2]"), is(notNullValue()));
 		assertThat(XpathUtil.getNode(document, "/core:root/core:foobar[3]"), is(nullValue()));
-		
-		assertThat(XpathUtil.getText(document, "/core:root/core:foobar[1]/text()"), is("foo"));
-		assertThat(XpathUtil.getText(document, "/core:root/core:foobar[2]/text()"), is("bar"));
 	}
 	
 	/**
@@ -107,9 +104,6 @@
 		assertThat(XpathUtil.getNode(document, "/core:root/view:hogefuga[1]"), is(notNullValue()));
 		assertThat(XpathUtil.getNode(document, "/core:root/view:hogefuga[2]"), is(notNullValue()));
 		assertThat(XpathUtil.getNode(document, "/core:root/view:hogefuga[3]"), is(nullValue()));
-		
-		assertThat(XpathUtil.getText(document, "/core:root/view:hogefuga[1]/text()"), is("hoge"));
-		assertThat(XpathUtil.getText(document, "/core:root/view:hogefuga[2]/text()"), is("fuga"));
 	}
 	
 	/**
@@ -131,10 +125,6 @@
 	 */
 	@Test
 	public void test04_要素の値が取得できる() throws Exception {
-		assertThat(XpathUtil.getText(document, "/core:root/core:content/text()"), is("unba"));
-		assertThat(XpathUtil.getText(document, "/core:root/core:empty/text()"), is(nullValue()));
-		assertThat(XpathUtil.getText(document, "/core:root/core:nul/text()"), is(nullValue()));
-		
 		assertThat(XpathUtil.getTextContent(document, "/core:root/core:content"), is("unba"));
 		assertThat(XpathUtil.getTextContent(document, "/core:root/core:empty1"), is(""));
 		assertThat(XpathUtil.getTextContent(document, "/core:root/core:empty2"), is(""));



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