Author: frankb
Date: Thu May 4 14:27:52 2006
New Revision: 399860
URL: http://svn.apache.org/viewcvs?rev=399860&view=rev
Log:
add support for sequenced type dynamic creation
Added:
incubator/tuscany/java/sdo/impl/src/test/resources/mixed2.xml
incubator/tuscany/java/sdo/impl/src/test/resources/mixedopen.xml
Modified:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
Modified:
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java?rev=399860&r1=399859&r2=399860&view=diff
==============================================================================
---
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
(original)
+++
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
Thu May 4 14:27:52 2006
@@ -262,7 +262,12 @@
public static void setOpen(Type type, boolean isOpen)
{
- if (type.isDataType() || !type.getProperties().isEmpty())
+ boolean hasProperties =
+ (type.isSequenced()) ?
+ type.getProperties().size() > 1 :
+ !type.getProperties().isEmpty();
+
+ if (type.isDataType() || hasProperties)
{
if (type.getName() != null) //FB TEMP ... figure out how to handle
document root
throw new IllegalArgumentException(); // type must a non dataType with
no properties yet
@@ -279,55 +284,38 @@
ExtendedMetaData.INSTANCE.setFeatureKind(eAttribute,
ExtendedMetaData.ELEMENT_WILDCARD_FEATURE);
ExtendedMetaData.INSTANCE.setProcessingKind(eAttribute,
ExtendedMetaData.LAX_PROCESSING);
ExtendedMetaData.INSTANCE.setWildcards(eAttribute,
Collections.singletonList("##any"));
- }
- }
-
- /*
- private static boolean hasNonWildcardFeatures(EClass eclass) {
- boolean answer = false;
- List features = eclass.getEStructuralFeatures();
- for (int n = 0; n < features.size(); n++) {
- EStructuralFeature feature = (EStructuralFeature) features.get(n);
- int kind = ExtendedMetaData.INSTANCE.getFeatureKind(feature);
- if (kind != ExtendedMetaData.ELEMENT_WILDCARD_FEATURE &&
- kind != ExtendedMetaData.ATTRIBUTE_WILDCARD_FEATURE) {
- answer = true;
- break;
+
+ if (type.isSequenced()) {
+ eAttribute.setDerived(true);
+ eAttribute.setTransient(true);
+ eAttribute.setVolatile(true);
}
}
- return answer;
}
- */
public static void setSequenced(Type type, boolean isSequenced)
{
- if (!isSequenced) return;
- throw new UnsupportedOperationException(); // TODO: implement this method
properly
- /*
if ((isSequenced && type.isSequenced()) ||
!isSequenced && !type.isSequenced()) return;
- if (!(type instanceof EClass)) return;
- EClass eclass = (EClass)type;
- if (type.isDataType() || hasNonWildcardFeatures(eclass))
+
+ if (type.isDataType() || !type.getProperties().isEmpty())
{
- if (type.getName() != null)
+ if (type.getName() != null) //FB TEMP ... figure out how to handle
document root
throw new IllegalArgumentException();
}
if (isSequenced) {
- ExtendedMetaData.INSTANCE.setContentKind(eclass,
ExtendedMetaData.MIXED_CONTENT);
+ EClass eClass = (EClass)type;
+ ExtendedMetaData.INSTANCE.setContentKind(eClass,
ExtendedMetaData.MIXED_CONTENT);
EAttribute mixedFeature = EcoreFactory.eINSTANCE.createEAttribute();
mixedFeature.setName("mixed");
mixedFeature.setUnique(false);
mixedFeature.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry());
mixedFeature.setLowerBound(0);
mixedFeature.setUpperBound(-1);
- eclass.getEStructuralFeatures().add(mixedFeature);
+ eClass.getEStructuralFeatures().add(mixedFeature);
ExtendedMetaData.INSTANCE.setFeatureKind(mixedFeature,
ExtendedMetaData.ELEMENT_WILDCARD_FEATURE);
ExtendedMetaData.INSTANCE.setName(mixedFeature, ":mixed");
- } else {
- // do I really need to do anything here?
}
- */
}
public static void setAbstract(Type type, boolean isAbstract)
@@ -350,6 +338,13 @@
ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature,
ExtendedMetaData.ELEMENT_FEATURE);
}
((EClass)containingType).getEStructuralFeatures().add(eStructuralFeature);
+
+ if (containingType.isSequenced()) {
+ eStructuralFeature.setDerived(true);
+ eStructuralFeature.setTransient(true);
+ eStructuralFeature.setVolatile(true);
+ }
+
return (Property)eStructuralFeature;
}
Modified:
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java?rev=399860&r1=399859&r2=399860&view=diff
==============================================================================
---
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
(original)
+++
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java
Thu May 4 14:27:52 2006
@@ -40,6 +40,7 @@
private static final String CUSTOMER2_XML = "/customer2.xml";
private static final String OPEN_XML = "/open2.xml";
private static final String MIXED_XML = "/mixed2.xml";
+ private static final String MIXEDOPEN_XML = "/mixedopen.xml";
public void testDefineTypeRoundTrip() throws Exception {
TypeHelper types = SDOUtil.createTypeHelper();
@@ -393,7 +394,7 @@
public void testDefineSequencedType() throws Exception
{
- /*
+
TypeHelper types = SDOUtil.createTypeHelper();
DataFactory factory = SDOUtil.createDataFactory(types);
XMLHelper xmlHelper = SDOUtil.createXMLHelper(types);
@@ -454,10 +455,97 @@
sequence.add("\n");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- xmlHelper.save(quote, "http://www.example.com/sequenced",
"mixedStockQuote", baos);
+ xmlHelper.save(quote, "http://www.example.com/mixed", "mixedStockQuote",
baos);
assertTrue(TestUtil.equalXmlFiles(new
ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXED_XML)));
- */
+
+ }
+
+ public void testDefineSequencedOpenType() throws Exception
+ {
+
+ TypeHelper types = SDOUtil.createTypeHelper();
+ DataFactory factory = SDOUtil.createDataFactory(types);
+ XMLHelper xmlHelper = SDOUtil.createXMLHelper(types);
+
+ Type stringType = types.getType("commonj.sdo", "String");
+ Type decimalType = types.getType("commonj.sdo", "Decimal");
+
+ // Define a new mixed type - MixedQuote
+ DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
+ mixedQuoteType.set("uri", "http://www.example.com/mixed");
+ mixedQuoteType.set("name", "MixedOpenQuote");
+ mixedQuoteType.set("sequenced", Boolean.TRUE);
+ mixedQuoteType.set("open", Boolean.TRUE);
+
+// DataObject symbolProperty = mixedQuoteType.createDataObject("property");
+// symbolProperty.set("name", "symbol");
+// symbolProperty.set("type", stringType);
+
+ DataObject companyNameProperty =
mixedQuoteType.createDataObject("property");
+ companyNameProperty.set("name", "companyName");
+ companyNameProperty.set("type", stringType);
+
+ DataObject priceProperty = mixedQuoteType.createDataObject("property");
+ priceProperty.set("name", "price");
+ priceProperty.set("type", decimalType);
+
+ DataObject quotesProperty = mixedQuoteType.createDataObject("property");
+ quotesProperty.set("name", "quotes");
+ quotesProperty.set("type", mixedQuoteType);
+ quotesProperty.set("many", Boolean.TRUE);
+ quotesProperty.set("containment", Boolean.TRUE);
+
+ types.define(mixedQuoteType);
+
+ // Define a global type
+ DataObject globalType = factory.create("commonj.sdo", "Type");
+ globalType.set("uri", "http://www.example.com/open");
+ // no need to specify the type's name
+
+ DataObject symbolProperty = globalType.createDataObject("property");
+ symbolProperty.set("name", "symbol");
+ symbolProperty.set("type", stringType);
+ symbolProperty.set("containment", Boolean.TRUE);
+
+ types.define(globalType);
+
+ DataObject quote = factory.create("http://www.example.com/mixed",
"MixedOpenQuote");
+
+ assertTrue(quote.getType().isSequenced());
+
+ Sequence sequence = quote.getSequence();
+
+ sequence.add("\n ");
+
+ Type definedGlobalType = types.getType("http://www.example.com/open",
null);
+
+ Property definedSymbolProperty = definedGlobalType.getProperty("symbol");
+ //sequence.add(definedSymbolProperty, "fbnt");
+ quote.setString(definedSymbolProperty, "fbnt");
+
+ sequence.add("\n ");
+
+ quote.setString("companyName", "FlyByNightTechnology");
+
+ sequence.add("\n some text\n ");
+
+ DataObject child = quote.createDataObject("quotes");
+ child.setBigDecimal("price", new BigDecimal("2000.0"));
+
+ sequence.add("\n more text\n ");
+
+ // quote.setBigDecimal("price", new BigDecimal("1000.0"));
+ sequence.add("price", new BigDecimal("1000.0"));
+
+ sequence.add("\n");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(quote, "http://www.example.com/mixed",
"mixedOpenStockQuote", baos);
+ xmlHelper.save(quote, "http://www.example.com/mixed",
"mixedOpenStockQuote", System.out);
+ assertTrue(TestUtil.equalXmlFiles(new
ByteArrayInputStream(baos.toByteArray()),
getClass().getResource(MIXEDOPEN_XML)));
+
}
+
public void testDefineOpenType() throws Exception
{
Added: incubator/tuscany/java/sdo/impl/src/test/resources/mixed2.xml
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/resources/mixed2.xml?rev=399860&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/resources/mixed2.xml (added)
+++ incubator/tuscany/java/sdo/impl/src/test/resources/mixed2.xml Thu May 4
14:27:52 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ASCII"?>
+<mixed:mixedStockQuote
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:mixed="http://www.example.com/mixed"
+ xsi:type="mixed:MixedQuote">
+ <symbol>fbnt</symbol>
+ <companyName>FlyByNightTechnology</companyName>
+ some text
+ <quotes><price>2000.0</price></quotes>
+ more text
+ <price>1000.0</price>
+</mixed:mixedStockQuote>
\ No newline at end of file
Added: incubator/tuscany/java/sdo/impl/src/test/resources/mixedopen.xml
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/resources/mixedopen.xml?rev=399860&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/resources/mixedopen.xml (added)
+++ incubator/tuscany/java/sdo/impl/src/test/resources/mixedopen.xml Thu May 4
14:27:52 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ASCII"?>
+<mixed:mixedOpenStockQuote
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:mixed="http://www.example.com/mixed"
+ xsi:type="mixed:MixedOpenQuote">
+ <symbol>fbnt</symbol>
+ <companyName>FlyByNightTechnology</companyName>
+ some text
+ <quotes><price>2000.0</price></quotes>
+ more text
+ <price>1000.0</price>
+</mixed:mixedOpenStockQuote>
\ No newline at end of file