Added: incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsImpl.java URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsImpl.java?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsImpl.java (added) +++ incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsImpl.java Mon May 8 07:35:35 2006 @@ -0,0 +1,439 @@ +/** + * <copyright> + * </copyright> + * + * $Id$ + */ +package com.example.sequences.impl; + +import com.example.sequences.TwoRCs; + +import commonj.sdo.Sequence; +import commonj.sdo.Type; + +import commonj.sdo.helper.TypeHelper; + +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sdo.impl.DataObjectBase; + +import org.apache.tuscany.sdo.util.BasicSequence; + +/** + * <!-- begin-user-doc --> + * An implementation of the model object '<em><b>Two RCs</b></em>'. + * <!-- end-user-doc --> + * <p> + * The following features are implemented: + * <ul> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getGroup <em>Group</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getA <em>A</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getB <em>B</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getSplit <em>Split</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getGroup1 <em>Group1</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getY <em>Y</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsImpl#getZ <em>Z</em>}</li> + * </ul> + * </p> + * + * @generated + */ +public class TwoRCsImpl extends DataObjectBase implements TwoRCs +{ + /** + * The feature id for the '<em><b>Group</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int GROUP = 0; + + /** + * The cached value of the '[EMAIL PROTECTED] #getGroup() <em>Group</em>}' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getGroup() + * @generated + * @ordered + */ + + // How to get BasicSequence from Sequence? + + protected BasicSequence group = null; + + /** + * The feature id for the '<em><b>A</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int A = 1; + + /** + * The feature id for the '<em><b>B</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int B = 2; + + /** + * The feature id for the '<em><b>Split</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int SPLIT = 3; + + /** + * The default value of the '[EMAIL PROTECTED] #getSplit() <em>Split</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSplit() + * @generated + * @ordered + */ + protected static final String SPLIT_DEFAULT_ = null; + + /** + * The cached value of the '[EMAIL PROTECTED] #getSplit() <em>Split</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSplit() + * @generated + * @ordered + */ + protected String split = SPLIT_DEFAULT_; + + /** + * The feature id for the '<em><b>Group1</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int GROUP1 = 4; + + /** + * The cached value of the '[EMAIL PROTECTED] #getGroup1() <em>Group1</em>}' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getGroup1() + * @generated + * @ordered + */ + + // How to get BasicSequence from Sequence? + + protected BasicSequence group1 = null; + + /** + * The feature id for the '<em><b>Y</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int Y = 5; + + /** + * The feature id for the '<em><b>Z</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int Z = 6; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected TwoRCsImpl() + { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Type getType() + { + return TypeHelper.INSTANCE.getType(TwoRCs.class); //TBD Generate a more efficient implementation + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Sequence getGroup() + { + if (group == null) + { + group = createSequence(GROUP); + + } + return group; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getA() + { + return getList(getGroup(), getType(), A); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getB() + { + return getList(getGroup(), getType(), B); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String getSplit() + { + return split; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setSplit(String newSplit) + { + String oldSplit = split; + split = newSplit; + if (isNotifying()) + notify(ChangeKind.SET, SPLIT, oldSplit, split); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Sequence getGroup1() + { + if (group1 == null) + { + group1 = createSequence(GROUP1); + + } + return group1; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getY() + { + return getList(getGroup1(), getType(), Y); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getZ() + { + return getList(getGroup1(), getType(), Z); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public ChangeContext inverseRemove(Object otherEnd, int propertyIndex, ChangeContext changeContext) + { + switch (propertyIndex) + { + case GROUP: + return removeFromSequence(getGroup(), otherEnd, changeContext); + case GROUP1: + return removeFromSequence(getGroup1(), otherEnd, changeContext); + } + return super.inverseRemove(otherEnd, propertyIndex, changeContext); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Object get(int propertyIndex, boolean resolve) + { + switch (propertyIndex) + { + case GROUP: + // XXX query introduce coreType as an argument? -- semantic = if true -- coreType - return the core EMF object if value is a non-EMF wrapper/view + //if (coreType) + return getGroup(); + case A: + return getA(); + case B: + return getB(); + case SPLIT: + return getSplit(); + case GROUP1: + // XXX query introduce coreType as an argument? -- semantic = if true -- coreType - return the core EMF object if value is a non-EMF wrapper/view + //if (coreType) + return getGroup1(); + case Y: + return getY(); + case Z: + return getZ(); + } + return super.get(propertyIndex, resolve); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void set(int propertyIndex, Object newValue) + { + switch (propertyIndex) + { + case GROUP: + setSequence(getGroup(), newValue); + return; + case A: + getA().clear(); + getA().addAll((Collection)newValue); + return; + case B: + getB().clear(); + getB().addAll((Collection)newValue); + return; + case SPLIT: + setSplit((String)newValue); + return; + case GROUP1: + setSequence(getGroup1(), newValue); + return; + case Y: + getY().clear(); + getY().addAll((Collection)newValue); + return; + case Z: + getZ().clear(); + getZ().addAll((Collection)newValue); + return; + } + super.set(propertyIndex, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void unset(int propertyIndex) + { + switch (propertyIndex) + { + case GROUP: + unsetSequence(getGroup()); + return; + case A: + getA().clear(); + return; + case B: + getB().clear(); + return; + case SPLIT: + setSplit(SPLIT_DEFAULT_); + return; + case GROUP1: + unsetSequence(getGroup1()); + return; + case Y: + getY().clear(); + return; + case Z: + getZ().clear(); + return; + } + super.unset(propertyIndex); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public boolean isSet(int propertyIndex) + { + switch (propertyIndex) + { + case GROUP: + // KDK - should this be !isSequenceEmpty? + return group != null && !isSequenceEmpty(getGroup()); + case A: + return !getA().isEmpty(); + case B: + return !getB().isEmpty(); + case SPLIT: + return SPLIT_DEFAULT_ == null ? split != null : !SPLIT_DEFAULT_.equals(split); + case GROUP1: + // KDK - should this be !isSequenceEmpty? + return group1 != null && !isSequenceEmpty(getGroup1()); + case Y: + return !getY().isEmpty(); + case Z: + return !getZ().isEmpty(); + } + return super.isSet(propertyIndex); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String toString() + { + if (isProxy()) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (group: "); + result.append(group); + result.append(", split: "); + result.append(split); + result.append(", group1: "); + result.append(group1); + result.append(')'); + return result.toString(); + } + +} //TwoRCsImpl
Added: incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsMixedImpl.java URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsMixedImpl.java?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsMixedImpl.java (added) +++ incubator/tuscany/java/sdo/tools/src/test/java/com/example/sequences/impl/TwoRCsMixedImpl.java Mon May 8 07:35:35 2006 @@ -0,0 +1,437 @@ +/** + * <copyright> + * </copyright> + * + * $Id$ + */ +package com.example.sequences.impl; + +import com.example.sequences.TwoRCsMixed; + +import commonj.sdo.Sequence; +import commonj.sdo.Type; + +import commonj.sdo.helper.TypeHelper; + +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sdo.impl.DataObjectBase; + +import org.apache.tuscany.sdo.util.BasicSequence; + +/** + * <!-- begin-user-doc --> + * An implementation of the model object '<em><b>Two RCs Mixed</b></em>'. + * <!-- end-user-doc --> + * <p> + * The following features are implemented: + * <ul> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getMixed <em>Mixed</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getGroup <em>Group</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getA <em>A</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getB <em>B</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getSplit <em>Split</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getGroup1 <em>Group1</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getY <em>Y</em>}</li> + * <li>[EMAIL PROTECTED] com.example.sequences.impl.TwoRCsMixedImpl#getZ <em>Z</em>}</li> + * </ul> + * </p> + * + * @generated + */ +public class TwoRCsMixedImpl extends DataObjectBase implements TwoRCsMixed +{ + /** + * The feature id for the '<em><b>Mixed</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int MIXED = 0; + + /** + * The cached value of the '[EMAIL PROTECTED] #getMixed() <em>Mixed</em>}' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getMixed() + * @generated + * @ordered + */ + + // How to get BasicSequence from Sequence? + + protected BasicSequence mixed = null; + + /** + * The feature id for the '<em><b>Group</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int GROUP = 1; + + /** + * The feature id for the '<em><b>A</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int A = 2; + + /** + * The feature id for the '<em><b>B</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int B = 3; + + /** + * The feature id for the '<em><b>Split</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int SPLIT = 4; + + /** + * The default value of the '[EMAIL PROTECTED] #getSplit() <em>Split</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSplit() + * @generated + * @ordered + */ + protected static final String SPLIT_DEFAULT_ = null; + + /** + * The feature id for the '<em><b>Group1</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int GROUP1 = 5; + + /** + * The feature id for the '<em><b>Y</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int Y = 6; + + /** + * The feature id for the '<em><b>Z</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public final static int Z = 7; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected TwoRCsMixedImpl() + { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Type getType() + { + return TypeHelper.INSTANCE.getType(TwoRCsMixed.class); //TBD Generate a more efficient implementation + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Sequence getMixed() + { + if (mixed == null) + { + mixed = createSequence(MIXED); + + } + return mixed; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Sequence getGroup() + { + return createSequence(getMixed(), getType(), GROUP); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getA() + { + return getList(getGroup(), getType(), A); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getB() + { + return getList(getGroup(), getType(), B); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String getSplit() + { + return (String)get(getMixed(), getType(), SPLIT); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setSplit(String newSplit) + { + set(getMixed(), getType(), SPLIT, newSplit); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Sequence getGroup1() + { + return createSequence(getMixed(), getType(), GROUP1); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getY() + { + return getList(getGroup1(), getType(), Y); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getZ() + { + return getList(getGroup1(), getType(), Z); + + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public ChangeContext inverseRemove(Object otherEnd, int propertyIndex, ChangeContext changeContext) + { + switch (propertyIndex) + { + case MIXED: + return removeFromSequence(getMixed(), otherEnd, changeContext); + case GROUP: + return removeFromSequence(getGroup(), otherEnd, changeContext); + case GROUP1: + return removeFromSequence(getGroup1(), otherEnd, changeContext); + } + return super.inverseRemove(otherEnd, propertyIndex, changeContext); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Object get(int propertyIndex, boolean resolve) + { + switch (propertyIndex) + { + case MIXED: + // XXX query introduce coreType as an argument? -- semantic = if true -- coreType - return the core EMF object if value is a non-EMF wrapper/view + //if (coreType) + return getMixed(); + case GROUP: + // XXX query introduce coreType as an argument? -- semantic = if true -- coreType - return the core EMF object if value is a non-EMF wrapper/view + //if (coreType) + return getGroup(); + case A: + return getA(); + case B: + return getB(); + case SPLIT: + return getSplit(); + case GROUP1: + // XXX query introduce coreType as an argument? -- semantic = if true -- coreType - return the core EMF object if value is a non-EMF wrapper/view + //if (coreType) + return getGroup1(); + case Y: + return getY(); + case Z: + return getZ(); + } + return super.get(propertyIndex, resolve); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void set(int propertyIndex, Object newValue) + { + switch (propertyIndex) + { + case MIXED: + setSequence(getMixed(), newValue); + return; + case GROUP: + setSequence(getGroup(), newValue); + return; + case A: + getA().clear(); + getA().addAll((Collection)newValue); + return; + case B: + getB().clear(); + getB().addAll((Collection)newValue); + return; + case SPLIT: + setSplit((String)newValue); + return; + case GROUP1: + setSequence(getGroup1(), newValue); + return; + case Y: + getY().clear(); + getY().addAll((Collection)newValue); + return; + case Z: + getZ().clear(); + getZ().addAll((Collection)newValue); + return; + } + super.set(propertyIndex, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void unset(int propertyIndex) + { + switch (propertyIndex) + { + case MIXED: + unsetSequence(getMixed()); + return; + case GROUP: + unsetSequence(getGroup()); + return; + case A: + getA().clear(); + return; + case B: + getB().clear(); + return; + case SPLIT: + setSplit(SPLIT_DEFAULT_); + return; + case GROUP1: + unsetSequence(getGroup1()); + return; + case Y: + getY().clear(); + return; + case Z: + getZ().clear(); + return; + } + super.unset(propertyIndex); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public boolean isSet(int propertyIndex) + { + switch (propertyIndex) + { + case MIXED: + // KDK - should this be !isSequenceEmpty? + return mixed != null && !isSequenceEmpty(getMixed()); + case GROUP: + return !isSequenceEmpty(getGroup()); + case A: + return !getA().isEmpty(); + case B: + return !getB().isEmpty(); + case SPLIT: + return SPLIT_DEFAULT_ == null ? getSplit() != null : !SPLIT_DEFAULT_.equals(getSplit()); + case GROUP1: + return !isSequenceEmpty(getGroup1()); + case Y: + return !getY().isEmpty(); + case Z: + return !getZ().isEmpty(); + } + return super.isSet(propertyIndex); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String toString() + { + if (isProxy()) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (mixed: "); + result.append(mixed); + result.append(')'); + return result.toString(); + } + +} //TwoRCsMixedImpl Added: incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/StaticSequenceNoEmfTest.java URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/StaticSequenceNoEmfTest.java?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/StaticSequenceNoEmfTest.java (added) +++ incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/StaticSequenceNoEmfTest.java Mon May 8 07:35:35 2006 @@ -0,0 +1,249 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * 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.apache.tuscany.sdo.test; + + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.sequences.MixedQuote; +import com.example.sequences.MixedRepeatingChoice; +import com.example.sequences.RepeatingChoice; +import com.example.sequences.SequencesFactory; +import com.example.sequences.TwoRCs; +import com.example.sequences.TwoRCsMixed; +import commonj.sdo.DataObject; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.XMLHelper; + + +public class StaticSequenceNoEmfTest extends TestCase { + private final String TEST_NAMESPACE = "http://www.example.com/sequences"; + private final String MQ_TEST_DATA = "/mixedStaticTestResult.xml"; + private final String RC_TEST_DATA = "/repeatingChoiceTestResult.xml"; + private final String MRC_TEST_DATA = "/mixedRepeatingChoiceTestResult.xml"; + private final String RC2_TEST_DATA = "/twoRepeatingChoicesTestResult.xml"; + private final String RC2M_TEST_DATA = "/twoRepeatingChoicesMixedTestResult.xml"; + + /** + * Sequenced type SDO 2 test. + */ + public void testMixedQuoteType() throws IOException { + MixedQuote quote = SequencesFactory.INSTANCE.createMixedQuote(); + + Type t = ((DataObject)quote).getType(); + List ps = t.getProperties(); + + + Sequence sequence = quote.getMixed(); + + sequence.add("\n "); + + quote.setSymbol("fbnt"); + + sequence.add("\n "); + + quote.setCompanyName("FlyByNightTechnology"); + + sequence.add("\n some text\n "); + + List quotes = quote.getQuotes(); + MixedQuote child = SequencesFactory.INSTANCE.createMixedQuote(); + quotes.add(child); + + child.setPrice(new BigDecimal("2000.0")); + + sequence.add("\n more text\n "); + + sequence.add("price", new BigDecimal("1000.0")); + + sequence.add("\n"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XMLHelper.INSTANCE.save((DataObject)quote, TEST_NAMESPACE, "mixedStockQuote", baos); + assertTrue(baos.toString(), TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MQ_TEST_DATA))); + } + + public void testRepeatingChoice() throws IOException + { + RepeatingChoice rc = SequencesFactory.INSTANCE.createRepeatingChoice(); + + List as = rc.getA(); + List bs = rc.getB(); + + bs.add(new Integer(1)); + as.add("foo"); + as.add("bar"); + bs.add(new Integer(2)); + + + + + Sequence group = rc.getGroup(); + assertEquals(group.size(), 4); + assertEquals(rc.getA().size(), 2); + assertEquals(rc.getB().size(),2); + + assertEquals(group.getValue(0), new Integer(1)); + assertEquals(group.getValue(1), "foo"); + assertEquals(group.getValue(2), "bar"); + assertEquals(group.getValue(3), new Integer(2)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + XMLHelper.INSTANCE.save((DataObject)rc, TEST_NAMESPACE, "rc", baos); + assertTrue(baos.toString(), TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(RC_TEST_DATA))); + } + + public void testMixedRepeatingChoice() throws Exception { + MixedRepeatingChoice mrc = SequencesFactory.INSTANCE.createMixedRepeatingChoice(); + + List as = mrc.getA(); + List bs = mrc.getB(); + + + bs.add(new Integer(1)); + as.add("foo"); + Sequence mixed = mrc.getMixed(); + mixed.add("some mixed text"); + as.add("bar"); + bs.add(new Integer(2)); + + // FIXME reintroduce check + // assertEquals(4, mrc.getGroup().size()); + assertEquals(5, mrc.getMixed().size()); + assertEquals(2, mrc.getA().size()); + assertEquals(2, mrc.getB().size(),2); + + + + assertEquals(mixed.getValue(0), new Integer(1)); + assertEquals(mixed.getValue(1), "foo"); + assertEquals(mixed.getValue(3), "bar"); + assertEquals(mixed.getValue(4), new Integer(2)); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + + XMLHelper.INSTANCE.save((DataObject)mrc, TEST_NAMESPACE, "mrc", baos); + assertTrue(baos.toString(), TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MRC_TEST_DATA))); + } + + public void test2RepeatingChoices() throws Exception { + TwoRCs rc2 = SequencesFactory.INSTANCE.createTwoRCs(); + + List as = rc2.getA(); + List bs = rc2.getB(); + List ys = rc2.getY(); + List zs = rc2.getZ(); + + zs.add(new Integer(99)); + bs.add(new Integer(1)); + ys.add("fred"); + as.add("foo"); + as.add("bar"); + bs.add(new Integer(2)); + rc2.setSplit("banana"); + + + Sequence group = rc2.getGroup(); + assertEquals(group.size(), 4); + assertEquals(rc2.getA().size(), 2); + assertEquals(rc2.getB().size(),2); + + Sequence group1 = rc2.getGroup1(); + assertEquals(group1.size(), 2); + assertEquals(rc2.getY().size(), 1); + assertEquals(rc2.getZ().size(),1); + + assertEquals(group.getValue(0), new Integer(1)); + assertEquals(group.getValue(1), "foo"); + assertEquals(group.getValue(2), "bar"); + assertEquals(group.getValue(3), new Integer(2)); + assertEquals(group1.getValue(0), new Integer(99)); + assertEquals(group1.getValue(1), "fred"); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + + XMLHelper.INSTANCE.save((DataObject)rc2, TEST_NAMESPACE, "rc2", baos); + assertTrue(baos.toString(), TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(RC2_TEST_DATA))); + } + + protected void setUp() throws Exception { + super.setUp(); + SDOUtil.registerStaticTypes(SequencesFactory.class); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void test2RepeatingChoicesMixed() throws Exception { + TwoRCsMixed rc2m = SequencesFactory.INSTANCE.createTwoRCsMixed(); + + List as = rc2m.getA(); + List bs = rc2m.getB(); + List ys = rc2m.getY(); + List zs = rc2m.getZ(); + Sequence mixed = rc2m.getMixed(); + + bs.add(new Integer(1)); + mixed.add("where will this appear?"); + as.add("foo"); + as.add("bar"); + bs.add(new Integer(2)); + rc2m.setSplit("pea"); + zs.add(new Integer(99)); + ys.add("fred"); + + + assertEquals(8, mixed.size()); + + Sequence group = rc2m.getGroup(); + // FIXME reintroduce test assertEquals(4, group.size()); + assertEquals(rc2m.getA().size(), 2); + assertEquals(rc2m.getB().size(),2); + + Sequence group1 = rc2m.getGroup1(); + // FIXME ditto assertEquals(group1.size(), 2); + assertEquals(rc2m.getY().size(), 1); + assertEquals(rc2m.getZ().size(),1); + + int i = 0; + assertEquals(mixed.getValue(i++), new Integer(1)); + assertEquals(mixed.getValue(i++), "where will this appear?"); + assertEquals(mixed.getValue(i++), "foo"); + assertEquals(mixed.getValue(i++), "bar"); + assertEquals(mixed.getValue(i++), new Integer(2)); + assertEquals(mixed.getValue(i++), "pea"); + assertEquals(mixed.getValue(i++), new Integer(99)); + assertEquals(mixed.getValue(i++), "fred"); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + XMLHelper.INSTANCE.save((DataObject)rc2m, TEST_NAMESPACE, "rc2m", baos); + assertTrue(baos.toString(), TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(RC2M_TEST_DATA))); + } + + +} Added: incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java (added) +++ incubator/tuscany/java/sdo/tools/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java Mon May 8 07:35:35 2006 @@ -0,0 +1,282 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * 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.apache.tuscany.sdo.test; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class TestUtil +{ + private static void getAllNodes(NodeList nodeList, List nodes) + { + int length = nodeList.getLength(); + if (length == 0) + { + return; + } + + for (int i=0; i<length; i++) + { + Node node = nodeList.item(i); + nodes.add(node); + getAllNodes(node.getChildNodes(), nodes); + } // for + } + + private static boolean equalNamedNodeMap(NamedNodeMap mapA, NamedNodeMap mapB) { + if (mapA == null) { + if (mapB == null) { + return true; + } + return false; + } + if (mapA.getLength() != mapB.getLength()) { + return false; + } + for (int i = 0; i < mapA.getLength(); i++) { + Node trialNode = mapA.item(i); + if (trialNode == null) { + return false; + } + Node checkNode = mapB.getNamedItem(trialNode.getNodeName()); + if (checkNode == null) { + return false; + } + if (!equalNode(trialNode, checkNode)) { + return false; + } + } + return true; + } + + private static boolean equalNode(Node nodeA, Node nodeB) { + if (nodeA == null) { + if (nodeB == null) { + return true; + } + return false; + } + // following is intended to provide same function as 1.5 isEqualNode() + if (nodeA.getNodeType() != nodeB.getNodeType()) { + return false; + } + if (!equalString(nodeA.getNodeName(), nodeB.getNodeName())) { + return false; + } + if (!equalString(nodeA.getLocalName(), nodeB.getLocalName())) { + return false; + } + if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) { + return false; + } + if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) { + return false; + } + if (!equalString(nodeA.getPrefix(), nodeB.getPrefix())) { + return false; + } + if (!equalString(nodeA.getNodeValue(), nodeB.getNodeValue())) { + return false; + } + if (!equalNamedNodeMap(nodeA.getAttributes(), nodeB.getAttributes())) { + return false; + } + if (!equalNodeList(nodeA.getChildNodes(), nodeB.getChildNodes())) { + return false; + } + if (nodeA.getNodeType() == Node.DOCUMENT_TYPE_NODE) { + DocumentType documentTypeA = (DocumentType) nodeA; + DocumentType documentTypeB = (DocumentType) nodeB; + if (!equalString(documentTypeA.getPublicId(), documentTypeB.getPublicId())) { + return false; + } + if (!equalString(documentTypeA.getSystemId(), documentTypeB.getSystemId())) { + return false; + } + if (!equalString(documentTypeA.getInternalSubset(), documentTypeB.getInternalSubset())) { + return false; + } + if (!equalNamedNodeMap(documentTypeA.getEntities(), documentTypeB.getEntities())) { + return false; + } + if (!equalNamedNodeMap(documentTypeA.getNotations(), documentTypeB.getNotations())) { + return false; + } + } + return true; + } + + private static boolean equalNodeList(NodeList nodeListA, NodeList nodeListB) { + if (nodeListA == null) { + if (nodeListB == null) { + return true; + } + return false; + } + return equalNodes(nodeListA, nodeListB); + } + + private static boolean equalString(String stringA, String stringB) { + if (stringA == null) { + if (stringB == null) { + return true; + } + return false; + } + return stringA.equals(stringB); + } + + private static boolean equalNodes(NodeList sourceNodeList, NodeList targetNodeList) + { + ArrayList sourceNodes = new ArrayList(); + ArrayList targetNodes = new ArrayList(); + + getAllNodes(sourceNodeList, sourceNodes); + getAllNodes(targetNodeList, targetNodes); + + int sourceLength = sourceNodes.size(); + int targetLength = targetNodes.size(); + + if (sourceLength != targetLength) + { + return false; + } + + for (int i=0; i<sourceLength; i++) + { + Node sourceNode = (Node)sourceNodes.get(i); + Node targetNode = (Node)targetNodes.get(i); + + /* remove comment when migrated to Java 1.5 + if (!sourceNode.isEqualNode(targetNode)) + { + return false; + } + */ + // following is intended as 1.4 equivalent of isEqualNode() + if (!equalNode(sourceNode, targetNode)) + { + return false; + } + } // for + + return true; + } + + public static boolean equalXmlFiles(URL source, URL target) + { + try { + return equalXmlFiles(source.openStream(), target.openStream()); + } + catch (IOException e) + { + return false; + } + } + + public static boolean equalXmlFiles(InputStream sourceStream, URL target) + { + try { + return equalXmlFiles(sourceStream, target.openStream()); + } + catch (IOException e) + { + return false; + } + } + + public static boolean equalXmlFiles(URL source, InputStream targetStream) + { + try { + return equalXmlFiles(source.openStream(), targetStream); + } + catch (IOException e) + { + return false; + } + } + + public static boolean equalXmlFiles(InputStream sourceStream, InputStream targetStream) + { + DocumentBuilder builder; + Document sourceDocument; + Document targetDocument; + + try { + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + sourceDocument = builder.parse(sourceStream); + targetDocument = builder.parse(targetStream); + } + catch (FactoryConfigurationError fce) { + return false; + } + catch (ParserConfigurationException ce) { + return false; + } + catch (SAXException se) + { + return false; + } + catch (IOException ie) + { + return false; + } + + sourceDocument.normalize(); + targetDocument.normalize(); + + /* remove comment when migrated to Java 1.5 + if (!sourceDocument.getXmlVersion().equals(targetDocument.getXmlVersion())) + { + return false; + } + + String sourceXmlEncoding = sourceDocument.getXmlEncoding(); + String targetXmlEncoding = targetDocument.getXmlEncoding(); + + if (sourceXmlEncoding != null && targetXmlEncoding != null && + sourceXmlEncoding.equalsIgnoreCase(targetXmlEncoding)) + { + // continue + } + else + { + return false; + } + */ + + NodeList sourceNodes = sourceDocument.getChildNodes(); + NodeList targetNodes = targetDocument.getChildNodes(); + + return equalNodes(sourceNodes, targetNodes); + } +} Added: incubator/tuscany/java/sdo/tools/src/test/resources/mixedRepeatingChoiceTestResult.xml URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/mixedRepeatingChoiceTestResult.xml?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/mixedRepeatingChoiceTestResult.xml (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/mixedRepeatingChoiceTestResult.xml Mon May 8 07:35:35 2006 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="ASCII"?> +<sequences:mrc xmlns:sequences="http://www.example.com/sequences"> + <b>1</b> + <a>foo</a> +some mixed text <a>bar</a> + <b>2</b> +</sequences:mrc> \ No newline at end of file Added: incubator/tuscany/java/sdo/tools/src/test/resources/mixedStaticTestResult.xml URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/mixedStaticTestResult.xml?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/mixedStaticTestResult.xml (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/mixedStaticTestResult.xml Mon May 8 07:35:35 2006 @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="ASCII"?> +<sequences:mixedStockQuote xmlns:sequences="http://www.example.com/sequences"> + + <symbol>fbnt</symbol> + + <companyName>FlyByNightTechnology</companyName> + + some text + <quotes> + <price>2000.0</price> + </quotes> + + more text + <price>1000.0</price> + +</sequences:mixedStockQuote> \ No newline at end of file Added: incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoice.xsd URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoice.xsd?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoice.xsd (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoice.xsd Mon May 8 07:35:35 2006 @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsd:schema xmlns:repchoice="http://www.example.com/repchoice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/repchoice"> + + <xsd:element name="rc" type="repchoice:RCType"/> + + <xsd:complexType name="RCType"> + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="s" type="xsd:string"/> + <xsd:element name="i" type="xsd:int"/> + <xsd:element name="f" type="xsd:float"/> + </xsd:choice> + </xsd:complexType> + +</xsd:schema> Added: incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoiceTestResult.xml URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoiceTestResult.xml?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoiceTestResult.xml (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/repeatingChoiceTestResult.xml Mon May 8 07:35:35 2006 @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="ASCII"?> +<sequences:rc xmlns:sequences="http://www.example.com/sequences"> + <b>1</b> + <a>foo</a> + <a>bar</a> + <b>2</b> +</sequences:rc> \ No newline at end of file Added: incubator/tuscany/java/sdo/tools/src/test/resources/sequences.xsd URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/sequences.xsd?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/sequences.xsd (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/sequences.xsd Mon May 8 07:35:35 2006 @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsd:schema xmlns:seq="http://www.example.com/sequences" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.example.com/sequences"> + + <xsd:element name="mixedStockQuote" type="seq:MixedQuote" /> + <xsd:element name="rc" type="seq:RepeatingChoice" /> + <xsd:element name="mrc" type="seq:MixedRepeatingChoice" /> + <xsd:element name="rc2" type="seq:TwoRCs" /> + <xsd:element name="mrc2" type="seq:TwoRCsMixed" /> + + + + <xsd:complexType mixed="true" name="MixedQuote"> + <xsd:sequence> + <xsd:element name="symbol" type="xsd:string" /> + <xsd:element name="companyName" type="xsd:string" /> + <xsd:element name="price" type="xsd:decimal" /> + <xsd:element name="open1" type="xsd:decimal" /> + <xsd:element name="high" type="xsd:decimal" /> + <xsd:element name="low" type="xsd:decimal" /> + <xsd:element name="volume" type="xsd:double" /> + <xsd:element name="change1" type="xsd:double" /> + <xsd:element maxOccurs="unbounded" minOccurs="0" + name="quotes" type="seq:MixedQuote" /> + </xsd:sequence> + </xsd:complexType> + + + <xsd:complexType name="RepeatingChoice"> + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="a" type="xsd:string" /> + <xsd:element name="b" type="xsd:int" /> + </xsd:choice> + </xsd:complexType> + + + <xsd:complexType mixed="true" name="MixedRepeatingChoice"> + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="a" type="xsd:string" /> + <xsd:element name="b" type="xsd:int" /> + </xsd:choice> + </xsd:complexType> + + + <xsd:complexType name="TwoRCs"> + <xsd:sequence> + + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="a" type="xsd:string" /> + <xsd:element name="b" type="xsd:int" /> + </xsd:choice> + + <xsd:element name="split" type="xsd:string" /> + + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="y" type="xsd:string" /> + <xsd:element name="z" type="xsd:int" /> + </xsd:choice> + + </xsd:sequence> + </xsd:complexType> + + <xsd:complexType mixed="true" name="TwoRCsMixed"> + <xsd:sequence> + + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="a" type="xsd:string" /> + <xsd:element name="b" type="xsd:int" /> + </xsd:choice> + + <xsd:element name="split" type="xsd:string" /> + + <xsd:choice maxOccurs="unbounded" minOccurs="0"> + <xsd:element name="y" type="xsd:string" /> + <xsd:element name="z" type="xsd:int" /> + </xsd:choice> + + </xsd:sequence> + </xsd:complexType> + +</xsd:schema> \ No newline at end of file Added: incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesMixedTestResult.xml URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesMixedTestResult.xml?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesMixedTestResult.xml (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesMixedTestResult.xml Mon May 8 07:35:35 2006 @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="ASCII"?> +<sequences:rc2m xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sequences="http://www.example.com/sequences" xsi:type="sequences:TwoRCsMixed"> + <b>1</b> +where will this appear? <a>foo</a> + <a>bar</a> + <b>2</b> + <split>pea</split> + <z>99</z> + <y>fred</y> +</sequences:rc2m> \ No newline at end of file Added: incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesTestResult.xml URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesTestResult.xml?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesTestResult.xml (added) +++ incubator/tuscany/java/sdo/tools/src/test/resources/twoRepeatingChoicesTestResult.xml Mon May 8 07:35:35 2006 @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="ASCII"?> +<sequences:rc2 xmlns:sequences="http://www.example.com/sequences"> + <b>1</b> + <a>foo</a> + <a>bar</a> + <b>2</b> + <split>banana</split> + <z>99</z> + <y>fred</y> +</sequences:rc2> \ No newline at end of file Added: incubator/tuscany/java/sdo/tools/templates/Header.javajetinc URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/tools/templates/Header.javajetinc?rev=405063&view=auto ============================================================================== --- incubator/tuscany/java/sdo/tools/templates/Header.javajetinc (added) +++ incubator/tuscany/java/sdo/tools/templates/Header.javajetinc Mon May 8 07:35:35 2006 @@ -0,0 +1,6 @@ +/** + * <copyright> + * </copyright> + * + * <%="$"%>Id<%="$"%> + */
