You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/09/24 12:30:25 UTC
svn commit: r578748 - in /incubator/tuscany/java/sdo:
impl/src/main/java/org/apache/tuscany/sdo/impl/
impl/src/test/java/org/apache/tuscany/sdo/test/
lib/src/main/java/org/apache/tuscany/sdo/lib/ tools-test/
tools-test/src/main/resources/ tools-test/sr...
Author: kelvingoodson
Date: Mon Sep 24 03:30:20 2007
New Revision: 578748
URL: http://svn.apache.org/viewvc?rev=578748&view=rev
Log:
Fix for TUSCANY-1726
Added:
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/lib/UnknownPropertyList.java
incubator/tuscany/java/sdo/tools-test/src/main/resources/listAccess.xsd
incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java
Modified:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
incubator/tuscany/java/sdo/tools-test/pom.xml
Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java?rev=578748&r1=578747&r2=578748&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/impl/DataObjectImpl.java Mon Sep 24 03:30:20 2007
@@ -23,17 +23,21 @@
import java.io.ObjectStreamException;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.tuscany.sdo.SDOPackage;
import org.apache.tuscany.sdo.impl.ChangeSummaryImpl.SDOChangeRecorder;
+import org.apache.tuscany.sdo.lib.UnknownPropertyList;
import org.apache.tuscany.sdo.util.DataObjectUtil;
import org.apache.tuscany.sdo.util.VirtualSequence;
+import org.apache.tuscany.sdo.util.DataObjectUtil.Accessor;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.EStructuralFeature.Internal.DynamicValueHolder;
@@ -372,7 +376,12 @@
*/
public List getList(String path)
{
- return (List)get(path);
+ List result = (List)get(path);
+ if (result == null) {
+ result = new UnknownPropertyList(this, path);
+ }
+
+ return result;
}
/**
@@ -1525,4 +1534,6 @@
*/
} //DataObjectImpl
+
+
Added: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java?rev=578748&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java (added)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java Mon Sep 24 03:30:20 2007
@@ -0,0 +1,129 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.tuscany.sdo.test;
+
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import junit.framework.TestCase;
+
+public class DataObjectGetListTestCase extends TestCase {
+ private HelperContext hc;
+ private DataObject companyDataObject;
+
+ private final String TEST_NAMESPACE = "http://www.example.com/getList";
+
+ private String xsdString =
+ "<xsd:schema " +
+ "xmlns:getList=\"http://www.example.com/getList\" " +
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
+ "targetNamespace=\"http://www.example.com/getList\">" +
+
+ "<xsd:element name=\"company\" type=\"getList:Company\"/>" +
+ "<xsd:element name=\"employee\" type=\"xsd:string\"/>" +
+
+ "<xsd:complexType name=\"Company\">" +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"openCompany\" type=\"getList:OpenCompany\"/>" +
+ "<xsd:element name=\"closeCompany\" type=\"getList:CloseCompany\"/>" +
+ "</xsd:sequence>" +
+ "</xsd:complexType>" +
+
+ "<xsd:complexType name=\"OpenCompany\">" +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"company\" type=\"xsd:string\"/>" +
+ "<xsd:element name=\"employees\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>" +
+ "<xsd:any maxOccurs=\"unbounded\" namespace=\"##any\"/>" +
+ "</xsd:sequence>" +
+ "</xsd:complexType>" +
+
+ "<xsd:complexType name=\"CloseCompany\">" +
+ "<xsd:sequence>" +
+ "<xsd:element name=\"company\" type=\"xsd:string\"/>" +
+ "<xsd:element name=\"employees\" maxOccurs=\"unbounded\" type=\"xsd:string\"/>" +
+ "</xsd:sequence>" +
+ "</xsd:complexType>" +
+
+ "</xsd:schema>";
+
+ /**
+ * Test DataObject.getList() on open type
+ */
+ public void testUnknownPropertyOnOpenType() throws IOException {
+ String companyName = companyDataObject.getString("openCompany/company");
+ assertEquals(companyName, "OpenCompany");
+ List unknownProperty = companyDataObject.getList("openCompany/unknownProperty");
+ assertNotNull(unknownProperty);
+ assertTrue(unknownProperty instanceof List);
+
+ List unknownProperty2 = companyDataObject.getList("openCompany/unknownProperty");
+ assertNotNull(unknownProperty2);
+ assertTrue(unknownProperty2 instanceof List);
+
+ // unknownProperty and unknownProperty2 are in fact the same value for the same property
+
+ unknownProperty.add("employee1");
+ assertTrue(unknownProperty.size() == 1);
+
+ unknownProperty2.add("employee2");
+ assertTrue(unknownProperty2.size() == 2);
+
+ unknownProperty.remove(0);
+ assertTrue(unknownProperty.size() == 1);
+
+ assertEquals(unknownProperty.get(0), "employee2");
+ }
+
+ /**
+ * Test DataObject.getList() on non-open type
+ */
+ public void testUnknownPropertyOnClosedType() throws IOException {
+ String companyName = companyDataObject.getString("closeCompany/company");
+ assertEquals(companyName, "CloseCompany");
+ List unknownProperty = companyDataObject.getList("closeCompany/unknownProperty");
+ assertNotNull(unknownProperty);
+ assertTrue(unknownProperty instanceof List);
+
+ try {
+ unknownProperty.add("employee1");
+ fail("An exception should have been thrown.");
+ }
+ catch (Exception e) {
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hc = SDOUtil.createHelperContext();
+ hc.getXSDHelper().define(xsdString);
+
+ companyDataObject = hc.getDataFactory().create(TEST_NAMESPACE, "Company");
+ DataObject openCompany = companyDataObject.createDataObject("openCompany");
+ openCompany.setString("company", "OpenCompany");
+ DataObject closeCompany = companyDataObject.createDataObject("closeCompany");
+ closeCompany.setString("company", "CloseCompany");
+ }
+}
Added: incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/lib/UnknownPropertyList.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/lib/UnknownPropertyList.java?rev=578748&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/lib/UnknownPropertyList.java (added)
+++ incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/lib/UnknownPropertyList.java Mon Sep 24 03:30:20 2007
@@ -0,0 +1,70 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.tuscany.sdo.lib;
+
+import java.util.AbstractList;
+import java.util.Collections;
+import java.util.List;
+
+import commonj.sdo.DataObject;
+
+public class UnknownPropertyList extends AbstractList {
+ protected List delegateList = Collections.EMPTY_LIST;
+ protected DataObject dataObject;
+ protected String path;
+
+ public UnknownPropertyList(DataObject dataObject, String path) {
+ this.dataObject = dataObject;
+ this.path = path;
+ }
+
+ public Object get(int index) {
+ return getDelegateList().get(index);
+ }
+
+ public int size() {
+ return getDelegateList().size();
+ }
+
+ public Object remove(int index) {
+ return getDelegateList().remove(index);
+ }
+ public Object set(int index, Object element) {
+ return getDelegateList().set(index, element);
+ }
+
+ public void add(int index, Object element) {
+ if (getDelegateList() == Collections.EMPTY_LIST && index == 0) {
+ dataObject.set(path, Collections.singletonList(element));
+ delegateList = (List)dataObject.get(path);
+ }
+ else {
+ delegateList.add(index, element);
+ }
+ }
+
+ protected List getDelegateList() {
+ if (delegateList == Collections.EMPTY_LIST) {
+ List propertyList = (List)dataObject.get(path);
+ if (propertyList != null) delegateList = propertyList;
+ }
+ return delegateList;
+ }
+}
Modified: incubator/tuscany/java/sdo/tools-test/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/pom.xml?rev=578748&r1=578747&r2=578748&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/tools-test/pom.xml (original)
+++ incubator/tuscany/java/sdo/tools-test/pom.xml Mon Sep 24 03:30:20 2007
@@ -164,7 +164,16 @@
<goals>
<goal>generate</goal>
</goals>
- </execution>
+ </execution>
+ <execution>
+ <id>listAccess</id>
+ <configuration>
+ <schemaFile>${basedir}/src/main/resources/listAccess.xsd</schemaFile>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
</executions>
</plugin>
</plugins>
Added: incubator/tuscany/java/sdo/tools-test/src/main/resources/listAccess.xsd
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/main/resources/listAccess.xsd?rev=578748&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/tools-test/src/main/resources/listAccess.xsd (added)
+++ incubator/tuscany/java/sdo/tools-test/src/main/resources/listAccess.xsd Mon Sep 24 03:30:20 2007
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+ -->
+ <xsd:schema
+ xmlns:getList="http://www.example.com/getList"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.example.com/getList">
+
+
+ <xsd:element name="company" type="getList:Company"/>
+ <xsd:element name="employee" type="xsd:string"/>
+
+ <xsd:complexType name="Company">
+ <xsd:sequence>
+ <xsd:element name="openCompany" type="getList:OpenCompany"/>
+ <xsd:element name="closeCompany" type="getList:CloseCompany"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+
+ <xsd:complexType name="OpenCompany">
+ <xsd:sequence>
+ <xsd:element name="company" type="xsd:string"/>
+ <xsd:element name="employees" maxOccurs="unbounded" type="xsd:string"/>
+ <xsd:any maxOccurs="unbounded" namespace="##any"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+
+ <xsd:complexType name="CloseCompany">
+ <xsd:sequence>
+ <xsd:element name="company" type="xsd:string"/>
+ <xsd:element name="employees" maxOccurs="unbounded" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+</xsd:schema>
\ No newline at end of file
Added: incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java?rev=578748&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java (added)
+++ incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/DataObjectGetListTestCase.java Mon Sep 24 03:30:20 2007
@@ -0,0 +1,99 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.tuscany.sdo.test;
+
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import com.example.get.list.ListFactory;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import junit.framework.TestCase;
+
+public class DataObjectGetListTestCase extends TestCase {
+ private HelperContext hc;
+ private DataObject companyDataObject;
+
+ private final String TEST_NAMESPACE = "http://www.example.com/getList";
+
+
+ /**
+ * Test DataObject.getList() on open type
+ */
+ public void testUnknownPropertyOnOpenType() throws IOException {
+ String companyName = companyDataObject.getString("openCompany/company");
+ assertEquals(companyName, "OpenCompany");
+ List unknownProperty = companyDataObject.getList("openCompany/unknownProperty");
+ assertNotNull(unknownProperty);
+ assertTrue(unknownProperty instanceof List);
+
+ List unknownProperty2 = companyDataObject.getList("openCompany/unknownProperty");
+ assertNotNull(unknownProperty2);
+ assertTrue(unknownProperty2 instanceof List);
+
+ // unknownProperty and unknownProperty2 are in fact the same value for the same property
+
+ unknownProperty.add("employee1");
+ assertTrue(unknownProperty.size() == 1);
+
+ unknownProperty2.add("employee2");
+ assertTrue(unknownProperty2.size() == 2);
+
+ unknownProperty.remove(0);
+ assertTrue(unknownProperty.size() == 1);
+
+ assertEquals(unknownProperty.get(0), "employee2");
+ }
+
+ /**
+ * Test DataObject.getList() on non-open type
+ */
+ public void testUnknownPropertyOnClosedType() throws IOException {
+ String companyName = companyDataObject.getString("closeCompany/company");
+ assertEquals(companyName, "CloseCompany");
+ List unknownProperty = companyDataObject.getList("closeCompany/unknownProperty");
+ assertNotNull(unknownProperty);
+ assertTrue(unknownProperty instanceof List);
+
+ try {
+ unknownProperty.add("employee1");
+ fail("An exception should have been thrown.");
+ }
+ catch (Exception e) {
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hc = SDOUtil.createHelperContext();
+ ListFactory.INSTANCE.register(hc);
+
+ companyDataObject = hc.getDataFactory().create(TEST_NAMESPACE, "Company");
+ DataObject openCompany = companyDataObject.createDataObject("openCompany");
+ openCompany.setString("company", "OpenCompany");
+ DataObject closeCompany = companyDataObject.createDataObject("closeCompany");
+ closeCompany.setString("company", "CloseCompany");
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org